x/sys/unix: xattr functions erroneously pass Go pointers as type uintptr on BSDs #58386
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
help wanted
NeedsFix
The path to resolution is known, but the work has not been done.
OS-FreeBSD
OS-NetBSD
Milestone
The
unsafe.Pointer
rules allow “conversion of aPointer
to auintptr
when callingsyscall.Syscall
”, with a caveat:The
linux
anddarwin
implementations of the.*xattr
functions (such asGetxattr
) appear to comply with that requirement.However, the BSD implementation does not:
https://cs.opensource.google/go/x/sys/+/master:unix/xattr_bsd.go;l=60;drc=4e121b1efb52d0ccc0c89c55272b7c3da9a475f8
Instead of calling
syscall.Syscall
directly, it passes thedest
pointer to another helper function (such asExtattrGetFile
) as typeuintptr
. That can cause a use-after-free bug if the Go garbage collector reclaims or relocates the destination slice concurrently with the system call. (The danger is especially high if the caller happens not to refer to the destination buffer after the call, although that situation is less likely.)It appears that the erroneous signatures were added in CL 147850043.
Probably this will need to be fixed by adding (unexported?) variants of the
Extattr
functions, with thedata
arguments correctly encoded as type*byte
orunsafe.Pointer
instead ofuintptr
, and then switchingGetxattr
and similar to use those safer variants. (For comparison, see theioctl
/ioctlPtr
split on Linux from #44834.)(attn @golang/freebsd @golang/netbsd; CC @tklauser @bradfitz @ianlancetaylor)
The text was updated successfully, but these errors were encountered: