Repository navigation
Conversation
Previously, if one of the handles in sandbox-expose-fd or sandbox-expose-fd-ro was out of range, we'd dereference error->message while error was NULL, and crash. Instead, use a function that checks for each error condition separately, and ends up with the error set on any failure. This intentionally doesn't check against validate_opath_fd, which we do separately: we only want to do that for fds that are to be re-exposed into a sandbox, but not for the app-fd, usr-fd or array of fds to inherit. Signed-off-by: Simon McVittie <[email protected]>
These only need to check that the handle is in range, and don't need to validate it as an O_PATH fd. Signed-off-by: Simon McVittie <[email protected]>
Now that all accesses to the fd list are going through peek_fd_for_handle(), we don't need this. Signed-off-by: Simon McVittie <[email protected]>
This pattern will allow us to add more checks after validate_opath_fd(), but before actually using the fd. Signed-off-by: Simon McVittie <[email protected]>
These were part of get_path_for_fd() before commit 3c50014 "portal: Use --bind-fd, --app-fd and --usr-fd options to avoid races". If these checks would fail, then the equivalent in bwrap is also going to fail, but we have the opportunity to provide better error messages here. For the /app and /usr fds, we always reported errors from these checks as an error; continue to do so. For the sandbox expose fds, a historical quirk of this code is that if these checks failed, we would merely log at g_info() level and ignore the request to expose the fd in the sandbox. With hindsight this was probably not appropriate, but apps are relying on it now: for example, org.gnome.Epiphany asks to expose files from /app and /usr in the subsandbox. When we ignored those requests (because /app and /usr have a different meaning on the host system), the app worked as intended anyway, because the subsandbox has access to the app's /app and the runtime's /usr whether they're explicitly added or not. Helps: flatpak#6584 Signed-off-by: Simon McVittie <[email protected]>
Ideally we probably want the apps that are affected by this to stop passing paths below /app or /usr, or non-filesystem objects, to the `flatpak-spawn --sandbox-expose` family of options: it's misleading if the app explicitly tells us to expose a path in the sandbox, but then we neither do so nor report a warning or error. Signed-off-by: Simon McVittie <[email protected]>
This was referenced Apr 9, 2026
Collaborator
Author
|
Replaced by #6588 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
portal: Factor out a function to validate fds attached to D-Bus message
Previously, if one of the handles in sandbox-expose-fd or
sandbox-expose-fd-ro was out of range, we'd dereference error->message
while error was NULL, and crash. Instead, use a function that checks
for each error condition separately, and ends up with the error set
on any failure.
This intentionally doesn't check against validate_opath_fd, which we
do separately: we only want to do that for fds that are to be re-exposed
into a sandbox, but not for the app-fd, usr-fd or array of fds to inherit.
portal: Use peek_fd_for_handle for inherited fds, app_fd, usr_fd
These only need to check that the handle is in range, and don't need
to validate it as an O_PATH fd.
portal: Remove fds array and fds_len
Now that all accesses to the fd list are going through
peek_fd_for_handle(), we don't need this.
portal: Early-return if validate_opath_fd() fails
This pattern will allow us to add more checks after validate_opath_fd(),
but before actually using the fd.
portal: Reinstate checks for whether we can use an app-supplied fd
These were part of get_path_for_fd() before commit 3c50014
"portal: Use --bind-fd, --app-fd and --usr-fd options to avoid races".
If these checks would fail, then the equivalent in bwrap is also going
to fail, but we have the opportunity to provide better error messages
here.
For the /app and /usr fds, we always reported errors from these checks
as an error; continue to do so.
For the sandbox expose fds, a historical quirk of this code is that if
these checks failed, we would merely log at g_info() level and ignore
the request to expose the fd in the sandbox. With hindsight this was
probably not appropriate, but apps are relying on it now: for example,
org.gnome.Epiphany asks to expose files from /app and /usr in the
subsandbox. When we ignored those requests (because /app and /usr
have a different meaning on the host system), the app worked as
intended anyway, because the subsandbox has access to the app's /app
and the runtime's /usr whether they're explicitly added or not.
Helps: [Bug]: Epiphany crashing with Flatpak 1.16.5: bwrap: Can't find source path /proc/self/fd/79: No such file or directory #6584
portal: Bump up log level for inability to expose fds to warning
Ideally we probably want the apps that are affected by this to stop
passing paths below /app or /usr, or non-filesystem objects, to the
flatpak-spawn --sandbox-exposefamily of options: it's misleadingif the app explicitly tells us to expose a path in the sandbox, but
then we neither do so nor report a warning or error.