-
Notifications
You must be signed in to change notification settings - Fork 30
Introduce Landlock isolation support #816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
fcfa50c
to
c61742d
Compare
Depends on #814. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
4 tasks
c61742d
to
ae44e0d
Compare
This comment was marked as outdated.
This comment was marked as outdated.
The change incorporates some changes from #844. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
n0toose
added a commit
to n0toose/uhyve
that referenced
this pull request
Jan 5, 2025
Ported from hermit-os#816, fixes a regression introduced by hermit-os/kernel#1529, which modified the Hermit kernel so that it uses absolute paths instead of relative ones.
This PR includes work that was split into separate PRs, #844 and #852, which should probably be merged first. This PR relies on hermit-os/kernel#1529. It includes some changes to our tests that reflect the changes made in hermit-os/kernel#1529. |
github-merge-queue bot
pushed a commit
that referenced
this pull request
Jan 9, 2025
Ported from #816, fixes a regression introduced by hermit-os/kernel#1529, which modified the Hermit kernel so that it uses absolute paths instead of relative ones.
20f56b7
to
c045ed7
Compare
n0toose
commented
Jan 10, 2025
n0toose
commented
Jan 10, 2025
This comment was marked as outdated.
This comment was marked as outdated.
f96d9c7
to
a7d0e7a
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
jounathaen
reviewed
Apr 23, 2025
jounathaen
reviewed
Apr 23, 2025
jounathaen
reviewed
Apr 23, 2025
jounathaen
reviewed
Apr 23, 2025
jounathaen
reviewed
Apr 23, 2025
jounathaen
reviewed
Apr 23, 2025
jounathaen
reviewed
Apr 23, 2025
jounathaen
reviewed
Apr 23, 2025
cad6641
to
4c411d0
Compare
jounathaen
reviewed
Apr 25, 2025
4c411d0
to
4d41caf
Compare
jounathaen
reviewed
Apr 28, 2025
jounathaen
reviewed
Apr 28, 2025
4d41caf
to
36581a6
Compare
Landlock is a stackable Linux Security Module that lets Uhyve restrict its own capabilities (specifically: access to the filesystem) before loading untrusted code (here: machine images, which we consider to be "black boxes"). The Landlock module is present in newer releases of modern Linux distributions. Uhyve's interaction with Landlock is managed by the class `UhyveLandlockWrapper`. After Uhyve "collects" all paths it requires to function, it enforces Landlock _before_ the image is loaded in `UhyveVm::load_kernel`. We determine whether a file or a directory is present at a path to: - whitelist a non-existent file's parent directory, see get_parent_directory. UhyveFileMap continues to protect the parent directory. - set the right permissions for paths instead of letting the crate "dynamically" remove directory access rights for files, because that causes breakage when using strict file isolation mode or CompatLevel::HardRequirement (see determine_ruleset). Additional integration tests were added to check for Landlock-specific cases, as well as unit tests of the Landlock component (which also increase coverage of UhyveFileMap). Uhyve's Landlock functionality is disabled on non-Linux hosts, as Landlock is never present on non-Linux hosts. Otherwise, it is enabled by default ("CompatLevel::BestEffort", plus the requirement that a version of Landlock (all ABIs) has to be present on the system. This goes up against Landlock's author's opinion of taking advantage of existing sandboxing features "opportunistically", depending on what is actually available on the operating system. What we chose instead is to prevent execution unless if the user explicitly opts-out using `--file-isolation none`). For now, we rely on the serial_test crate to not break filesystem tests. Such tests should be run in separate, newly created processes, but that was left for later. For now, `--file-isolation strict`'s functionality is ensured by checking against `cargo run` for now in the CI. We check whether Landlock was already enabled once before, which should be useful when using Uhyve as a library. If that is the case, Uhyve returns an error, as it (probably) cannot function in conjuction with an existing set of enforced Landlock rulesets. As soon as a Landlock ruleset is enforced, it cannot be "relaxed".
36581a6
to
e39a532
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
feature/file system
feature/security
Concerns security-related behavior, soundness, isolation or reliability.
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.
Leaving this here for now, the most important design problem with this is how Landlock does not allow whitelisting files if they are not created. (So, we'd have to force the user to use a directory for that instead.)
We also need to avoid "parsing" the same
--file-mapping
inputs twice, as well as not useOnceLock
for enforcing the whitelist when the kernel is actually being loaded.UhyveVm::new
is called in a new thread because Landlock enforces the restrictions for the entire process and its children. We're not testing if the sandbox is applied correctly yet.See: https://docs.kernel.org/userspace-api/landlock.html
Fixes #766