Netdev List
 help / color / mirror / Atom feed
* [PATCH] net/smc: deregister the MR when SG mapping fails
@ 2026-11-04  2:28 Wentao Liang
  2026-11-04  2:32 ` netdev-bot+sinfo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Wentao Liang @ 2026-11-04  2:28 UTC (permalink / raw)
  To: D. Wythe, Dust Li, Sidraya Jayagond, Mahanta Jambigi, Tony Lu,
	Wen Gu, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman
  Cc: linux-rdma, linux-s390, netdev

When smc_ib_map_mr_sg() maps fewer entries than the SG table holds,
smc_ib_get_memory_region() returns -EINVAL with the memory region
still allocated and its pointer left in buf_slot->mr[link_idx].
The caller only undoes the DMA mapping and frees the SG table, and
because buf_desc->is_map_ib[] is set only after this function
succeeds, smcr_buf_unmap_link() later skips the buffer.  Both the
MR and the pd->usecnt reference taken by ib_alloc_mr() are lost.

The stale pointer is also harmful: a retry takes the "already done"
shortcut and treats a memory region that was never mapped as valid.

Deregister the memory region and clear the slot before returning.

Fixes: 897e1c245773 ("net/smc: use separate memory regions for RMBs")
Cc: stable@vger.kernel.org
Assisted-by: DeepSeek-V4.1-Flash and OpenAI Codex
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 net/smc/smc_ib.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/smc/smc_ib.c b/net/smc/smc_ib.c
index daaa8a72da90..fa21d269196e 100644
--- a/net/smc/smc_ib.c
+++ b/net/smc/smc_ib.c
@@ -735,8 +735,11 @@ int smc_ib_get_memory_region(struct ib_pd *pd, int access_flags,
 	}
 
 	if (smc_ib_map_mr_sg(buf_slot, link_idx) !=
-			     buf_slot->sgt[link_idx].orig_nents)
+			     buf_slot->sgt[link_idx].orig_nents) {
+		smc_ib_put_memory_region(buf_slot->mr[link_idx]);
+		buf_slot->mr[link_idx] = NULL;
 		return -EINVAL;
+	}
 
 	return 0;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-05  9:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-04  2:28 [PATCH] net/smc: deregister the MR when SG mapping fails Wentao Liang
2026-11-04  2:32 ` netdev-bot+sinfo
2026-11-05  8:54 ` Dust Li
2026-11-05  9:50 ` Mahanta Jambigi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox