Skip to content

x/sys/unix: FreeBSD PtraceIO violates unsafe.Pointer rules #58351

@bcmills

Description

@bcmills

The fix for #54113 appears to have been only partial.
GOOS=freebsd GOARCH=amd64 go vet ./... in the x/sys module shows a true-positive violation of the unsafe.Pointer rules in syscall_freebsd_amd64.go:

ioDesc := PtraceIoDesc{Op: int32(req), Offs: uintptr(unsafe.Pointer(addr)), Addr: uintptr(unsafe.Pointer(&out[0])), Len: uint64(countin)}
err = ptrace(PT_IO, pid, uintptr(unsafe.Pointer(&ioDesc)), 0)

Absent an API for pinning Go object addresses (#46787), this is incorrect and could lead to arbitrary memory corruption: if the out slice refers to memory in the Go heap, that memory can be collected (and reused for another allocation) concurrently with the call to ptrace.

(Note that the unsafe.Pointer rule that allows conversion of an unsafe.Pointer to a uintptr when calling syscall.Syscall applies only with the call expression itself, not within other variable declarations in the same function that makes the call.

This was apparently masked by #41205.

(attn @golang/freebsd; CC @tklauser @ianlancetaylor @aarzilli @mdempsky)

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions