[Toybox] [PATCH] Correct Setting of uid and gid when extracting CPIO archive

Mike Moreton Mike.Moreton at frontier-silicon.com
Wed Dec 2 05:39:07 PST 2015


Hi, I've fixed a couple of bugs in cpio.

When you run it as root CPIO is meant to set the uid and guid of files from information in the archive, but it currently doesn't do this because of a couple of bugs:

1)      It's looking at the wrong parts of the header

2)      The "Am I root?" test is coded as "getpid() == 0" rather than "geteuid() == 0".  It's difficult to think of a realistic scenario where the former would be true!

There may be people out there who are depending on the old, incorrect, behaviour, so I've also implemented a "--no-preserve-owner" option (as in GNU cpio) to re-enable this behaviour.  This is separated out in the second patch, but I think both patches need to be added at the same time.

To test it I ran:

cd /tmp && rm -rf s d && (mkdir s d && cp -a /dev/tty s && mkdir s/dir && touch s/file && chown test:system s/* && (cd s && ls | cpio -o > .s.cpio) && (cd d && cpio -i < ../s/.s.cpio) && (ls -l s ; ls -l d)) ; rm -rf /tmp/d

Before the change I got:

total 0

drwxr-xr-x 2 test system     40 1970-01-01 00:21 dir

-rw-r--r-- 1 test system      0 1970-01-01 00:21 file

crw-rw-rw- 1 test system 5,   0 1970-01-01 00:00 tty

total 0

drwxr-xr-x 2 root root     40 1970-01-01 00:21 dir

-rw-r--r-- 1 root root      0 1970-01-01 00:21 file

crw-r--r-- 1 root root 0,  13 1970-01-01 00:00 tty

and afterwards:

total 0

drwxr-xr-x 2 test system     40 1970-01-01 00:02 dir

-rw-r--r-- 1 test system      0 1970-01-01 00:02 file

crw-rw-rw- 1 test system 5,   0 1970-01-01 00:00 tty

total 0

drwxr-xr-x 2 test system     40 1970-01-01 00:02 dir

-rw-r--r-- 1 test system      0 1970-01-01 00:02 file

crw-r--r-- 1 test system 5,   0 1970-01-01 00:00 tty

I also checked that --no-preserve-owner works as expected, and that non-root operation doesn't preserve the ownership info.

Mike.






Mike Moreton
Software Project Leader
Frontier Silicon Ltd

D +44 1223 497780

www.frontier-silicon.com <http://www.frontier-silicon.com/>
Ashwell Point, Babraham Road, Sawston, Cambridge, CB22 3LJ, UK

Frontier Silicon Ltd is a Toumaz Group company (the Group also includes Sensium Healthcare and Frontier Microsystems), registered in England and Wales - company no. 4213838. Registered address: 137 Euston Road, London, NW1 2AA
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20151202/1416e758/attachment-0003.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Correct-setting-of-guid-and-uid-when-extracting-from.patch
Type: application/octet-stream
Size: 3174 bytes
Desc: 0001-Correct-setting-of-guid-and-uid-when-extracting-from.patch
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20151202/1416e758/attachment-0008.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-CPIO-Add-no-preserve-owner-option.patch
Type: application/octet-stream
Size: 2581 bytes
Desc: 0002-CPIO-Add-no-preserve-owner-option.patch
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20151202/1416e758/attachment-0009.obj>


More information about the Toybox mailing list