Repository navigation
portal: Fix --env-fd regressions - #4283
Conversation
|
It looks like fixing #4285 was masking a different bug in the portal (#4286), which was also introduced while we were fixing CVE-2021-21261: Fixing #4285 accidentally mitigated that bug: as we leak more I'm now trying to write a unit test for the portal that we can use as a reproducer for both of these. [edited: I've opened separate issues for the two things I was fixing and edited this comment to refer to them] |
Otherwise we'll run out of file descriptors eventually, when starting a sufficiently large number of subsandboxes. Resolves: flatpak#4285 Fixes: aeb6a7a "portal: Convert --env in extra-args into --env-fd" Signed-off-by: Simon McVittie <[email protected]>
This will allow us to add additional mapping entries for fds to be used internally by `flatpak run`, in particular --env-fd. Defer the second pass through the fd array until the last possible moment, so that any extra fds we want to add (like the --env-fd) have already been added by then. Helps: flatpak#4286 Signed-off-by: Simon McVittie <[email protected]>
Just because we can allocate a new, unused fd in the portal's fd space, that doesn't mean that fd number is going to be unused in the child process's fd space: we might need to remap it. Resolves: flatpak#4286 Fixes: aeb6a7a "portal: Convert --env in extra-args into --env-fd" Signed-off-by: Simon McVittie <[email protected]>
This makes them easier to test, and easier to use in related tests. Signed-off-by: Simon McVittie <[email protected]>
Signed-off-by: Simon McVittie <[email protected]>
Signed-off-by: Simon McVittie <[email protected]>
|
OK, try this. Originally, this branch was just the first commit, fixing #4285; but that makes #4286 more likely to happen, and I think we should fix both at the same time (meaning at least the first three commits). The refactoring in The test coverage is also not strictly necessary, but is good to have. |
|
/cc @RyuzakiKK |
During unit testing we don't have a complete Flatpak app or runtime available, and `flatpak run` is not necessarily in FLATPAK_BINDIR yet; but we can run the portal with this environment variable set, to specify a mock implementation of Flatpak. This helps to reproduce flatpak#4286. Signed-off-by: Simon McVittie <[email protected]>
This exercises Spawn() and reproduces flatpak#4286. Signed-off-by: Simon McVittie <[email protected]>
|
LGTM |
portal: Don't leak fd used for serialized environment
Otherwise we'll run out of file descriptors eventually, when starting
a sufficiently large number of subsandboxes.
Resolves: portal: --env-fd is leaked #4285
Fixes: aeb6a7a "portal: Convert --env in extra-args into --env-fd"
portal: Use a GArray to store fds
This will allow us to add additional mapping entries for fds to be
used internally by
flatpak run, in particular --env-fd.Defer the second pass through the fd array until the last possible
moment, so that any extra fds we want to add (like the --env-fd) have
already been added by then.
Helps: portal: --env-fd can collide with fds passed across D-Bus #4286
portal: Remap --env-fd into child process's fd space
Just because we can allocate a new, unused fd in the portal's fd space,
that doesn't mean that fd number is going to be unused in the child
process's fd space: we might need to remap it.
Resolves: portal: --env-fd can collide with fds passed across D-Bus #4286
Fixes: aeb6a7a "portal: Convert --env in extra-args into --env-fd"
context: Factor out functions to parse an environment block
This makes them easier to test, and easier to use in related tests.
tests: Test environment block parsing
portal: Add NONE values for flags sets
portal: Add some design-for-test
During unit testing we don't have a complete Flatpak app or runtime
available, and
flatpak runis not necessarily in FLATPAK_BINDIR yet;but we can run the portal with this environment variable set, to
specify a mock implementation of Flatpak.
This helps to reproduce portal: --env-fd can collide with fds passed across D-Bus #4286.
portal: Add some test coverage
This exercises Spawn() and reproduces portal: --env-fd can collide with fds passed across D-Bus #4286.
The first 3 commits should also be applied to 1.10.x, 1.8.x and anything else that got aeb6a7a backported to it.