New AT_ flags for restricting pathname lookup
New AT_ flags for restricting pathname lookup
Posted Oct 5, 2018 7:13 UTC (Fri) by kostix (guest, #119803)In reply to: New AT_ flags for restricting pathname lookup by wahern
Parent article: New AT_ flags for restricting pathname lookup
Since fork() clones the state of just a single thread — the one which happened to execute that syscall, — as soon as the control resumes in the child process, there is literally no Go runtime anymore around the goroutine "awoken" in the cloned thread, and as soon as it happens to call anything which would normally reach for the runtime, it is hosed. And normally such a call would happen pretty soon.
So basically the only sensible thing one might safely do after forking a process running a Go program is to do a controlled set of preparations and exec().
And actually that's what the syscall.ForkExec does — with some added complexity stemming from Go having an execution model other than C ;-)
You can look at ForkExec in https://golang.org/src/syscall/exec_unix.go and then at forkAndExecInChild in https://golang.org/src/syscall/exec_linux.go — the code is very easy to follow for any programmer with a C background, and it is extensively commented.
Posted Oct 6, 2018 1:37 UTC (Sat)
by wahern (subscriber, #37304)
[Link]
It might not be particularly efficient and come with a ton of gotchas, but it would at least make some currently impossible things possible, such as using geteuid and forking helper processes. Those things tend to happen early on, anyhow, so performance and other limitations wouldn't matter much.
New AT_ flags for restricting pathname lookup
