Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,24 @@ func startInitialization() (retErr error) {
return err
}

if _, err := unix.Setsid(); err != nil {
return os.NewSyscallError("setsid", err)
}

if err := unix.Setuid(0); err != nil {
return os.NewSyscallError("setuid", err)
}

if err := unix.Setgid(0); err != nil {
return os.NewSyscallError("setgid", err)
}

if !config.Config.RootlessEUID && requiresRootOrMappingTool(config.Config.GIDMappings) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is requiresRootOrMappingTool() equivalent to config.is_setgroup?

if err := unix.Setgroups([]int{0}); err != nil {
return os.NewSyscallError("setgroups", err)
}
}

// If init succeeds, it will not return, hence none of the defers will be called.
return containerInit(it, &config, syncPipe, consoleSocket, pidfdSocket, fifoFile, logPipe)
}
Expand Down
14 changes: 0 additions & 14 deletions libcontainer/nsenter/nsexec.c
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is there any non async-signal-safe fuction remaining here, as defined in man signal-safety, after the fork/clone?

Original file line number Diff line number Diff line change
Expand Up @@ -782,20 +782,6 @@ void nsexec(void)
prctl(PR_SET_NAME, (unsigned long)"runc:[2:INIT]", 0, 0, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep this. It's way simpler the init stage now, but still things can go wrong (specially since we are doing big changes) and it is useful to have this IMHO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 make sense.

write_log(DEBUG, "~> nsexec stage-2");

if (setsid() < 0)
bail("setsid failed");

if (setuid(0) < 0)
bail("setuid failed");

if (setgid(0) < 0)
bail("setgid failed");

if (!config.is_rootless_euid && config.is_setgroup) {
if (setgroups(0, NULL) < 0)
bail("setgroups failed");
}

close(syncfd);

/* Free netlink data. */
Expand Down