Skip to content

Commit bcdd0d0

Browse files
ayushr2gvisor-bot
authored andcommitted
Update tmpfs root inode metadata from tar header.
When reading from a tar file, use the root dir metadata (UID, GID, Mode, MTime) to update the tmpfs filesystem's root inode. Previously, the root inode was always pre-populated in the path map without considering the tar header's metadata. PiperOrigin-RevId: 824690885
1 parent f611d7f commit bcdd0d0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pkg/sentry/fsimpl/tmpfs/tar.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func (fs *filesystem) UntarUpperLayer(ctx context.Context, inFile *os.File) erro
5050
// - filesystem.mu must be locked.
5151
func (fs *filesystem) readFromTar(ctx context.Context, tr *tar.Reader) error {
5252
pathToInode := map[string]*inode{}
53-
pathToInode["./"] = fs.root.inode
5453
directoryToHeader := map[string]*tar.Header{}
5554
fileToHeader := map[string]*tar.Header{}
5655
symlinkToHeader := map[string]*tar.Header{}
@@ -127,6 +126,15 @@ func (fs *filesystem) mkdirFromTar(hdr *tar.Header, pathToInode map[string]*inod
127126
if ino, ok := pathToInode[hdr.Name]; ok {
128127
return ino, nil
129128
}
129+
if hdr.Name == "./" {
130+
ino := fs.root.inode
131+
ino.uid.Store(uint32(hdr.Uid))
132+
ino.gid.Store(uint32(hdr.Gid))
133+
ino.mode.Store(uint32(hdr.Mode) | linux.S_IFDIR)
134+
ino.mtime.Store(hdr.ModTime.UnixNano())
135+
pathToInode[hdr.Name] = ino
136+
return ino, nil
137+
}
130138
dir, name := filepath.Split(strings.TrimSuffix(path, "/"))
131139
parentInode, ok := pathToInode[dir]
132140
if !ok {

0 commit comments

Comments
 (0)