[PATCH procd] Fix retriggering of init.d-scripts.

Henrique de Moraes Holschuh henrique at nic.br
Wed Aug 30 06:12:06 PDT 2023


Em 28/08/2023 11:12, Markus Gothe escreveu:
> Fix retriggering of init.d-scripts which calls
> commands dependent on functional STDIN/STDOUT/STDERR.

Yeah, it is no fun when some library decides to become allergic to one 
of FD0-2 being closed, and a O.S. update suddenly exposes this issue. 
Been there, suffered through it, learned from it.

So, this is right up there in the "Just don't do it" list, right after 
calling execve() with NULL for argv[0].  Avoid closed FDs 0-2 at program 
start like the plague: fix it first thing.  Never execve() anything with 
closed FDs 0-2 in the general case.

It is also true for shell scripts: don't close FDs 0-2, redirect them 
to/from /dev/null instead.  Don't repurpose them, either.

Data corruption (due to unexpected writes from just about anything) is a 
possible outcome of running stuff with FDs 0-2 closed or repurposed, 
BTW.  Consider yourself lucky when things just crash or exit with an 
error, instead.

IMHO, if they're not doing it already, ubus and all its helpers, such as 
rpcd, should be defensive about FDs 0-2 and ensure they are always 
properly open (to /dev/null if need be), preferably at program start, 
and certainly when they are about to execve() anything.

PS: I have attached an example of how one could do generic self-healing 
of the standard low FDs in C in a POSIX environment where fcntl() and 
dup2() are available.  Note that FD 2 is expected to be R/W, according 
to the C specification for stdio.h streams.

-- 
Henrique de Moraes Holschuh
Analista de Projetos
Centro de Estudos e Pesquisas em Tecnologias de Redes e Operações 
(Ceptro.br)
+55 11 5509-3537 R.:4023
INOC 22548*625
www.nic.br
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sanitize_std_fds.c
Type: text/x-csrc
Size: 1307 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20230830/30438e7f/attachment.bin>


More information about the openwrt-devel mailing list