-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: crypto/rand: use private reader, not Reader, in Read #42713
Comments
I agree that lacking support for immutable values is a potential security threat for Go programs. |
Change https://golang.org/cl/272326 mentions this issue: |
I think this is a duplicate of #24160. |
Thank you for chiming in Rodolfo, and for the reference. They are similar
in the problem detailed, but that referenced issue is proposing a change of
APIs which is a Go2 change, this one simply keeps the prior APIs and
provides the guards. That issue’s qualms shall be solved for Go1.17, so I
shall tag it as an update.
…On Wed, Nov 25, 2020 at 4:51 PM Rodolfo Carvalho ***@***.***> wrote:
I think this is a duplicate of #24160
<#24160>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#42713 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFL3V2RZM2ILUULRKQSWRTSRWQ7DANCNFSM4T25CQ3Q>
.
|
Note discussion on https://go-review.googlesource.com/c/go/+/272326/ re attack models. |
This proposal has been added to the active column of the proposals project |
Quoting @FiloSottile on the CL:
Changing may be a compatibility issue too, but it definitely doesn't improve security. It only appears to. |
Based on the discussion above, this proposal seems like a likely decline. |
No change in consensus, so declined. |
Motivation
One of my clients heavily uses cryptographic primitives and the parts in their Go code heavily call crypto/rand.Reader to get randomness. Their systems are high value by definition, and have big bounties on them, so I have to examine every scenario I can think of. To attack and then mitigate, I crafted a way of controlling the random bytes used heavily by them, and can deploy that in a random dependency down the chain disguised as code that generates Go code in a template (which lots of code out there does)
Problem
As of go tip 5ba1c3f, it is possible for a rogue dependency that hasn't been audited but snuck in, in a chain of massive other dependencies, to simply intercept and control crypto/rand.Reader just by assignment in an init for example https://play.golang.org/p/XD8npXHwIob or inlined below
which prints out
particularly when one needs to target a specific size or knowing where code came from
Unix
go/src/crypto/rand/rand_unix.go
Lines 30 to 36 in 5ba1c3f
Windows
go/src/crypto/rand/rand_windows.go
Line 15 in 5ba1c3f
Js
go/src/crypto/rand/rand_js.go
Lines 11 to 28 in 5ba1c3f
and Read for all those platforms invoke Reader
Proposal
Let's create an unexported variable in place of Reader, called internalReader which will take the place of platform specific Reader, and then in rand.go, we can make our assignment
Reader = internalReader
. Sure, a determined attacker could dig and modify the memory of the internalReader given its address, and manipulate its methods, but at least starting by making an assignment difficult is a start and then later on, perhaps for Go2, we could try to work out some sort of non re-assignable non-const.The text was updated successfully, but these errors were encountered: