From nobody Tue Oct 29 15:46:10 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XdF3Q6j0Bz5bcbt; Tue, 29 Oct 2024 15:46:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XdF3Q69NWz4dnv; Tue, 29 Oct 2024 15:46:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730216770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DKYMc20f27jLBXwbO1R+mmoDPsYnX4V2ZpwpGm3zOHU=; b=kwHy4o+OqoXFD5OVUOUqmU4E6RzEWIpBDKR1JSnB2fxr0HzdUjwl935dVRm+h4j1HmpnXm SKIaLoJinweplUL4PKg/mPx2C649ct6B03X66YGObazfRIDvjagkf588dMKI0WGcC0VM51 Uq4aenT3hco1q/BVtExotVD12yWZxZq2F9OaXkpnMdpYolmJ8HkhbH+64Fi6RefGIMcC97 th2lAH6grdzhU/ZgmHomWOFyrK/agi4ADt0BTacAP3CgssKWQhnkTm8CbLodCshrxrrAET rm6Ei8e5E9hAKH/tDF8TzTOOZ4v65tmku6YH0j653iUpqXdfDkUmGjpcbU4C5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730216770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=DKYMc20f27jLBXwbO1R+mmoDPsYnX4V2ZpwpGm3zOHU=; b=MZ4Yf3s+G2tUNAW3c+iIBMM+Nm0E3aj6QZLYBKTXsQK0EfJKrJ2swsYzhy467dZBSxYQ9j lwWtVCY+NfMF/JAK9VPtzrc2oBTF70x39vA9iz9M2yZHNcE6oKVO/gw7MDzs7YQg0tBZ0X PXxN3p1XQ3NgPAiO26kMzxI9RsRCH5iy4oEjFeaJixU6g/xi8XRsE8gukkasJsTxCHWz3h od3YWOYSButXFHU4NBgfl3m36h4RdxihU4PMHKw8k8H45q26GzvxECXUkdlb0LjM9vHr5H dItwJ1QTRXgjTkvTqkZXDebKOmqiBMMOLN8YOTj3vNtH6eT0FVWlaYp8u4sHtg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730216770; a=rsa-sha256; cv=none; b=E+3mD6RxmF08eyiV4NCAagc1pC0Npp0Nq9EEhLOzR1FC/ET1+sY99S2hibRegVuYK1nwMR k9lnQ8fKsspi9gy/pkpKnkJdTt9y9+Ms4KrJuhAD4pWIN6iDkYLctu4tEO5TtvuZm3Cgr3 vu1WUVWQL3wxJFDqlGM7Pa5wOoCJfN50j9iVShdVNO+86ZtDCo96V40EOScp7Xl805M396 E76B02Ew1PgrKhdHjwLivwFP6uIHIThI6L/9zidPq7Nw0eZJwIdQxW/63Zkon/fyQ+8chs 2uYRKXjdfGXS6DIEoE2LQX+VuV6NurUwjI4p5w27hL5ZvJyFNymL22A0SzYNXw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XdF3Q5lwczV3F; Tue, 29 Oct 2024 15:46:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49TFkAD4082554; Tue, 29 Oct 2024 15:46:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49TFkA8Y082551; Tue, 29 Oct 2024 15:46:10 GMT (envelope-from git) Date: Tue, 29 Oct 2024 15:46:10 GMT Message-Id: <202410291546.49TFkA8Y082551@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Robert Clausecker Subject: git: 1af027e583ec - stable/14 - lib/libcrypt: use explicit_bzero() to clear sensitive buffers List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: fuz X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 1af027e583ec725ae772a4cc0b128652553fa7ec Auto-Submitted: auto-generated The branch stable/14 has been updated by fuz: URL: https://cgit.FreeBSD.org/src/commit/?id=1af027e583ec725ae772a4cc0b128652553fa7ec commit 1af027e583ec725ae772a4cc0b128652553fa7ec Author: Robert Clausecker AuthorDate: 2024-10-10 09:08:35 +0000 Commit: Robert Clausecker CommitDate: 2024-10-29 15:45:31 +0000 lib/libcrypt: use explicit_bzero() to clear sensitive buffers Prevent a potentially sufficiently smart compiler from optimising away our attempts to clear sensitive buffers. A related change was discussed and rejected in D16059, but I don't believe the reasoning there applies: the code clearly documents its intent that the `memset` calls clear sensitive buffers so they don't hang around. `explicit_bzero` is the appropriate function for this purpose. A potential performance disadvantage seems less important: the functions in crypt are specifically designed to be slow, so a few extra calls to guarantee that sensitive buffers are cleared does not significantly affect runtime. See also: D16059 Reviewed by: delphij, kevans MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D47037 (cherry picked from commit a2c0d2026fb422ade2171da4bc6d5d2773b268a6) --- lib/libcrypt/crypt-md5.c | 5 +++-- lib/libcrypt/crypt-sha256.c | 7 ++++--- lib/libcrypt/crypt-sha512.c | 7 ++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/libcrypt/crypt-md5.c b/lib/libcrypt/crypt-md5.c index 3fb80c1ba540..5313f59a4098 100644 --- a/lib/libcrypt/crypt-md5.c +++ b/lib/libcrypt/crypt-md5.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include "crypt.h" @@ -85,7 +86,7 @@ crypt_md5(const char *pw, const char *salt, char *buffer) (u_int)(pl > MD5_SIZE ? MD5_SIZE : pl)); /* Don't leave anything around in vm they could use. */ - memset(final, 0, sizeof(final)); + explicit_bzero(final, sizeof(final)); /* Then something really weird... */ for (i = strlen(pw); i; i >>= 1) @@ -141,7 +142,7 @@ crypt_md5(const char *pw, const char *salt, char *buffer) *buffer = '\0'; /* Don't leave anything around in vm they could use. */ - memset(final, 0, sizeof(final)); + explicit_bzero(final, sizeof(final)); return (0); } diff --git a/lib/libcrypt/crypt-sha256.c b/lib/libcrypt/crypt-sha256.c index 35c36bf93f3d..6da1d518b12d 100644 --- a/lib/libcrypt/crypt-sha256.c +++ b/lib/libcrypt/crypt-sha256.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "crypt.h" @@ -234,9 +235,9 @@ crypt_sha256(const char *key, const char *salt, char *buffer) * the SHA256 implementation as well. */ SHA256_Init(&ctx); SHA256_Final(alt_result, &ctx); - memset(temp_result, '\0', sizeof(temp_result)); - memset(p_bytes, '\0', key_len); - memset(s_bytes, '\0', salt_len); + explicit_bzero(temp_result, sizeof(temp_result)); + explicit_bzero(p_bytes, key_len); + explicit_bzero(s_bytes, salt_len); return (0); } diff --git a/lib/libcrypt/crypt-sha512.c b/lib/libcrypt/crypt-sha512.c index 640398afadc4..b760623b5d8d 100644 --- a/lib/libcrypt/crypt-sha512.c +++ b/lib/libcrypt/crypt-sha512.c @@ -41,6 +41,7 @@ #include #include #include +#include #include "crypt.h" @@ -246,9 +247,9 @@ crypt_sha512(const char *key, const char *salt, char *buffer) * the SHA512 implementation as well. */ SHA512_Init(&ctx); SHA512_Final(alt_result, &ctx); - memset(temp_result, '\0', sizeof(temp_result)); - memset(p_bytes, '\0', key_len); - memset(s_bytes, '\0', salt_len); + explicit_bzero(temp_result, sizeof(temp_result)); + explicit_bzero(p_bytes, key_len); + explicit_bzero(s_bytes, salt_len); return (0); }