Skip to content

Conversation

@ChiamakaUI
Copy link
Contributor

@ChiamakaUI ChiamakaUI commented Jan 30, 2026

Summary

Fixes SELinux cleanup logic in mknod when setting the security context fails.

Previously, uutils attempted to clean up a partially created device node using std::fs::remove_dir, which does not work for device nodes or FIFOs. This could leave behind a mislabeled node on SELinux-enforcing systems.

Changes

  • Replaced std::fs::remove_dir with std::fs::remove_file for proper cleanup
  • Ensure failed SELinux context application does not leave artifacts behind

Test / Reproduction Steps

mknod --context=invalid_context_t /tmp/testnode c 1 3
ls -Z /tmp/testnode

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/basenc/bounded-memory is now passing!

@cakebaker cakebaker linked an issue Jan 30, 2026 that may be closed by this pull request
@ChiamakaUI
Copy link
Contributor Author

It looks like CI failed in an unrelated dd test (test_bytes_oseek_bytes_oflag). My changes are limited to mknod SELinux cleanup logic and do not affect dd or shared code.

Happy to rebase or rerun CI if needed.

@ChrisDryden
Copy link
Collaborator

ChrisDryden commented Jan 31, 2026

Can you make a regression test for this in test_mknod.rs?

@ChrisDryden
Copy link
Collaborator

test_selinux_invalid in tests/by-util/test_mkdir.rs is almost identical

You can use arg("p") for FIFO and at.file_exists() instead of at.dir_exists()

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)

@ChrisDryden
Copy link
Collaborator

can you run cargo fmt?

@ChiamakaUI
Copy link
Contributor Author

can you run cargo fmt?

I ran cargo fmt and cargo fmt --check locally — both complete successfully with no changes.

@ChrisDryden
Copy link
Collaborator

The error in the CI https://github.com/uutils/coreutils/actions/runs/21542607295/job/62082424264?pr=10582 is

Diff in /home/runner/work/coreutils/coreutils/tests/by-util/test_mknod.rs:258:
     // invalid context → node must not exist
     assert!(!at.file_exists(dest));
 }
+

That is good feedback though, I think there should be a way that we can change the settings to make it so that no matter what platform you're on it can fix this errors. I'm assuming you're on a windows or mac?

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/inotify-dir-recreate (passes in this run but fails in the 'main' branch)

@ChiamakaUI
Copy link
Contributor Author

The error in the CI https://github.com/uutils/coreutils/actions/runs/21542607295/job/62082424264?pr=10582 is

Diff in /home/runner/work/coreutils/coreutils/tests/by-util/test_mknod.rs:258:
     // invalid context → node must not exist
     assert!(!at.file_exists(dest));
 }
+

That is good feedback though, I think there should be a way that we can change the settings to make it so that no matter what platform you're on it can fix this errors. I'm assuming you're on a windows or mac?

I noticed other test files end with a newline, so I added one here as well. Yes, i am on mac

@ChrisDryden ChrisDryden merged commit 42b2ad8 into uutils:main Jan 31, 2026
129 of 130 checks passed
@ChrisDryden
Copy link
Collaborator

Thanks for the contribution!

@ChiamakaUI ChiamakaUI deleted the fix-mknod-selinux-cleanup branch January 31, 2026 20:31
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.

mknod: SELinux context applied after creation with broken cleanup

2 participants