From f5eef58e4381259cbd84b3f2074c79607fb5c821 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 13 Mar 2023 20:59:14 -0700 Subject: syscall: restore original NOFILE rlimit in child process If we increased the NOFILE rlimit when starting the program, restore the original rlimit when forking a child process. For #46279 Change-Id: Ia5d2af9ef435e5932965c15eec2e428d2130d230 Reviewed-on: https://go-review.googlesource.com/c/go/+/476097 Reviewed-by: Bryan Mills Reviewed-by: Ian Lance Taylor TryBot-Bypass: Ian Lance Taylor --- src/syscall/exec_linux.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/syscall/exec_linux.go') diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go index d5f00dd33e..2a1f7ef1a7 100644 --- a/src/syscall/exec_linux.go +++ b/src/syscall/exec_linux.go @@ -240,6 +240,8 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att c uintptr ) + rlim, rlimOK := origRlimitNofile.Load().(Rlimit) + if sys.UidMappings != nil { puid = []byte("/proc/self/uid_map\000") uidmap = formatIDMappings(sys.UidMappings) @@ -609,6 +611,11 @@ func forkAndExecInChild1(argv0 *byte, argv, envv []*byte, chroot, dir *byte, att } } + // Restore original rlimit. + if rlimOK && rlim.Cur != 0 { + rawSetrlimit(RLIMIT_NOFILE, &rlim) + } + // Enable tracing if requested. // Do this right before exec so that we don't unnecessarily trace the runtime // setting up after the fork. See issue #21428. -- cgit v1.3