James Y Knight ([info]fuhm) wrote,
@ 2007-09-24 17:14:00
Previous Entry  Add to memories!  Tell a Friend  Next Entry
suid without eating environment?
So I want to write a setuid program. And, I want it to not eat the environment (namely, LD_LIBRARY_PATH). It seems that this is impossible to do in linux.

Now, you might reasonably ask why I would want to do such a thing?

Here's an outline of what I want:

a) User invokes setuid program, giving as arguments another program they want to execute.
b) setuid program does some stuff as root (let's say, for illustrative purposes, setting niceness level to -10)
c) setuid program drops privileges
d) setuid program calls exec, passing the user-specified program.

So, see, I'd really like LD_LIBRARY_PATH to pass through my setuid app, to the exec'd (as the originally invoking user) process.

Here's what I found:

ld.so eats all the linker environment variables before even starting my program. Okay, surely it'd be better to ignore them instead of removing them, but whatever, I'll just link my program statically, that ought to solve the problem, right?

NOPE. I lose. In the name of security, the statically-linked-program startup code also erases the environment variables. Apparently there was a security hole at one point with some statically linked suid program calling exec without passing an explicit sane environment. The program it exec'd, if dynamically linked, would of course use the LD_LIBRARY_PATH in the environment, since it wasn't suid. Oops, instant root vuln. So to fix this, even statically linked programs cleanse their environment.

But one silver lining: in the statically linked case, it's actually glibc startup code which is eating the environment, which theoretically I should be able to override in some fashion. All I have to do is take control of the startup sequence before glibc cleanses the environment, make a copy, and continue the normal startup sequence. I thought perhaps defining _start myself, or something along those lines, but I can't manage to get it to work.

Can anyone help me?



(3 comments) - (Post a new comment)

Same pain.
[info]antti.kaihola.fi
2009-05-19 07:31 pm UTC (link)
Have you found any solution?

(Reply to this) (Thread)

Re: Same pain.
[info]fuhm
2009-05-19 08:34 pm UTC (link)
No, I haven't, I gave up. I still believe it's possible...It'd probably be absolutely trivial if I knew what I was doing at that low level, but I don't really. I don't know how to write a program which runs my code absolutely first thing before glibc startup.

(Reply to this) (Parent)(Thread)

Re: Same pain.
(Anonymous)
2009-08-05 05:10 am UTC (link)
Does it have to be in the one file? You could create a script to dump the environment to a file/pipe/etc, run your SUID app, then have your SUID app load the environment back up again from the file and lauch the program.

(Reply to this) (Parent)


(3 comments) - (Post a new comment)

Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…