Skip to content

Conversation

@smcv
Copy link
Contributor

@smcv smcv commented Aug 15, 2025

  • flatpak-spawn: Factor out parse_fd_option()

  • flatpak-spawn: Validate --forward-fd arguments early

    This avoids accidentally forwarding a fd that flatpak-spawn opened for
    its own purposes, like the signalfd for forward_signals(), which would
    result in confusing error messages when flatpak-spawn tries to work
    with a fd that has already been closed.

    A frequent symptom of this is that apps that use a sandbox-escape via
    flatpak-spawn --host to mount FUSE filesystems hard-code that the
    $_FUSE_COMMFD is always going to be 3, which is not actually true
    (flatpak-spawn: Unable to read struct signalfd_siginfo: Bad file descriptor #46).

smcv added 2 commits August 15, 2025 13:23
This avoids accidentally forwarding a fd that flatpak-spawn opened for
its own purposes, like the signalfd for forward_signals(), which would
result in confusing error messages when flatpak-spawn tries to work
with a fd that has already been closed.

A frequent symptom of this is that apps that use a sandbox-escape via
`flatpak-spawn --host` to mount FUSE filesystems hard-code that the
`$_FUSE_COMMFD` is always going to be 3, which is not actually true
(flatpak#46).

Signed-off-by: Simon McVittie <[email protected]>
@smcv
Copy link
Contributor Author

smcv commented Aug 15, 2025

Now this is a proper error, instead of trampling on an unrelated fd used internally and causing weird warnings:

$ ./_build/src/flatpak-spawn --host --forward-fd=3 -- true 
./_build/src/flatpak-spawn: --forward-fd=3: Bad file descriptor
Try "./_build/src/flatpak-spawn --help" for more information.

and as a bonus, if debug messages are enabled, it will remind you that --forward-fd={0,1,2} are never necessary:

$ G_MESSAGES_DEBUG=all ./_build/src/flatpak-spawn --host --forward-fd=2 -- true
** (./_build/src/flatpak-spawn:32863): DEBUG: 13:28:48.040: Ignoring --forward-fd=2, fds 0-2 are always forwarded
…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant