Skip to content

Commit c31f26c

Browse files
committed
bnxt: prevent skb UAF after handing over to PTP worker
When reading the timestamp is required bnxt_tx_int() hands over the ownership of the completed skb to the PTP worker. The skb should not be used afterwards, as the worker may run before the rest of our code and free the skb, leading to a use-after-free. Since dev_kfree_skb_any() accepts NULL make the loss of ownership more obvious and set skb to NULL. Fixes: 83bb623 ("bnxt_en: Transmit and retrieve packet timestamps") Reviewed-by: Andy Gospodarek <[email protected]> Reviewed-by: Michael Chan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3aac7ad commit c31f26c

File tree

1 file changed

+5
-5
lines changed
  • drivers/net/ethernet/broadcom/bnxt

1 file changed

+5
-5
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,6 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
659659

660660
for (i = 0; i < nr_pkts; i++) {
661661
struct bnxt_sw_tx_bd *tx_buf;
662-
bool compl_deferred = false;
663662
struct sk_buff *skb;
664663
int j, last;
665664

@@ -668,6 +667,8 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
668667
skb = tx_buf->skb;
669668
tx_buf->skb = NULL;
670669

670+
tx_bytes += skb->len;
671+
671672
if (tx_buf->is_push) {
672673
tx_buf->is_push = 0;
673674
goto next_tx_int;
@@ -688,8 +689,9 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
688689
}
689690
if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) {
690691
if (bp->flags & BNXT_FLAG_CHIP_P5) {
692+
/* PTP worker takes ownership of the skb */
691693
if (!bnxt_get_tx_ts_p5(bp, skb))
692-
compl_deferred = true;
694+
skb = NULL;
693695
else
694696
atomic_inc(&bp->ptp_cfg->tx_avail);
695697
}
@@ -698,9 +700,7 @@ static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
698700
next_tx_int:
699701
cons = NEXT_TX(cons);
700702

701-
tx_bytes += skb->len;
702-
if (!compl_deferred)
703-
dev_kfree_skb_any(skb);
703+
dev_kfree_skb_any(skb);
704704
}
705705

706706
netdev_tx_completed_queue(txq, nr_pkts, tx_bytes);

0 commit comments

Comments
 (0)