* [PATCH v2 2/6] smb: clear the aes_cmac_key and aes_cmac_ctx when done [not found] <20260807125845.1477067-1-thuth@redhat.com> @ 2026-08-07 12:58 ` Thomas Huth 2026-08-11 10:31 ` Namjae Jeon 0 siblings, 1 reply; 4+ messages in thread From: Thomas Huth @ 2026-08-07 12:58 UTC (permalink / raw) To: Eric Biggers, Steve French, Namjae Jeon Cc: Herbert Xu, David S. Miller, linux-crypto, linux-kernel, Steve French, Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM, Sergey Senozhatsky, linux-cifs, samba-technical From: Thomas Huth <thuth@redhat.com> 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 <thuth@redhat.com> --- 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]; diff --git a/fs/smb/server/auth.c b/fs/smb/server/auth.c index 4e7b6f0e6b8cd..e8d1c068a43e8 100644 --- a/fs/smb/server/auth.c +++ b/fs/smb/server/auth.c @@ -509,7 +509,7 @@ void ksmbd_sign_smb2_pdu(struct ksmbd_conn *conn, char *key, struct kvec *iov, void ksmbd_sign_smb3_pdu(struct ksmbd_conn *conn, char *key, struct kvec *iov, int n_vec, char *sig) { - struct aes_cmac_key cmac_key; + struct aes_cmac_key cmac_key __cleanup(aes_cmac_zeroize_key); struct aes_cmac_ctx cmac_ctx; int i; -- 2.55.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/6] smb: clear the aes_cmac_key and aes_cmac_ctx when done 2026-08-07 12:58 ` [PATCH v2 2/6] smb: clear the aes_cmac_key and aes_cmac_ctx when done Thomas Huth @ 2026-08-11 10:31 ` Namjae Jeon 2026-08-11 12:57 ` Thomas Huth 0 siblings, 1 reply; 4+ messages in thread From: Namjae Jeon @ 2026-08-11 10:31 UTC (permalink / raw) To: Thomas Huth Cc: Eric Biggers, Steve French, Herbert Xu, David S. Miller, linux-crypto, linux-kernel, Steve French, Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM, Sergey Senozhatsky, linux-cifs, samba-technical > 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]; Shouldn’t we also clear the raw key with memzero_explicit(key, sizeof(key)) immediately after aes_cmac_preparekey() ? rc = aes_cmac_preparekey(&cmac_key, key, SMB2_CMACAES_SIZE); + memzero_explicit(key, sizeof(key)); if (rc) { cifs_server_dbg(VFS, "%s: Could not set key for cmac aes\n", __func__); return rc; } ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/6] smb: clear the aes_cmac_key and aes_cmac_ctx when done 2026-08-11 10:31 ` Namjae Jeon @ 2026-08-11 12:57 ` Thomas Huth 2026-08-12 12:44 ` Namjae Jeon 0 siblings, 1 reply; 4+ messages in thread From: Thomas Huth @ 2026-08-11 12:57 UTC (permalink / raw) To: Namjae Jeon Cc: Eric Biggers, Steve French, Herbert Xu, David S. Miller, linux-crypto, linux-kernel, Steve French, Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM, Sergey Senozhatsky, linux-cifs, samba-technical On 11/08/2026 12.31, Namjae Jeon wrote: >> 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]; > Shouldn’t we also clear the raw key with memzero_explicit(key, > sizeof(key)) immediately after aes_cmac_preparekey() ? > > rc = aes_cmac_preparekey(&cmac_key, key, SMB2_CMACAES_SIZE); > + memzero_explicit(key, sizeof(key)); > if (rc) { > cifs_server_dbg(VFS, "%s: Could not set key for cmac > aes\n", __func__); > return rc; > } Yes, but I was planning to do all the scrubbing for such other spots in a separate patch series (similar to what I've posted for the smb/server code already) ... this patch series here focuses on aes_cmac_zeroize_key and aes_cmac_zeroize_ctx only. I hope that's ok? Thomas ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/6] smb: clear the aes_cmac_key and aes_cmac_ctx when done 2026-08-11 12:57 ` Thomas Huth @ 2026-08-12 12:44 ` Namjae Jeon 0 siblings, 0 replies; 4+ messages in thread From: Namjae Jeon @ 2026-08-12 12:44 UTC (permalink / raw) To: Thomas Huth Cc: Eric Biggers, Steve French, Herbert Xu, David S. Miller, linux-crypto, linux-kernel, Steve French, Paulo Alcantara, Ronnie Sahlberg, Shyam Prasad N, Tom Talpey, Bharath SM, Sergey Senozhatsky, linux-cifs, samba-technical On Tue, Aug 11, 2026 at 9:57 PM Thomas Huth <thuth@redhat.com> wrote: > > On 11/08/2026 12.31, Namjae Jeon wrote: > >> 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]; > > Shouldn’t we also clear the raw key with memzero_explicit(key, > > sizeof(key)) immediately after aes_cmac_preparekey() ? > > > > rc = aes_cmac_preparekey(&cmac_key, key, SMB2_CMACAES_SIZE); > > + memzero_explicit(key, sizeof(key)); > > if (rc) { > > cifs_server_dbg(VFS, "%s: Could not set key for cmac > > aes\n", __func__); > > return rc; > > } > Yes, but I was planning to do all the scrubbing for such other spots in a > separate patch series (similar to what I've posted for the smb/server code > already) ... this patch series here focuses on aes_cmac_zeroize_key and > aes_cmac_zeroize_ctx only. I hope that's ok? Acked-by: Namjae Jeon <linkinjeon@kernel.org> Thanks. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-12 12:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20260807125845.1477067-1-thuth@redhat.com>
2026-08-07 12:58 ` [PATCH v2 2/6] smb: clear the aes_cmac_key and aes_cmac_ctx when done Thomas Huth
2026-08-11 10:31 ` Namjae Jeon
2026-08-11 12:57 ` Thomas Huth
2026-08-12 12:44 ` Namjae Jeon
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox