-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: passing method on value receiver causes memory corruption #18410
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
Comments
Marking as Go1.8maybe for now since this seems significant (discovered in production code). Feel free to mark as Go1.9. |
I don't think we can fix this at this stage of Go1.8. Also, it's not a regression (looks like the bug was there in 1.4). Finally, there's a work-around (provide an explicit closure):
|
Hold up a second, on the playground running go1.7.4, the program prints out the right output that @dsnet expects ie https://play.golang.org/p/X6YL_-v-TB therefore I wonder what's really different, perhaps an OS thing? but in deed it fails on tip on OSX $ go run X6YL_-v-TB.go
0x1128a80 0xc420018360
runtime.Version: devel +0937441 Tue Dec 20 02:44:01 2016 -0800
$ uname -a
Darwin Emmanuels-MBP-2 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64 |
@odeke-em That might have more to do with stack layout and the NaCl calling convention. |
This seems like a pretty bad security issue.
the B slice is picking up garbage on the stack frame, so
it might actually gives the method a way to read/write
arbitrary memory locations, and it might also cause
GC/stack copy to crash on invalid pointers.
For example, I added a Printf of len(t.B) and cap(t.B),
and both values on my systems are: 0xc4200001a0.
|
@minux When I was playing with this earlier, it's looked like stack allocated objects aren't cleared, but heap allocated ones were. |
This can be used to overwrite the stack and control the return address: Code here: https://play.golang.org/p/V37IeKl5pN
Playground output:
|
It will be a fun exercise to use this vulnerability to do a ROP demo
on the playground.
Now I hope this hole is not closed too fast as I haven't had time
to play with this idea yet.....
(Note: I don't thinking such an "attack" will affect the real security
of the playground.)
|
No, but it probably affects appengine which is still on 1.6.3. |
Problem has (something) to do with treatment of STRUCTLIT under a CALLPART, vs under AS to a target.
|
CL https://golang.org/cl/34622 mentions this issue. |
CL https://golang.org/cl/35636 mentions this issue. |
…full initialization CALLPART of STRUCTLIT did not check for incomplete initialization of struct; modify PTRLIT treatment to force zeroing. Test for structlit, believe this might have also failed for arraylit. Fixes #18410. Change-Id: I511abf8ef850e300996d40568944665714efe1fc Reviewed-on: https://go-review.googlesource.com/34622 Run-TryBot: David Chase <drchase@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-on: https://go-review.googlesource.com/35636 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Using
go1.7.4
, but seems to have been present sincego1.3
OS:
Linux carbonite 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
Consider the following code:
Currently this prints:
I expect this to print:
The
Print
method is declared on a value receiver. In the main function we define a struct literal of type X and explicitly set the A field to be some value, but we expect the B field to be implicitly be zeroed out. ThePrint
method of that struct literal is passed to another function as a callback.When the callback is called, it shows that the B field is not zeroed and contains a pointer to some arbitrary piece of memory.
\cc @randall77 @dr2chase @paranoiacblack
The text was updated successfully, but these errors were encountered: