Debian Codegraph @

localfs_mknod_other.go

raw
1 //go:build !linux && !windows
2
3 package desync
4
5 import (
6 "os"
7 "path"
8 "path/filepath"
9
10 "golang.org/x/sys/unix"
11 )
12
13 // createDeviceNode creates a device node confined to the extraction root.
14 // Darwin (and other non-Linux Unix) has no mknodat(2), so the parent
15 // directory is first resolved through the os.Root handle - which refuses to
16 // traverse any symlink that escapes the root - to validate confinement, and
17 // the node is then created on the corresponding real path. Extraction is
18 // single-threaded, so there is no concurrent attacker able to swap a
19 // component between this check and the mknod call.
20 func (fs *LocalFS) createDeviceNode(r *os.Root, n NodeDevice) error {
21 df, err := r.Open(path.Dir(n.Name))
22 if err != nil {
23 return err
24 }
25 df.Close()
26 dst := filepath.Join(fs.rootReal, n.Name)
27 return unix.Mknod(dst, FilemodeToStatMode(n.Mode)|0666, int(mkdev(n.Major, n.Minor)))
28 }