Skip to content

smb: server: Clear sensitive data before freeing it

Thomas Huth lkml 2 versions – Applied

Status from this message: Applied them to #ksmbd-for-next-next.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest5 patches 1 replyApplied
  2. v14 patches 2 repliesSuperseded

Changes in v2 from the cover letter

- Calculate proper size for the kvfree_sensitive() in the first patch
- Add "kfree_sensitive(target)" hunk to the connection.c patch
- Add patch to clear Preauth_HashValue in smb2pdu.c

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/5smb: server: Clear sensitive stack and heap data in auth.cfs/smb/server/auth.c+10 -20 replies
2/5smb: server: Make sure that passkey is not leaked on the heap in user_config.cfs/smb/server/mgmt/user_config.c+3 -30 replies
3/5smb: server: Free session data in user_session.c with kfree_sensitive()fs/smb/server/mgmt/user_session.c+2 -20 replies
4/5smb: server: Free sensitive data in connection.c with kfree_sensitive()fs/smb/server/connection.c+3 -30 replies
5/5smb: server: Clear Preauth_HashValue in smb2pdu.c with kfree_sensitive()fs/smb/server/smb2pdu.c+2 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/5] smb: server: Clear sensitive data before freeing it

Sensitive data like keys that are stored in stack-local arrays could be leaked via the stack to the calling functions, or via the heap when using only normal kfree() functions.

It's good security practice to clear sensitive data on the stack first with memzero_explicit() before leaving the context, and to use kfree_sensitive() for data that is returned to the heap.

Disclaimer: The spots that need clearing have been identified with AI, but the patches have been created manually (for double-checking whether the findings really make sense). Anyway, I'm not very familiar with the smb code, so please review carefully. Thanks!

v2:
- Calculate proper size for the kvfree_sensitive() in the first patch
- Add "kfree_sensitive(target)" hunk to the connection.c patch
- Add patch to clear Preauth_HashValue in smb2pdu.c

Thomas Huth (5):
smb: server: Clear sensitive stack and heap data in auth.c
smb: server: Make sure that passkey is not leaked on the heap in
user_config.c
smb: server: Free session data in user_session.c with
kfree_sensitive()
smb: server: Free sensitive data in connection.c with
kfree_sensitive()
smb: server: Clear Preauth_HashValue in smb2pdu.c with
kfree_sensitive()

 fs/smb/server/auth.c              | 12 ++++++++++--
 fs/smb/server/connection.c        |  6 +++---
 fs/smb/server/mgmt/user_config.c  |  6 +++---
 fs/smb/server/mgmt/user_session.c |  4 ++--
 fs/smb/server/smb2pdu.c           |  4 ++--
 5 files changed, 20 insertions(+), 12 deletions(-)
Signature · 1 line
2.55.0