summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorRicardo Mestre <mestre@cvs.openbsd.org>2017-05-03 09:51:40 +0000
committerRicardo Mestre <mestre@cvs.openbsd.org>2017-05-03 09:51:40 +0000
commitdce3ca59e0bfb31467829ba436634072a5c09a94 (patch)
tree3ee52c1b525fb89cd3731d8ee40a7f42516e8a07 /usr.bin
parent88384d18b5e0b1be0b4ae3e5d552e8d0ac317a65 (diff)
Use the safe idiom of cleaning sensitive data from memory with explicit_bzero,
instead of relying on other methods, after readpassphrase. Some programs on this diff won't benefit that much since it happens near the terminal path, but someone might copy the unsafe idiom to another program and place it where it may leak sensitive data. Discussed aeons ago with tb@, OK deraadt@ and beck@
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/encrypt/encrypt.c3
-rw-r--r--usr.bin/lock/lock.c14
-rw-r--r--usr.bin/skey/skey.c8
-rw-r--r--usr.bin/x99token/x99token.c6
4 files changed, 21 insertions, 10 deletions
diff --git a/usr.bin/encrypt/encrypt.c b/usr.bin/encrypt/encrypt.c
index 5a80fdd081f..5670929b51d 100644
--- a/usr.bin/encrypt/encrypt.c
+++ b/usr.bin/encrypt/encrypt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: encrypt.c,v 1.45 2016/09/04 15:36:13 tb Exp $ */
+/* $OpenBSD: encrypt.c,v 1.46 2017/05/03 09:51:39 mestre Exp $ */
/*
* Copyright (c) 1996, Jason Downs. All rights reserved.
@@ -134,6 +134,7 @@ main(int argc, char **argv)
err(1, "readpassphrase");
print_passwd(string, operation, extra);
(void)fputc('\n', stdout);
+ explicit_bzero(string, sizeof(string));
} else {
size_t len;
/* Encrypt stdin to stdout. */
diff --git a/usr.bin/lock/lock.c b/usr.bin/lock/lock.c
index 9aeb0c5560e..b403f55459c 100644
--- a/usr.bin/lock/lock.c
+++ b/usr.bin/lock/lock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lock.c,v 1.33 2016/05/28 16:11:10 tedu Exp $ */
+/* $OpenBSD: lock.c,v 1.34 2017/05/03 09:51:39 mestre Exp $ */
/* $NetBSD: lock.c,v 1.8 1996/05/07 18:32:31 jtc Exp $ */
/*
@@ -162,7 +162,7 @@ main(int argc, char *argv[])
warnx("\apasswords didn't match.");
exit(1);
}
- s[0] = '\0';
+ explicit_bzero(s, sizeof(s));
}
/* set signal handlers */
@@ -205,10 +205,16 @@ main(int argc, char *argv[])
p = NULL;
else
p = s;
- if (auth_userokay(pw->pw_name, nstyle, "auth-lock", p))
+ if (auth_userokay(pw->pw_name, nstyle, "auth-lock",
+ p)) {
+ explicit_bzero(s, sizeof(s));
break;
- } else if (strcmp(s, s1) == 0)
+ }
+ } else if (strcmp(s, s1) == 0) {
+ explicit_bzero(s, sizeof(s));
+ explicit_bzero(s1, sizeof(s1));
break;
+ }
(void)putc('\a', stderr);
cnt %= tries;
if (++cnt > backoff) {
diff --git a/usr.bin/skey/skey.c b/usr.bin/skey/skey.c
index f72beee4d0c..9f5f6b5cb47 100644
--- a/usr.bin/skey/skey.c
+++ b/usr.bin/skey/skey.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: skey.c,v 1.33 2015/12/01 00:00:19 millert Exp $ */
+/* $OpenBSD: skey.c,v 1.34 2017/05/03 09:51:39 mestre Exp $ */
/*
* OpenBSD S/Key (skey.c)
*
@@ -122,8 +122,12 @@ main(int argc, char *argv[])
exit(1);
/* Crunch seed and passphrase into starting key */
- if (keycrunch(key, seed, passwd) != 0)
+ if (keycrunch(key, seed, passwd) != 0) {
+ explicit_bzero(passwd, sizeof(passwd));
errx(1, "key crunch failed");
+ }
+
+ explicit_bzero(passwd, sizeof(passwd));
if (cnt == 1) {
while (n-- != 0)
diff --git a/usr.bin/x99token/x99token.c b/usr.bin/x99token/x99token.c
index 0aaa0919bdc..4775f1b0882 100644
--- a/usr.bin/x99token/x99token.c
+++ b/usr.bin/x99token/x99token.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: x99token.c,v 1.12 2015/10/15 19:30:03 bluhm Exp $ */
+/* $OpenBSD: x99token.c,v 1.13 2017/05/03 09:51:39 mestre Exp $ */
/*
* X9.9 calculator
@@ -169,8 +169,8 @@ main(int argc, char **argv)
predict(ks, buf, cnt);
- memset(&ks, 0, sizeof(ks));
- memset(buf, 0, sizeof(buf));
+ explicit_bzero(&ks, sizeof(ks));
+ explicit_bzero(buf, sizeof(buf));
exit(0);
}