* [PATCH] driver: tg3: fix potential UAF in tigon3_dma_hwbug_workaround()
@ 2020-01-16 3:30 Gen Zhang
2020-01-19 10:00 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Gen Zhang @ 2020-01-16 3:30 UTC (permalink / raw)
To: siva.kallam, prashant, mchan, davem; +Cc: netdev, linux-kernel
In tigon3_dma_hwbug_workaround(), pskb is first stored in skb. And this
function is to store new_skb into pskb at the end. However, in the error
paths when new_skb is freed by dev_kfree_skb_any(), stroing new_skb to pskb
should be prevented.
And freeing skb with dev_consume_skb_any() should be executed after storing
new_skb to pskb, because freeing skb will free pskb (alias).
Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
---
diff --git a/drivers/net/ethernet/broadcom/tg3.c b/drivers/net/ethernet/broadcom/tg3.c
index ca3aa12..dbfac26 100644
--- a/drivers/net/ethernet/broadcom/tg3.c
+++ b/drivers/net/ethernet/broadcom/tg3.c
@@ -7826,6 +7826,7 @@ static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi,
if (!new_skb) {
ret = -1;
+ goto new_skb_err;
} else {
/* New SKB is guaranteed to be linear. */
new_addr = pci_map_single(tp->pdev, new_skb->data, new_skb->len,
@@ -7834,6 +7835,7 @@ static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi,
if (pci_dma_mapping_error(tp->pdev, new_addr)) {
dev_kfree_skb_any(new_skb);
ret = -1;
+ goto new_skb_err;
} else {
u32 save_entry = *entry;
@@ -7849,12 +7851,14 @@ static int tigon3_dma_hwbug_workaround(struct tg3_napi *tnapi,
tg3_tx_skb_unmap(tnapi, save_entry, -1);
dev_kfree_skb_any(new_skb);
ret = -1;
+ goto new_skb_err;
}
}
}
- dev_consume_skb_any(skb);
*pskb = new_skb;
+ dev_consume_skb_any(skb);
+new_skb_err:
return ret;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] driver: tg3: fix potential UAF in tigon3_dma_hwbug_workaround()
2020-01-16 3:30 [PATCH] driver: tg3: fix potential UAF in tigon3_dma_hwbug_workaround() Gen Zhang
@ 2020-01-19 10:00 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2020-01-19 10:00 UTC (permalink / raw)
To: blackgod016574; +Cc: siva.kallam, prashant, mchan, netdev, linux-kernel
From: Gen Zhang <blackgod016574@gmail.com>
Date: Thu, 16 Jan 2020 11:30:44 +0800
> In tigon3_dma_hwbug_workaround(), pskb is first stored in skb. And this
> function is to store new_skb into pskb at the end. However, in the error
> paths when new_skb is freed by dev_kfree_skb_any(), stroing new_skb to pskb
> should be prevented.
>
> And freeing skb with dev_consume_skb_any() should be executed after storing
> new_skb to pskb, because freeing skb will free pskb (alias).
>
> Signed-off-by: Gen Zhang <blackgod016574@gmail.com>
There are no bugs here.
The caller never references "*pskb" when an error is returned. So it is
safe to store any value whatsoever into that pointer.
'skb' never changes it's value even if we store something into *pskb
because we've loaded it into a local variable. So it is always safe to
call dev_consume_skb_any() on 'skb' in any order with respect to that
assignment.
I'm not applying this until you can show a real bug resulting from
the current code, and if so you'll need to add that explanation to
your commit message.
Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-01-19 11:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-16 3:30 [PATCH] driver: tg3: fix potential UAF in tigon3_dma_hwbug_workaround() Gen Zhang
2020-01-19 10:00 ` David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.