Commit 049c8dbf authored by Jason A. Donenfeld's avatar Jason A. Donenfeld Committed by Alex Brainman

syscall: allow setting security attributes on processes

This allows creating processes that can only be debugged/accessed by
certain tokens, according to a particular security descriptor. We
already had everything ready for this but just neglected to pass through
the value from the user-accessible SysProcAttr.

Change-Id: I4a3fcc9f5078aa0058b26c103355c984093ae03f
Reviewed-on: https://go-review.googlesource.com/c/go/+/174197
Run-TryBot: Jason Donenfeld <Jason@zx2c4.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
parent e85d6195
...@@ -219,10 +219,12 @@ type ProcAttr struct { ...@@ -219,10 +219,12 @@ type ProcAttr struct {
} }
type SysProcAttr struct { type SysProcAttr struct {
HideWindow bool HideWindow bool
CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
CreationFlags uint32 CreationFlags uint32
Token Token // if set, runs new process in the security context represented by the token Token Token // if set, runs new process in the security context represented by the token
ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
} }
var zeroProcAttr ProcAttr var zeroProcAttr ProcAttr
...@@ -323,9 +325,9 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle ...@@ -323,9 +325,9 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
flags := sys.CreationFlags | CREATE_UNICODE_ENVIRONMENT flags := sys.CreationFlags | CREATE_UNICODE_ENVIRONMENT
if sys.Token != 0 { if sys.Token != 0 {
err = CreateProcessAsUser(sys.Token, argv0p, argvp, nil, nil, true, flags, createEnvBlock(attr.Env), dirp, si, pi) err = CreateProcessAsUser(sys.Token, argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, true, flags, createEnvBlock(attr.Env), dirp, si, pi)
} else { } else {
err = CreateProcess(argv0p, argvp, nil, nil, true, flags, createEnvBlock(attr.Env), dirp, si, pi) err = CreateProcess(argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, true, flags, createEnvBlock(attr.Env), dirp, si, pi)
} }
if err != nil { if err != nil {
return 0, 0, err return 0, 0, err
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment