device: in setZero, keep arr alive after being written to
PATCH 1/1 device: in setZero, keep arr alive after being written to
This is to prevent dead store elimination.
See the discussion at
golang/go#33325 .
device/noise-helpers.go +7 -1
@@ -10,6 +10,7 @@ import ( "crypto/rand" "crypto/subtle" "hash" + "runtime" "golang.org/x/crypto/blake2s" "golang.org/x/crypto/curve25519"
@@ -69,11 +70,16 @@ func isZero(val []byte) bool { return acc == 1 } -/* This function is not used as pervasively as it should because this is mostly impossible in Go at the moment */ +/* This function is not used as pervasively as it should */ func setZero(arr []byte) { for i := range arr { arr[i] = 0 } + + // This should keep arr's backing array live and thus prevent dead store + // elimination, according to discussion at + // https://github.com/golang/go/issues/33325 . + runtime.KeepAlive(arr) } func (sk *NoisePrivateKey) clamp() {
_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard
But this doesn't prevent the runtime from copying things to places we can't control, right?
_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard
Quoted 2 lines
But this doesn't prevent the runtime from copying things to places we can't control, right?
Correct.
_______________________________________________
WireGuard mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/wireguard