Skip to content
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 9 commits into from
Feb 14, 2025

Conversation

cyphar
Copy link
Member

@cyphar cyphar commented Jan 10, 2025

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

@cyphar cyphar added the tests Related to the test framework. label Jan 10, 2025
@cyphar cyphar added this to the 0.2.0 milestone Jan 10, 2025
@cyphar cyphar force-pushed the test-racing branch 3 times, most recently from fc44a19 to b40251f Compare January 15, 2025 15:52
@cyphar cyphar force-pushed the test-racing branch 2 times, most recently from 327d1a8 to 215fc3e Compare February 13, 2025 07:21
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>
@cyphar cyphar merged commit 5a30f9a into openSUSE:main Feb 14, 2025
49 checks passed
@cyphar cyphar deleted the test-racing branch February 17, 2025 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Related to the test framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tests: add basic resolution racing tests
1 participant