]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/libsystemd/sd-bus/bus-socket.c
fd-util: move certain fds above fd #2 (#8129)
authorLennart Poettering <lennart@poettering.net>
Fri, 9 Feb 2018 16:53:28 +0000 (17:53 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 9 Feb 2018 16:53:28 +0000 (17:53 +0100)
commit7fe2903c2315db9d9f501ae255a6b6e4f01ba46c
treecd8b2db64685b0ecc76e305ef8ba43d1183a7df8
parente25937a3ed740ed0618a8943dee32e8966541cdf
fd-util: move certain fds above fd #2 (#8129)

This adds some paranoia code that moves some of the fds we allocate for
longer periods of times to fds > 2 if they are allocated below this
boundary. This is a paranoid safety thing, in order to avoid that
external code might end up erroneously use our fds under the assumption
they were valid stdin/stdout/stderr. Think: some app closes
stdin/stdout/stderr and then invokes 'fprintf(stderr, …' which causes
writes on our fds.

This both adds the helper to do the moving as well as ports over a
number of users to this new logic. Since we don't want to litter all our
code with invocations of this I tried to strictly focus on fds we keep
open for long periods of times only and only in code that is frequently
loaded into foreign programs (under the assumptions that in our own
codebase we are smart enough to always keep stdin/stdout/stderr
allocated to avoid this pitfall). Specifically this means all code used
by NSS and our sd-xyz API:

1. our logging APIs
2. sd-event
3. sd-bus
4. sd-resolve
5. sd-netlink

This changed was inspired by this:

https://github.com/systemd/systemd/issues/8075#issuecomment-363689755

This shows that apparently IRL there are programs that do close
stdin/stdout/stderr, and we should accomodate for that.

Note that this won't fix any bugs, this just makes sure that buggy
programs are less likely to interfere with out own code.
src/basic/fd-util.c
src/basic/fd-util.h
src/basic/log.c
src/libsystemd/sd-bus/bus-container.c
src/libsystemd/sd-bus/bus-socket.c
src/libsystemd/sd-event/sd-event.c
src/libsystemd/sd-netlink/netlink-socket.c
src/libsystemd/sd-resolve/sd-resolve.c
src/test/test-fd-util.c