file permissions when stripping under fakeroot

Eli Schwartz eschwartz@archlinux.org
Mon Feb 8 05:38:42 GMT 2021


On 2021-02-07, Alan Modra wrote:
>>On Sun, Feb 07, 2021 at 02:39:51PM +1000, Allan McRae wrote:
>>> >From local testing, glibc-2.33 appears to be needed in combination with
>>> binutils-2.36.1 for this issue to occur.  This would explain the issue
>>> being present on rawhide and not on release Fedora versions.
>>
>>Note that for a very long time, if you objcopy/strip a file when you
>>lack write permission for the file then ownership can change.  eg.
>>
>>$ gcc -o hello -g ~/src/tmp/hello.c
>>$ sudo chown root. hello
>>[sudo] password for alan:
>>$ ls -l hello
>>-rwxr-xr-x 1 root root 18392 Feb  7 16:19 hello
>>$ strip hello
>>ls -l hello
>>-rwxr-xr-x 1 alan alan 14312 Feb  7 16:20 hello
>>
>>This shouldn't be surprising at all.
>>
>>$ sudo chown root. hello
>>[sudo] password for alan:
>>$ ls -l hello
>>-rwxr-xr-x 1 root root 14312 Feb  7 16:20 hello
>>$ cp -p hello hello.new
>>$ rm -f hello
>>$ mv hello.new hello
>>$ ls -l hello
>>-rwxr-xr-x 1 alan alan 14312 Feb  7 16:20 hello
> 
> strip creates a temporary file and does a rename for such "fake-in-place" modification.
> Arguably distributions should not rely on the root chown/fchown behavior.
> (what's the extend to which attributes are preserved? What about xattr? :))
> 
> If distributions need such a behavior, they could explicitly obtain owner/group
> and restore it.
> https://groups.google.com/g/linux.gentoo.dev/c/WG-OLQe3yng/m/ZlqM-QC6BQAJ
> 
> (
> I am fairly suspicious when ChromeOS folks wanted to port such a root chown behavior to llvm-strip, so I chatted with Rich, who reported
> https://sourceware.org/bugzilla/show_bug.cgi?id=26945 ...
> )

xattr has always been a problem, since strip always removed this for us.

At any rate the Arch solution to this entire situation is to use
strip/objcopy's -o outfile option to write our own temporary file, then
cat it into the original file. This *preserves* ownership rather than
recreating it (whether fakeroot is capable of picking up on it or not)
and, for the first time ever, preserves xattrs too.

https://git.archlinux.org/pacman.git/commit/?id=88d054093c1c99a697d95b26bd9aad5bc4d8e170

So our use case for packaging under fakeroot is no longer affected (once
this change percolates to a release).

-- 
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User


More information about the Binutils mailing list