linux-yocto/fs/cifs
Wang Zhaolong 5d047b12f8 smb: client: fix use-after-free in crypt_message when using async crypto
[ Upstream commit b220bed633 ]

The CVE-2024-50047 fix removed asynchronous crypto handling from
crypt_message(), assuming all crypto operations are synchronous.
However, when hardware crypto accelerators are used, this can cause
use-after-free crashes:

  crypt_message()
    // Allocate the creq buffer containing the req
    creq = smb2_get_aead_req(..., &req);

    // Async encryption returns -EINPROGRESS immediately
    rc = enc ? crypto_aead_encrypt(req) : crypto_aead_decrypt(req);

    // Free creq while async operation is still in progress
    kvfree_sensitive(creq, ...);

Hardware crypto modules often implement async AEAD operations for
performance. When crypto_aead_encrypt/decrypt() returns -EINPROGRESS,
the operation completes asynchronously. Without crypto_wait_req(),
the function immediately frees the request buffer, leading to crashes
when the driver later accesses the freed memory.

This results in a use-after-free condition when the hardware crypto
driver later accesses the freed request structure, leading to kernel
crashes with NULL pointer dereferences.

The issue occurs because crypto_alloc_aead() with mask=0 doesn't
guarantee synchronous operation. Even without CRYPTO_ALG_ASYNC in
the mask, async implementations can be selected.

Fix by restoring the async crypto handling:
- DECLARE_CRYPTO_WAIT(wait) for completion tracking
- aead_request_set_callback() for async completion notification
- crypto_wait_req() to wait for operation completion

This ensures the request buffer isn't freed until the crypto operation
completes, whether synchronous or asynchronous, while preserving the
CVE-2024-50047 fix.

Fixes: b0abcd65ec ("smb: client: fix UAF in async decryption")
Link: https://lore.kernel.org/all/8b784a13-87b0-4131-9ff9-7a8993538749@huaweicloud.com/
Cc: stable@vger.kernel.org
Reviewed-by: Paulo Alcantara (Red Hat) <pc@manguebit.org>
Signed-off-by: Wang Zhaolong <wangzhaolong@huaweicloud.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-08-28 16:22:53 +02:00
..
asn1.c
cache.c
cifs_debug.c smb: client: fix potential UAF in cifs_stats_proc_show() 2025-05-02 07:41:06 +02:00
cifs_debug.h
cifs_dfs_ref.c
cifs_fs_sb.h
cifs_ioctl.h
cifs_spnego.c cifs: spnego: add ';' in HOST_KEY_LEN 2023-11-28 16:54:55 +00:00
cifs_spnego.h
cifs_unicode.c
cifs_unicode.h
cifs_uniupr.h
cifsacl.c
cifsacl.h
cifsencrypt.c
cifsfs.c cifs: Fix non-availability of dedup breaking generic/304 2023-12-13 18:27:07 +01:00
cifsfs.h cifs: fix DFS traversal oops without CONFIG_CIFS_DFS_UPCALL 2023-04-05 11:23:49 +02:00
cifsglob.h cifs: Fix UAF in cifs_demultiplex_thread() 2025-05-02 07:41:06 +02:00
cifspdu.h
cifsproto.h smb: client: fix potential deadlock when releasing mids 2025-05-02 07:41:06 +02:00
cifsroot.c
cifssmb.c cifs: Fix calling CIFSFindFirst() for root path without msearch 2025-08-28 16:22:44 +02:00
connect.c cifs: print TIDs as hex 2025-05-02 07:41:13 +02:00
dfs_cache.c
dfs_cache.h
dir.c
dns_resolve.c
dns_resolve.h
export.c
file.c cifs: Release folio lock on fscache read hit. 2023-08-26 15:26:55 +02:00
fs_context.c
fs_context.h
fscache.c
fscache.h
inode.c
ioctl.c
Kconfig
link.c cifs: Fix uninitialized memory read for smb311 posix symlink create 2023-01-18 11:44:54 +01:00
Makefile
misc.c cifs: Fix cifs_query_path_info() for Windows NT servers 2025-07-17 18:27:35 +02:00
netmisc.c
nterr.c
nterr.h
ntlmssp.h
readdir.c smb: client: Reset all search buffer pointers when releasing buffer 2025-06-04 14:37:08 +02:00
rfc1002pdu.h
sess.c
smb1ops.c
smb2file.c
smb2glob.h
smb2inode.c cifs: Fix smb2_set_path_size() 2023-03-22 13:30:03 +01:00
smb2maperror.c
smb2misc.c cifs: avoid NULL pointer dereference in dbg call 2025-05-02 07:41:13 +02:00
smb2ops.c smb: client: fix use-after-free in crypt_message when using async crypto 2025-08-28 16:22:53 +02:00
smb2pdu.c smb: client: fix NULL ptr deref in crypto_aead_setkey() 2025-05-02 07:41:06 +02:00
smb2pdu.h smb3: Replace smb2pdu 1-element arrays with flex-arrays 2024-02-23 08:41:55 +01:00
smb2proto.h smb: client: fix potential OOBs in smb2_parse_contexts() 2024-03-01 13:16:43 +01:00
smb2status.h
smb2transport.c smb: client: fix deadlock in smb2_find_smb_tcon() 2024-07-05 09:12:45 +02:00
smbdirect.c smb: client: let recv_done() cleanup before notifying the callers. 2025-08-28 16:22:37 +02:00
smbdirect.h
smbencrypt.c
smberr.h
smbfsctl.h
trace.c
trace.h
transport.c smb: client: fix potential deadlock when releasing mids 2025-05-02 07:41:06 +02:00
winucase.c
xattr.c smb3: fix caching of ctime on setxattr 2023-12-08 08:46:15 +01:00