Skip to content

Commit 067dc3c

Browse files
committed
replace some nsexec stage-2 c code with go implemention
Signed-off-by: lifubang <[email protected]>
1 parent 8272332 commit 067dc3c

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

libcontainer/init_linux.go

+18
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,24 @@ func startInitialization() (retErr error) {
222222
return err
223223
}
224224

225+
if _, err := unix.Setsid(); err != nil {
226+
return os.NewSyscallError("setsid", err)
227+
}
228+
229+
if err := unix.Setuid(0); err != nil {
230+
return os.NewSyscallError("setuid", err)
231+
}
232+
233+
if err := unix.Setgid(0); err != nil {
234+
return os.NewSyscallError("setgid", err)
235+
}
236+
237+
if !config.Config.RootlessEUID && requiresRootOrMappingTool(config.Config.GIDMappings) {
238+
if err := unix.Setgroups([]int{0}); err != nil {
239+
return os.NewSyscallError("setgroups", err)
240+
}
241+
}
242+
225243
// If init succeeds, it will not return, hence none of the defers will be called.
226244
return containerInit(it, &config, syncPipe, consoleSocket, pidfdSocket, fifoFile, logPipe)
227245
}

libcontainer/nsenter/nsexec.c

-14
Original file line numberDiff line numberDiff line change
@@ -782,20 +782,6 @@ void nsexec(void)
782782
prctl(PR_SET_NAME, (unsigned long)"runc:[2:INIT]", 0, 0, 0);
783783
write_log(DEBUG, "~> nsexec stage-2");
784784

785-
if (setsid() < 0)
786-
bail("setsid failed");
787-
788-
if (setuid(0) < 0)
789-
bail("setuid failed");
790-
791-
if (setgid(0) < 0)
792-
bail("setgid failed");
793-
794-
if (!config.is_rootless_euid && config.is_setgroup) {
795-
if (setgroups(0, NULL) < 0)
796-
bail("setgroups failed");
797-
}
798-
799785
close(syncfd);
800786

801787
/* Free netlink data. */

0 commit comments

Comments
 (0)