Linux FSCRYPT development
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: linux-fscrypt@vger.kernel.org
Cc: Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH] fscrypt: Explicitly zeroize sw_secret in error path
Date: Wed, 21 Oct 2026 22:44:31 +0000	[thread overview]
Message-ID: <20261021224431.2353673-1-ebiggers@kernel.org> (raw)

Explicitly zeroize the sw_secret array in the case where
fscrypt_derive_sw_secret() fails, in case anything was written to it.
Doesn't really matter, but this came up in a code review.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 fs/crypto/keyring.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/crypto/keyring.c b/fs/crypto/keyring.c
index 874cc183ee624..09364fddcb7a1 100644
--- a/fs/crypto/keyring.c
+++ b/fs/crypto/keyring.c
@@ -561,8 +561,10 @@ static int add_master_key(struct super_block *sb,
 		if (secret->is_hw_wrapped) {
 			err = fscrypt_derive_sw_secret(sb, secret->bytes,
 						       secret->size, sw_secret);
-			if (err)
+			if (err) {
+				memzero_explicit(sw_secret, sizeof(sw_secret));
 				return err;
+			}
 			kdf_key = sw_secret;
 			kdf_key_size = sizeof(sw_secret);
 			/*

base-commit: ccc4d9f8912a5d9f519a34c3633fe53c8f9b429e
-- 
2.56.0.218.g1ec904b173-goog


             reply	other threads:[~2026-10-21 22:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 22:44 Eric Biggers [this message]
2026-10-24 18:03 ` [PATCH] fscrypt: Explicitly zeroize sw_secret in error path Eric Biggers

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=20261021224431.2353673-1-ebiggers@kernel.org \
    --to=ebiggers@kernel.org \
    --cc=linux-fscrypt@vger.kernel.org \
    /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