Skip to content

Commit 8fc1b70

Browse files
Bob Pearsonjgunthorpe
authored andcommitted
RDMA/rxe: Fix coding error in rxe_rcv_mcast_pkt
rxe_rcv_mcast_pkt() in rxe_recv.c can leak SKBs in error path code. The loop over the QPs attached to a multicast group creates new cloned SKBs for all but the last QP in the list and passes the SKB and its clones to rxe_rcv_pkt() for further processing. Any QPs that do not pass some checks are skipped. If the last QP in the list fails the tests the SKB is leaked. This patch checks if the SKB for the last QP was used and if not frees it. Also removes a redundant loop invariant assignment. Fixes: 8700e3e ("Soft RoCE driver") Fixes: 71abf20 ("RDMA/rxe: Handle skb_clone() failure in rxe_recv.c") Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bob Pearson <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent e328197 commit 8fc1b70

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

drivers/infiniband/sw/rxe/rxe_recv.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)
256256

257257
list_for_each_entry(mce, &mcg->qp_list, qp_list) {
258258
qp = mce->qp;
259-
pkt = SKB_TO_PKT(skb);
260259

261260
/* validate qp for incoming packet */
262261
err = check_type_state(rxe, pkt, qp);
@@ -268,12 +267,18 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)
268267
continue;
269268

270269
/* for all but the last qp create a new clone of the
271-
* skb and pass to the qp.
270+
* skb and pass to the qp. If an error occurs in the
271+
* checks for the last qp in the list we need to
272+
* free the skb since it hasn't been passed on to
273+
* rxe_rcv_pkt() which would free it later.
272274
*/
273-
if (mce->qp_list.next != &mcg->qp_list)
275+
if (mce->qp_list.next != &mcg->qp_list) {
274276
per_qp_skb = skb_clone(skb, GFP_ATOMIC);
275-
else
277+
} else {
276278
per_qp_skb = skb;
279+
/* show we have consumed the skb */
280+
skb = NULL;
281+
}
277282

278283
if (unlikely(!per_qp_skb))
279284
continue;
@@ -288,9 +293,8 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)
288293

289294
rxe_drop_ref(mcg); /* drop ref from rxe_pool_get_key. */
290295

291-
return;
292-
293296
err1:
297+
/* free skb if not consumed */
294298
kfree_skb(skb);
295299
}
296300

0 commit comments

Comments
 (0)