Skip to content

Conversation

@cerdelen
Copy link
Contributor

Fix: #10307

Instead of blindly taking the uid as gid we will parse it out of passwd instead.

I am not sure how to write a test in the by_util/chroot.rs file as i dont see any precedence of how to create a user so im not sure how i could set up a test of a user with a different gid to their uid, happy to take pointers how this could be done in the testing framework.

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/seq/seq-epipe is now passing!

@sylvestre
Copy link
Contributor

please add a test to make sure we won't regress, thanks!

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/date/date-ethiopia is no longer failing!
Congrats! The gnu test tests/date/date-iran is no longer failing!
Congrats! The gnu test tests/date/date-thailand is no longer failing!

@cerdelen cerdelen force-pushed the chroot_gid_from_uid branch from b265ce1 to 5e7eccd Compare January 26, 2026 18:18
@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/date/date-ethiopia is no longer failing!
Congrats! The gnu test tests/date/date-iran is no longer failing!
Congrats! The gnu test tests/date/date-thailand is no longer failing!

@github-actions
Copy link

GNU testsuite comparison:

Congrats! The gnu test tests/pr/bounded-memory is no longer failing!

}
// Ubuntu has a sync user whose gid is 65534 per default
if let Ok(result) = run_ucmd_as_root(&ts, &["--userspec=sync", "/", "id", "-g"]) {
result.success().no_stderr().stdout_is("{gid}");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Were you able to get this test to run? This is missing a format! and is interpreting it as a string literal

stdout_is(format!("{gid}"))

Copy link
Contributor Author

@cerdelen cerdelen Feb 11, 2026

Choose a reason for hiding this comment

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

You are correct.
I wasn't aware that the chroot tests were behind a feature wall. I had run the tests without the feature flags so for me no errors appeared.

Sorry for that oversight

Some(UserSpec::UserOnly(user)) => {
let uid = name_to_uid(user)?;
let gid = uid as libc::gid_t;
let gid = usr_name_to_gid(user)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is incorrect fallback logic:

Suggested change
let gid = usr_name_to_gid(user)?;
let gid = Passwd::locate(uid)
.map(|p| p.gid)
.map_err(|_| ChrootError::NoGroupSpecified(uid))?;

You can see the difference with GNU with the params --userspec=99999 --groups=root

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the tip. I will leave the abstraction of usr2gid that is being used in alot of other places too and change the map_err at this location.

@cerdelen cerdelen requested a review from ChrisDryden February 11, 2026 18:18
@cerdelen cerdelen force-pushed the chroot_gid_from_uid branch from 58441e7 to 0219fbe Compare February 11, 2026 18:28
@github-actions
Copy link

GNU testsuite comparison:

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

@ChrisDryden ChrisDryden merged commit 04e258f into uutils:main Feb 12, 2026
153 of 155 checks passed
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.

chroot: incorrect gid when different from uid

3 participants