Skip to content

Commit 049c8db

Browse files
zx2c4alexbrainman
authored andcommitted
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: Alex Brainman <alex.brainman@gmail.com>
1 parent e85d619 commit 049c8db

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/syscall/exec_windows.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,12 @@ type ProcAttr struct {
219219
}
220220

221221
type SysProcAttr struct {
222-
HideWindow bool
223-
CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
224-
CreationFlags uint32
225-
Token Token // if set, runs new process in the security context represented by the token
222+
HideWindow bool
223+
CmdLine string // used if non-empty, else the windows command line is built by escaping the arguments passed to StartProcess
224+
CreationFlags uint32
225+
Token Token // if set, runs new process in the security context represented by the token
226+
ProcessAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the new process
227+
ThreadAttributes *SecurityAttributes // if set, applies these security attributes as the descriptor for the main thread of the new process
226228
}
227229

228230
var zeroProcAttr ProcAttr
@@ -323,9 +325,9 @@ func StartProcess(argv0 string, argv []string, attr *ProcAttr) (pid int, handle
323325

324326
flags := sys.CreationFlags | CREATE_UNICODE_ENVIRONMENT
325327
if sys.Token != 0 {
326-
err = CreateProcessAsUser(sys.Token, argv0p, argvp, nil, nil, true, flags, createEnvBlock(attr.Env), dirp, si, pi)
328+
err = CreateProcessAsUser(sys.Token, argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, true, flags, createEnvBlock(attr.Env), dirp, si, pi)
327329
} else {
328-
err = CreateProcess(argv0p, argvp, nil, nil, true, flags, createEnvBlock(attr.Env), dirp, si, pi)
330+
err = CreateProcess(argv0p, argvp, sys.ProcessAttributes, sys.ThreadAttributes, true, flags, createEnvBlock(attr.Env), dirp, si, pi)
329331
}
330332
if err != nil {
331333
return 0, 0, err

0 commit comments

Comments
 (0)