Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How does Linux know that it has to give euid 0 (uid of root) to only certain process like passwd, setuid, etc.

If a process can gain root permissions, will it not lead to potential security breaches in the Linux platform?

For example, if I write a program that can can gain root user permissions like passwd, I may corrupt important system files like /etc/passwd, /etc/groups.

How does Linux manage to still be secure?

share|improve this question

migrated from stackoverflow.com Nov 17 '13 at 7:19

This question came from our site for professional and enthusiast programmers.

    
Flag this question and ask for moderator attention to migrate it to the other SE site. –  Gumbo Nov 11 '13 at 17:05

2 Answers 2

The passwd program has the setuid bit set, which you can see with ls -l:

-rwsr-xr-x 1 root root 39104 2009-12-06 05:35 /usr/bin/passwd

It's the s (the fourth character of the line).

All programs that have this permission bit set run as the owner of that program. In this example, the user is root (third word of the line).

These setuid programs need to make sure that they don't damage anything, since every user of the system can run them with effective root privileges. That's why you can only change your own password. Linux and other similar operating systems are still secure because the authors of these setuid programs take a lot of care.

See for example suexec.c from the Apache Web Server, which is a popular setuid program. There are unusually many comments in that source code.

share|improve this answer

As an addendum to Roland Illig's answer, it's entirely possible to write a program that, when given root permissions, corrupts system files and/or compromises your system in various ways.

The problem is that just writing it doesn't mean it automatically gets to run as root -- it needs to have its owner set to root, and then the setuid bit that Roland refers to has to be set -- and only root has the right to do that.

In short: Yes, every binary with the setuid bit set is at least potentially a security risk. Exploiting a flaw in a setuid-enabled binary to gain root privileges is the most common source of so-called Privilege Escalation attacks and they tend to be a big deal when they happen. Because of this, there are relatively few pieces of software that use setuid and the ones that exist tend to be under high scrutiny.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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