1

Our sudo executable would be owned by root with the setuid bit. The executable would do 2 things:

  1. check if the user is allowed
  2. execve argv[1] (pseudo-code)

Normally this would allow a normal user to run a program as root. The problem is how to check if the user is allowed, since we are root at startup due to setuid and therefore don't know who is the user?

2 Answers 2

4

The problem is how to check if the user is allowed, since we are root at startup due to setuid and therefore don't know who is the user ?

This is where the notions of uid and effective uid come in. When you run a setuid program, getuid still returns the uid of the “real” user; the setuid bit causes the effective uid to change. See man getuid and the related documentation for details.

2

What you have suggested is exactly how sudo works... At least, that's the start.

A lot more has to be done to make things actually work, and sudo does some rather elaborate things to make sure it is secure and also logs the event. It is very easy to write a naive version that is easily tricked into running things even when it should not, and when the user is not authorized to use it.

You must log in to answer this question.

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