[PATCH] sanitize when kernel starts init without any fd opened

Maxime Bizon mbizon at freebox.fr
Wed Jun 13 12:28:11 UTC 2007


On Wed, 2007-06-13 at 00:42 +0200, Denis Vlasenko wrote:

Hello Denis,

> Which daemons are not working?

I did not try any busybox daemon beside udhcpd which run fine. I had
problem with non busybox code (personal code and hostapd).

I also got the following ash bug with echo builtin, which broke my rcS
script:

> cd /
> cat test.sh 
#!/bin/sh

echo test1 > /foo
echo test2

> ./unsanitize /bin/sh /test.sh 
> cat /foo
test1
test2
> 

unsanitize closes 0, 1 and 2 and exec argv[].


> I would like to have all busybox applets work right even if they
> happen to be started with some of fd 0,1,2 closed.

Agreed, this is good programming practice and may help reveal bugs.

But, as I told in another mail, a lot of (non busybox) code assumes that
fd 0, 1 and 2 are open at startup. Even libc, by offering daemon(). This
makes daemon init code usually looks like:

open all files and sockets
daemon()
event_loop


> How to fix it in daemons and init. Example from login.c

We may and should patch busybox code so it behaves correctly in the "no
fd opened" case.

But embedded systems (and moreover desktops) often run more than
busybox. Should we impose patching all other code with something like
bb_daemonize_or_rexec() ?

I think it's against busybox purpose of reducing code size.

Not to mention the difficulty for users of identifying the problem at
first. Any bug caused by this vanishes when you foreground the daemon,
run it from a shell instead of init, or even try to open a trace file to
understand what's happening.

Regards,

-- 
Maxime




More information about the busybox mailing list