exec_linux.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. // Copyright 2011 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. //go:build linux
  5. package syscall
  6. import (
  7. "internal/itoa"
  8. "unsafe"
  9. )
  10. //sysnb raw_prctl(option int, arg2 int, arg3 int, arg4 int, arg5 int) (ret int, err Errno)
  11. //prctl(option _C_int, arg2 _C_long, arg3 _C_long, arg4 _C_long, arg5 _C_long) _C_int
  12. //sysnb rawUnshare(flags int) (err Errno)
  13. //unshare(flags _C_int) _C_int
  14. //sysnb rawMount(source *byte, target *byte, fstype *byte, flags uintptr, data *byte) (err Errno)
  15. //mount(source *byte, target *byte, fstype *byte, flags _C_long, data *byte) _C_int
  16. //sysnb rawOpenat(dirfd int, pathname *byte, flags int, perm uint32) (fd int, err Errno)
  17. //__go_openat(dirfd _C_int, pathname *byte, flags _C_int, perm Mode_t) _C_int
  18. // SysProcIDMap holds Container ID to Host ID mappings used for User Namespaces in Linux.
  19. // See user_namespaces(7).
  20. type SysProcIDMap struct {
  21. ContainerID int // Container ID.
  22. HostID int // Host ID.
  23. Size int // Size.
  24. }
  25. type SysProcAttr struct {
  26. Chroot string // Chroot.
  27. Credential *Credential // Credential.
  28. // Ptrace tells the child to call ptrace(PTRACE_TRACEME).
  29. // Call runtime.LockOSThread before starting a process with this set,
  30. // and don't call UnlockOSThread until done with PtraceSyscall calls.
  31. Ptrace bool
  32. Setsid bool // Create session.
  33. // Setpgid sets the process group ID of the child to Pgid,
  34. // or, if Pgid == 0, to the new child's process ID.
  35. Setpgid bool
  36. // Setctty sets the controlling terminal of the child to
  37. // file descriptor Ctty. Ctty must be a descriptor number
  38. // in the child process: an index into ProcAttr.Files.
  39. // This is only meaningful if Setsid is true.
  40. Setctty bool
  41. Noctty bool // Detach fd 0 from controlling terminal
  42. Ctty int // Controlling TTY fd
  43. // Foreground places the child process group in the foreground.
  44. // This implies Setpgid. The Ctty field must be set to
  45. // the descriptor of the controlling TTY.
  46. // Unlike Setctty, in this case Ctty must be a descriptor
  47. // number in the parent process.
  48. Foreground bool
  49. Pgid int // Child's process group ID if Setpgid.
  50. Pdeathsig Signal // Signal that the process will get when its parent dies (Linux and FreeBSD only)
  51. Cloneflags uintptr // Flags for clone calls (Linux only)
  52. Unshareflags uintptr // Flags for unshare calls (Linux only)
  53. UidMappings []SysProcIDMap // User ID mappings for user namespaces.
  54. GidMappings []SysProcIDMap // Group ID mappings for user namespaces.
  55. // GidMappingsEnableSetgroups enabling setgroups syscall.
  56. // If false, then setgroups syscall will be disabled for the child process.
  57. // This parameter is no-op if GidMappings == nil. Otherwise for unprivileged
  58. // users this should be set to false for mappings work.
  59. GidMappingsEnableSetgroups bool
  60. AmbientCaps []uintptr // Ambient capabilities (Linux only)
  61. }
  62. var (
  63. none = [...]byte{'n', 'o', 'n', 'e', 0}
  64. slash = [...]byte{'/', 0}
  65. )
  66. // Implemented in runtime package.
  67. func runtime_BeforeFork()
  68. func runtime_AfterFork()
  69. func runtime_AfterForkInChild()
  70. // Implemented in clone_linux.c
  71. //go:noescape
  72. func rawClone(flags _C_ulong, child_stack *byte, ptid *Pid_t, ctid *Pid_t, regs unsafe.Pointer) _C_long
  73. // Fork, dup fd onto 0..len(fd), and exec(argv0, argvv, envv) in child.
  74. // If a dup or exec fails, write the errno error to pipe.
  75. // (Pipe is close-on-exec so if exec succeeds, it will be closed.)
  76. // In the child, this function must not acquire any locks, because
  77. // they might have been locked at the time of the fork. This means
  78. // no rescheduling, no malloc calls, and no new stack segments.
  79. // For the same reason compiler does not race instrument it.
  80. // The calls to RawSyscall are okay because they are assembly
  81. // functions that do not grow the stack.
  82. //go:norace
  83. func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) {
  84. // Set up and fork. This returns immediately in the parent or
  85. // if there's an error.
  86. r1, err1, p, locked := forkAndExecInChild1(argv0, argv, envv, chroot, dir, attr, sys, pipe)
  87. if locked {
  88. runtime_AfterFork()
  89. }
  90. if err1 != 0 {
  91. return 0, err1
  92. }
  93. // parent; return PID
  94. pid = int(r1)
  95. if sys.UidMappings != nil || sys.GidMappings != nil {
  96. Close(p[0])
  97. var err2 Errno
  98. // uid/gid mappings will be written after fork and unshare(2) for user
  99. // namespaces.
  100. if sys.Unshareflags&CLONE_NEWUSER == 0 {
  101. if err := writeUidGidMappings(pid, sys); err != nil {
  102. err2 = err.(Errno)
  103. }
  104. }
  105. raw_write(p[1], (*byte)(unsafe.Pointer(&err2)), int(unsafe.Sizeof(err2)))
  106. Close(p[1])
  107. }
  108. return pid, 0
  109. }
  110. const _LINUX_CAPABILITY_VERSION_3 = 0x20080522
  111. type capHeader struct {
  112. version uint32
  113. pid int32
  114. }
  115. type capData struct {
  116. effective uint32
  117. permitted uint32
  118. inheritable uint32
  119. }
  120. type caps struct {
  121. hdr capHeader
  122. data [2]capData
  123. }
  124. // See CAP_TO_INDEX in linux/capability.h:
  125. func capToIndex(cap uintptr) uintptr { return cap >> 5 }
  126. // See CAP_TO_MASK in linux/capability.h:
  127. func capToMask(cap uintptr) uint32 { return 1 << uint(cap&31) }
  128. // forkAndExecInChild1 implements the body of forkAndExecInChild up to
  129. // the parent's post-fork path. This is a separate function so we can
  130. // separate the child's and parent's stack frames if we're using
  131. // vfork.
  132. //
  133. // This is go:noinline because the point is to keep the stack frames
  134. // of this and forkAndExecInChild separate.
  135. //
  136. //go:noinline
  137. //go:norace
  138. func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr *ProcAttr, sys *SysProcAttr, pipe int) (r1 uintptr, err1 Errno, p [2]int, locked bool) {
  139. // Defined in linux/prctl.h starting with Linux 4.3.
  140. const (
  141. PR_CAP_AMBIENT = 0x2f
  142. PR_CAP_AMBIENT_RAISE = 0x2
  143. )
  144. // vfork requires that the child not touch any of the parent's
  145. // active stack frames. Hence, the child does all post-fork
  146. // processing in this stack frame and never returns, while the
  147. // parent returns immediately from this frame and does all
  148. // post-fork processing in the outer frame.
  149. // Declare all variables at top in case any
  150. // declarations require heap allocation (e.g., err1).
  151. var (
  152. err2 Errno
  153. nextfd int
  154. i int
  155. r2 int
  156. caps caps
  157. fd1 int
  158. puid, psetgroups, pgid []byte
  159. uidmap, setgroups, gidmap []byte
  160. )
  161. if sys.UidMappings != nil {
  162. puid = []byte("/proc/self/uid_map\000")
  163. uidmap = formatIDMappings(sys.UidMappings)
  164. }
  165. if sys.GidMappings != nil {
  166. psetgroups = []byte("/proc/self/setgroups\000")
  167. pgid = []byte("/proc/self/gid_map\000")
  168. if sys.GidMappingsEnableSetgroups {
  169. setgroups = []byte("allow\000")
  170. } else {
  171. setgroups = []byte("deny\000")
  172. }
  173. gidmap = formatIDMappings(sys.GidMappings)
  174. }
  175. // Record parent PID so child can test if it has died.
  176. ppid := raw_getpid()
  177. // Guard against side effects of shuffling fds below.
  178. // Make sure that nextfd is beyond any currently open files so
  179. // that we can't run the risk of overwriting any of them.
  180. fd := make([]int, len(attr.Files))
  181. nextfd = len(attr.Files)
  182. for i, ufd := range attr.Files {
  183. if nextfd < int(ufd) {
  184. nextfd = int(ufd)
  185. }
  186. fd[i] = int(ufd)
  187. }
  188. nextfd++
  189. // Allocate another pipe for parent to child communication for
  190. // synchronizing writing of User ID/Group ID mappings.
  191. if sys.UidMappings != nil || sys.GidMappings != nil {
  192. if err := forkExecPipe(p[:]); err != nil {
  193. err1 = err.(Errno)
  194. return
  195. }
  196. }
  197. // About to call fork.
  198. // No more allocation or calls of non-assembly functions.
  199. runtime_BeforeFork()
  200. locked = true
  201. r2 = int(rawClone(_C_ulong(uintptr(SIGCHLD)|sys.Cloneflags), nil, nil, nil, unsafe.Pointer(nil)))
  202. if r2 < 0 {
  203. err1 = GetErrno()
  204. }
  205. if r2 != 0 {
  206. // If we're in the parent, we must return immediately
  207. // so we're not in the same stack frame as the child.
  208. // This can at most use the return PC, which the child
  209. // will not modify, and the results of
  210. // rawVforkSyscall, which must have been written after
  211. // the child was replaced.
  212. r1 = uintptr(r2)
  213. return
  214. }
  215. // Fork succeeded, now in child.
  216. // Enable the "keep capabilities" flag to set ambient capabilities later.
  217. if len(sys.AmbientCaps) > 0 {
  218. _, err1 = raw_prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0)
  219. if err1 != 0 {
  220. goto childerror
  221. }
  222. }
  223. // Wait for User ID/Group ID mappings to be written.
  224. if sys.UidMappings != nil || sys.GidMappings != nil {
  225. if err1 = raw_close(p[1]); err1 != 0 {
  226. goto childerror
  227. }
  228. r2, err1 = raw_read(p[0], (*byte)(unsafe.Pointer(&err2)), int(unsafe.Sizeof(err2)))
  229. if err1 != 0 {
  230. goto childerror
  231. }
  232. if r2 != int(unsafe.Sizeof(err2)) {
  233. err1 = EINVAL
  234. goto childerror
  235. }
  236. if err2 != 0 {
  237. err1 = err2
  238. goto childerror
  239. }
  240. }
  241. // Session ID
  242. if sys.Setsid {
  243. err1 = raw_setsid()
  244. if err1 != 0 {
  245. goto childerror
  246. }
  247. }
  248. // Set process group
  249. if sys.Setpgid || sys.Foreground {
  250. // Place child in process group.
  251. err1 = raw_setpgid(0, sys.Pgid)
  252. if err1 != 0 {
  253. goto childerror
  254. }
  255. }
  256. if sys.Foreground {
  257. pgrp := Pid_t(sys.Pgid)
  258. if pgrp == 0 {
  259. pgrp = raw_getpid()
  260. }
  261. // Place process group in foreground.
  262. _, err1 = raw_ioctl_ptr(sys.Ctty, TIOCSPGRP, unsafe.Pointer(&pgrp))
  263. if err1 != 0 {
  264. goto childerror
  265. }
  266. }
  267. // Restore the signal mask. We do this after TIOCSPGRP to avoid
  268. // having the kernel send a SIGTTOU signal to the process group.
  269. runtime_AfterForkInChild()
  270. // Unshare
  271. if sys.Unshareflags != 0 {
  272. err1 = rawUnshare(int(sys.Unshareflags))
  273. if err1 != 0 {
  274. goto childerror
  275. }
  276. if sys.Unshareflags&CLONE_NEWUSER != 0 && sys.GidMappings != nil {
  277. dirfd := int(_AT_FDCWD)
  278. if fd1, err1 = rawOpenat(dirfd, &psetgroups[0], O_WRONLY, 0); err1 != 0 {
  279. goto childerror
  280. }
  281. _, err1 = raw_write(fd1, &setgroups[0], len(setgroups))
  282. if err1 != 0 {
  283. goto childerror
  284. }
  285. if err1 = raw_close(fd1); err1 != 0 {
  286. goto childerror
  287. }
  288. if fd1, err1 = rawOpenat(dirfd, &pgid[0], O_WRONLY, 0); err1 != 0 {
  289. goto childerror
  290. }
  291. _, err1 = raw_write(fd1, &gidmap[0], len(gidmap))
  292. if err1 != 0 {
  293. goto childerror
  294. }
  295. if err1 = raw_close(fd1); err1 != 0 {
  296. goto childerror
  297. }
  298. }
  299. if sys.Unshareflags&CLONE_NEWUSER != 0 && sys.UidMappings != nil {
  300. dirfd := int(_AT_FDCWD)
  301. if fd1, err1 = rawOpenat(dirfd, &puid[0], O_WRONLY, 0); err1 != 0 {
  302. goto childerror
  303. }
  304. _, err1 = raw_write(fd1, &uidmap[0], len(uidmap))
  305. if err1 != 0 {
  306. goto childerror
  307. }
  308. if err1 = raw_close(fd1); err1 != 0 {
  309. goto childerror
  310. }
  311. }
  312. // The unshare system call in Linux doesn't unshare mount points
  313. // mounted with --shared. Systemd mounts / with --shared. For a
  314. // long discussion of the pros and cons of this see debian bug 739593.
  315. // The Go model of unsharing is more like Plan 9, where you ask
  316. // to unshare and the namespaces are unconditionally unshared.
  317. // To make this model work we must further mark / as MS_PRIVATE.
  318. // This is what the standard unshare command does.
  319. if sys.Unshareflags&CLONE_NEWNS == CLONE_NEWNS {
  320. err1 = rawMount(&none[0], &slash[0], nil, MS_REC|MS_PRIVATE, nil)
  321. if err1 != 0 {
  322. goto childerror
  323. }
  324. }
  325. }
  326. // Chroot
  327. if chroot != nil {
  328. err1 = raw_chroot(chroot)
  329. if err1 != 0 {
  330. goto childerror
  331. }
  332. }
  333. // User and groups
  334. if cred := sys.Credential; cred != nil {
  335. ngroups := len(cred.Groups)
  336. var groups unsafe.Pointer
  337. if ngroups > 0 {
  338. groups = unsafe.Pointer(&cred.Groups[0])
  339. }
  340. if !(sys.GidMappings != nil && !sys.GidMappingsEnableSetgroups && ngroups == 0) && !cred.NoSetGroups {
  341. err1 = raw_setgroups(ngroups, groups)
  342. if err1 != 0 {
  343. goto childerror
  344. }
  345. }
  346. _, _, err1 = RawSyscall(sys_SETGID, uintptr(cred.Gid), 0, 0)
  347. if err1 != 0 {
  348. goto childerror
  349. }
  350. _, _, err1 = RawSyscall(sys_SETUID, uintptr(cred.Uid), 0, 0)
  351. if err1 != 0 {
  352. goto childerror
  353. }
  354. }
  355. if len(sys.AmbientCaps) != 0 {
  356. // Ambient capabilities were added in the 4.3 kernel,
  357. // so it is safe to always use _LINUX_CAPABILITY_VERSION_3.
  358. caps.hdr.version = _LINUX_CAPABILITY_VERSION_3
  359. if _, _, err1 = RawSyscall(SYS_CAPGET, uintptr(unsafe.Pointer(&caps.hdr)), uintptr(unsafe.Pointer(&caps.data[0])), 0); err1 != 0 {
  360. goto childerror
  361. }
  362. for _, c := range sys.AmbientCaps {
  363. // Add the c capability to the permitted and inheritable capability mask,
  364. // otherwise we will not be able to add it to the ambient capability mask.
  365. caps.data[capToIndex(c)].permitted |= capToMask(c)
  366. caps.data[capToIndex(c)].inheritable |= capToMask(c)
  367. }
  368. if _, _, err1 = RawSyscall(SYS_CAPSET, uintptr(unsafe.Pointer(&caps.hdr)), uintptr(unsafe.Pointer(&caps.data[0])), 0); err1 != 0 {
  369. goto childerror
  370. }
  371. for _, c := range sys.AmbientCaps {
  372. _, _, err1 = RawSyscall6(SYS_PRCTL, PR_CAP_AMBIENT, uintptr(PR_CAP_AMBIENT_RAISE), c, 0, 0, 0)
  373. if err1 != 0 {
  374. goto childerror
  375. }
  376. }
  377. }
  378. // Chdir
  379. if dir != nil {
  380. err1 = raw_chdir(dir)
  381. if err1 != 0 {
  382. goto childerror
  383. }
  384. }
  385. // Parent death signal
  386. if sys.Pdeathsig != 0 {
  387. _, err1 = raw_prctl(PR_SET_PDEATHSIG, int(sys.Pdeathsig), 0, 0, 0)
  388. if err1 != 0 {
  389. goto childerror
  390. }
  391. // Signal self if parent is already dead. This might cause a
  392. // duplicate signal in rare cases, but it won't matter when
  393. // using SIGKILL.
  394. r1 := raw_getppid()
  395. if r1 != ppid {
  396. pid := raw_getpid()
  397. err1 = raw_kill(pid, sys.Pdeathsig)
  398. if err1 != 0 {
  399. goto childerror
  400. }
  401. }
  402. }
  403. // Pass 1: look for fd[i] < i and move those up above len(fd)
  404. // so that pass 2 won't stomp on an fd it needs later.
  405. if pipe < nextfd {
  406. err1 = raw_dup3(pipe, nextfd, O_CLOEXEC)
  407. if err1 != 0 {
  408. goto childerror
  409. }
  410. pipe = nextfd
  411. nextfd++
  412. }
  413. for i = 0; i < len(fd); i++ {
  414. if fd[i] >= 0 && fd[i] < int(i) {
  415. if nextfd == pipe { // don't stomp on pipe
  416. nextfd++
  417. }
  418. err1 = raw_dup3(fd[i], nextfd, O_CLOEXEC)
  419. if err1 != 0 {
  420. goto childerror
  421. }
  422. fd[i] = nextfd
  423. nextfd++
  424. }
  425. }
  426. // Pass 2: dup fd[i] down onto i.
  427. for i = 0; i < len(fd); i++ {
  428. if fd[i] == -1 {
  429. raw_close(i)
  430. continue
  431. }
  432. if fd[i] == int(i) {
  433. // dup2(i, i) won't clear close-on-exec flag on Linux,
  434. // probably not elsewhere either.
  435. _, err1 = raw_fcntl(fd[i], F_SETFD, 0)
  436. if err1 != 0 {
  437. goto childerror
  438. }
  439. continue
  440. }
  441. // The new fd is created NOT close-on-exec,
  442. // which is exactly what we want.
  443. err1 = raw_dup3(fd[i], i, 0)
  444. if err1 != 0 {
  445. goto childerror
  446. }
  447. }
  448. // By convention, we don't close-on-exec the fds we are
  449. // started with, so if len(fd) < 3, close 0, 1, 2 as needed.
  450. // Programs that know they inherit fds >= 3 will need
  451. // to set them close-on-exec.
  452. for i = len(fd); i < 3; i++ {
  453. raw_close(i)
  454. }
  455. // Detach fd 0 from tty
  456. if sys.Noctty {
  457. _, err1 = raw_ioctl(0, TIOCNOTTY, 0)
  458. if err1 != 0 {
  459. goto childerror
  460. }
  461. }
  462. // Set the controlling TTY to Ctty
  463. if sys.Setctty {
  464. _, err1 = raw_ioctl(sys.Ctty, TIOCSCTTY, 1)
  465. if err1 != 0 {
  466. goto childerror
  467. }
  468. }
  469. // Enable tracing if requested.
  470. // Do this right before exec so that we don't unnecessarily trace the runtime
  471. // setting up after the fork. See issue #21428.
  472. if sys.Ptrace {
  473. err1 = raw_ptrace(_PTRACE_TRACEME, 0, 0, 0)
  474. if err1 != 0 {
  475. goto childerror
  476. }
  477. }
  478. // Time to exec.
  479. err1 = raw_execve(argv0, &argv[0], &envv[0])
  480. childerror:
  481. // send error code on pipe
  482. raw_write(pipe, (*byte)(unsafe.Pointer(&err1)), int(unsafe.Sizeof(err1)))
  483. for {
  484. raw_exit(253)
  485. }
  486. }
  487. // Try to open a pipe with O_CLOEXEC set on both file descriptors.
  488. func forkExecPipe(p []int) (err error) {
  489. return Pipe2(p, O_CLOEXEC)
  490. }
  491. func formatIDMappings(idMap []SysProcIDMap) []byte {
  492. var data []byte
  493. for _, im := range idMap {
  494. data = append(data, []byte(itoa.Itoa(im.ContainerID)+" "+itoa.Itoa(im.HostID)+" "+itoa.Itoa(im.Size)+"\n")...)
  495. }
  496. return data
  497. }
  498. // writeIDMappings writes the user namespace User ID or Group ID mappings to the specified path.
  499. func writeIDMappings(path string, idMap []SysProcIDMap) error {
  500. fd, err := Open(path, O_RDWR, 0)
  501. if err != nil {
  502. return err
  503. }
  504. if _, err := Write(fd, formatIDMappings(idMap)); err != nil {
  505. Close(fd)
  506. return err
  507. }
  508. if err := Close(fd); err != nil {
  509. return err
  510. }
  511. return nil
  512. }
  513. // writeSetgroups writes to /proc/PID/setgroups "deny" if enable is false
  514. // and "allow" if enable is true.
  515. // This is needed since kernel 3.19, because you can't write gid_map without
  516. // disabling setgroups() system call.
  517. func writeSetgroups(pid int, enable bool) error {
  518. sgf := "/proc/" + itoa.Itoa(pid) + "/setgroups"
  519. fd, err := Open(sgf, O_RDWR, 0)
  520. if err != nil {
  521. return err
  522. }
  523. var data []byte
  524. if enable {
  525. data = []byte("allow")
  526. } else {
  527. data = []byte("deny")
  528. }
  529. if _, err := Write(fd, data); err != nil {
  530. Close(fd)
  531. return err
  532. }
  533. return Close(fd)
  534. }
  535. // writeUidGidMappings writes User ID and Group ID mappings for user namespaces
  536. // for a process and it is called from the parent process.
  537. func writeUidGidMappings(pid int, sys *SysProcAttr) error {
  538. if sys.UidMappings != nil {
  539. uidf := "/proc/" + itoa.Itoa(pid) + "/uid_map"
  540. if err := writeIDMappings(uidf, sys.UidMappings); err != nil {
  541. return err
  542. }
  543. }
  544. if sys.GidMappings != nil {
  545. // If the kernel is too old to support /proc/PID/setgroups, writeSetGroups will return ENOENT; this is OK.
  546. if err := writeSetgroups(pid, sys.GidMappingsEnableSetgroups); err != nil && err != ENOENT {
  547. return err
  548. }
  549. gidf := "/proc/" + itoa.Itoa(pid) + "/gid_map"
  550. if err := writeIDMappings(gidf, sys.GidMappings); err != nil {
  551. return err
  552. }
  553. }
  554. return nil
  555. }