Problems with setuid(), SVr2v2 - (nf)

Guy Harris guy at sun.uucp
Sat Sep 27 05:22:55 AEST 1986


> Same is true on Xenix System V -- apparently you can give up root priv's
> by turning on the set-uid bit on an executable owned by someone other
> than root, but you can't get them back by doing a setuid() back to
> the real uid of 0.  It does work correctly for all other real uid's.

This is true on S5 as distributed by AT&T-IS, and presumably Microsoft left
that code alone.  The trouble is that there are really at least *two
different* "setuid" operations in modern UNIX systems:  one that sets the
real *and* effective *and* saved set-user IDs - this one is used by "login"
and "su", for setting the environment of a user - and one that sets *only*
the effective ID, used for giving up or regaining privileges in a set-UID
program.

Unfortunately, System V isn't modern enough; they didn't pick up the 4.2BSD
"setreuid" system call, which permits you to set both user IDs
independently.  Instead, they overloaded "setuid".  If the argument to
"setuid" is non-zero, and it matches either the real or saved set-user ID,
it is treated as the second kind of "setuid", which sets only the effective
UID.  Otherwise, it is treated as the first kind of "setuid", which sets
them both; this version is, of course, restricted to the super-user.

Thus, "setuid(0)" is always treated as the first kind of "setuid", and since
the set-UID program's effective UID isn't root, it fails.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Net.bugs.usg mailing list