Skip to contentSkip to conversation

SMB Direct: double-free of send_io on ib_post_send failure in batch flush path

PATCH In review Stefan Metzmacher 4 participants 6 messages Apr 10 – Apr 11

Subsystems (3)
lore
Share & tools
lore

Stefan Metzmacher

author reviewer
#0 lore raw

cover SMB Direct: double-free of send_io on ib_post_send failure in batch flush path

Hi Steve,

here are the real patches for the changes already tested by Ruikai Peng for the double-free problem reported, see:
https://lore.kernel.org/linux-cifs/CAFD3drNOSJ05y3A+jNXSDxW-2w09KHQ0DivhxQ_pcc7immVVOQ@mail.gmail.com/

I prepared a branch that can replace ksmbd-for-next.
The 2 changes are rebased below the smbdirect.ko changes,
I resolved the conflicts and made sure the problem is also solved in the new common code. This in for-7.1/smbdirect-ko-20260410-v12
at commit: 274b415378bbd0cf6fde1a719e264cee2eefc06f
git fetch https://git.samba.org/metze/linux/wip.git for-7.1/smbdirect-ko-20260410-v12
https://git.samba.org/?p=metze/linux/wip.git;a=shortlog;h=refs/heads/for-7.1/smbdirect-ko-20260410-v12
I made sure each commit compiles fine...

Stefan Metzmacher (2):
smb: client: avoid double-free in smbd_free_send_io() after
smbd_send_batch_flush()
smb: server: avoid double-free in smb_direct_free_sendmsg after
smb_direct_flush_send_list()

 fs/smb/client/smbdirect.c      | 8 ++++++++
 fs/smb/server/transport_rdma.c | 8 +++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
author reviewer
#1 lore raw

PATCH 1/2 smb: client: avoid double-free in smbd_free_send_io() after smbd_send_batch_flush()

smbd_send_batch_flush() already calls smbd_free_send_io(), so we should not call it again after smbd_post_send() moved it to the batch list.

---
 fs/smb/client/smbdirect.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/smb/client/smbdirect.c +8 -0
