Repository navigation
Make /dev/shm shareable between app instances - #4214
Merged
Merged
Conversation
smcv
commented
Apr 8, 2021
| * or %FALSE with @error set if it does not. | ||
| */ | ||
| gboolean | ||
| flatpak_instance_claim_per_app_temp_directory (const char *app_id, |
Collaborator
Author
There was a problem hiding this comment.
As with this function's earlier existence in #4093, it's security-sensitive, so please review carefully.
I added test coverage for all the branches except fstat() failing (which I don't know how to trigger on-demand). To get full test coverage for it, you need to run tests as non-root, and pre-create /tmp/flatpak-com.example.App-OwnedByRoot owned by root (which I'm going to try to add to the CI).
This was referenced Apr 8, 2021
alexlarsson
reviewed
Apr 12, 2021
alexlarsson
reviewed
Apr 12, 2021
alexlarsson
reviewed
Apr 12, 2021
alexlarsson
reviewed
Apr 12, 2021
Similar to /tmp, applications might well use /dev/shm as an IPC rendezvous between instances, which wouldn't have worked without --device=shm until now. Because /dev/shm has specific characteristics (in particular it's meant to always be a tmpfs), we offload the actual storage into a subdirectory of the real /dev/shm. Because /dev/shm is a shared directory between all uids, we have to be extra-careful how we do this, which is why the test coverage here is important. This is done on an opt-in basis because of its extra complexity. Signed-off-by: Simon McVittie <[email protected]>
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.
Fixes #4091.
Design
The interesting subset of the host filesystem is now:
As with #4093, the shared
/dev/shmis only used forflatpak run, not forflatpak build(which reinvents a lot offlatpak_run_app()), and also not forapply_extra.Whenever we garbage-collect the numbered per-instance directories, we check their app info. If an instance is disappearing, we attempt to garbage-collect the corresponding
dev-shmif no apps are still using it. The shared/dev/shmis currently backed by a directory/dev/shm/flatpak-com.example.App-XXXXXX, so that it's basically guaranteed to be genuinely a tmpfs.The format of the temporary directory
/dev/shm/flatpak-com.example.App-XXXXXXis checked, to defend against being tricked into deleting a directory that we didn't mean to. The app name is included in the directory name, so that if an app uses an excessive amount of space, users can blame the app and not Flatpak itself.The flag file
.flatpak-tmpdiris also checked for, again as a safety-catch against deleting unintended directories. This is loosely based on the.testtmpused in the libostree and Flatpak unit tests.Having a shared
/dev/shmis guarded by a feature flag as @alexlarsson requested: we don't expect so many apps to need this.Commits
run: Add option to share /dev/shm between instances of an app-ID
Similar to /tmp, applications might well use /dev/shm as an IPC
rendezvous between instances, which wouldn't have worked without
--device=shm until now.
Because /dev/shm has specific characteristics (in particular it's
meant to always be a tmpfs), we offload the actual storage into a
subdirectory of the real /dev/shm. Because /dev/shm is a shared
directory between all uids, we have to be extra-careful how we
do this, which is why the test coverage here is important.
This is done on an opt-in basis because of its extra complexity.