FAILED: patch "[PATCH] smb: client: fix UAF and buffer leak in cifs_check_trans2()" failed to apply to 5.15-stable tree
Subsystems (4)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 730d0bb19507b9e19c2fe5343109ac618e2fbce5
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026090304-muscular-diligent-73ea@gregkh' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 730d0bb19507b9e19c2fe5343109ac618e2fbce5 Mon Sep 17 00:00:00 2001
From: Frank Sorenson <[email protected]>
Date: Wed, 12 Aug 2026 21:39:51 -0500
Subject: [PATCH] smb: client: fix UAF and buffer leak in cifs_check_trans2()
for malformed secondary T2
When a valid primary TRANSACT2 response has been received (mid->resp_buf set, mid->multiRsp true) and a subsequent secondary response causes cifs_check_trans2() to return false -- either because the SMB header is invalid (malformed != 0) or because check2ndT2() rejects the PDU -- handle_mid() overwrites mid->resp_buf with the new buffer (leaking the primary buffer) and, because mid->multiRsp is set, skips the server->smallbuf/bigbuf NULL-out. When the user thread frees mid->resp_buf, server->smallbuf or server->bigbuf is left dangling; the demux thread reuses it for the next packet, resulting in a use-after-free.
Combine both early-exit conditions and, when mid->multiRsp is already set, abort the pending transaction inline: set multiEnd, call dequeue_mid() with malformed=true, and return true so handle_mid() exits without touching mid->resp_buf or the server buffer pointers.
fs/smb/client/smb1transport.c +11 -3
@@ -449,10 +449,18 @@ bool cifs_check_trans2(struct mid_q_entry *mid, struct TCP_Server_Info *server, char *buf, int malformed) { - if (malformed) - return false; -if (check2ndT2 (buf) <=0 ) + if (malformed || check2ndT2(buf) <= 0) { + /* mid->multiRsp blocks the server buf detach in handle_mid(); + * returning false here would leak resp_buf and leave a dangling + * server->smallbuf/bigbuf after the user thread frees resp_buf. + */ + if (mid->multiRsp) { + mid->multiEnd = true; +dequeue_mid (server, mid, true); +return true; + }return false; + } mid->multiRsp = true;if (mid->resp_buf) {/* merge response - fix up 1st*/
Sasha Levin
maintainerPATCH 1/2 cifs: SMB1 split: Create smb1proto.h for SMB1 declarations
From: David Howells <[email protected]>
[ Upstream commit 86c666506ea2c42649879eeac7f29e7bedef2f23 ]
[ sashal: Reduced backport -- upstream 86c666506ea2c touches 3 file(s), this
backport carries 5. Not backported here:
fs/smb/client/cifsglob.h
fs/smb/client/cifsproto.h
fs/smb/client/smb1proto.h
This note is generated from the file lists only; see the resolution record for the reasoning. ]
Stable-dep-of: 730d0bb19507 ("smb: client: fix UAF and buffer leak in cifs_check_trans2() for malformed secondary T2")
--- fs/cifs/cifsglob.h | 2 - fs/cifs/cifsproto.h | 11 +- fs/cifs/smb1ops.c | 1247 +------------------------------- fs/cifs/smb1proto.h | 40 ++ fs/smb/client/smb1transport.c | 1251 +++++++++++++++++++++++++++++++++ 5 files changed, 1293 insertions(+), 1258 deletions(-) create mode 100644 fs/cifs/smb1proto.h create mode 100644 fs/smb/client/smb1transport.c
fs/cifs/cifsglob.h +0 -2
@@ -1910,8 +1910,6 @@ extern mempool_t *cifs_mid_poolp;#define SMB1_VERSION_STRING "1.0"#define SMB20_VERSION_STRING "2.0"#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY -extern struct smb_version_operations smb1_operations; -extern struct smb_version_values smb1_values;extern struct smb_version_operations smb20_operations;extern struct smb_version_values smb20_values;#endif /* CIFS_ALLOW_INSECURE_LEGACY */
fs/cifs/cifsproto.h +1 -10
@@ -12,6 +12,7 @@#ifdef CONFIG_CIFS_DFS_UPCALL #include "dfs_cache.h" #endif +#include "smb1proto.h" struct statfs ;struct smb_rqst ;
@@ -379,16 +380,6 @@ extern int CIFSSMBSetFileSize(const unsigned int xid, struct cifs_tcon *tcon, struct cifsFileInfo *cfile, __u64 size, bool set_allocation); -struct cifs_unix_set_info_args { -__u64 ctime; -__u64 atime; -__u64 mtime; -__u64 mode; -kuid_t uid; -kgid_t gid; -dev_t device; -}; - extern int CIFSSMBUnixSetFileInfo(const unsigned int xid, struct cifs_tcon *tcon, const struct cifs_unix_set_info_args *args,
fs/cifs/smb1ops.c +1 -1246
1,248 lines not on this page · raw message
fs/cifs/smb1proto.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: LGPL-2.1 */ +/* +* +* Copyright (c) International Business Machines Corp., 2002,2008 +* Author(s): Steve French ([email protected]) +* +*/ +#ifndef _SMB1PROTO_H +#define _SMB1PROTO_H + +struct cifs_unix_set_info_args { +__u64 ctime; +__u64 atime; +__u64 mtime; +__u64 mode; +kuid_t uid; +kgid_t gid; +dev_t device; +}; + +#ifdef CONFIG_CIFS_ALLOW_INSECURE_LEGACY + +/* +* cifssmb.c +*/ + +/* +* smb1ops.c +*/ +extern struct smb_version_operations smb1_operations; +extern struct smb_version_values smb1_values; + +/* +* smb1transport.c +*/ +bool cifs_check_trans2 (struct mid_q_entry *mid,struct TCP_Server_Info *server, +char *buf,int malformed); + +#endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ +#endif /* _SMB1PROTO_H */
fs/smb/client/smb1transport.c new file +1251 -0
1,251 lines not on this page · raw message
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 smb: client: fix UAF and buffer leak in cifs_check_trans2() for malformed secondary T2
From: Frank Sorenson <[email protected]>
[ Upstream commit 730d0bb19507b9e19c2fe5343109ac618e2fbce5 ]
When a valid primary TRANSACT2 response has been received (mid->resp_buf set, mid->multiRsp true) and a subsequent secondary response causes cifs_check_trans2() to return false -- either because the SMB header is invalid (malformed != 0) or because check2ndT2() rejects the PDU -- handle_mid() overwrites mid->resp_buf with the new buffer (leaking the primary buffer) and, because mid->multiRsp is set, skips the server->smallbuf/bigbuf NULL-out. When the user thread frees mid->resp_buf, server->smallbuf or server->bigbuf is left dangling; the demux thread reuses it for the next packet, resulting in a use-after-free.
Combine both early-exit conditions and, when mid->multiRsp is already set, abort the pending transaction inline: set multiEnd, call dequeue_mid() with malformed=true, and return true so handle_mid() exits without touching mid->resp_buf or the server buffer pointers.
--- fs/smb/client/smb1transport.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
fs/smb/client/smb1transport.c +11 -3
@@ -382,10 +382,18 @@ bool cifs_check_trans2(struct mid_q_entry *mid, struct TCP_Server_Info *server, char *buf, int malformed) { - if (malformed) - return false; -if (check2ndT2 (buf) <=0 ) + if (malformed || check2ndT2(buf) <= 0) { + /* mid->multiRsp blocks the server buf detach in handle_mid(); + * returning false here would leak resp_buf and leave a dangling + * server->smallbuf/bigbuf after the user thread frees resp_buf. + */ + if (mid->multiRsp) { + mid->multiEnd = true; +dequeue_mid (server, mid, true); +return true; + }return false; + } mid->multiRsp = true;if (mid->resp_buf) {/* merge response - fix up 1st*/
Signature · 1 line
2.53.0