From fffc111ba8e8939bed934df1a17d350d000308c1 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Wed, 28 Feb 2018 03:01:02 +0900 Subject: [PATCH] archive: fix logic for skipping mknod when running in userns Signed-off-by: Akihiro Suda --- archive/tar_unix.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/archive/tar_unix.go b/archive/tar_unix.go index f577996ee..72651aea9 100644 --- a/archive/tar_unix.go +++ b/archive/tar_unix.go @@ -87,10 +87,6 @@ func mkdir(path string, perm os.FileMode) error { return os.Chmod(path, perm) } -func skipFile(*tar.Header) bool { - return false -} - var ( inUserNS bool nsOnce sync.Once @@ -100,15 +96,22 @@ func setInUserNS() { inUserNS = system.RunningInUserNS() } -// handleTarTypeBlockCharFifo is an OS-specific helper function used by -// createTarFile to handle the following types of header: Block; Char; Fifo -func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error { - nsOnce.Do(setInUserNS) - if inUserNS { +func skipFile(hdr *tar.Header) bool { + switch hdr.Typeflag { + case tar.TypeBlock, tar.TypeChar: // cannot create a device if running in user namespace - return nil + nsOnce.Do(setInUserNS) + return inUserNS + default: + return false } +} +// handleTarTypeBlockCharFifo is an OS-specific helper function used by +// createTarFile to handle the following types of header: Block; Char; Fifo. +// This function must not be called for Block and Char when running in userns. +// (skipFile() should return true for them.) +func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error { mode := uint32(hdr.Mode & 07777) switch hdr.Typeflag { case tar.TypeBlock: