Skip to content

Commit 85aec73

Browse files
Ivan Veceradavem330
authored andcommitted
tg3: avoid double-freeing of rx data memory
If build_skb fails the memory associated with the ring buffer is freed but the ri->data member is not zeroed in this case. This causes a double-free of this memory in tg3_free_rings->... path. The patch moves this block after setting ri->data to NULL. It would be nice to fix this bug also in stable >= v3.4 trees. Cc: Nithin Nayak Sujir <[email protected]> Cc: Michael Chan <[email protected]> Signed-off-by: Ivan Vecera <[email protected]> Acked-by: Michael Chan <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 28fb965 commit 85aec73

File tree

1 file changed

+6
-6
lines changed
  • drivers/net/ethernet/broadcom

1 file changed

+6
-6
lines changed

drivers/net/ethernet/broadcom/tg3.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6862,19 +6862,19 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
68626862
pci_unmap_single(tp->pdev, dma_addr, skb_size,
68636863
PCI_DMA_FROMDEVICE);
68646864

6865-
skb = build_skb(data, frag_size);
6866-
if (!skb) {
6867-
tg3_frag_free(frag_size != 0, data);
6868-
goto drop_it_no_recycle;
6869-
}
6870-
skb_reserve(skb, TG3_RX_OFFSET(tp));
68716865
/* Ensure that the update to the data happens
68726866
* after the usage of the old DMA mapping.
68736867
*/
68746868
smp_wmb();
68756869

68766870
ri->data = NULL;
68776871

6872+
skb = build_skb(data, frag_size);
6873+
if (!skb) {
6874+
tg3_frag_free(frag_size != 0, data);
6875+
goto drop_it_no_recycle;
6876+
}
6877+
skb_reserve(skb, TG3_RX_OFFSET(tp));
68786878
} else {
68796879
tg3_recycle_rx(tnapi, tpr, opaque_key,
68806880
desc_idx, *post_ptr);

0 commit comments

Comments
 (0)