9

Based on part of the first answer of this questions:

read from a file (the kernel must check that the permissions allow you to read from said file, and then the kernel carries out the actual instructions to the disk to read the file)

It requires to have root privilege to change permission to a file. With root privilege, user can access any files without worrying about permission. So, are the any relationships between root and kernel?

2
  • Question is too vague / unclear to be answerable.
    – psusi
    Mar 27, 2014 at 13:47
  • This question practically involves several things. It may require one to read about system call, privilege and privilege level. I do not know how to word the question better. Somehow, Steven D understands what I mean.
    – Ron Vince
    Mar 28, 2014 at 14:03

1 Answer 1

14

First, a clarification:

It requires to have root privilege to change permission to a file.

From man 2 chmod we can see that the chmod() system call will return EPERM (a permissions error) if:

The effective UID does not match the owner of the file, and the process is not privileged (Linux: it does not have the CAP_FOWNER capability).

This typically means that you either need to be the owner of the file or the root user. But we can see that the situation in Linux might be a bit more complicated.

So, are the any relationships between root and kernel?

As the text you quoted has pointed out, the kernel is responsible for checking that the UID of the process making a system call (that is, the user it is running as) is allowed to do what it is asking. Thus, root's superpowers come from the fact that the kernel has been programmed to always permit an operation requested by the root user (UID=0).

In the case of Linux, most of the various permissions checks that happen check whether the given UID has the necessary capability. The capabilities system allows more fine grained control over who is allowed to do what.

However, in order to preserve the traditional UNIX meaning of the "root" user, a process executed with the UID of 0 has all capabilities.

Note that while processes running as UID=0 have superuser privileges they still have to make requests of the kernel via the system call interface.

Thus, a userspace process, even running as root, is still limited in what it can do as it is running in "user mode" and the kernel is running in "kernel mode" which are actually distinct modes of operation for the CPU itself. In kernel mode a process can access any memory or issue any instruction. In user mode (on x86 CPUs there are actually a number of different protected modes), a process can only access its own memory and can only issue some instructions. Thus a userspace process running as root still only has access to the kernel mode features that the kernel exposes to it.

6
  • Should we say that root or UID=0 has the kernel level privilege? Or are there any restrictions applied by the kernel to the root?
    – Ron Vince
    Mar 27, 2014 at 5:45
  • Processes running as UID=0 have superuser privileges; however, they still make requests of the kernel via the system call interface. A userspace process, even running as root, is still limited in what it can do as it is running in "user mode" and the kernel is running in "kernel mode" which are actually distinct modes of operation for the CPU itself. A userspace process running as root still only has access to the kernel mode features that the kernel exposes to it. See linfo.org/kernel_mode.html for more info.
    – Steven D
    Mar 27, 2014 at 6:00
  • I've added my commend to the answer with some links.
    – Steven D
    Mar 27, 2014 at 6:11
  • Do you have any recommendations of Unix books?
    – Ron Vince
    Mar 27, 2014 at 12:13
  • Owh..thank you for telling that. I am still doing literature review based on the given answers. They point to the idea and literature materials but I do not have certainty yet to determine the right or wrong of those answers.
    – Ron Vince
    Mar 27, 2014 at 15:22

Not the answer you're looking for? Browse other questions tagged .