-
Notifications
You must be signed in to change notification settings - Fork 2.2k
rootfs: prohibit symlinks that conflicts with readonlyPaths and/or maskedPaths to prevent CVE-2023-27561
#3756
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
Changes from all 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 |
|---|---|---|
|
|
@@ -6,11 +6,12 @@ function setup() { | |
| setup_busybox | ||
|
|
||
| # Create fake rootfs. | ||
| mkdir rootfs/testdir | ||
| mkdir rootfs/testdir rootfs/testdir2 | ||
| echo "Forbidden information!" >rootfs/testfile | ||
| echo "Forbidden information! (in a nested dir)" >rootfs/testdir2/file2 | ||
|
|
||
| # add extra masked paths | ||
| update_config '(.. | select(.maskedPaths? != null)) .maskedPaths += ["/testdir", "/testfile"]' | ||
| update_config '(.. | select(.maskedPaths? != null)) .maskedPaths += ["/testdir", "/testfile", "/testdir2/testfile2"]' | ||
| } | ||
|
|
||
| function teardown() { | ||
|
|
@@ -56,3 +57,41 @@ function teardown() { | |
| [ "$status" -eq 1 ] | ||
| [[ "${output}" == *"Operation not permitted"* ]] | ||
| } | ||
|
|
||
| @test "mask paths [prohibit symlink /proc]" { | ||
| ln -s /symlink rootfs/proc | ||
| runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox | ||
| [ "$status" -eq 1 ] | ||
| [[ "${output}" == *"must not be a symlink"* ]] | ||
| } | ||
|
|
||
| @test "mask paths [prohibit symlink /sys]" { | ||
| ln -s /symlink rootfs/sys | ||
| runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox | ||
| [ "$status" -eq 1 ] | ||
| [[ "${output}" == *"must not be a symlink"* ]] | ||
| } | ||
|
|
||
| @test "mask paths [prohibit symlink /testdir]" { | ||
| rmdir rootfs/testdir | ||
| ln -s /symlink rootfs/testdir | ||
| runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox | ||
| [ "$status" -eq 1 ] | ||
| [[ "${output}" == *"must not be a symlink"* ]] | ||
| } | ||
|
|
||
| @test "mask paths [prohibit symlink /testfile]" { | ||
| rm -f rootfs/testfile | ||
| ln -s /symlink rootfs/testfile | ||
| runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox | ||
| [ "$status" -eq 1 ] | ||
| [[ "${output}" == *"must not be a symlink"* ]] | ||
| } | ||
|
|
||
| @test "mask paths [prohibit symlink /testdir2 (parent of /testdir2/testfile2)]" { | ||
|
Member
Author
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. RFC: Should we prohibit these symlinks, or should we just prohibit symlinking /proc and /sys ? The latter might be better for compatibility, but might be less secure.
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. I think that the former is the right approach (parents should not be symlinks). |
||
| rm -rf rootfs/testdir2 | ||
| ln -s /symlink rootfs/testdir2 | ||
| runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox | ||
| [ "$status" -eq 1 ] | ||
| [[ "${output}" == *"must not be a symlink"* ]] | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is still subject to races, I wonder if a better solution might be to make
utils.WithProcfdtake an argument (or have autils.WithProcfdNoSymlinksvariant) which blocks symlink traversal so that we don't allow mounting on symlinks for paths where we don't want indirection (such as for masked and read-only paths as well asprocfsandsysfs)? Withopenat2this can be done withRESOLVE_NO_SYMLINKS-- though I'll need to see what to do about path components... Doing it this way is a little bit closer to how libpathrs would be used so might make things easier for that transition too...To be honest, I read the issue and I don't understand why this appears to be a race condition problem -- isn't the issue that the check we added for the original CVE is completely ignored now because
utils.WithProcfdblindly resolves the symlink?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too new (kernel 5.6)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the problem is just that
securejoinfollows symlinks?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we have to continue to support following symlinks for most mount operations
runc/tests/integration/mounts.bats
Lines 51 to 65 in 6d0261c
/procand/syscan be exceptions thoughThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we don't use
WithProcfdformaskPath()runc/libcontainer/rootfs_linux.go
Lines 1017 to 1030 in 214c16f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand how the issue got reintroduced then... I'm taking a look...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cyphar the issue was reintroduced because the checking code added by 3291d66:
runc/libcontainer/rootfs_linux.go
Line 392 in 206008a
depends on
destbeing the actual path provided by a user. It stopped working as it is supposed to after commit 0ca91f4#diff-e0932af06cb46065b2ef5fc89bc2bd9b880c9578e01b89ef4ecaeffb78a8bef0L331 changed fromdest = filepath.Join (rootfs, dest)todest = securejoin.SecureJoin(rootfs, dest).Now,
SecureJoinresolves all symlinks underdestand thus checking is now done for link destination not the link itself.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... thus the check "if dest is a symlink" is no longer working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you're right. I kept missing than when I was looking over it. I personally prefer the approach in #3773. Doing a pre-flight "scan" of the rootfs seems less than ideal (neither approach protects against races but the pre-flight one is more obviously incapable of handling races -- the approach in #3773 seems closer to what libpathrs would do and actually fixes the core bug in the CVE fix I wrote).