Pádraig Brady <[email protected]> writes: > This could be considered a security fix in the edge case > where in a user writeable directory with a root owned file, > a user could rename a setuid file in place, and rename back. > If a root chmod is operating in parallel it could read say setuid > from the first file, and then set that on the replaced root file. > > * src/chmod.c (adjust_file_mode): A new function to apply changes > based on an opened descriptor where supported, thus avoiding > races between reading and writing of permissions. > * tests/chmod/rename.sh: Add a new test using strace to induce the race. > * tests/local.mk: Reference the new test. > * NEWS: Mention the bug fix. > > Discovered by Anthropic's OSS Scanner, as bug ANT-2026-H9P7Y138. > --- > NEWS | 5 ++++ > src/chmod.c | 51 ++++++++++++++++++++++++++++++++----- > tests/chmod/rename.sh | 58 +++++++++++++++++++++++++++++++++++++++++++ > tests/local.mk | 1 + > 4 files changed, 109 insertions(+), 6 deletions(-) > create mode 100755 tests/chmod/rename.sh > > diff --git a/NEWS b/NEWS > index 868d96d85..202711bb1 100644 > --- a/NEWS > +++ b/NEWS > @@ -39,6 +39,11 @@ GNU coreutils NEWS -*- > outline -*- > these operations now diagnose the unsupported changes and exit with > failure. > [bug introduced in coreutils-9.5] > > + 'chmod' now computes and applies permissions to the same file, > + even if it is renamed during the operation. If built on older systems > + with glibc < 2.39, this guarantee relies on /proc being available. > + [This bug was present in "the beginning".] > +
I was looking at this one a bit yesterday (didn't have anything close to a patch being finished, so don't worry about that), and wanted to see if FTS_NOSTAT could be used to avoid stat'ing twice where O_PATH is available. I guess it doesn't matter too much in practice. It is a larger refactoring that can probably just be done later. Also, I didn't love calling it a bug given that O_PATH and AT_EMPTY_PATH are Linux-isms, meaning that the bug, i.e., the second lookup, occurs everywhere else. Maybe that can be mentioned in the NEWS entry, if it can be done without making it too wordy? Collin
