Computer Systems: a Programmer's Perspective says
In order for the operating system kernel to provide an airtight process abstraction, the processor must provide a mechanism that restricts the instructions that an application can execute, as well as the portions of the address space that it can access.
Processors typically provide this capability with a mode bit in some control register that characterizes the privileges that the process currently enjoys. When the mode bit is set, the process is running in kernel mode (sometimes called supervisor mode). A process running in kernel mode can execute any instruction in the instruction set and access any memory location in the system.
When the mode bit is not set, the process is running in user mode. A process in user mode is not allowed to execute privileged instructions that do things such as halt the processor, change the mode bit, or initiate an I/O operation. Nor is it allowed to directly reference code or data in the kernel area of the address space. Any such attempt results in a fatal protection fault. User programs must instead access kernel code and data indirectly via the system call interface.
A process running application code is initially in user mode. The only way for the process to change from user mode to kernel mode is via an exception such as an interrupt, a fault, or a trapping system call. When the exception occurs, and control passes to the exception handler, the processor changes the mode from user mode to kernel mode. The handler runs in kernel mode. When it returns to the application code, the processor changes the mode from kernel mode back to user mode.
If a user-mode process wants to change to kernel mode, does it always succeed?
Does whether the change of mode succeed depend on what the process wants to do after change to kernel mode?
For examples,
A process may or may not have the right to access a file, depending on the uid of the process and the access control bits of the file. When the process issues a system call to access the file, can it always succeed in changing from user mode to kernel mode? Does whether the process can change from user to kernel mode depends on whether it can access the file?
Does
sudo
have nothing to do with whether a process can change from user to kernel mode?
Thanks.