-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
chroot: fix gid being set by uid with --userspec #10307 #10465
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
Conversation
|
GNU testsuite comparison: |
|
please add a test to make sure we won't regress, thanks! |
|
GNU testsuite comparison: |
b265ce1 to
5e7eccd
Compare
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
tests/by-util/test_chroot.rs
Outdated
| } | ||
| // 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}"); |
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.
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}"))
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.
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
src/uu/chroot/src/chroot.rs
Outdated
| Some(UserSpec::UserOnly(user)) => { | ||
| let uid = name_to_uid(user)?; | ||
| let gid = uid as libc::gid_t; | ||
| let gid = usr_name_to_gid(user)?; |
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 think this is incorrect fallback logic:
| 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
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.
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.
58441e7 to
0219fbe
Compare
|
GNU testsuite comparison: |
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.