index c79304012b08..461658105013 100644
@@ -1551,17 +1551,25 @@ static int smbd_post_send_iter(struct smbdirect_socket *sc,
 
 	rc = smbd_post_send(sc, batch, request);
 	if (!rc) {
+		/*
+		 * From here request is moved to batch
+		 * and we should not free it explicitly.
+		 */
+
 		if (batch != &_batch)
 			return 0;
 
 		rc = smbd_send_batch_flush(sc, batch, true);
 		if (!rc)
 			return 0;
+
+		goto err_flush;
 	}
 
 err_dma:
 	smbd_free_send_io(request);
 
+err_flush:
 err_alloc:
 	atomic_inc(&sc->send_io.credits.count);
 	wake_up(&sc->send_io.credits.wait_queue);
Signature · 1 line
2.43.0
author reviewer
#2 lore raw

PATCH 2/2 smb: server: avoid double-free in smb_direct_free_sendmsg after smb_direct_flush_send_list()

In reply to Stefan Metzmacher

smb_direct_flush_send_list() already calls smb_direct_free_sendmsg(), so we should not call it again after post_sendmsg()
moved it to the batch list.

---
 fs/smb/server/transport_rdma.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/smb/server/transport_rdma.c +7 -1
index 188572491d53..dbc8dedb85dc 100644
@@ -1588,15 +1588,21 @@ static int smb_direct_post_send_data(struct smbdirect_socket *sc,
 	if (ret)
 		goto err;
 
+	/*
+	 * From here msg is moved to send_ctx
+	 * and we should not free it explicitly.
+	 */
+
 	if (send_ctx == &_send_ctx) {
 		ret = smb_direct_flush_send_list(sc, send_ctx, true);
 		if (ret)
-			goto err;
+			goto flush_failed;
 	}
 
 	return 0;
 err:
 	smb_direct_free_sendmsg(sc, msg);
+flush_failed:
 header_failed:
 	atomic_inc(&sc->send_io.credits.count);
 credit_failed:
Signature · 1 line
2.43.0
maintainer Acked-by on the v1 series
#3 lore raw
In reply to Stefan Metzmacher
Quoted 20 lines · Stefan Metzmacher

here are the real patches for the changes already tested by Ruikai Peng for the double-free problem reported, see:
https://lore.kernel.org/linux-cifs/CAFD3drNOSJ05y3A+jNXSDxW-2w09KHQ0DivhxQ_pcc7immVVOQ@mail.gmail.com/

I prepared a branch that can replace ksmbd-for-next.
The 2 changes are rebased below the smbdirect.ko changes,
I resolved the conflicts and made sure the problem is also solved in the new common code. This in for-7.1/smbdirect-ko-20260410-v12
at commit: 274b415378bbd0cf6fde1a719e264cee2eefc06f
git fetch https://git.samba.org/metze/linux/wip.git for-7.1/smbdirect-ko-20260410-v12
https://git.samba.org/?p=metze/linux/wip.git;a=shortlog;h=refs/heads/for-7.1/smbdirect-ko-20260410-v12
I made sure each commit compiles fine...

Stefan Metzmacher (2):
smb: client: avoid double-free in smbd_free_send_io() after
smbd_send_batch_flush()
smb: server: avoid double-free in smb_direct_free_sendmsg after
smb_direct_flush_send_list()

Quoted 3 lines
 fs/smb/client/smbdirect.c      | 8 ++++++++
 fs/smb/server/transport_rdma.c | 8 +++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
maintainer Acked-by on the v1 series
#4 lore raw
In reply to Stefan Metzmacher
Quoted 17 lines · Stefan Metzmacher

Hi Steve,

here are the real patches for the changes already tested by Ruikai Peng for the double-free problem reported, see:
https://lore.kernel.org/linux-cifs/CAFD3drNOSJ05y3A+jNXSDxW-2w09KHQ0DivhxQ_pcc7immVVOQ@mail.gmail.com/

I prepared a branch that can replace ksmbd-for-next.
The 2 changes are rebased below the smbdirect.ko changes,
I resolved the conflicts and made sure the problem is also solved in the new common code. This in for-7.1/smbdirect-ko-20260410-v12
at commit: 274b415378bbd0cf6fde1a719e264cee2eefc06f
git fetch https://git.samba.org/metze/linux/wip.git for-7.1/smbdirect-ko-20260410-v12
https://git.samba.org/?p=metze/linux/wip.git;a=shortlog;h=refs/heads/for-7.1/smbdirect-ko-20260410-v12
I made sure each commit compiles fine...

Quoted 6 lines

Stefan Metzmacher (2):
smb: client: avoid double-free in smbd_free_send_io() after
smbd_send_batch_flush()
smb: server: avoid double-free in smb_direct_free_sendmsg after
smb_direct_flush_send_list()

Thanks!

#5 lore raw

Added the acked-by and updated ksmbd-for-next

Quoted 27 lines · Namjae Jeon
Quoted 17 lines · Stefan Metzmacher

Hi Steve,

here are the real patches for the changes already tested by Ruikai Peng for the double-free problem reported, see:
https://lore.kernel.org/linux-cifs/CAFD3drNOSJ05y3A+jNXSDxW-2w09KHQ0DivhxQ_pcc7immVVOQ@mail.gmail.com/

I prepared a branch that can replace ksmbd-for-next.
The 2 changes are rebased below the smbdirect.ko changes,
I resolved the conflicts and made sure the problem is also solved in the new common code. This in for-7.1/smbdirect-ko-20260410-v12
at commit: 274b415378bbd0cf6fde1a719e264cee2eefc06f
git fetch https://git.samba.org/metze/linux/wip.git for-7.1/smbdirect-ko-20260410-v12
https://git.samba.org/?p=metze/linux/wip.git;a=shortlog;h=refs/heads/for-7.1/smbdirect-ko-20260410-v12
I made sure each commit compiles fine...

Quoted 6 lines

Stefan Metzmacher (2):
smb: client: avoid double-free in smbd_free_send_io() after
smbd_send_batch_flush()
smb: server: avoid double-free in smb_direct_free_sendmsg after
smb_direct_flush_send_list()

Thanks!

Signature · 3 lines
Thanks,

Steve