diff options
author | Andrei Vagin <avagin@google.com> | 2019-01-14 14:07:05 -0800 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2019-01-14 14:08:19 -0800 |
commit | a46b6d453d198b96949342a81750114bfa5a5429 (patch) | |
tree | 71c32eae0ee72b46576226b0266ed63e0bf93463 /runsc/cmd/cmd.go | |
parent | 7182b9cf52087bc354104ad2a23fcf4c468ab20e (diff) |
runsc: set up a minimal chroot from the sandbox process
In this case, new mounts are not created in the host mount namspaces, so
tearDownChroot isn't needed, because chroot will be destroyed with a
sandbox mount namespace.
In additional, pivot_root can't be called instead of chroot.
PiperOrigin-RevId: 229250871
Change-Id: I765bdb587d0b8287a6a8efda8747639d37c7e7b6
Diffstat (limited to 'runsc/cmd/cmd.go')
-rw-r--r-- | runsc/cmd/cmd.go | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/runsc/cmd/cmd.go b/runsc/cmd/cmd.go index a1c3491a3..fbfc18fc9 100644 --- a/runsc/cmd/cmd.go +++ b/runsc/cmd/cmd.go @@ -86,6 +86,28 @@ func setCapsAndCallSelf(args []string, caps *specs.LinuxCapabilities) error { } log.Infof("Execve %q again, bye!", binPath) - syscall.Exec(binPath, args, []string{}) - panic("unreachable") + err = syscall.Exec(binPath, args, []string{}) + return fmt.Errorf("error executing %s: %v", binPath, err) +} + +// callSelfAsNobody sets UID and GID to nobody and then execve's itself again. +func callSelfAsNobody(args []string) error { + // Keep thread locked while user/group are changed. + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + const nobody = 65534 + + if _, _, err := syscall.RawSyscall(syscall.SYS_SETGID, uintptr(nobody), 0, 0); err != 0 { + return fmt.Errorf("error setting uid: %v", err) + } + if _, _, err := syscall.RawSyscall(syscall.SYS_SETUID, uintptr(nobody), 0, 0); err != 0 { + return fmt.Errorf("error setting gid: %v", err) + } + + binPath := "/runsc" + + log.Infof("Execve %q again, bye!", binPath) + err := syscall.Exec(binPath, args, []string{}) + return fmt.Errorf("error executing %s: %v", binPath, err) } |