Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ioctl should take an unsafe.Pointer, not a uintptr #116

Open
bazile-clyde opened this issue Feb 22, 2023 · 0 comments
Open

Ioctl should take an unsafe.Pointer, not a uintptr #116

bazile-clyde opened this issue Feb 22, 2023 · 0 comments

Comments

@bazile-clyde
Copy link

From the unsafe.Pointer rule (4) Conversion of a Pointer to a uintptr when calling syscall.Syscall.

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

syscall.Syscall(SYS_READ, uintptr(fd), uintptr(unsafe.Pointer(p)), uintptr(n))

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 wrapper Ioctl violates this rule by requiring uintptrs in their arguments and later passing those to unix.Syscall. This will allow the object at the address the uintptr points to to be garbage collected. This could result in a random address being written to. A similar issue is being working in Go's ptrace function. See https://go-review.googlesource.com/c/go/+/470299. Ioctl should instead take unsafe.Pointers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant