x/sys/unix: OpenBSD's Pledge and Unveil functions can be annulled #60322
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
FeatureRequest
Issues asking for a new feature that does not need a proposal.
help wanted
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
OS-OpenBSD
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I ran this program:
Where the package
bar
contains this source file:What did you expect to see?
I didn't really expect it, but ideally the program would exit immediately, because the
unix.Pledge
call didn't allow the use of standard IO andbar.init
is printing something to the standard output.In C programs, pledge is often called as the first thing in the main function, to prevent any code (written by the author themself or the author of a used library) to use undesired syscalls. Because in Go the init function of used libraries/packages are always executed before the init function and variable declarations of the main package, I see no way to replicate this C pattern in Go. Thus
unix.Pledge
cannot provide the same safety guarantees in Go as in C.I suspect this is a problem that cannot be solved without a change in the language. I think there should at least be a warning in the documentation of the
Pledge
,PledgeExecpromises
andPledgePromises
, but alsoUnveil
andUnveilBlock
functions.If there is a way to force Go to execute
unix.Pledge
as the first thing in a program, I'm gladly taking instructions on how to do this.What did you see instead?
The program ran the
init
function of thebar
package, before runningunix.Pledge
:The text was updated successfully, but these errors were encountered: