Skip to contentSkip to conversation

smb: client: fix double-free in SMB2_flush() replay

PATCH In review Ren Wei 2 participants 2 messages Jun 18 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Ren Wei

author
#1 lore raw

PATCH 1/1 smb: client: fix double-free in SMB2_flush() replay

From: Zhao Zhang <[email protected]>

SMB2_flush() keeps its response buffer bookkeeping across replay attempts. If a replayable flush response is received and the retry then fails before cifs_send_recv() stores a replacement response, flush_exit will free the stale response pointer a second time.

Reinitialize resp_buftype and rsp_iov at the top of the replay loop so cleanup only acts on response state produced by the current attempt. This fixes a double-free without changing replay handling for successful requests.

Fixes 4f1fffa23769 ("cifs: commands that are retried should have replay flag set")
Assisted-by Codex:GPT-5.4
---
 fs/smb/client/smb2pdu.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/smb2pdu.c +2 -0
index 958ca0753774..2d7b147f2892 100644
@@ -4433,6 +4433,8 @@ SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 
 replay_again:
 	/* reinitialize for possible replay */
+	resp_buftype = CIFS_NO_BUFFER;
+	memset(&rsp_iov, 0, sizeof(rsp_iov));
 	flags = 0;
 	server = cifs_pick_channel(ses);
 
Signature · 1 line
2.47.3
#2 lore raw

tentatively merged into cifs-2.6.git for-next pending testing and additional review

Quoted 42 lines · Ren Wei

From: Zhao Zhang <[email protected]>

SMB2_flush() keeps its response buffer bookkeeping across replay attempts. If a replayable flush response is received and the retry then fails before cifs_send_recv() stores a replacement response, flush_exit will free the stale response pointer a second time.

Reinitialize resp_buftype and rsp_iov at the top of the replay loop so cleanup only acts on response state produced by the current attempt. This fixes a double-free without changing replay handling for successful requests.

Fixes 4f1fffa23769 ("cifs: commands that are retried should have replay flag set")
Assisted-by Codex:GPT-5.4
---
 fs/smb/client/smb2pdu.c | 2 ++
 1 file changed, 2 insertions(+)
fs/smb/client/smb2pdu.c +2 -1
index 958ca0753774..2d7b147f2892 100644
@@ -4433,6 +4433,8 @@ SMB2_flush(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 
 replay_again:
        /* reinitialize for possible replay */
+       resp_buftype = CIFS_NO_BUFFER;
+       memset(&rsp_iov, 0, sizeof(rsp_iov));
        flags = 0;
        server = cifs_pick_channel(ses);
 
--

2.47.3

Signature · 3 lines
Thanks,

Steve