* [PATCH net] tg3: avoid double-freeing of rx data memory
@ 2013-11-06 13:02 Ivan Vecera
2013-11-06 19:23 ` Michael Chan
2013-11-08 0:10 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Ivan Vecera @ 2013-11-06 13:02 UTC (permalink / raw)
To: netdev; +Cc: davem, Nithin Nayak Sujir, Michael Chan
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 <nsujir@broadcom.com>
Cc: Michael Chan <mchan@broadcom.com>
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
drivers/net/ethernet/broadcom/tg3.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index 12d961c..cd76d2a 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -6848,12 +6848,6 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
pci_unmap_single(tp->pdev, dma_addr, skb_size,
PCI_DMA_FROMDEVICE);
- skb = build_skb(data, frag_size);
- if (!skb) {
- tg3_frag_free(frag_size != 0, data);
- goto drop_it_no_recycle;
- }
- skb_reserve(skb, TG3_RX_OFFSET(tp));
/* Ensure that the update to the data happens
* after the usage of the old DMA mapping.
*/
@@ -6861,6 +6855,12 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
ri->data = NULL;
+ skb = build_skb(data, frag_size);
+ if (!skb) {
+ tg3_frag_free(frag_size != 0, data);
+ goto drop_it_no_recycle;
+ }
+ skb_reserve(skb, TG3_RX_OFFSET(tp));
} else {
tg3_recycle_rx(tnapi, tpr, opaque_key,
desc_idx, *post_ptr);
--
1.8.1.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net] tg3: avoid double-freeing of rx data memory
2013-11-06 13:02 [PATCH net] tg3: avoid double-freeing of rx data memory Ivan Vecera
@ 2013-11-06 19:23 ` Michael Chan
2013-11-08 0:10 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Michael Chan @ 2013-11-06 19:23 UTC (permalink / raw)
To: Ivan Vecera; +Cc: netdev, davem, Nithin Nayak Sujir
On Wed, 2013-11-06 at 14:02 +0100, Ivan Vecera wrote:
> 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.
Good catch, thanks. To be precise, the double free will only happen if
the ring is freed before the ring wraps around once.
Acked-by: Michael Chan <mchan@broadcom.com>
>
> Cc: Nithin Nayak Sujir <nsujir@broadcom.com>
> Cc: Michael Chan <mchan@broadcom.com>
> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
> ---
> drivers/net/ethernet/broadcom/tg3.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
> index 12d961c..cd76d2a 100644
> --- a/drivers/net/ethernet/broadcom/tg3.c
> +++ b/drivers/net/ethernet/broadcom/tg3.c
> @@ -6848,12 +6848,6 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
> pci_unmap_single(tp->pdev, dma_addr, skb_size,
> PCI_DMA_FROMDEVICE);
>
> - skb = build_skb(data, frag_size);
> - if (!skb) {
> - tg3_frag_free(frag_size != 0, data);
> - goto drop_it_no_recycle;
> - }
> - skb_reserve(skb, TG3_RX_OFFSET(tp));
> /* Ensure that the update to the data happens
> * after the usage of the old DMA mapping.
> */
> @@ -6861,6 +6855,12 @@ static int tg3_rx(struct tg3_napi *tnapi, int budget)
>
> ri->data = NULL;
>
> + skb = build_skb(data, frag_size);
> + if (!skb) {
> + tg3_frag_free(frag_size != 0, data);
> + goto drop_it_no_recycle;
> + }
> + skb_reserve(skb, TG3_RX_OFFSET(tp));
> } else {
> tg3_recycle_rx(tnapi, tpr, opaque_key,
> desc_idx, *post_ptr);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net] tg3: avoid double-freeing of rx data memory
2013-11-06 13:02 [PATCH net] tg3: avoid double-freeing of rx data memory Ivan Vecera
2013-11-06 19:23 ` Michael Chan
@ 2013-11-08 0:10 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2013-11-08 0:10 UTC (permalink / raw)
To: ivecera; +Cc: netdev, nsujir, mchan
From: Ivan Vecera <ivecera@redhat.com>
Date: Wed, 6 Nov 2013 14:02:36 +0100
> 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 <nsujir@broadcom.com>
> Cc: Michael Chan <mchan@broadcom.com>
> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
Applied.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-11-08 0:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-06 13:02 [PATCH net] tg3: avoid double-freeing of rx data memory Ivan Vecera
2013-11-06 19:23 ` Michael Chan
2013-11-08 0:10 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).