landley / toybox

toybox
http://landley.net/toybox
BSD Zero Clause License
2.44k stars 340 forks source link

tar honor umask test fails on Android #512

Closed kongy closed 4 months ago

kongy commented 4 months ago

When integrating e4a106afa0e93e04c5c73c422fe615c6f7bd96f0 to Android, the newly introduced tar honor umask test fails:

FAIL: tar honor umask
echo -ne '' | umask 0022 && rm -rf dir && mkdir dir && tar xf $FILES/tar/dir.tar && stat -c%A dir dir/file
--- expected    2024-07-23 15:26:31.080000408 +0000
+++ actual  2024-07-23 15:26:31.196000408 +0000
@@ -1,2 +1,2 @@
-drwxr-xr-x
--rwxr-xr-x
+drwxrwxrwx
+-rwxrwxrwx
enh-google commented 4 months ago

fwiw, it's only that test that fails (the two following ones are fine).

one oddity worth mentioning is that the default umask for root on Android is 0?

enh-google commented 4 months ago

strace on the host, where the test passes:

openat(AT_FDCWD, "dir/file", O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0700) = 4
copy_file_range(3, NULL, 4, NULL, 6, 0) = 6
close(4)                                = 0
geteuid()                               = 73769 
chmod("dir/file", 0755)                 = 0

strace on Android, where it fails:

openat(AT_FDCWD, "dir/file", O_WRONLY|O_CREAT|O_EXCL|O_CLOEXEC, 0700) = 4
copy_file_range(3, NULL, 4, NULL, 6, 0) = 6
close(4)                                = 0
geteuid()                               = 0
fchownat(AT_FDCWD, "dir/file", 1000, 1000, AT_SYMLINK_NOFOLLOW) = 0 
fchmodat(AT_FDCWD, "dir/file", 0100777) = 0
enh-google commented 4 months ago

so a bit more printf() debugging, and it looks like in

  if (!S_ISLNK(ala)) chmod(name, FLAG(p) ? ala : ala&0777&~toys.old_umask);

Android always has FLAG(p) set?

which looks like it's probably coming from tar_main()?

  if (!geteuid()) toys.optflags |= FLAG_p;
enh-google commented 4 months ago

(test patch sent to mailing list...)