-
Notifications
You must be signed in to change notification settings - Fork 6
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
tests: add race attack tests for resolve_partial #144
Merged
Merged
Conversation
This file contains 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
fc44a19
to
b40251f
Compare
327d1a8
to
215fc3e
Compare
If we hit a symlink like "../../../../../../../../../../foo", we skip no-op ".." components (i.e. ".." components while we are at "/") in the opath resolver. However, we forgot to pop said components from the symlink stack, which resulted in bad symlink stack errors when walking into such symlinks. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
The opath resolver will return SafetyViolation if it notices a safety violation, but because openat2 just gets -EXDEV (and resolve_partial is implemented in terms of resolve) we ended up returning the safety violation as a partial resolution. In theory, returning a partial resolution is fine (since users of partial-resolutions need to be race-safe anyway) but it is preferable to avoid an attacker being able to trick libpathrs into continuing to execute after we've detected an attack. This also unifies our behaviour. In addition, remove the unused code at the end of the partial resolver (coverage analysis shows that this code is never executed and we can be fairly sure of that). Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
It is possible for multiple threads to run Root::remove_all at the same time, and the preferred behaviour should be that if the directory is removed we treat that as being a success even if it wasn't removed by us. This also means that trying to remove a non-existent directory should also succeed -- this matches the os.RemoveAll behaviour we want to mirror (as well as 'rm -rf'). This doesn't match the behaviour of std::fs::remove_dir_all, but that is a bit of an outlier. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
The logic in the Makefile for running the tests is getting a little complicated, and we will need to add some more logic to it soon (for the racing tests as well as to deal with the new procfs-mount-blocking stuff in Linux >= 6.12) so moving it to a shell script makes a lot of sense. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
These tests are mostly based on the filepath-securejoin tests, though with a few additional tests added to check for tricky symlinks. Unfortunately, because the rename exchange thread can affect any openat2 call, we cannot run these tests in parallel with other tests (otherwise you get spurrious errors because one test gets -EAGAIN too many times). So we split the rust test execution into two groups manually (nextest doesn't support natively specifying a test group as being "exclusive" in this way, unfortunately). Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
We need to bump the open files ulimit in the tests to make sure we don't get -EMFILE while running the 128-thread remove_all tests. Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
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.
These tests are mostly based on the filepath-securejoin tests, though
with a few additional tests added to check for tricky symlinks.
Unfortunately, because the rename exchange thread can affect any openat2
call, we cannot run these tests in parallel with other tests (otherwise
you get spurrious errors because one test gets -EAGAIN too many times).
Fixes #155
Signed-off-by: Aleksa Sarai cyphar@cyphar.com