From: <nsajko@gmail.com>
To: <wireguard@lists.zx2c4.com>
Subject: [PATCH] device: in setZero, keep arr alive after being written to
Date: Wed, 31 Jul 2019 06:36:29 -0700 (PDT) [thread overview]
Message-ID: <5d41995d.1c69fb81.35aae.ce0c@mx.google.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 979 bytes --]
This is to prevent dead store elimination.
See the discussion at
golang/go#33325 .
diff --git a/device/noise-helpers.go b/device/noise-helpers.go
index f5e4b4b..29430da 100644
--- a/device/noise-helpers.go
+++ b/device/noise-helpers.go
@@ -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() {
[-- Attachment #2: Type: text/plain, Size: 148 bytes --]
_______________________________________________
WireGuard mailing list
WireGuard@lists.zx2c4.com
https://lists.zx2c4.com/mailman/listinfo/wireguard
next reply other threads:[~2019-08-21 15:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-31 13:36 nsajko [this message]
2019-08-27 22:54 ` [PATCH] device: in setZero, keep arr alive after being written to Jason A. Donenfeld
2019-08-27 23:02 ` Neven Sajko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5d41995d.1c69fb81.35aae.ce0c@mx.google.com \
--to=nsajko@gmail.com \
--cc=wireguard@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox