mainGNU tar - Support: sr #110903, extraction fails with...


sr #110903: extraction fails with "permission denied" when using "--xattrs"

Submitter:  None
Submitted:  Mon 24 Jul 2023 06:52:25 PM UTC
Category:  None Priority:  5 - Normal
Severity:  3 - Normal Status:  None
Privacy:  Public Assigned to:  None
Originator Email:  -email is unavailable- Open/Closed:  Open
Operating System:  None
* Mandatory Fields

Add a New Comment Rich Markup

Mon 24 Jul 2023 06:52:25 PM UTC, original submission:  

While trying to extract a tarball with somewhat unusual permissions, I encountered an error that only seems to happen when the "--xattrs" flag is specified. The tarball in question can be found here, but I've cooked up a simpler working example. Here's a script I've called "" (also attached)


# cleanup previous
rm -rf foo foo.tgz

# setup directory
mkdir foo
touch foo/noperms
chmod 000 foo/noperms

# modify acl
sudo setfacl -m "u:$USER:r" foo/noperms

# tar it
sudo tar --xattrs -czf foo.tgz foo

# un-tar
tar --xattrs -xvf foo.tgz

Running the script, you get

$ ./
[sudo] password:
tar: foo/noperms: Cannot open: Permission denied
tar: Exiting with failure status due to previous errors

which is the exact permission error I encountered with the centos7 tarball. I've used the tarball generated from "" and strace(1) to track the system calls made from both a successful and a failed extraction as follows:

$ mkdir foo_unpacked
$ strace -f -o strace_fail.txt tar --xattrs -xf foo.tgz -C foo_unpacked
tar: foo/noperms: Cannot open: Permission denied
tar: Exiting with failure status due to previous errors
$ rm -rf foo_unpacked
$ mkdir foo_unpacked
$ strace -f -o strace_success.txt tar  -xf foo.tgz -C foo_unpacked

Inspecting the files generated by strace(1), it seems the failure with "--xattrs" specified occurs here

455955 mkdirat(4, "foo", 0775)          = 0
455955 mknodat(4, "foo/noperms", 040)   = 0
455955 openat(4, "foo/noperms", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK|O_CLOEXEC, 040) = -1 EACCES (Permission denied)

So what seems to be happening is that tar calls mknodat(2) to create the file with unusual permissions (noperms), then calls openat(2) to open the file, which fails with EACCESS due to said permissions. When "--xattrs" is not specified, strace(1) gives you this:

455963 mkdirat(4, "foo", 0775)          = 0
455963 openat(4, "foo/noperms", O_WRONLY|O_CREAT|O_EXCL|O_NOCTTY|O_NONBLOCK|O_CLOEXEC, 040) = 5

The key difference here seems to be the absence of a mknodat(2) call. It looks like openat(2) is successful in this case because it is also creating the file.



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #54961: added by None (255B - text/x-sh)
file #54962:  strace_success.txt added by None (17KiB - text/plain)
file #54963:  strace_fail.txt added by None (19KiB - text/plain)


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by None (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.


    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-07-24 None Attached File- Added, #54961
        Attached File- Added strace_success.txt, #54962
        Attached File- Added strace_fail.txt, #54963

    Back to the top

    Powered by Savane 3.13-b921.
    Corresponding source code