summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--auth2-chall.c4
-rw-r--r--authfd.c4
-rw-r--r--authfile.c8
-rw-r--r--bufaux.c4
-rw-r--r--bufec.c6
-rw-r--r--canohost.c2
-rw-r--r--channels.c10
-rw-r--r--cipher-chachapoly.c10
-rw-r--r--clientloop.c6
-rw-r--r--configure.ac5
-rw-r--r--hostfile.c6
-rw-r--r--kexc25519.c4
-rw-r--r--krl.c12
-rw-r--r--monitor.c4
-rw-r--r--openbsd-compat/explicit_bzero.c20
-rw-r--r--openbsd-compat/openbsd-compat.h6
-rw-r--r--sandbox-systrace.c4
-rw-r--r--session.c4
-rw-r--r--sftp-client.c4
-rw-r--r--ssh-keygen.c4
-rw-r--r--ssh.c12
-rw-r--r--sshconnect2.c4
-rw-r--r--sshd.c8
-rw-r--r--sshlogin.c2
25 files changed, 96 insertions, 65 deletions
diff --git a/ChangeLog b/ChangeLog
index 269f5363d..a3f75a8d2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -36,6 +36,14 @@
36 allow shutdown(2) syscall in sandbox - it may be called by packet_close() 36 allow shutdown(2) syscall in sandbox - it may be called by packet_close()
37 from portable 37 from portable
38 (Id sync only; change is already in portable) 38 (Id sync only; change is already in portable)
39 - tedu@cvs.openbsd.org 2014/01/31 16:39:19
40 [auth2-chall.c authfd.c authfile.c bufaux.c bufec.c canohost.c]
41 [channels.c cipher-chachapoly.c clientloop.c configure.ac hostfile.c]
42 [kexc25519.c krl.c monitor.c sandbox-systrace.c session.c]
43 [sftp-client.c ssh-keygen.c ssh.c sshconnect2.c sshd.c sshlogin.c]
44 [openbsd-compat/explicit_bzero.c openbsd-compat/openbsd-compat.h]
45 replace most bzero with explicit_bzero, except a few that cna be memset
46 ok djm dtucker
39 47
4020140131 4820140131
41 - (djm) [sandbox-seccomp-filter.c sandbox-systrace.c] Allow shutdown(2) 49 - (djm) [sandbox-seccomp-filter.c sandbox-systrace.c] Allow shutdown(2)
diff --git a/auth2-chall.c b/auth2-chall.c
index 031c2828c..4cfd8ff5b 100644
--- a/auth2-chall.c
+++ b/auth2-chall.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: auth2-chall.c,v 1.39 2013/11/08 00:39:14 djm Exp $ */ 1/* $OpenBSD: auth2-chall.c,v 1.40 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Copyright (c) 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001 Markus Friedl. All rights reserved.
4 * Copyright (c) 2001 Per Allansson. All rights reserved. 4 * Copyright (c) 2001 Per Allansson. All rights reserved.
@@ -148,7 +148,7 @@ kbdint_free(KbdintAuthctxt *kbdintctxt)
148 if (kbdintctxt->device) 148 if (kbdintctxt->device)
149 kbdint_reset_device(kbdintctxt); 149 kbdint_reset_device(kbdintctxt);
150 free(kbdintctxt->devices); 150 free(kbdintctxt->devices);
151 bzero(kbdintctxt, sizeof(*kbdintctxt)); 151 explicit_bzero(kbdintctxt, sizeof(*kbdintctxt));
152 free(kbdintctxt); 152 free(kbdintctxt);
153} 153}
154/* get next device */ 154/* get next device */
diff --git a/authfd.c b/authfd.c
index f9636903a..cea3f97b4 100644
--- a/authfd.c
+++ b/authfd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: authfd.c,v 1.91 2013/12/29 04:29:25 djm Exp $ */ 1/* $OpenBSD: authfd.c,v 1.92 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -102,7 +102,7 @@ ssh_get_authentication_socket(void)
102 if (!authsocket) 102 if (!authsocket)
103 return -1; 103 return -1;
104 104
105 bzero(&sunaddr, sizeof(sunaddr)); 105 memset(&sunaddr, 0, sizeof(sunaddr));
106 sunaddr.sun_family = AF_UNIX; 106 sunaddr.sun_family = AF_UNIX;
107 strlcpy(sunaddr.sun_path, authsocket, sizeof(sunaddr.sun_path)); 107 strlcpy(sunaddr.sun_path, authsocket, sizeof(sunaddr.sun_path));
108 108
diff --git a/authfile.c b/authfile.c
index 7eccbb2c9..22da0eb05 100644
--- a/authfile.c
+++ b/authfile.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: authfile.c,v 1.101 2013/12/29 04:35:50 djm Exp $ */ 1/* $OpenBSD: authfile.c,v 1.102 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -703,17 +703,17 @@ key_load_file(int fd, const char *filename, Buffer *blob)
703 __func__, filename == NULL ? "" : filename, 703 __func__, filename == NULL ? "" : filename,
704 filename == NULL ? "" : " ", strerror(errno)); 704 filename == NULL ? "" : " ", strerror(errno));
705 buffer_clear(blob); 705 buffer_clear(blob);
706 bzero(buf, sizeof(buf)); 706 explicit_bzero(buf, sizeof(buf));
707 return 0; 707 return 0;
708 } 708 }
709 buffer_append(blob, buf, len); 709 buffer_append(blob, buf, len);
710 if (buffer_len(blob) > MAX_KEY_FILE_SIZE) { 710 if (buffer_len(blob) > MAX_KEY_FILE_SIZE) {
711 buffer_clear(blob); 711 buffer_clear(blob);
712 bzero(buf, sizeof(buf)); 712 explicit_bzero(buf, sizeof(buf));
713 goto toobig; 713 goto toobig;
714 } 714 }
715 } 715 }
716 bzero(buf, sizeof(buf)); 716 explicit_bzero(buf, sizeof(buf));
717 if ((st.st_mode & (S_IFSOCK|S_IFCHR|S_IFIFO)) == 0 && 717 if ((st.st_mode & (S_IFSOCK|S_IFCHR|S_IFIFO)) == 0 &&
718 st.st_size != buffer_len(blob)) { 718 st.st_size != buffer_len(blob)) {
719 debug("%s: key file %.200s%schanged size while reading", 719 debug("%s: key file %.200s%schanged size while reading",
diff --git a/bufaux.c b/bufaux.c
index 9401fe1d0..f1f14b33d 100644
--- a/bufaux.c
+++ b/bufaux.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bufaux.c,v 1.54 2014/01/12 08:13:13 djm Exp $ */ 1/* $OpenBSD: bufaux.c,v 1.55 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -216,7 +216,7 @@ buffer_get_cstring_ret(Buffer *buffer, u_int *length_ptr)
216 if (cp == ret + length - 1) 216 if (cp == ret + length - 1)
217 error("buffer_get_cstring_ret: string contains \\0"); 217 error("buffer_get_cstring_ret: string contains \\0");
218 else { 218 else {
219 bzero(ret, length); 219 explicit_bzero(ret, length);
220 free(ret); 220 free(ret);
221 return NULL; 221 return NULL;
222 } 222 }
diff --git a/bufec.c b/bufec.c
index 6c0048978..89482b906 100644
--- a/bufec.c
+++ b/bufec.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bufec.c,v 1.2 2013/05/17 00:13:13 djm Exp $ */ 1/* $OpenBSD: bufec.c,v 1.3 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Copyright (c) 2010 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2010 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -77,7 +77,7 @@ buffer_put_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve,
77 ret = 0; 77 ret = 0;
78 out: 78 out:
79 if (buf != NULL) { 79 if (buf != NULL) {
80 bzero(buf, len); 80 explicit_bzero(buf, len);
81 free(buf); 81 free(buf);
82 } 82 }
83 BN_CTX_free(bnctx); 83 BN_CTX_free(bnctx);
@@ -130,7 +130,7 @@ buffer_get_ecpoint_ret(Buffer *buffer, const EC_GROUP *curve,
130 ret = 0; 130 ret = 0;
131 out: 131 out:
132 BN_CTX_free(bnctx); 132 BN_CTX_free(bnctx);
133 bzero(buf, len); 133 explicit_bzero(buf, len);
134 free(buf); 134 free(buf);
135 return ret; 135 return ret;
136} 136}
diff --git a/canohost.c b/canohost.c
index a19a60cda..a61a8c94d 100644
--- a/canohost.c
+++ b/canohost.c
@@ -192,7 +192,7 @@ ipv64_normalise_mapped(struct sockaddr_storage *addr, socklen_t *len)
192 memcpy(&inaddr, ((char *)&a6->sin6_addr) + 12, sizeof(inaddr)); 192 memcpy(&inaddr, ((char *)&a6->sin6_addr) + 12, sizeof(inaddr));
193 port = a6->sin6_port; 193 port = a6->sin6_port;
194 194
195 bzero(a4, sizeof(*a4)); 195 memset(a4, 0, sizeof(*a4));
196 196
197 a4->sin_family = AF_INET; 197 a4->sin_family = AF_INET;
198 *len = sizeof(*a4); 198 *len = sizeof(*a4);
diff --git a/channels.c b/channels.c
index e741f29b9..013accdc4 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.c,v 1.328 2013/12/19 01:04:36 djm Exp $ */ 1/* $OpenBSD: channels.c,v 1.329 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -423,7 +423,7 @@ channel_free(Channel *c)
423 if (cc->abandon_cb != NULL) 423 if (cc->abandon_cb != NULL)
424 cc->abandon_cb(c, cc->ctx); 424 cc->abandon_cb(c, cc->ctx);
425 TAILQ_REMOVE(&c->status_confirms, cc, entry); 425 TAILQ_REMOVE(&c->status_confirms, cc, entry);
426 bzero(cc, sizeof(*cc)); 426 explicit_bzero(cc, sizeof(*cc));
427 free(cc); 427 free(cc);
428 } 428 }
429 if (c->filter_cleanup != NULL && c->filter_ctx != NULL) 429 if (c->filter_cleanup != NULL && c->filter_ctx != NULL)
@@ -2671,7 +2671,7 @@ channel_input_status_confirm(int type, u_int32_t seq, void *ctxt)
2671 return; 2671 return;
2672 cc->cb(type, c, cc->ctx); 2672 cc->cb(type, c, cc->ctx);
2673 TAILQ_REMOVE(&c->status_confirms, cc, entry); 2673 TAILQ_REMOVE(&c->status_confirms, cc, entry);
2674 bzero(cc, sizeof(*cc)); 2674 explicit_bzero(cc, sizeof(*cc));
2675 free(cc); 2675 free(cc);
2676} 2676}
2677 2677
@@ -3304,9 +3304,7 @@ channel_connect_ctx_free(struct channel_connect *cctx)
3304 free(cctx->host); 3304 free(cctx->host);
3305 if (cctx->aitop) 3305 if (cctx->aitop)
3306 freeaddrinfo(cctx->aitop); 3306 freeaddrinfo(cctx->aitop);
3307 bzero(cctx, sizeof(*cctx)); 3307 memset(cctx, 0, sizeof(*cctx));
3308 cctx->host = NULL;
3309 cctx->ai = cctx->aitop = NULL;
3310} 3308}
3311 3309
3312/* Return CONNECTING channel to remote host, port */ 3310/* Return CONNECTING channel to remote host, port */
diff --git a/cipher-chachapoly.c b/cipher-chachapoly.c
index 91b0830fd..251b94ec8 100644
--- a/cipher-chachapoly.c
+++ b/cipher-chachapoly.c
@@ -14,7 +14,7 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17/* $OpenBSD: cipher-chachapoly.c,v 1.3 2013/12/15 21:42:35 djm Exp $ */ 17/* $OpenBSD: cipher-chachapoly.c,v 1.4 2014/01/31 16:39:19 tedu Exp $ */
18 18
19#include "includes.h" 19#include "includes.h"
20 20
@@ -58,7 +58,7 @@ chachapoly_crypt(struct chachapoly_ctx *ctx, u_int seqnr, u_char *dest,
58 * Run ChaCha20 once to generate the Poly1305 key. The IV is the 58 * Run ChaCha20 once to generate the Poly1305 key. The IV is the
59 * packet sequence number. 59 * packet sequence number.
60 */ 60 */
61 bzero(poly_key, sizeof(poly_key)); 61 memset(poly_key, 0, sizeof(poly_key));
62 put_u64(seqbuf, seqnr); 62 put_u64(seqbuf, seqnr);
63 chacha_ivsetup(&ctx->main_ctx, seqbuf, NULL); 63 chacha_ivsetup(&ctx->main_ctx, seqbuf, NULL);
64 chacha_encrypt_bytes(&ctx->main_ctx, 64 chacha_encrypt_bytes(&ctx->main_ctx,
@@ -90,9 +90,9 @@ chachapoly_crypt(struct chachapoly_ctx *ctx, u_int seqnr, u_char *dest,
90 r = 0; 90 r = 0;
91 91
92 out: 92 out:
93 bzero(expected_tag, sizeof(expected_tag)); 93 explicit_bzero(expected_tag, sizeof(expected_tag));
94 bzero(seqbuf, sizeof(seqbuf)); 94 explicit_bzero(seqbuf, sizeof(seqbuf));
95 bzero(poly_key, sizeof(poly_key)); 95 explicit_bzero(poly_key, sizeof(poly_key));
96 return r; 96 return r;
97} 97}
98 98
diff --git a/clientloop.c b/clientloop.c
index f30c8b6b5..fd3ff49e8 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: clientloop.c,v 1.256 2013/11/20 20:54:10 deraadt Exp $ */ 1/* $OpenBSD: clientloop.c,v 1.257 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -549,7 +549,7 @@ client_global_request_reply(int type, u_int32_t seq, void *ctxt)
549 gc->cb(type, seq, gc->ctx); 549 gc->cb(type, seq, gc->ctx);
550 if (--gc->ref_count <= 0) { 550 if (--gc->ref_count <= 0) {
551 TAILQ_REMOVE(&global_confirms, gc, entry); 551 TAILQ_REMOVE(&global_confirms, gc, entry);
552 bzero(gc, sizeof(*gc)); 552 explicit_bzero(gc, sizeof(*gc));
553 free(gc); 553 free(gc);
554 } 554 }
555 555
@@ -876,7 +876,7 @@ process_cmdline(void)
876 int cancel_port, ok; 876 int cancel_port, ok;
877 Forward fwd; 877 Forward fwd;
878 878
879 bzero(&fwd, sizeof(fwd)); 879 memset(&fwd, 0, sizeof(fwd));
880 fwd.listen_host = fwd.connect_host = NULL; 880 fwd.listen_host = fwd.connect_host = NULL;
881 881
882 leave_raw_mode(options.request_tty == REQUEST_TTY_FORCE); 882 leave_raw_mode(options.request_tty == REQUEST_TTY_FORCE);
diff --git a/configure.ac b/configure.ac
index dfd32cd85..a350a2a55 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
1# $Id: configure.ac,v 1.568 2014/01/30 00:26:46 djm Exp $ 1# $Id: configure.ac,v 1.569 2014/02/04 00:18:21 djm Exp $
2# 2#
3# Copyright (c) 1999-2004 Damien Miller 3# Copyright (c) 1999-2004 Damien Miller
4# 4#
@@ -15,7 +15,7 @@
15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 16
17AC_INIT([OpenSSH], [Portable], [openssh-unix-dev@mindrot.org]) 17AC_INIT([OpenSSH], [Portable], [openssh-unix-dev@mindrot.org])
18AC_REVISION($Revision: 1.568 $) 18AC_REVISION($Revision: 1.569 $)
19AC_CONFIG_SRCDIR([ssh.c]) 19AC_CONFIG_SRCDIR([ssh.c])
20AC_LANG([C]) 20AC_LANG([C])
21 21
@@ -1649,6 +1649,7 @@ AC_CHECK_FUNCS([ \
1649 closefrom \ 1649 closefrom \
1650 dirfd \ 1650 dirfd \
1651 endgrent \ 1651 endgrent \
1652 explicit_bzero \
1652 fchmod \ 1653 fchmod \
1653 fchown \ 1654 fchown \
1654 freeaddrinfo \ 1655 freeaddrinfo \
diff --git a/hostfile.c b/hostfile.c
index 0198cd001..8bc9540b7 100644
--- a/hostfile.c
+++ b/hostfile.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hostfile.c,v 1.54 2014/01/27 18:58:14 markus Exp $ */ 1/* $OpenBSD: hostfile.c,v 1.55 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -333,10 +333,10 @@ free_hostkeys(struct hostkeys *hostkeys)
333 free(hostkeys->entries[i].host); 333 free(hostkeys->entries[i].host);
334 free(hostkeys->entries[i].file); 334 free(hostkeys->entries[i].file);
335 key_free(hostkeys->entries[i].key); 335 key_free(hostkeys->entries[i].key);
336 bzero(hostkeys->entries + i, sizeof(*hostkeys->entries)); 336 explicit_bzero(hostkeys->entries + i, sizeof(*hostkeys->entries));
337 } 337 }
338 free(hostkeys->entries); 338 free(hostkeys->entries);
339 bzero(hostkeys, sizeof(*hostkeys)); 339 explicit_bzero(hostkeys, sizeof(*hostkeys));
340 free(hostkeys); 340 free(hostkeys);
341} 341}
342 342
diff --git a/kexc25519.c b/kexc25519.c
index 48ca4aaa2..ee79b4327 100644
--- a/kexc25519.c
+++ b/kexc25519.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kexc25519.c,v 1.4 2014/01/12 08:13:13 djm Exp $ */ 1/* $OpenBSD: kexc25519.c,v 1.5 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Copyright (c) 2001, 2013 Markus Friedl. All rights reserved. 3 * Copyright (c) 2001, 2013 Markus Friedl. All rights reserved.
4 * Copyright (c) 2010 Damien Miller. All rights reserved. 4 * Copyright (c) 2010 Damien Miller. All rights reserved.
@@ -70,7 +70,7 @@ kexc25519_shared_key(const u_char key[CURVE25519_SIZE],
70#endif 70#endif
71 buffer_clear(out); 71 buffer_clear(out);
72 buffer_put_bignum2_from_string(out, shared_key, CURVE25519_SIZE); 72 buffer_put_bignum2_from_string(out, shared_key, CURVE25519_SIZE);
73 memset(shared_key, 0, CURVE25519_SIZE); /* XXX explicit_bzero() */ 73 explicit_bzero(shared_key, CURVE25519_SIZE);
74} 74}
75 75
76void 76void
diff --git a/krl.c b/krl.c
index b2d0354f2..3b4cded05 100644
--- a/krl.c
+++ b/krl.c
@@ -14,7 +14,7 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17/* $OpenBSD: krl.c,v 1.13 2013/07/20 22:20:42 djm Exp $ */ 17/* $OpenBSD: krl.c,v 1.14 2014/01/31 16:39:19 tedu Exp $ */
18 18
19#include "includes.h" 19#include "includes.h"
20 20
@@ -238,7 +238,7 @@ insert_serial_range(struct revoked_serial_tree *rt, u_int64_t lo, u_int64_t hi)
238 struct revoked_serial rs, *ers, *crs, *irs; 238 struct revoked_serial rs, *ers, *crs, *irs;
239 239
240 KRL_DBG(("%s: insert %llu:%llu", __func__, lo, hi)); 240 KRL_DBG(("%s: insert %llu:%llu", __func__, lo, hi));
241 bzero(&rs, sizeof(rs)); 241 memset(&rs, 0, sizeof(rs));
242 rs.lo = lo; 242 rs.lo = lo;
243 rs.hi = hi; 243 rs.hi = hi;
244 ers = RB_NFIND(revoked_serial_tree, rt, &rs); 244 ers = RB_NFIND(revoked_serial_tree, rt, &rs);
@@ -1115,7 +1115,7 @@ is_key_revoked(struct ssh_krl *krl, const Key *key)
1115 struct revoked_certs *rc; 1115 struct revoked_certs *rc;
1116 1116
1117 /* Check explicitly revoked hashes first */ 1117 /* Check explicitly revoked hashes first */
1118 bzero(&rb, sizeof(rb)); 1118 memset(&rb, 0, sizeof(rb));
1119 if ((rb.blob = key_fingerprint_raw(key, SSH_FP_SHA1, &rb.len)) == NULL) 1119 if ((rb.blob = key_fingerprint_raw(key, SSH_FP_SHA1, &rb.len)) == NULL)
1120 return -1; 1120 return -1;
1121 erb = RB_FIND(revoked_blob_tree, &krl->revoked_sha1s, &rb); 1121 erb = RB_FIND(revoked_blob_tree, &krl->revoked_sha1s, &rb);
@@ -1126,7 +1126,7 @@ is_key_revoked(struct ssh_krl *krl, const Key *key)
1126 } 1126 }
1127 1127
1128 /* Next, explicit keys */ 1128 /* Next, explicit keys */
1129 bzero(&rb, sizeof(rb)); 1129 memset(&rb, 0, sizeof(rb));
1130 if (plain_key_blob(key, &rb.blob, &rb.len) != 0) 1130 if (plain_key_blob(key, &rb.blob, &rb.len) != 0)
1131 return -1; 1131 return -1;
1132 erb = RB_FIND(revoked_blob_tree, &krl->revoked_keys, &rb); 1132 erb = RB_FIND(revoked_blob_tree, &krl->revoked_keys, &rb);
@@ -1147,7 +1147,7 @@ is_key_revoked(struct ssh_krl *krl, const Key *key)
1147 return 0; /* No entry for this CA */ 1147 return 0; /* No entry for this CA */
1148 1148
1149 /* Check revocation by cert key ID */ 1149 /* Check revocation by cert key ID */
1150 bzero(&rki, sizeof(rki)); 1150 memset(&rki, 0, sizeof(rki));
1151 rki.key_id = key->cert->key_id; 1151 rki.key_id = key->cert->key_id;
1152 erki = RB_FIND(revoked_key_id_tree, &rc->revoked_key_ids, &rki); 1152 erki = RB_FIND(revoked_key_id_tree, &rc->revoked_key_ids, &rki);
1153 if (erki != NULL) { 1153 if (erki != NULL) {
@@ -1162,7 +1162,7 @@ is_key_revoked(struct ssh_krl *krl, const Key *key)
1162 if (key_cert_is_legacy(key) || key->cert->serial == 0) 1162 if (key_cert_is_legacy(key) || key->cert->serial == 0)
1163 return 0; 1163 return 0;
1164 1164
1165 bzero(&rs, sizeof(rs)); 1165 memset(&rs, 0, sizeof(rs));
1166 rs.lo = rs.hi = key->cert->serial; 1166 rs.lo = rs.hi = key->cert->serial;
1167 ers = RB_FIND(revoked_serial_tree, &rc->revoked_serials, &rs); 1167 ers = RB_FIND(revoked_serial_tree, &rc->revoked_serials, &rs);
1168 if (ers != NULL) { 1168 if (ers != NULL) {
diff --git a/monitor.c b/monitor.c
index c923e7c0b..79bd7c0c4 100644
--- a/monitor.c
+++ b/monitor.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: monitor.c,v 1.129 2014/01/29 06:18:35 djm Exp $ */ 1/* $OpenBSD: monitor.c,v 1.130 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Copyright 2002 Niels Provos <provos@citi.umich.edu> 3 * Copyright 2002 Niels Provos <provos@citi.umich.edu>
4 * Copyright 2002 Markus Friedl <markus@openbsd.org> 4 * Copyright 2002 Markus Friedl <markus@openbsd.org>
@@ -544,7 +544,7 @@ monitor_read(struct monitor *pmonitor, struct mon_table *ent,
544 struct pollfd pfd[2]; 544 struct pollfd pfd[2];
545 545
546 for (;;) { 546 for (;;) {
547 bzero(&pfd, sizeof(pfd)); 547 memset(&pfd, 0, sizeof(pfd));
548 pfd[0].fd = pmonitor->m_sendfd; 548 pfd[0].fd = pmonitor->m_sendfd;
549 pfd[0].events = POLLIN; 549 pfd[0].events = POLLIN;
550 pfd[1].fd = pmonitor->m_log_recvfd; 550 pfd[1].fd = pmonitor->m_log_recvfd;
diff --git a/openbsd-compat/explicit_bzero.c b/openbsd-compat/explicit_bzero.c
new file mode 100644
index 000000000..b106741e5
--- /dev/null
+++ b/openbsd-compat/explicit_bzero.c
@@ -0,0 +1,20 @@
1/* OPENBSD ORIGINAL: lib/libc/string/explicit_bzero.c */
2/* $OpenBSD: explicit_bzero.c,v 1.1 2014/01/22 21:06:45 tedu Exp $ */
3/*
4 * Public domain.
5 * Written by Ted Unangst
6 */
7
8#include "includes.h"
9
10#ifndef HAVE_EXPLICIT_BZERO
11
12/*
13 * explicit_bzero - don't let the compiler optimize away bzero
14 */
15void
16explicit_bzero(void *p, size_t n)
17{
18 bzero(p, n);
19}
20#endif
diff --git a/openbsd-compat/openbsd-compat.h b/openbsd-compat/openbsd-compat.h
index f34619e4a..bc9888e31 100644
--- a/openbsd-compat/openbsd-compat.h
+++ b/openbsd-compat/openbsd-compat.h
@@ -1,4 +1,4 @@
1/* $Id: openbsd-compat.h,v 1.60 2013/12/07 00:51:54 djm Exp $ */ 1/* $Id: openbsd-compat.h,v 1.61 2014/02/04 00:18:23 djm Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved. 4 * Copyright (c) 1999-2003 Damien Miller. All rights reserved.
@@ -246,6 +246,10 @@ int bcrypt_pbkdf(const char *, size_t, const u_int8_t *, size_t,
246 u_int8_t *, size_t, unsigned int); 246 u_int8_t *, size_t, unsigned int);
247#endif 247#endif
248 248
249#ifndef HAVE_EXPLICIT_BZERO
250void explicit_bzero(void *p, size_t n);
251#endif
252
249void *xmmap(size_t size); 253void *xmmap(size_t size);
250char *xcrypt(const char *password, const char *salt); 254char *xcrypt(const char *password, const char *salt);
251char *shadow_pw(struct passwd *pw); 255char *shadow_pw(struct passwd *pw);
diff --git a/sandbox-systrace.c b/sandbox-systrace.c
index 70af3862f..6706c9a80 100644
--- a/sandbox-systrace.c
+++ b/sandbox-systrace.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sandbox-systrace.c,v 1.8 2014/01/30 22:26:14 djm Exp $ */ 1/* $OpenBSD: sandbox-systrace.c,v 1.9 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org> 3 * Copyright (c) 2011 Damien Miller <djm@mindrot.org>
4 * 4 *
@@ -142,7 +142,7 @@ ssh_sandbox_parent(struct ssh_sandbox *box, pid_t child_pid,
142 box->systrace_fd, child_pid, strerror(errno)); 142 box->systrace_fd, child_pid, strerror(errno));
143 143
144 /* Allocate and assign policy */ 144 /* Allocate and assign policy */
145 bzero(&policy, sizeof(policy)); 145 memset(&policy, 0, sizeof(policy));
146 policy.strp_op = SYSTR_POLICY_NEW; 146 policy.strp_op = SYSTR_POLICY_NEW;
147 policy.strp_maxents = SYS_MAXSYSCALL; 147 policy.strp_maxents = SYS_MAXSYSCALL;
148 if (ioctl(box->systrace_fd, STRIOCPOLICY, &policy) == -1) 148 if (ioctl(box->systrace_fd, STRIOCPOLICY, &policy) == -1)
diff --git a/session.c b/session.c
index 12dd9ab10..f5049774b 100644
--- a/session.c
+++ b/session.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: session.c,v 1.269 2014/01/18 09:36:26 dtucker Exp $ */ 1/* $OpenBSD: session.c,v 1.270 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 3 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
4 * All rights reserved 4 * All rights reserved
@@ -1889,7 +1889,7 @@ session_unused(int id)
1889 fatal("%s: insane session id %d (max %d nalloc %d)", 1889 fatal("%s: insane session id %d (max %d nalloc %d)",
1890 __func__, id, options.max_sessions, sessions_nalloc); 1890 __func__, id, options.max_sessions, sessions_nalloc);
1891 } 1891 }
1892 bzero(&sessions[id], sizeof(*sessions)); 1892 memset(&sessions[id], 0, sizeof(*sessions));
1893 sessions[id].self = id; 1893 sessions[id].self = id;
1894 sessions[id].used = 0; 1894 sessions[id].used = 0;
1895 sessions[id].chanid = -1; 1895 sessions[id].chanid = -1;
diff --git a/sftp-client.c b/sftp-client.c
index fc035f2ef..2f5907c85 100644
--- a/sftp-client.c
+++ b/sftp-client.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp-client.c,v 1.113 2014/01/17 00:21:06 djm Exp $ */ 1/* $OpenBSD: sftp-client.c,v 1.114 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -310,7 +310,7 @@ get_decode_statvfs(struct sftp_conn *conn, struct sftp_statvfs *st,
310 SSH2_FXP_EXTENDED_REPLY, type); 310 SSH2_FXP_EXTENDED_REPLY, type);
311 } 311 }
312 312
313 bzero(st, sizeof(*st)); 313 memset(st, 0, sizeof(*st));
314 st->f_bsize = buffer_get_int64(&msg); 314 st->f_bsize = buffer_get_int64(&msg);
315 st->f_frsize = buffer_get_int64(&msg); 315 st->f_frsize = buffer_get_int64(&msg);
316 st->f_blocks = buffer_get_int64(&msg); 316 st->f_blocks = buffer_get_int64(&msg);
diff --git a/ssh-keygen.c b/ssh-keygen.c
index eae83a461..8140447f7 100644
--- a/ssh-keygen.c
+++ b/ssh-keygen.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-keygen.c,v 1.238 2013/12/06 13:39:49 markus Exp $ */ 1/* $OpenBSD: ssh-keygen.c,v 1.239 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1994 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1716,7 +1716,7 @@ parse_absolute_time(const char *s)
1716 fatal("Invalid certificate time format %s", s); 1716 fatal("Invalid certificate time format %s", s);
1717 } 1717 }
1718 1718
1719 bzero(&tm, sizeof(tm)); 1719 memset(&tm, 0, sizeof(tm));
1720 if (strptime(buf, fmt, &tm) == NULL) 1720 if (strptime(buf, fmt, &tm) == NULL)
1721 fatal("Invalid certificate time %s", s); 1721 fatal("Invalid certificate time %s", s);
1722 if ((tt = mktime(&tm)) < 0) 1722 if ((tt = mktime(&tm)) < 0)
diff --git a/ssh.c b/ssh.c
index 5de8fcf43..ec957333b 100644
--- a/ssh.c
+++ b/ssh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh.c,v 1.397 2013/12/29 05:42:16 djm Exp $ */ 1/* $OpenBSD: ssh.c,v 1.398 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -239,7 +239,7 @@ resolve_host(const char *name, u_int port, int logerr, char *cname, size_t clen)
239 int gaierr, loglevel = SYSLOG_LEVEL_DEBUG1; 239 int gaierr, loglevel = SYSLOG_LEVEL_DEBUG1;
240 240
241 snprintf(strport, sizeof strport, "%u", port); 241 snprintf(strport, sizeof strport, "%u", port);
242 bzero(&hints, sizeof(hints)); 242 memset(&hints, 0, sizeof(hints));
243 hints.ai_family = options.address_family; 243 hints.ai_family = options.address_family;
244 hints.ai_socktype = SOCK_STREAM; 244 hints.ai_socktype = SOCK_STREAM;
245 if (cname != NULL) 245 if (cname != NULL)
@@ -1697,8 +1697,8 @@ load_public_identity_files(void)
1697#endif /* PKCS11 */ 1697#endif /* PKCS11 */
1698 1698
1699 n_ids = 0; 1699 n_ids = 0;
1700 bzero(identity_files, sizeof(identity_files)); 1700 memset(identity_files, 0, sizeof(identity_files));
1701 bzero(identity_keys, sizeof(identity_keys)); 1701 memset(identity_keys, 0, sizeof(identity_keys));
1702 1702
1703#ifdef ENABLE_PKCS11 1703#ifdef ENABLE_PKCS11
1704 if (options.pkcs11_provider != NULL && 1704 if (options.pkcs11_provider != NULL &&
@@ -1773,9 +1773,9 @@ load_public_identity_files(void)
1773 memcpy(options.identity_files, identity_files, sizeof(identity_files)); 1773 memcpy(options.identity_files, identity_files, sizeof(identity_files));
1774 memcpy(options.identity_keys, identity_keys, sizeof(identity_keys)); 1774 memcpy(options.identity_keys, identity_keys, sizeof(identity_keys));
1775 1775
1776 bzero(pwname, strlen(pwname)); 1776 explicit_bzero(pwname, strlen(pwname));
1777 free(pwname); 1777 free(pwname);
1778 bzero(pwdir, strlen(pwdir)); 1778 explicit_bzero(pwdir, strlen(pwdir));
1779 free(pwdir); 1779 free(pwdir);
1780} 1780}
1781 1781
diff --git a/sshconnect2.c b/sshconnect2.c
index 8343db10e..c60a8511b 100644
--- a/sshconnect2.c
+++ b/sshconnect2.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect2.c,v 1.202 2014/01/29 06:18:35 djm Exp $ */ 1/* $OpenBSD: sshconnect2.c,v 1.203 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Copyright (c) 2000 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000 Markus Friedl. All rights reserved.
4 * Copyright (c) 2008 Damien Miller. All rights reserved. 4 * Copyright (c) 2008 Damien Miller. All rights reserved.
@@ -1190,7 +1190,7 @@ pubkey_prepare(Authctxt *authctxt)
1190 /* If IdentitiesOnly set and key not found then don't use it */ 1190 /* If IdentitiesOnly set and key not found then don't use it */
1191 if (!found && options.identities_only) { 1191 if (!found && options.identities_only) {
1192 TAILQ_REMOVE(&files, id, next); 1192 TAILQ_REMOVE(&files, id, next);
1193 bzero(id, sizeof(*id)); 1193 explicit_bzero(id, sizeof(*id));
1194 free(id); 1194 free(id);
1195 } 1195 }
1196 } 1196 }
diff --git a/sshd.c b/sshd.c
index cb2e7db40..b7411fe83 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshd.c,v 1.416 2014/01/29 00:19:26 djm Exp $ */ 1/* $OpenBSD: sshd.c,v 1.417 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -621,7 +621,7 @@ privsep_preauth_child(void)
621 arc4random_stir(); 621 arc4random_stir();
622 arc4random_buf(rnd, sizeof(rnd)); 622 arc4random_buf(rnd, sizeof(rnd));
623 RAND_seed(rnd, sizeof(rnd)); 623 RAND_seed(rnd, sizeof(rnd));
624 bzero(rnd, sizeof(rnd)); 624 explicit_bzero(rnd, sizeof(rnd));
625 625
626 /* Demote the private keys to public keys. */ 626 /* Demote the private keys to public keys. */
627 demote_sensitive_data(); 627 demote_sensitive_data();
@@ -756,7 +756,7 @@ privsep_postauth(Authctxt *authctxt)
756 arc4random_stir(); 756 arc4random_stir();
757 arc4random_buf(rnd, sizeof(rnd)); 757 arc4random_buf(rnd, sizeof(rnd));
758 RAND_seed(rnd, sizeof(rnd)); 758 RAND_seed(rnd, sizeof(rnd));
759 bzero(rnd, sizeof(rnd)); 759 explicit_bzero(rnd, sizeof(rnd));
760 760
761 /* Drop privileges */ 761 /* Drop privileges */
762 do_setusercontext(authctxt->pw); 762 do_setusercontext(authctxt->pw);
@@ -1355,7 +1355,7 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
1355 arc4random_stir(); 1355 arc4random_stir();
1356 arc4random_buf(rnd, sizeof(rnd)); 1356 arc4random_buf(rnd, sizeof(rnd));
1357 RAND_seed(rnd, sizeof(rnd)); 1357 RAND_seed(rnd, sizeof(rnd));
1358 bzero(rnd, sizeof(rnd)); 1358 explicit_bzero(rnd, sizeof(rnd));
1359 } 1359 }
1360 1360
1361 /* child process check (or debug mode) */ 1361 /* child process check (or debug mode) */
diff --git a/sshlogin.c b/sshlogin.c
index 2688d8d7b..e79ca9b47 100644
--- a/sshlogin.c
+++ b/sshlogin.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshlogin.c,v 1.27 2011/01/11 06:06:09 djm Exp $ */ 1/* $OpenBSD: sshlogin.c,v 1.28 2014/01/31 16:39:19 tedu Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland