-
Notifications
You must be signed in to change notification settings - Fork 21
test(iso4-path): Add path confinement tests #1338
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,5 +3,6 @@ pub mod memory; | |
| pub mod signal; | ||
|
|
||
| pub use cage::*; | ||
| pub use dashmap::DashMap; | ||
| pub use memory::*; | ||
| pub use signal::*; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,4 @@ sysdefs = { path = "../sysdefs" } | |
| default = ["fast"] | ||
| fast = [] | ||
| secure = [] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| symlink_confinement test: PASS |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| #include <assert.h> | ||
| #include <errno.h> | ||
| #include <fcntl.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <unistd.h> | ||
|
|
||
| int main() { | ||
| unlink("evil_link"); | ||
|
|
||
| assert(symlink("/etc/passwd", "evil_link") == 0); | ||
|
|
||
| /* | ||
| NOTE: this only checks that symlink resolution is internally consistent | ||
| (following evil_link behaves like a normal read), not that either path | ||
| is actually confined. See the /lind/README.md-based checks below for | ||
| the actual confinement/escape proof. | ||
| */ | ||
| errno = 0; | ||
| int direct_fd = open("/etc/passwd", O_RDONLY); | ||
| int direct_errno = errno; | ||
|
|
||
| errno = 0; | ||
| int link_fd = open("evil_link", O_RDONLY); | ||
| int link_errno = errno; | ||
|
|
||
| if(direct_fd == -1) { | ||
| assert(link_fd == -1); | ||
| assert(link_errno == direct_errno); | ||
| } else { | ||
| assert(link_fd != -1); | ||
|
|
||
| char direct_buf[256]; | ||
| char link_buf[256]; | ||
| ssize_t direct_n = read(direct_fd, direct_buf, sizeof(direct_buf)); | ||
| ssize_t link_n = read(link_fd, link_buf, sizeof(link_buf)); | ||
|
|
||
| assert(direct_n >= 0); | ||
| assert(link_n == direct_n); | ||
| assert(memcmp(direct_buf, link_buf, (size_t)direct_n) == 0); | ||
|
|
||
| close(direct_fd); | ||
| close(link_fd); | ||
| } | ||
|
|
||
| unlink("evil_link"); | ||
|
|
||
| errno = 0; | ||
| /* | ||
| NOTE: /lind/README.md is specific to this dev-conatainer's mount | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. container //typo
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opening A suggested solution is to have a file within the virtual filesystem and outside either. File and File So when you run it within lind-wasm, the following three conditions can hold,
|
||
| layout(repo checked out at /lind, matching LINDFS_ROOT's hardcoded | ||
| assumption in sysdefs). If this runs somewhere that mounts the repo | ||
| differently, this path may not exist at all, in which case this | ||
| check would accidentally pass via ENOENT. | ||
| Re-verify this path is valid if test is run in a new environment. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The solution could be to pin the expected output instead of deriving it from an unconfined run. Adding: tests/unit-tests/file_tests/deterministic/expected/symlink_confinement.outputmakes |
||
| */ | ||
| int escape_fd = open("/lind/README.md", O_RDONLY); | ||
| int escape_errno = errno; | ||
|
|
||
| if(escape_fd != -1) { | ||
| fprintf(stderr, "symlink_confinement test: FAIL -- opened " | ||
| "/lind/README.md from inside the cage, chroot escape\n"); | ||
| close(escape_fd); | ||
| assert(0); | ||
| } | ||
| assert(escape_errno == ENOENT); | ||
|
|
||
| unlink("evil_link_readme"); | ||
| assert(symlink("/lind/README.md", "evil_link_readme") == 0); | ||
|
|
||
| errno = 0; | ||
| int link_escape_fd = open("evil_link_readme", O_RDONLY); | ||
| int link_escape_errno = errno; | ||
| if(link_escape_fd != -1) { | ||
| fprintf(stderr, "symlink_confinement test: FAIL -- opened " | ||
| "/lind/README.md via symlink from inside the cage, " | ||
| "chroot escape via symlink target\n"); | ||
| close(link_escape_fd); | ||
| assert(0); | ||
| } | ||
| assert(link_escape_errno == ENOENT); | ||
| unlink("evil_link_readme"); | ||
|
|
||
| printf("symlink_confinement test: PASS\n"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test asserts that opening via
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I agree with this. |
||
| return 0; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.