]> git.ipfire.org Git - thirdparty/systemd.git/commit
sd-varlink: hook up fd passing control with SO_PASSRIGHTS
authorMike Yuan <me@yhndnzj.com>
Fri, 6 Jun 2025 19:47:39 +0000 (21:47 +0200)
committerMike Yuan <me@yhndnzj.com>
Tue, 17 Jun 2025 11:16:44 +0000 (13:16 +0200)
commited6b7b6acea44b2e0233aa0d6d2c0b147ecac968
tree92346b47eda379dd07c84f22b56f8c692c139d63
parent72098df8439411b65ddeeddc1e50c8fb3f06be47
sd-varlink: hook up fd passing control with SO_PASSRIGHTS

This is a tricky one, because we effectively turn fd passing input
toggle into a tristate: unset, disabled, and enabled; whereas unset
and disabled were identical previously. *Unset* state silently
ignores SCM_RIGHTS passed by invoking recv() instead of recvmsg(),
and for disabled we now disable SO_PASSRIGHTS completely.

The plot thickens when it comes to the server, since we want to
turn off the SO_PASSRIGHTS already on the listening socket so that
there's no race between accept() and recvmsg() wrt SO_PASSRIGHTS state.
However, if we do this unconditionally, the existing use case of
creating a custom connection callback and enabling fd passing there
would be broken.

Hence, let's introduce a new flag,
SD_VARLINK_SERVER_FD_PASSING_INPUT_STRICT, which when set
ties the enablement of fd passing to SO_PASSRIGHTS in server,
and set it for all our varlink servers.

Refer to the previous commit for the rationale behind return value
change in sd_varlink_set_allow_fd_passing_input().
src/libsystemd/sd-varlink/sd-varlink.c
src/libsystemd/sd-varlink/varlink-internal.h
src/libsystemd/sd-varlink/varlink-util.c
src/systemd/sd-varlink.h