-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime: non-atomic pointer writes in memclr/memmove #13160
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
Amusingly arm/ppc are probably okay because we tracked this exact issue down in #12552. At the time I thought the other platforms were okay, but you're definitely right about the tails. |
I checked all the memclr & memmove code, CL out for review. It was just x86, the other architectures look ok to me. The only other place we do byte-at-a-time copy is in the reflect.callX functions. Both the source (a newly allocated chunk of memory) and the destination (the local stack) should be ok for non-atomic pointer copy. |
CL https://golang.org/cl/16668 mentions this issue. |
This might be worth fixing for Go 1.5.2, if we release a Go 1.5.2. |
Make sure that we're moving or zeroing pointers atomically. Anything that is a multiple of pointer size and at least pointer aligned might have pointers in it. All the code looks ok except for the 1-pointer-sized moves. Fixes #13160 Update #12552 Change-Id: Ib97d9b918fa9f4cc5c56c67ed90255b7fdfb7b45 Reviewed-on: https://go-review.googlesource.com/16668 Reviewed-by: Dmitry Vyukov <[email protected]> Run-TryBot: Keith Randall <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-on: https://go-review.googlesource.com/16910 Reviewed-by: Russ Cox <[email protected]>
The following program crashes when run with
GODEBUG=invalidptr=1 GOARCH=386
:The problem is that memclr clears 4-byte regions on 386 with 2 separate 2-byte stores:
This exposes corrupted pointer to GC.
Not sure whether it can crash without invalidptr, I would not exclude such possibility. But it's clearly bad and can lead to false retention. Also it makes data race failure modes significantly worse, introducing exploitation possibilities like use-after-free and easy controlled overwrite.
There is similar issue in amd64p32 memclr which clears pointers with byte stores:
Similar issue in 386 memmove which moves pointer with 2 stores:
Similar issue in plan9/386 memclr:
Similar issue in amd64 memclr:
Did not look at arm/ppc. I guess we just need to go through all of them one-by-one.
@rsc @randall77 @RLH @aclements @dr2chase @davecheney @minux @0intro @4ad
The text was updated successfully, but these errors were encountered: