Skip to content

Commit 379ce56

Browse files
committed
pkg/archive: handleTarTypeBlockCharFifo: don't discard EPERM errors
This function was discarding EPERM errors if it detected that userns was enabled; move such checks to the caller-site, so that they can decide how to handle the error (which, in case of userns may be to log and ignore). Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent af85e47 commit 379ce56

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

pkg/archive/archive.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, o
712712

713713
case tar.TypeBlock, tar.TypeChar:
714714
if inUserns { // cannot create devices in a userns
715+
log.G(context.TODO()).WithFields(log.Fields{"path": path, "type": hdr.Typeflag}).Debug("skipping device nodes in a userns")
715716
return nil
716717
}
717718
// Handle this is an OS-specific way
@@ -722,6 +723,11 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, o
722723
case tar.TypeFifo:
723724
// Handle this is an OS-specific way
724725
if err := handleTarTypeBlockCharFifo(hdr, path); err != nil {
726+
if inUserns && errors.Is(err, syscall.EPERM) {
727+
// In most cases, cannot create a fifo if running in user namespace
728+
log.G(context.TODO()).WithFields(log.Fields{"error": err, "path": path, "type": hdr.Typeflag}).Debug("creating fifo node in a userns")
729+
return nil
730+
}
725731
return err
726732
}
727733

pkg/archive/archive_unix.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"strings"
1212
"syscall"
1313

14-
"github.com/containerd/containerd/pkg/userns"
1514
"github.com/docker/docker/pkg/idtools"
1615
"github.com/docker/docker/pkg/system"
1716
"golang.org/x/sys/unix"
@@ -95,7 +94,10 @@ func getFileUIDGID(stat interface{}) (idtools.Identity, error) {
9594
}
9695

9796
// handleTarTypeBlockCharFifo is an OS-specific helper function used by
98-
// createTarFile to handle the following types of header: Block; Char; Fifo
97+
// createTarFile to handle the following types of header: Block; Char; Fifo.
98+
//
99+
// Creating device nodes is not supported when running in a user namespace,
100+
// produces a [syscall.EPERM] in most cases.
99101
func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
100102
mode := uint32(hdr.Mode & 0o7777)
101103
switch hdr.Typeflag {
@@ -107,12 +109,7 @@ func handleTarTypeBlockCharFifo(hdr *tar.Header, path string) error {
107109
mode |= unix.S_IFIFO
108110
}
109111

110-
err := system.Mknod(path, mode, int(system.Mkdev(hdr.Devmajor, hdr.Devminor)))
111-
if errors.Is(err, syscall.EPERM) && userns.RunningInUserNS() {
112-
// In most cases, cannot create a device if running in user namespace
113-
err = nil
114-
}
115-
return err
112+
return system.Mknod(path, mode, int(system.Mkdev(hdr.Devmajor, hdr.Devminor)))
116113
}
117114

118115
func handleLChmod(hdr *tar.Header, path string, hdrInfo os.FileInfo) error {

0 commit comments

Comments
 (0)