Skip to content

syscall,x/sys/unix: ptrace wrappers erroneously pass Go pointers as type uintptr #58387

@bcmills

Description

@bcmills

The unsafe.Pointer rules allow “conversion of a Pointer to a uintptr when calling syscall.Syscall”, with a caveat:

If a pointer argument must be converted to uintptr for use as an argument, that conversion must appear in the call expression itself:

The compiler handles a Pointer converted to a uintptr in the argument list of a call to a function implemented in assembly by arranging that the referenced allocated object, if any, is retained and not moved until the call completes, even though from the types alone it would appear that the object is no longer needed during the call.

The ptrace wrappers on both Linux and FreeBSD violate that requirement. They pass a uintptr argument to the ptrace helper function, which is what ultimately calls syscall.Syscall, and the arguments to the ptrace helper often do point to buffers allocated in Go:

These issues appear to date all the way back to 2009: the ptrace wrapper function was added in commit 9df5287 (CC @aclements), and in CL 126960043 which copied that pattern to x/sys.

The ptrace function likely needs a split like the one done for ioctl in #44834.

(attn @golang/runtime; CC @ianlancetaylor @bradfitz @tklauser)

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions