Skip to content

Commit

Permalink
Don't mount /dev/ inside privileged containers running systemd
Browse files Browse the repository at this point in the history
According to https://systemd.io/CONTAINER_INTERFACE/, systemd will try take
control over /dev/tty if exported, which can cause conflicts with the host's tty
in privileged containers. Thus we will not expose these to privileged containers
in systemd mode, as this is a bad idea according to systemd's maintainers.

This fixes containers#15878

Signed-off-by: Dan Čermák <dcermak@suse.com>
  • Loading branch information
dcermak committed Sep 22, 2022
1 parent a49aa13 commit 85cfd18
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion libpod/container_internal_common.go
Expand Up @@ -109,7 +109,11 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
// If the flag to mount all devices is set for a privileged container, add
// all the devices from the host's machine into the container
if c.config.MountAllDevices {
if err := util.AddPrivilegedDevices(&g); err != nil {
systemdMode := false
if c.config.Systemd != nil {
systemdMode = *c.config.Systemd
}
if err := util.AddPrivilegedDevices(&g, systemdMode); err != nil {
return nil, err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/utils_freebsd.go
Expand Up @@ -13,6 +13,6 @@ func GetContainerPidInformationDescriptors() ([]string, error) {
return []string{}, errors.New("this function is not supported on freebsd")
}

func AddPrivilegedDevices(g *generate.Generator) error {
func AddPrivilegedDevices(g *generate.Generator, systemdMode bool) error {
return nil
}
5 changes: 4 additions & 1 deletion pkg/util/utils_linux.go
Expand Up @@ -70,7 +70,7 @@ func FindDeviceNodes() (map[string]string, error) {
return nodes, nil
}

func AddPrivilegedDevices(g *generate.Generator) error {
func AddPrivilegedDevices(g *generate.Generator, systemdMode bool) error {
hostDevices, err := getDevices("/dev")
if err != nil {
return err
Expand Down Expand Up @@ -104,6 +104,9 @@ func AddPrivilegedDevices(g *generate.Generator) error {
}
} else {
for _, d := range hostDevices {
if systemdMode && strings.HasPrefix(d.Path, "/dev/tty") {
continue
}
g.AddDevice(d)
}
// Add resources device - need to clear the existing one first.
Expand Down

0 comments on commit 85cfd18

Please sign in to comment.