-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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
x/sys: invalid use of unsafe.Pointer in ioctl arg parameters #44834
Comments
This is safe.
|
cc @mdempsky |
I don't think that code is safe. The |
Hmm, so, whether it violates unsafe pointer rule? Maybe the right fix is passing in an unsafe.Pointer instead of an uintptr 🤔 |
or using |
I think so. The Linux |
@mdlayher added |
From https://man7.org/linux/man-pages/man2/ioctl.2.html:
From https://docs.oracle.com/cd/E23824_01/html/821-1463/ioctl-2.html
It thus seems like |
Relevant issue: #34684 |
Change https://golang.org/cl/340915 mentions this issue: |
The existing ioctl stubs for all UNIX-like platforms take a value of type uintptr for the arg parameter. However, arguments which are cast from unsafe.Pointer to uintptr technically violate the rules for package unsafe. unsafe only allows a conversion from unsafe.Pointer to uintptr directly within a call to Syscall. ioctl is used on all UNIX-like operating systems and each one will have to be updated accordingly where pointer arguments are passed to system calls. To remedy this on Linux, we generate a new function called ioctlPtr which takes a value of type unsafe.Pointer for arg. More operating systems can be updated in future CLs by folks who have access to those systems and can run the appropriate code generator. Updates golang/go#44834 Change-Id: Ia9424be424b3dba91bb44d3a7a12bfb2179f0d86 Reviewed-on: https://go-review.googlesource.com/c/sys/+/340915 Trust: Matt Layher <mdlayher@gmail.com> Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Matt Layher <mdlayher@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
@mdempsky, @ianlancetaylor, @mdlayher: was this fixed by CL 340915, or is there more to do here? |
I believe the reason I didn't close this before was because I only fixed it for Linux. Similar changes would have to be made for *BSD and etc. |
Here we are, |
Change https://go.dev/cl/469315 mentions this issue: |
Change https://go.dev/cl/469675 mentions this issue: |
This is a followup for CL 340915 that adds ioctlPtr for all other UNIX-like platforms. For golang/go#44834 Change-Id: I0ecf84e53f13e5a8da736b3ba7f643262596d23c Reviewed-on: https://go-review.googlesource.com/c/sys/+/469315 Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com>
Change https://go.dev/cl/469835 mentions this issue: |
Avoid passing Go pointers as uintptr in exec_unix_test.go by introducing syscall.IoctlPtr() which accepts arg as unsafe.Pointer. For #44834 Fixes #58609 Change-Id: I6d0ded023e5f3c9989783aee7075bb88100d9ec2 Reviewed-on: https://go-review.googlesource.com/c/go/+/469675 Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Avoid passing Go pointers as uintptr in exec_unix_test.go by introducing syscall.IoctlPtr() which accepts arg as unsafe.Pointer. For golang#44834 Fixes golang#58609 Change-Id: I6d0ded023e5f3c9989783aee7075bb88100d9ec2 Reviewed-on: https://go-review.googlesource.com/c/go/+/469675 Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Change https://go.dev/cl/471119 mentions this issue: |
CL 469315 missed a few conversions, this CL adds them. While here, also update syscall wrapper generators. For golang/go#44834 Change-Id: I4418a8c177ee6d1a269c1cc2c806b199dc7ccf0b Reviewed-on: https://go-review.googlesource.com/c/sys/+/471119 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Dmitri Goutnik <dgoutnik@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com>
@dmgk, can this issue be closed now, or is there more work remaining for it? |
I believe this is done, closing. |
Thanks a lot to everyone involved |
From the documentation of unsafe.Pointer:
Now, as far as I can tell this forces packages to adhere to exactly that.
The code in x/sys clearly violates that rule.
in unix/ioctl.go there's
and the declaration of ioctl in zsyskall_linux.go:
I've asked on the mailing list if that's valid usage of unsafe, @ianlancetaylor wasn't sure and told me to open an issue here for further discussion. (https://groups.google.com/g/golang-nuts/c/Ocpy8CKs7ZI/m/3ym8gnuBFgAJ)
The text was updated successfully, but these errors were encountered: