[PATCH v2 0/3] More caution with NONBLOCK flag on Unix sockets
This is a revision of the one patch from my pesto series that wasn't merged: a rework to the handling of the blocking flag for both listening and accepted Unix sockets. This new version is split into several pieces to make the rationales clearer at each step. It's also a bit more cautious in what it does, so should avoid the problems with the original version. David Gibson (3): treewide: Add SOCK_CLOEXEC to accept() calls that are missing it tap: Report accept() errors conf, repair, tap: Document reasons for blocking Unix sockets conf.c | 6 ++++++ repair.c | 9 +++++++-- tap.c | 13 +++++++++++-- 3 files changed, 24 insertions(+), 4 deletions(-) -- 2.54.0
Generally we try to set the O_CLOEXEC flag on every fd we create. This
seems to be generally accepted security best practice these days, and we
never exec(), so certainly have no need to pass fds to exec()ed processes.
A handful of accept4() calls on Unix sockets are missing the SOCK_CLOEXEC
flag to set this though. Add the missing flag.
Signed-off-by: David Gibson
Most of our operation is asynchronous, based on non-blocking fds handled
in our epoll loop. However, our several Unix sockets (tap client, repair
helper, control client) are all blocking fds after accept().
That is in fact correct, but for not especially obvious reasons that are
slightly different in each case. Add explanatory comments to each of them.
Signed-off-by: David Gibson
On Mon, 18 May 2026 13:22:43 +1000
David Gibson
Most of our operation is asynchronous, based on non-blocking fds handled in our epoll loop. However, our several Unix sockets (tap client, repair helper, control client) are all blocking fds after accept().
That is in fact correct, but for not especially obvious reasons that are slightly different in each case. Add explanatory comments to each of them.
Signed-off-by: David Gibson
--- conf.c | 6 ++++++ repair.c | 4 ++++ tap.c | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/conf.c b/conf.c index 029b9c7c..5c7dfea1 100644 --- a/conf.c +++ b/conf.c @@ -2084,6 +2084,12 @@ static void conf_accept(struct ctx *c) int fd, rc;
retry: + /* Currently we perform the configuration transaction more-or-less + * synchronously, so we want the accepted socket to be blocking. + * + * FIXME: We should make the configuration update asynchronous, like + * most of our operation, so a misbehaving configuration client can't + * block the main forwarding loop. */
Nit I fixed on merge: * [...] loop. */ -- Stefano
On Mon, 18 May 2026 13:22:40 +1000
David Gibson
This is a revision of the one patch from my pesto series that wasn't merged: a rework to the handling of the blocking flag for both listening and accepted Unix sockets. This new version is split into several pieces to make the rationales clearer at each step. It's also a bit more cautious in what it does, so should avoid the problems with the original version.
David Gibson (3): treewide: Add SOCK_CLOEXEC to accept() calls that are missing it tap: Report accept() errors conf, repair, tap: Document reasons for blocking Unix sockets
Applied, with the nit I reported on 3/3 fixed up. -- Stefano
On Wed, May 20, 2026 at 02:52:14AM +0200, Stefano Brivio wrote:
On Mon, 18 May 2026 13:22:43 +1000 David Gibson
wrote: Most of our operation is asynchronous, based on non-blocking fds handled in our epoll loop. However, our several Unix sockets (tap client, repair helper, control client) are all blocking fds after accept().
That is in fact correct, but for not especially obvious reasons that are slightly different in each case. Add explanatory comments to each of them.
Signed-off-by: David Gibson
--- conf.c | 6 ++++++ repair.c | 4 ++++ tap.c | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/conf.c b/conf.c index 029b9c7c..5c7dfea1 100644 --- a/conf.c +++ b/conf.c @@ -2084,6 +2084,12 @@ static void conf_accept(struct ctx *c) int fd, rc;
retry: + /* Currently we perform the configuration transaction more-or-less + * synchronously, so we want the accepted socket to be blocking. + * + * FIXME: We should make the configuration update asynchronous, like + * most of our operation, so a misbehaving configuration client can't + * block the main forwarding loop. */
Nit I fixed on merge:
* [...] loop. */
Oh, thanks. -- David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson
participants (2)
-
David Gibson
-
Stefano Brivio