Repository navigation
open(O_PATH|O_NOFOLLOW) of a symlink opens the link: tar -p no longer fails - #32
Merged
Merged
Conversation
… fails tar extracting as root (node_modules/.bin links, in a node:24 container) printed "Cannot change mode to rwxrwxrwx: Too many levels of symbolic links" for each symlink and exited 2. tar chmods every link it makes with fchmodat(AT_SYMLINK_NOFOLLOW); glibc before 2.39 does that by opening the path with O_PATH|O_NOFOLLOW, fstat'ing the descriptor and answering EOPNOTSUPP for a link, which tar ignores. The engine opened O_PATH as a plain read-only open, so O_NOFOLLOW on a symlink failed with ELOOP and tar reported it. An O_PATH|O_NOFOLLOW open of a symlink on disk now opens the link itself (macOS O_SYMLINK, still with O_NOFOLLOW_ANY so no link before the leaf is followed); fstat on it reports S_IFLNK. Without O_PATH, O_NOFOLLOW on a link is ELOOP as before. Links in the in-memory layer already worked. tests/native/opath_link_guest.c (fork suite) checks a dangling link and a link to a file: the O_PATH open, fstat and fstatat(AT_EMPTY_PATH) give S_IFLNK, O_NOFOLLOW alone is ELOOP, fchmodat2 NOFOLLOW is EOPNOTSUPP, and O_PATH without O_NOFOLLOW reaches the file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Extracting a tar archive as root in a container (for example
node_modules/.binlinks innode:24) printedCannot change mode to rwxrwxrwx: Too many levels of symbolic linksfor every symlink, and tar exited 2.tar chmods each link it makes with
fchmodat(AT_SYMLINK_NOFOLLOW). glibc before 2.39 implements that call in three steps:O_PATH|O_NOFOLLOW.fstatthe descriptor.EOPNOTSUPPfor a link, which tar ignores.The engine handled
O_PATHas a plain read-only open, so step 1 failed withELOOP.Fix
native/fs.hfs_open: anO_PATH|O_NOFOLLOWopen of a symlink on disk now opens the link itself.O_SYMLINK, still together withO_NOFOLLOW_ANY, so no link before the leaf is followed.fstaton the descriptor reportsS_IFLNK.O_NOFOLLOWwithoutO_PATHstill returnsELOOP.O_SYMLINKasO_PATH's value.Tests
tests/native/opath_link_guest.cwas added toverify_fork_sockets.py. It covers a dangling link and a link to a file:O_PATH|O_NOFOLLOWopen,fstatandfstatat(AT_EMPTY_PATH)giveS_IFLNK;O_NOFOLLOWalone givesELOOP;fchmodat2withAT_SYMLINK_NOFOLLOWgivesEOPNOTSUPP;O_PATHwithoutO_NOFOLLOWreaches the file.verify_fork_sockets.py --cpus 1and--cpus 4: 100 PASS, 0 FAIL each (interpreter and hvf).go test -race ./...: ok.verify_dockivad.py --new-homeon the bundle: 31/31.node:24on a test engine:../../b/tlink gives rc 0, andopen(O_PATH|O_NOFOLLOW)works;ELOOP.gcc:14.