Repository navigation
uucore: look up the -Z context of a relative name by its absolute name #15336
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 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 |
|---|---|---|
|
|
@@ -594,6 +594,62 @@ fn test_selinux_invalid() { | |
| assert!(!at.dir_exists(dest)); | ||
| } | ||
|
|
||
| // -Z looks the name up in the policy, which lists absolute names only: a relative | ||
| // name must get the same label as the absolute one. | ||
| #[test] | ||
| #[cfg(all(feature = "selinux", any(target_os = "linux", target_os = "android")))] | ||
| fn test_selinux_default_context_relative_name() { | ||
| use uucore::selinux::{ | ||
| get_selinux_security_context, is_selinux_enabled, set_selinux_security_context, | ||
| }; | ||
| use uutests::util::AtPath; | ||
|
|
||
| if !is_selinux_enabled() { | ||
| println!("Skipping SELinux test: SELinux is not enabled"); | ||
| return; | ||
| } | ||
| // The policy has no default under /tmp, so both names would inherit there; | ||
| // target/tmp is usually under $HOME, which has one. | ||
| let dir = tempfile::tempdir_in(env!("CARGO_TARGET_TMPDIR")).unwrap(); | ||
| let at = AtPath::new(dir.path()); | ||
| let scene = TestScenario::new(util_name!()); | ||
| // A type the policy won't hand out here, so a missed lookup shows as inheritance. | ||
|
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. as you said, this passes without the fix under /tmp, so CI won't catch a regression
Contributor
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. Done. The tests now run in |
||
| at.mkdir("parent"); | ||
| let ctx = String::from("root:object_r:etc_t:s0"); | ||
| if set_selinux_security_context(&at.plus("parent"), Some(&ctx)).is_err() { | ||
| println!("Skipping SELinux test: cannot set a context on the fixture"); | ||
| return; | ||
| } | ||
| let type_of = |p: &str| { | ||
| let ctx = get_selinux_security_context(&at.plus(p), false).unwrap(); | ||
| ctx.split(':').nth(2).unwrap().to_owned() | ||
| }; | ||
|
|
||
| scene | ||
| .ucmd() | ||
| .args(&["-Z", &at.plus_as_string("parent/absolute")]) | ||
| .succeeds(); | ||
| let expected = type_of("parent/absolute"); | ||
| if expected == "etc_t" { | ||
| println!("Skipping SELinux test: the policy has no default for {dir:?}"); | ||
| return; | ||
| } | ||
| scene | ||
| .ucmd() | ||
| .current_dir(dir.path()) | ||
| .args(&["-Z", "parent/relative"]) | ||
| .succeeds(); | ||
| scene | ||
| .ucmd() | ||
| .current_dir(dir.path()) | ||
| .args(&["-p", "-Z", "parent/new/relative"]) | ||
| .succeeds(); | ||
|
|
||
| for name in ["parent/relative", "parent/new", "parent/new/relative"] { | ||
| assert_eq!(type_of(name), expected, "{name}"); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_mkdir_deep_nesting() { | ||
| // Regression test for stack overflow with deeply nested directories. | ||
|
|
||
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.
mknod and mkfifo go through the same code, please add a test for one of them too
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.
Done, added one for mkfifo.