* [PATCH] arc_emac: fix
@ 2013-12-20 1:58 Eric Dumazet
2013-12-20 2:05 ` Eric Dumazet
2013-12-20 2:10 ` [PATCH v2] arc_emac: fix potential use after free Eric Dumazet
0 siblings, 2 replies; 5+ messages in thread
From: Eric Dumazet @ 2013-12-20 1:58 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Alexey Brodkin, Richard Cochran
Signed-off-by: Eric Dumazet <edumazet@google.com>
skb_tx_timestamp(skb) should be called _before_ TX completion
has a chance to trigger, otherwise it is too late and we access
freed memory.
Fixes: e4f2379db6c6 ("ethernet/arc/arc_emac - Add new driver")
From: Eric Dumazet <edumazet@google.com>
Cc: Alexey Brodkin <Alexey.Brodkin@synopsys.com>
Cc: Richard Cochran <richardcochran@gmail.com>
---
drivers/net/ethernet/arc/emac_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c
index b2ffad1304d2..248baf6273fb 100644
--- a/drivers/net/ethernet/arc/emac_main.c
+++ b/drivers/net/ethernet/arc/emac_main.c
@@ -565,6 +565,8 @@ static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev)
/* Make sure pointer to data buffer is set */
wmb();
+ skb_tx_timestamp(skb);
+
*info = cpu_to_le32(FOR_EMAC | FIRST_OR_LAST_MASK | len);
/* Increment index to point to the next BD */
@@ -579,8 +581,6 @@ static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev)
arc_reg_set(priv, R_STATUS, TXPL_MASK);
- skb_tx_timestamp(skb);
-
return NETDEV_TX_OK;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] arc_emac: fix
2013-12-20 1:58 [PATCH] arc_emac: fix Eric Dumazet
@ 2013-12-20 2:05 ` Eric Dumazet
2013-12-20 2:10 ` [PATCH v2] arc_emac: fix potential use after free Eric Dumazet
1 sibling, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2013-12-20 2:05 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Alexey Brodkin, Richard Cochran
On Thu, 2013-12-19 at 17:58 -0800, Eric Dumazet wrote:
> Signed-off-by: Eric Dumazet <edumazet@google.com>
>
> skb_tx_timestamp(skb) should be called _before_ TX completion
> has a chance to trigger, otherwise it is too late and we access
> freed memory.
>
> Fixes: e4f2379db6c6 ("ethernet/arc/arc_emac - Add new driver")
> From: Eric Dumazet <edumazet@google.com>
> Cc: Alexey Brodkin <Alexey.Brodkin@synopsys.com>
> Cc: Richard Cochran <richardcochran@gmail.com>
> ---
> drivers/net/ethernet/arc/emac_main.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c
> index b2ffad1304d2..248baf6273fb 100644
> --- a/drivers/net/ethernet/arc/emac_main.c
> +++ b/drivers/net/ethernet/arc/emac_main.c
> @@ -565,6 +565,8 @@ static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev)
> /* Make sure pointer to data buffer is set */
> wmb();
>
> + skb_tx_timestamp(skb);
> +
> *info = cpu_to_le32(FOR_EMAC | FIRST_OR_LAST_MASK | len);
>
> /* Increment index to point to the next BD */
> @@ -579,8 +581,6 @@ static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev)
>
> arc_reg_set(priv, R_STATUS, TXPL_MASK);
>
> - skb_tx_timestamp(skb);
> -
> return NETDEV_TX_OK;
> }
>
Sorry I messed patch title, will resend
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] arc_emac: fix potential use after free
2013-12-20 1:58 [PATCH] arc_emac: fix Eric Dumazet
2013-12-20 2:05 ` Eric Dumazet
@ 2013-12-20 2:10 ` Eric Dumazet
2013-12-20 14:06 ` Alexey Brodkin
2013-12-27 18:05 ` David Miller
1 sibling, 2 replies; 5+ messages in thread
From: Eric Dumazet @ 2013-12-20 2:10 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Alexey Brodkin, Richard Cochran
Signed-off-by: Eric Dumazet <edumazet@google.com>
skb_tx_timestamp(skb) should be called _before_ TX completion
has a chance to trigger, otherwise it is too late and we access
freed memory.
Fixes: e4f2379db6c6 ("ethernet/arc/arc_emac - Add new driver")
From: Eric Dumazet <edumazet@google.com>
Cc: Alexey Brodkin <Alexey.Brodkin@synopsys.com>
Cc: Richard Cochran <richardcochran@gmail.com>
---
drivers/net/ethernet/arc/emac_main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/arc/emac_main.c b/drivers/net/ethernet/arc/emac_main.c
index b2ffad1304d2..248baf6273fb 100644
--- a/drivers/net/ethernet/arc/emac_main.c
+++ b/drivers/net/ethernet/arc/emac_main.c
@@ -565,6 +565,8 @@ static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev)
/* Make sure pointer to data buffer is set */
wmb();
+ skb_tx_timestamp(skb);
+
*info = cpu_to_le32(FOR_EMAC | FIRST_OR_LAST_MASK | len);
/* Increment index to point to the next BD */
@@ -579,8 +581,6 @@ static int arc_emac_tx(struct sk_buff *skb, struct net_device *ndev)
arc_reg_set(priv, R_STATUS, TXPL_MASK);
- skb_tx_timestamp(skb);
-
return NETDEV_TX_OK;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] arc_emac: fix potential use after free
2013-12-20 2:10 ` [PATCH v2] arc_emac: fix potential use after free Eric Dumazet
@ 2013-12-20 14:06 ` Alexey Brodkin
2013-12-27 18:05 ` David Miller
1 sibling, 0 replies; 5+ messages in thread
From: Alexey Brodkin @ 2013-12-20 14:06 UTC (permalink / raw)
To: eric.dumazet@gmail.com
Cc: davem@davemloft.net, netdev@vger.kernel.org,
richardcochran@gmail.com
On Thu, 2013-12-19 at 18:10 -0800, Eric Dumazet wrote:
> Signed-off-by: Eric Dumazet <edumazet@google.com>
>
> skb_tx_timestamp(skb) should be called _before_ TX completion
> has a chance to trigger, otherwise it is too late and we access
> freed memory.
>
> Fixes: e4f2379db6c6 ("ethernet/arc/arc_emac - Add new driver")
Hi Eric,
thanks for this fix.
Indeed I missed this part and description of "skb_tx_timestamp" which
clearly directs to use it earlier:
=======
* skb_tx_timestamp() - Driver hook for transmit timestamping
*
* Ethernet MAC Drivers should call this function in their hard_xmit()
* function immediately before giving the sk_buff to the MAC hardware.
=======
-Alexey
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] arc_emac: fix potential use after free
2013-12-20 2:10 ` [PATCH v2] arc_emac: fix potential use after free Eric Dumazet
2013-12-20 14:06 ` Alexey Brodkin
@ 2013-12-27 18:05 ` David Miller
1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2013-12-27 18:05 UTC (permalink / raw)
To: eric.dumazet; +Cc: netdev, Alexey.Brodkin, richardcochran
From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 19 Dec 2013 18:10:40 -0800
> Signed-off-by: Eric Dumazet <edumazet@google.com>
>
> skb_tx_timestamp(skb) should be called _before_ TX completion
> has a chance to trigger, otherwise it is too late and we access
> freed memory.
>
> Fixes: e4f2379db6c6 ("ethernet/arc/arc_emac - Add new driver")
> From: Eric Dumazet <edumazet@google.com>
> Cc: Alexey Brodkin <Alexey.Brodkin@synopsys.com>
> Cc: Richard Cochran <richardcochran@gmail.com>
Applied, thanks.
I've seen this bug enough times that I've expanded the comment
a bit more.
====================
[PATCH] net: Add some clarification to skb_tx_timestamp() comment.
We've seen so many instances of people invoking skb_tx_timestamp()
after the device already has been given the packet, that it's worth
being a little bit more verbose and explicit in this comment.
Signed-off-by: David S. Miller <davem@davemloft.net>
---
include/linux/skbuff.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 6aae838..6f69b3f 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -2531,6 +2531,10 @@ static inline void sw_tx_timestamp(struct sk_buff *skb)
* Ethernet MAC Drivers should call this function in their hard_xmit()
* function immediately before giving the sk_buff to the MAC hardware.
*
+ * Specifically, one should make absolutely sure that this function is
+ * called before TX completion of this packet can trigger. Otherwise
+ * the packet could potentially already be freed.
+ *
* @skb: A socket buffer.
*/
static inline void skb_tx_timestamp(struct sk_buff *skb)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-12-27 18:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-20 1:58 [PATCH] arc_emac: fix Eric Dumazet
2013-12-20 2:05 ` Eric Dumazet
2013-12-20 2:10 ` [PATCH v2] arc_emac: fix potential use after free Eric Dumazet
2013-12-20 14:06 ` Alexey Brodkin
2013-12-27 18:05 ` 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).