DF-2364 / fix.diff
--- a/sys/crypto/chachapoly.c +++ b/sys/crypto/chachapoly.c @@ -74,6 +74,9 @@ /* Initialize the authenticator. */ poly1305_init(&ctx->poly, poly_key); + /* wipe the one-time key from the stack (DF-2363) */ + explicit_bzero(poly_key, sizeof(poly_key)); + ctx->flags |= (enc_mode ? F_MODE_ENCRYPTION : 0); ctx->flags |= F_INITIALIZED; } @@ -113,6 +116,8 @@ KKASSERT((ctx->flags & F_INITIALIZED) != 0); KKASSERT(in_len == 0 || (in_len > 0 && out != NULL)); KKASSERT(in_len % CHACHA_BLOCKLEN == 0); /* must be complete blocks */ + /* chacha_encrypt_bytes() takes a uint32_t byte count (DF-2364) */ + KKASSERT(in_len <= 0xffffffffU); if ((ctx->flags & F_AD_DONE) == 0) { poly1305_update(&ctx->poly, pad0, PADDING_LEN(ctx->ad_len)); @@ -313,8 +318,10 @@ /* Skip possibly empty mbufs. */ while (m != NULL && m->m_len == 0) m = m->m_next; - if (m == NULL) + if (m == NULL) { + explicit_bzero(ctx, sizeof(*ctx)); return (EINVAL); /* because len > 0 */ + } } if (m->m_len >= off + sizeof(block)) { @@ -334,8 +341,10 @@ /* Advance pointer. */ m = m_getptr(m, off + sizeof(block), &off); - if (m == NULL) + if (m == NULL) { + explicit_bzero(ctx, sizeof(*ctx)); return (EINVAL); + } len -= (int)sizeof(block); } |