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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

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 #129
Signed-off-by: Aleksa Sarai [email protected]

@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 2 times, most recently from 1257b82 to fc44a19 Compare January 12, 2025 15:15
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
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 racing tests
1 participant