-1

Some university lecture notes claim that

In Unix systems, it is written into the operating system that some functionalities can only be accessed by the root user: modifying passwords, accessing to network ports used for communication protocols, interaction with hardware, etc.

Is this description correct? Where exactly is this implemented "in the OS"? How can non-root users change their own passwords if they cannot write /etc/passwd?

As far as I know, there are UNIX-based systems like SELinux, where the root user doesn't have unlimited powers?

  • 1
    Is the latest incarnation of Apple's Mac operating system still a real (read: certified OR wholly-compliant to spec [unlike Linux]) UNIX? If so, that is an example of a real UNIX where root has limited power. passwd is SUID. I feel that most of these restrictions are placed by the utilities and filesystem permissions rather than "the OS", but there are some assumptions "the OS" makes (e.g. the init system is run as UID 0) – Fox Oct 21 '17 at 14:17
  • Well, I guess OSX is just nix, isn't it? – gen Oct 21 '17 at 14:22
  • 1
    I've been prompted to check. macOS 10.12 and 10.13 on Intel-based computers are still certified by The Open Group. And some parts of the filesystem are non-writable by root under any circumstances on these systems (though you can boot to single-user mode and disable this). That was mostly just a response to your last paragraph – Fox Oct 21 '17 at 14:28
  • Putting a question mark at the end does not of itself turn a declarative statement into a question. If you want your last paragraph to be a question, then frame it as an actual question, not as something that has been incorrectly punctuated. – JdeBP Oct 21 '17 at 16:39
4

Is this description correct?

Yes and no, these statements are incomplete at best. More precisely:

  • Modifying passwords: users can change their own password, but only root can change the passwords of other users. This is enforced by access permissions on /etc/shadow. The passwd(1) binary can bypass permissions on /etc/shadow because passwd is setuid to root, and thus it can gain root's privileges to write to /etc/shadow.
  • Accessing to network ports used for communication protocols: only root can bind TCP and UDP ports below 1024, but everybody can bind any other port. This is enforced by the kernel. Also only root can use raw sockets (in particular this is why ping needs to be setuid to root to run). But the details of accessing raw sockets are OS-dependent, and access can sometimes be granted by various non-standard ACL mechanisms.
  • Interaction with hardware: in principle only root processes can send raw commands to hardware. This is mainly enforced by permissions to the devices in /dev. However most systems have mechanisms to allow users to bypass these permissions, f.i. to mount USB disks, write CDs, use audio hardware, etc.

Where exactly is this implemented "in the OS"?

There is a system of permissions implemented by the kernel. Most OSes supplement this system with various other mechanisms, such as OpenBSD's pledge, or Linux's SELinux.

As far as I know, there are UNIX-based systems like SELinux, where the root user doesn't have unlimited powers?

Yes.

2

Lets go back to the original statement because I think its incorrect to compare to Linux here since Linux is not Unix.

The manual for the passwd command on Unix specifically states only root can use the utility.

http://man.cat-v.org/unix-1st/5/passwd

Similarly opening ports only privileged processes are allowed to change to certain ports. The sys/socket.h is defined under Unix. http://pubs.opengroup.org/onlinepubs/7908799/xns/syssocket.h.html

and as described here:

http://man7.org/linux/man-pages/man7/ip.7.html

Permissions for this amounted to requiring root.

Interaction with hardware is slightly more broad even vague. But is likely referring to the fact that /dev/ interfaces such as mknod required root.

So the statement is essentially accurate.

  • It's also interesting to compare to Linux which for example uses a privilege system. Udev allows various levels of access to hardware. Passwd allows the same user to change their own passwd. And Linux uses PAM instead of just the getuid syscall. So none of these statements are true if we try to apply it to Linux. – jdwolf Oct 21 '17 at 17:12
  • The manual for the passwd command on Unix specifically states only root can use the utility. - You're reading passwd(5), the manual for the file /etc/passwd. Apparently UNIX didn't have a passwd(1) back then, but it did in V6, and the man page explicitly states the user can change his own password. – Satō Katsura Oct 21 '17 at 17:22
  • Thats a good point. You should edit it into the answer. – jdwolf Oct 21 '17 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.