Skip to content
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

install does not handle the creation of "drwxr-s---" correctly #486

Closed
firasuke opened this issue Mar 16, 2024 · 6 comments
Closed

install does not handle the creation of "drwxr-s---" correctly #486

firasuke opened this issue Mar 16, 2024 · 6 comments

Comments

@firasuke
Copy link
Contributor

Hey there,

I am unable to create directories with the following permissions drwxr-s---. Normally I run install -dm 02750 directory with coreutils version of install and I get the correct permissions, but with toybox's install I am getting the following permissions instead drwxr-xr-x.

Any ideas what might be the issue here?

@landley
Copy link
Owner

landley commented Mar 17, 2024

Hmmm, the -m argument is handled in the install_node() dirtree callback but -d and -D are handled in install_main(). In part because "install -dm +x" hasn't got a previous mode to delta from, so... vs 777? Or vs umask?

Bit sleep deprived to fix this at the moment but I'll try to work out the correct thing to do in the morning. (And add a test.)

@firasuke
Copy link
Contributor Author

Hmmm, the -m argument is handled in the install_node() dirtree callback but -d and -D are handled in install_main(). In part because "install -dm +x" hasn't got a previous mode to delta from, so... vs 777? Or vs umask?

I see, so they're handled separately.

Bit sleep deprived to fix this at the moment but I'll try to work out the correct thing to do in the morning. (And add a test.)

Yeah, no worries. I can help with the testing if needed.

@landley
Copy link
Owner

landley commented Mar 21, 2024

Oops, sorry, got distracted. I'll try to get this in tonight.

@landley
Copy link
Owner

landley commented Mar 22, 2024

Did you know that the linux mkdirat() syscall strips permission bits outside 01777? Meaning seting the set group ID bit on a directory (so newly created files in the directory inherit the directory's group rather than the users) is inherently racy.

I can open it (with the no follow symlink bit), stat it to confirm it's a directory (albeit not necessarily the one you just created, or somebody may have done a chown on it in the race window), and then do an fchmod() on that filehandle... except this needs to interact with -g and -o correctly, I think...?

@landley
Copy link
Owner

landley commented Mar 22, 2024

Eh, the chown's already racy if you're being security paranoid, and it has to go after the chown because that would reset suid bits anyway. (I tested by hand that "sudo ./toybox install -dm 1750 -g root directory" is both T and root, meaning the chown doesn't strip the sticky bit, but didn't add it to scripts/install.test because it would require root to test.)

Commit 39dea77.

@firasuke
Copy link
Contributor Author

Eh, the chown's already racy if you're being security paranoid, and it has to go after the chown because that would reset suid bits anyway. (I tested by hand that "sudo ./toybox install -dm 1750 -g root directory" is both T and root, meaning the chown doesn't strip the sticky bit, but didn't add it to scripts/install.test because it would require root to test.)

Commit 39dea77.

Upon further testing, the issue appears to have been fixed. Thanks!

@landley landley closed this as completed Mar 22, 2024
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

No branches or pull requests

2 participants