execve: fix deadlock/crash
authorAlan Cox <alan@linux.intel.com>
Sun, 4 Dec 2016 14:31:54 +0000 (14:31 +0000)
committerAlan Cox <alan@linux.intel.com>
Sun, 4 Dec 2016 14:31:54 +0000 (14:31 +0000)
commitd8beed10620c9fd8e93655e3108bd9ad35985d48
treeff060af7244cf69cd8d1d09f1fb6bc86d823ed52
parent7b0da50926eae56fdf91410d4aa62395e84a79b8
execve: fix deadlock/crash

If a process sets files to be closed with O_CLOEXEC and those files are ones
that sleep during the close (eg a socket), and at the same time as it is
sleeping then on a little box with not many buffers you can easily deadlock
or run out of buffers.

Only allow one execve process at a time. As the disk I/O on a little 8bit
micro takes the full CPU time, and the only blocking case is the obscure
O_CLOEXEC one the performance impact of this change is pretty close to nil,
but it does mean we need to be careful not to let anything block for long
while closing.

For networking this will need a little bit of care and it also introduces
a bizarre corner case deadlock if you are using the userspace networking
daemon. You must ensure the daemon does not itself try to do an execve
while a socket might be waiting to close. As the network daemon can already
tie itself in knots if it attempts to use sockets, and is very special this
seems acceptable.
Kernel/syscall_exec16.c