3

I have a wrapper script A which is calling program B. A must be invoked as root so some initial setup can happen. After that, A calls setuid() and setgid() to reduce its own privileges, for safety and security. Then, A invokes B.

The problem is that B exhibits undesirable behavior if and only if A has called setuid()/setgid() before invoking B. This does not happen when I invoke B directly as different users via sudo -u xxx -g xxx. As far as I can tell (correct me if I am wrong), the only way B could know that A has changed the user is via the issetuid() syscall (I've checked the environment variables; they match).

How can I clear this bit, so that B behaves normally? It seems that the use of issetuid() is something about keeping track of whether the process is "tainted", i.e. carries artifacts from a less privileged environment (?). But I've reduced my privileges, not elevated them! And on top of that, I've scrubbed my env vars anyway!

Beyond the very terse man page on issetuid(), I can find almost nothing about this syscall/magical program state. Can anyone lend a better understanding?

8
  • In which package does issetuid (header files, documentation, library) live in? I can't find it on my systems, so I assume it is not in libc6-dev or libstd++6-4.6-dev or similar. You can find out the package name automatically with a command like: dpkg -S $(man -w issetuid).
    – taneli
    May 15, 2012 at 8:28
  • 2
    This could be better suited to StackOverflow or even SuperUser
    – nanofarad
    May 18, 2012 at 20:10
  • FWIK setuid bit on script files won't work due to security reasons. Google suid script security may help.
    – Lenik
    May 22, 2012 at 12:12
  • 2
    There is no issetuid syscall. Nor is it a function in the C library. I have no idea where you found a manpage for it; neither man nor Google can. Further, every non-root process has a setuid (or similar) in its history, as init starts as root and spawns them all.
    – derobert
    Jun 13, 2012 at 18:56
  • 1
    @trbabb None of us seem to be able to find anything about an issetuid function. Is it possible you mean issetugid? Your description, especially the use of the adjective tainted, comports with the description in that function's manpage, and the function it similar to what you seem to have in mind, though it also returns true if the process is setgid (even if not also setuid). Jul 16, 2012 at 23:10

1 Answer 1

0

Without more information ( such as the name of A and B software ), this is hard to diagnose.

However, I would look at the environment variable, there is surely one that was not cleaned by A and that is cleaned by sudo.

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