mirror of
https://github.com/golang/go
synced 2024-11-14 20:10:30 -07:00
Revert "crypto/rand: add randcrash=0 GODEBUG"
A GODEBUG is actually a security risk here: most programs will start to ignore errors from Read because they can't happen (which is the intended behavior), but then if a program is run with GODEBUG=randcrash=0 it will use a partial buffer in case an error occurs, which may be catastrophic. Note that the proposal was accepted without the GODEBUG, which was only added later. This (partially) reverts CL 608435. I kept the tests. Updates #66821 Change-Id: I3fd20f9cae0d34115133fe935f0cfc7a741a2662 Reviewed-on: https://go-review.googlesource.com/c/go/+/622115 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Roland Shoemaker <roland@golang.org> Auto-Submit: Filippo Valsorda <filippo@golang.org> Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
This commit is contained in:
parent
7a256adbaf
commit
0138c1abef
@ -168,11 +168,6 @@ For Go 1.24, it now defaults to multipathtcp="2", thus
|
||||
enabled by default on listerners. Using multipathtcp="0" reverts to the
|
||||
pre-Go 1.24 behavior.
|
||||
|
||||
Go 1.24 changed [`crypto/rand.Read`](/pkg/crypto/rand/#Read) to crash the
|
||||
program on any error. This setting is controlled by the `randcrash` setting.
|
||||
For Go 1.24 it defaults to `randcrash=1`.
|
||||
Using `randcrash=0` reverts to the pre-Go 1.24 behavior.
|
||||
|
||||
### Go 1.23
|
||||
|
||||
Go 1.23 changed the channels created by package time to be unbuffered
|
||||
|
@ -8,7 +8,6 @@ package rand
|
||||
|
||||
import (
|
||||
"crypto/internal/boring"
|
||||
"internal/godebug"
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
@ -65,8 +64,6 @@ func (r *reader) Read(b []byte) (n int, err error) {
|
||||
//go:linkname fatal
|
||||
func fatal(string)
|
||||
|
||||
var randcrash = godebug.New("randcrash")
|
||||
|
||||
// Read fills b with cryptographically secure random bytes. It never returns an
|
||||
// error, and always fills b entirely.
|
||||
//
|
||||
@ -86,10 +83,6 @@ func Read(b []byte) (n int, err error) {
|
||||
copy(b, bb)
|
||||
}
|
||||
if err != nil {
|
||||
if randcrash.Value() == "0" {
|
||||
randcrash.IncNonDefault()
|
||||
return 0, err
|
||||
}
|
||||
fatal("crypto/rand: failed to read random data (see https://go.dev/issue/66821): " + err.Error())
|
||||
panic("unreachable") // To be sure.
|
||||
}
|
||||
|
@ -198,8 +198,7 @@ func TestReadError(t *testing.T) {
|
||||
}
|
||||
testenv.MustHaveExec(t)
|
||||
|
||||
// We run this test in a subprocess because it's expected to crash the
|
||||
// program unless the GODEBUG is set.
|
||||
// We run this test in a subprocess because it's expected to crash.
|
||||
if os.Getenv("GO_TEST_READ_ERROR") == "1" {
|
||||
defer func(r io.Reader) { Reader = r }(Reader)
|
||||
Reader = readerFunc(func([]byte) (int, error) {
|
||||
@ -221,13 +220,6 @@ func TestReadError(t *testing.T) {
|
||||
if !bytes.Contains(out, []byte(exp)) {
|
||||
t.Errorf("subprocess output does not contain %q: %s", exp, out)
|
||||
}
|
||||
|
||||
cmd = testenv.Command(t, os.Args[0], "-test.run=TestReadError")
|
||||
cmd.Env = append(os.Environ(), "GO_TEST_READ_ERROR=1", "GODEBUG=randcrash=0")
|
||||
out, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
t.Errorf("subprocess failed: %v\n%s", err, out)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkRead(b *testing.B) {
|
||||
|
@ -47,7 +47,6 @@ var All = []Info{
|
||||
{Name: "netedns0", Package: "net", Changed: 19, Old: "0"},
|
||||
{Name: "panicnil", Package: "runtime", Changed: 21, Old: "1"},
|
||||
{Name: "randautoseed", Package: "math/rand"},
|
||||
{Name: "randcrash", Package: "crypto/rand", Changed: 24, Old: "0"},
|
||||
{Name: "randseednop", Package: "math/rand", Changed: 24, Old: "0"},
|
||||
{Name: "tarinsecurepath", Package: "archive/tar"},
|
||||
{Name: "tls10server", Package: "crypto/tls", Changed: 22, Old: "1"},
|
||||
|
@ -306,10 +306,6 @@ Below is the full list of supported metrics, ordered lexicographically.
|
||||
The number of non-default behaviors executed by the math/rand
|
||||
package due to a non-default GODEBUG=randautoseed=... setting.
|
||||
|
||||
/godebug/non-default-behavior/randcrash:events
|
||||
The number of non-default behaviors executed by the crypto/rand
|
||||
package due to a non-default GODEBUG=randcrash=... setting.
|
||||
|
||||
/godebug/non-default-behavior/randseednop:events
|
||||
The number of non-default behaviors executed by the math/rand
|
||||
package due to a non-default GODEBUG=randseednop=... setting.
|
||||
|
Loading…
Reference in New Issue
Block a user