Skip to content

Commit

Permalink
RDMA/rxe: Fix coding error in rxe_rcv_mcast_pkt
Browse files Browse the repository at this point in the history
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/20210128174752.16128-1-rpearson@hpe.com
Signed-off-by: Bob Pearson <rpearson@hpe.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
  • Loading branch information
Bob Pearson authored and Jason Gunthorpe committed Feb 5, 2021
1 parent e328197 commit 8fc1b70
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions drivers/infiniband/sw/rxe/rxe_recv.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)

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

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

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

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

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

return;

err1:
/* free skb if not consumed */
kfree_skb(skb);
}

Expand Down

0 comments on commit 8fc1b70

Please sign in to comment.