Skip to content

Commit a3372da

Browse files
committed
archive: fix logic for skipping mknod when running in userns
Signed-off-by: Akihiro Suda <[email protected]>
1 parent cfd0439 commit a3372da

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

archive/tar_unix.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ func mkdir(path string, perm os.FileMode) error {
6767
return os.Chmod(path, perm)
6868
}
6969

70-
func skipFile(*tar.Header) bool {
71-
return false
72-
}
73-
7470
var (
7571
inUserNS bool
7672
nsOnce sync.Once
@@ -80,15 +76,22 @@ func setInUserNS() {
8076
inUserNS = system.RunningInUserNS()
8177
}
8278

83-
// handleTarTypeBlockCharFifo is an OS-specific helper function used by
84-
// createTarFile to handle the following types of header: Block; Char; Fifo
85-
func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
86-
nsOnce.Do(setInUserNS)
87-
if inUserNS {
79+
func skipFile(hdr *tar.Header) bool {
80+
switch hdr.Typeflag {
81+
case tar.TypeBlock, tar.TypeChar:
8882
// cannot create a device if running in user namespace
89-
return nil
83+
nsOnce.Do(setInUserNS)
84+
return inUserNS
85+
default:
86+
return false
9087
}
88+
}
9189

90+
// handleTarTypeBlockCharFifo is an OS-specific helper function used by
91+
// createTarFile to handle the following types of header: Block; Char; Fifo.
92+
// This function must not be called for Block and Char when running in userns.
93+
// (skipFile() should return true for them.)
94+
func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
9295
mode := uint32(hdr.Mode & 07777)
9396
switch hdr.Typeflag {
9497
case tar.TypeBlock:

0 commit comments

Comments
 (0)