Re: [PATCH 2/6] smb: clear the aes_cmac_key and aes_cmac_ctx when done
Eric Biggers <[email protected]> Wed, 5 Aug 2026 14:12:11 -0700
| Newsgroups | org.kernel.vger.linux-crypto,org.kernel.vger.linux-cifs,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <20260805211211.GJ3438@quark> |
On Wed, Aug 05, 2026 at 04:36:05PM +0200, Thomas Huth wrote: > From: Thomas Huth <[email protected]> > > Clear the local crypto-related structures via __cleanup() functions > when we're done with them to avoid that sensitive data could leak on > the stack. > > Note: cmac_ctx in ksmbd_sign_smb3_pdu() gets cleared in aes_cmac_final() > already, so this does not need a __cleanup() marker. > > Signed-off-by: Thomas Huth <[email protected]> > --- > fs/smb/client/smb2transport.c | 4 ++-- > fs/smb/server/auth.c | 2 +- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/fs/smb/client/smb2transport.c b/fs/smb/client/smb2transport.c > index 1143ee52470a7..d23566da2ac81 100644 > --- a/fs/smb/client/smb2transport.c > +++ b/fs/smb/client/smb2transport.c > @@ -464,8 +464,8 @@ smb3_calc_signature(struct smb_rqst *rqst, struct TCP_Server_Info *server) > unsigned char smb3_signature[SMB2_CMACAES_SIZE]; > struct kvec *iov = rqst->rq_iov; > struct smb2_hdr *shdr = (struct smb2_hdr *)iov[0].iov_base; > - struct aes_cmac_key cmac_key; > - struct aes_cmac_ctx cmac_ctx; > + struct aes_cmac_key cmac_key __cleanup(aes_cmac_zeroize_key); > + struct aes_cmac_ctx cmac_ctx __cleanup(aes_cmac_zeroize_ctx); > struct smb_rqst drqst; > u8 key[SMB3_SIGN_KEY_SIZE]; This is another example of a driver that has never made much attempt at key zeroization. Even considering just this function, the raw key is still on the stack and not zeroized. But it is not just this function, e.g. the smb2 code does the same. So yes, the '__cleanup' trick makes zeroizing these structs easy enough that we might as well do it anyway, but it would be nice to try to be a bit more comprehensive. - Eric