Skip to contentSkip to conversation

RDMA/mad: Reject receive completions shorter than GRH

PATCH Applied Jiale Yao 3 participants 3 messages Sep 26 – Sep 29 InfiniBand

lore
Share & tools
lore

Jiale Yao

author
#0 lore raw

PATCH 1/1 RDMA/mad: Reject receive completions shorter than GRH

ib_mad_recv_done() derives the OPA MAD length by subtracting the GRH size from wc->byte_len without ensuring the receive completion covers the GRH. If it is shorter, the subtraction wraps before the result is stored in mad_len and an invalid length can be passed downstream.

Reject receive completions shorter than the GRH before inspecting the MAD header or deriving the MAD length.

Fixes 8e4349d13f33 ("IB/mad: Add final OPA MAD processing")
---
 drivers/infiniband/core/mad.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/infiniband/core/mad.c +2 -0
index 3c91f00d09c6..8124e0b5a87d 100644
@@ -2342,6 +2342,8 @@ static void ib_mad_recv_done(struct ib_cq *cq, struct ib_wc *wc)
 			    recv->header.mapping,
 			    mad_priv_dma_size(recv),
 			    DMA_FROM_DEVICE);
+	if (unlikely(wc->byte_len < sizeof(struct ib_grh)))
+		goto out;
 
 	/* Setup MAD receive work completion from "normal" work completion */
 	recv->header.wc = *wc;
Signature · 1 line
2.34.1
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines

ib_mad_recv_done() derives the OPA MAD length by subtracting the GRH size from wc->byte_len without ensuring the receive completion covers the GRH. If it is shorter, the subtraction wraps before the result is stored in mad_len and an invalid length can be passed downstream.

Reject receive completions shorter than the GRH before inspecting the MAD header or deriving the MAD length.

Fixes 8e4349d13f33 ("IB/mad: Add final OPA MAD processing")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Jiale Yao
Quoted 9 lines · Jiale Yao

ib_mad_recv_done() derives the OPA MAD length by subtracting the GRH size from wc->byte_len without ensuring the receive completion covers the GRH. If it is shorter, the subtraction wraps before the result is stored in mad_len and an invalid length can be passed downstream.

Reject receive completions shorter than the GRH before inspecting the MAD header or deriving the MAD length.

[...]

Applied, thanks!

[1/1] RDMA/mad: Reject receive completions shorter than GRH

      https://git.kernel.org/rdma/rdma/c/2dc2126e690203

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>