Skip to content

Commit

Permalink
SetupRootless(): only reexec when needed
Browse files Browse the repository at this point in the history
We should never try to reexxec when we are already root with
CAP_SYS_ADMIN. The code contained a bug when --cgroups=disabled is used
as it tried to perfom a reexec even when it was not needed.

Fixes: 900e295 ("libpod: do not move podman with --cgroups=disabled")

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Jul 8, 2024
1 parent 3350cd3 commit a2c83cb
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pkg/domain/infra/abi/system_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,16 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, noMoveProcess bool,
}
}

configureCgroup := cgroupMode != "disabled"
if configureCgroup {
hasCapSysAdmin, err := unshare.HasCapSysAdmin()
if err != nil {
return err
}

// check for both euid == 0 and CAP_SYS_ADMIN because we may be running in a container with CAP_SYS_ADMIN set.
if os.Geteuid() == 0 && hasCapSysAdmin {
// do it only after podman has already re-execed and running with uid==0.
hasCapSysAdmin, err := unshare.HasCapSysAdmin()
if err != nil {
return err
}
// check for both euid == 0 and CAP_SYS_ADMIN because we may be running in a container with CAP_SYS_ADMIN set.
if os.Geteuid() == 0 && hasCapSysAdmin {
configureCgroup := cgroupMode != "disabled"
if configureCgroup {
ownsCgroup, err := cgroups.UserOwnsCurrentSystemdCgroup()
if err != nil {
logrus.Infof("Failed to detect the owner for the current cgroup: %v", err)
Expand All @@ -55,8 +56,8 @@ func (ic *ContainerEngine) SetupRootless(_ context.Context, noMoveProcess bool,
}
}
}
return nil
}
return nil
}

pausePidPath, err := util.GetRootlessPauseProcessPidPath()
Expand Down

0 comments on commit a2c83cb

Please sign in to comment.