[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: discarding root privileges in suid perl



On Wed, Oct 18, 2000 at 09:35:10AM +1100, Brian May wrote:
>     Daniel>        The super-user may set real, effective and saved
>     Daniel> user ID to arbitrary values.
> 
>     Daniel> It's not clear what happens when saved uid is zero and the
>     Daniel> others are nonzero, but I bet that's what you're seeing.
>     Daniel> Note that saved uid is -not- preserved across exec() IIRC.
>     Daniel> So if you drop priviledges and then run a script that
>     Daniel> tries to get them back, it will fail, even if the parent
>     Daniel> could.
> 
> This sounds correct. Where did you find this documented? I tried
> looking up the functions in the info documentation for libc, but it
> doesn't seem to contain anything (that I could find).

The documentation I pasted was from setresuid(2).  Oddly, setresuid is
nowhere in the libc documentation.  This looks useful, though:
% info libc 'Enable/Disable Setuid'

It's not terribly clear, though.

This has something to do with the use of file system ids... from a
nearby node:

   When the setuid bit of an executable file is on, executing that file
gives the process a third user ID: the "file user ID".  This ID is set
to the owner ID of the file.  The system then changes the effective
user ID to the file user ID.  The real user ID remains as it was.
Likewise, if the setgid bit is on, the process is given a "file group
ID" equal to the group ID of the file, and its effective group ID is
changed to the file group ID.

   If a process has a file ID (user or group), then it can at any time
change its effective ID to its real ID and back to its file ID.
Programs use this feature to relinquish their special privileges except
when they actually need them.  This makes it less likely that they can
be tricked into doing something inappropriate with their privileges.



So you need to clear the fsuid, I guess.



Dan

/--------------------------------\  /--------------------------------\
|       Daniel Jacobowitz        |__|        SCS Class of 2002       |
|   Debian GNU/Linux Developer    __    Carnegie Mellon University   |
|         dan@debian.org         |  |       dmj+@andrew.cmu.edu      |
\--------------------------------/  \--------------------------------/



Reply to: