Skip to content

Commit

Permalink
merge #4039 into opencontainers/runc:main
Browse files Browse the repository at this point in the history
Kir Kolyshkin (1):
  libct: use chmod instead of umask

LGTMs: lifubang cyphar
  • Loading branch information
cyphar committed Oct 4, 2023
2 parents 634280f + 2e2ecf2 commit 9350f90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions libcontainer/console_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import (
// mount initializes the console inside the rootfs mounting with the specified mount label
// and applying the correct ownership of the console.
func mountConsole(slavePath string) error {
oldMask := unix.Umask(0o000)
defer unix.Umask(oldMask)
f, err := os.Create("/dev/console")
if err != nil && !os.IsExist(err) {
return err
}
if f != nil {
// Ensure permission bits (can be different because of umask).
if err := f.Chmod(0o666); err != nil {
return err
}
f.Close()
}
return mount(slavePath, "/dev/console", "bind", unix.MS_BIND, "")
Expand Down
7 changes: 4 additions & 3 deletions libcontainer/container_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,13 @@ func (c *Container) createExecFifo() error {
if _, err := os.Stat(fifoName); err == nil {
return fmt.Errorf("exec fifo %s already exists", fifoName)
}
oldMask := unix.Umask(0o000)
if err := unix.Mkfifo(fifoName, 0o622); err != nil {
unix.Umask(oldMask)
return &os.PathError{Op: "mkfifo", Path: fifoName, Err: err}
}
// Ensure permission bits (can be different because of umask).
if err := os.Chmod(fifoName, 0o622); err != nil {
return err
}
unix.Umask(oldMask)
return os.Chown(fifoName, rootuid, rootgid)
}

Expand Down
7 changes: 4 additions & 3 deletions libcontainer/rootfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,6 @@ func reOpenDevNull() error {
// Create the device nodes in the container.
func createDevices(config *configs.Config) error {
useBindMount := userns.RunningInUserNS() || config.Namespaces.Contains(configs.NEWUSER)
oldMask := unix.Umask(0o000)
for _, node := range config.Devices {

// The /dev/ptmx device is setup by setupPtmx()
Expand All @@ -715,11 +714,9 @@ func createDevices(config *configs.Config) error {
// containers running in a user namespace are not allowed to mknod
// devices so we can just bind mount it from the host.
if err := createDeviceNode(config.Rootfs, node, useBindMount); err != nil {
unix.Umask(oldMask)
return err
}
}
unix.Umask(oldMask)
return nil
}

Expand Down Expand Up @@ -782,6 +779,10 @@ func mknodDevice(dest string, node *devices.Device) error {
if err := unix.Mknod(dest, uint32(fileMode), int(dev)); err != nil {
return &os.PathError{Op: "mknod", Path: dest, Err: err}
}
// Ensure permission bits (can be different because of umask).
if err := os.Chmod(dest, fileMode); err != nil {
return err
}
return os.Chown(dest, int(node.Uid), int(node.Gid))
}

Expand Down

0 comments on commit 9350f90

Please sign in to comment.