Skip to content

Commit e904d81

Browse files
Joshua Rogerssmfrench
authored andcommitted
smb: server: rdma: avoid unmapping posted recv on accept failure
smb_direct_prepare_negotiation() posts a recv and then, if smb_direct_accept_client() fails, calls put_recvmsg() on the same buffer. That unmaps and recycles a buffer that is still posted on the QP., which can lead to device DMA into unmapped or reused memory. Track whether the recv was posted and only return it if it was never posted. If accept fails after a post, leave it for teardown to drain and complete safely. Signed-off-by: Joshua Rogers <linux@joshua.hu> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent e9a6fb0 commit e904d81

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

fs/smb/server/transport_rdma.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,7 @@ static int smb_direct_accept_client(struct smbdirect_socket *sc)
18831883
static int smb_direct_prepare_negotiation(struct smbdirect_socket *sc)
18841884
{
18851885
struct smbdirect_recv_io *recvmsg;
1886+
bool recv_posted = false;
18861887
int ret;
18871888

18881889
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_CREATED);
@@ -1899,6 +1900,7 @@ static int smb_direct_prepare_negotiation(struct smbdirect_socket *sc)
18991900
pr_err("Can't post recv: %d\n", ret);
19001901
goto out_err;
19011902
}
1903+
recv_posted = true;
19021904

19031905
ret = smb_direct_accept_client(sc);
19041906
if (ret) {
@@ -1908,7 +1910,14 @@ static int smb_direct_prepare_negotiation(struct smbdirect_socket *sc)
19081910

19091911
return 0;
19101912
out_err:
1911-
put_recvmsg(sc, recvmsg);
1913+
/*
1914+
* If the recv was never posted, return it to the free list.
1915+
* If it was posted, leave it alone so disconnect teardown can
1916+
* drain the QP and complete it (flush) and the completion path
1917+
* will unmap it exactly once.
1918+
*/
1919+
if (!recv_posted)
1920+
put_recvmsg(sc, recvmsg);
19121921
return ret;
19131922
}
19141923

0 commit comments

Comments
 (0)