On Thu, Feb 13, 2020 at 1:14 PM Caleb Spare <
ces...@gmail.com> wrote:
>
> Hi! I have a Linux-specific question about capabilities, threads, and syscalls.
>
> I have a Go program which runs other programs with specific
> capabilities set. It basically does the following:
>
> cmd := exec.Command(...)
> runtime.LockOSThread()
> unix.RawSyscall(unix.CAPSET, ...)
> cmd.Start()
>
> Empirically, it seems to work well, having run in production for several years.
>
> I wrote it this way because, from my reading of capabilities
> documentation, capset only affects the current thread, so it's
> important that we use the same OS thread for running the capset
> syscall as the fork. I also used RawSyscall (rather than Syscall) for
> this reason.
>
> I noticed that more recently the x/sys/unix package added Capget and
> Capset which use Syscall rather than RawSyscall. Thinking about it
> more now, ISTM that using Syscall is fine, and that LockOSThread is
> all I need to ensure that the thread with the raised capabilities is
> the one that runs the fork. Is that correct?
It's possible that this is a performance bug. I don't know of any