Skip to content

uucore: look up the -Z context of a relative name by its absolute name - #15336

Open
abendrothj wants to merge 1 commit into
uutils:mainfrom
abendrothj:uucore-fscreate-relative-lookup
Open

abendrothj wants to merge 1 commit into
uutils:mainfrom
abendrothj:uucore-fscreate-relative-lookup

Conversation

@abendrothj

@abendrothj abendrothj commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #15335

FsCreateContext asked the policy for the default context of the name as given. The policy lists absolute names only, so a relative name matched nothing, the miss counted as "no default", and the new object kept the type it inherited from its parent. The name now goes through absolute_for_policy_lookup, as set_selinux_security_context already does for cp -Z.

Checked as root on Fedora 44 (enforcing) against GNU 9.12: mkdir -Z with a relative name, with -p, and with an absolute name now gets the same type. Added test_selinux_default_context_relative_name for mkdir and one for mkfifo. They run in cargo's target/tmp, where the SELinux CI job's policy has a default, and fail without the change there; where there's no default they skip.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 05:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codspeed

codspeed Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

⚠️ 119 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

⚡ 2 improved benchmarks
❌ 1 regressed benchmark
✅ 398 untouched benchmarks
⏩ 70 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation factor_five_38_bit_primes 1.6 s 2 s -17.03%
⚡ Simulation factor_three_39_bit_primes 567 ms 291.9 ms +94.26%
⚡ Simulation factor_thirteen_39_bit_primes 9.5 s 9 s +5.85%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing abendrothj:uucore-fscreate-relative-lookup (203d45c) with main (c76f272)

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread src/uucore/src/lib/features/selinux.rs Outdated

/// Like `canonicalize`, but a directory that does not exist yet, as for one about to be
/// created, is resolved through its parents with its own name kept.
fn canonicalize_existing(directory: &Path) -> std::io::Result<PathBuf> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the name says existing but it's for dirs that don't exist yet, could you rename it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, it's now canonicalize_allow_missing, in #15333.

Comment thread src/uucore/src/lib/features/selinux.rs Outdated
("branch/../quokka", directory.join("quokka")),
("branch/..", directory.clone()),
(".", directory.clone()),
// Parents that are about to be created, as for `install -d -Z a/b/c`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is for install, not mkdir (mkdir -p creates one level at a time)
please move it to the install PR with a test in tests/by-util/test_install.rs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, moved to #15333 with a test in test_install.rs.

// 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() {

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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.

}
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
// A type the policy won't hand out here, so a missed lookup shows as inheritance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
could you use a dir the policy has a default for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. The tests now run in target/tmp, which is under the home dir in the SELinux job, so the policy has a default there. They fail without the fix in a Fedora VM set up like that job, and skip where the policy has no default.

Copilot AI balanced review requested due to automatic review settings October 14, 2026 22:08
@abendrothj
abendrothj force-pushed the uucore-fscreate-relative-lookup branch from b933376 to 203d45c Compare October 14, 2026 22:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mkdir, mknod, mkfifo: -Z ignores the policy default for a relative name

3 participants