netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 4/4] net/core/dev.c : Race condition in net_tx_action.
@ 2015-02-25 17:50 Ameen Ali
  2015-02-25 18:16 ` Eric Dumazet
  2015-02-25 18:47 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Ameen Ali @ 2015-02-25 17:50 UTC (permalink / raw)
  To: davem; +Cc: netdev, linux-kernel, Ameen Ali

Transmitting asynchronously on all the network devices available we will  notice the following behaviour:
a) The instruction "if (sd->completion_queue) {" saves on a CPU register the pointer value (register contents is used for the comparison)
b) The interupt is disabled (using "local_irq_disable")
c) when the content of "clist" is updated, the register is used, instead of re-read the "completion_queue" variable.

So, when a low-level tx interrupt arrives after the latching of "completion_queue", but before "local_irq_disable",
 the value stored in "clist" reflect the situation before low-level tx interrupt, resulting in a sk_buff leak
---
 net/core/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index 8f9710c..db3e59e 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3413,7 +3413,7 @@ EXPORT_SYMBOL(netif_rx_ni);
 
 static void net_tx_action(struct softirq_action *h)
 {
-	struct softnet_data *sd = this_cpu_ptr(&softnet_data);
+	volatile struct softnet_data *sd = &__get_cpu_var(softnet_data);
 
 	if (sd->completion_queue) {
 		struct sk_buff *clist;
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 4/4] net/core/dev.c : Race condition in net_tx_action.
  2015-02-25 17:50 [PATCH 4/4] net/core/dev.c : Race condition in net_tx_action Ameen Ali
@ 2015-02-25 18:16 ` Eric Dumazet
  2015-02-25 18:47 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2015-02-25 18:16 UTC (permalink / raw)
  To: Ameen Ali; +Cc: davem, netdev, linux-kernel

On Wed, 2015-02-25 at 19:50 +0200, Ameen Ali wrote:
> Transmitting asynchronously on all the network devices available we will  notice the following behaviour:
> a) The instruction "if (sd->completion_queue) {" saves on a CPU register the pointer value (register contents is used for the comparison)
> b) The interupt is disabled (using "local_irq_disable")
> c) when the content of "clist" is updated, the register is used, instead of re-read the "completion_queue" variable.
> 
> So, when a low-level tx interrupt arrives after the latching of "completion_queue", but before "local_irq_disable",
>  the value stored in "clist" reflect the situation before low-level tx interrupt, resulting in a sk_buff leak
> ---
>  net/core/dev.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/core/dev.c b/net/core/dev.c
> index 8f9710c..db3e59e 100644
> --- a/net/core/dev.c
> +++ b/net/core/dev.c
> @@ -3413,7 +3413,7 @@ EXPORT_SYMBOL(netif_rx_ni);
>  
>  static void net_tx_action(struct softirq_action *h)
>  {
> -	struct softnet_data *sd = this_cpu_ptr(&softnet_data);
> +	volatile struct softnet_data *sd = &__get_cpu_var(softnet_data);
>  
>  	if (sd->completion_queue) {
>  		struct sk_buff *clist;

Seems real bug is elsewhere. This is becoming a FAQ.

Which arch are you using, and which compiler ?

volatile are highly discouraged in favor of ACCESS_ONCE, READ_ONCE(),
WRITE_ONCE() : read
Documentation/volatile-considered-harmful.txt:19:safe

local_irq_disable() acts as a barrier the compiler should reload the
value from memory.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 4/4] net/core/dev.c : Race condition in net_tx_action.
  2015-02-25 17:50 [PATCH 4/4] net/core/dev.c : Race condition in net_tx_action Ameen Ali
  2015-02-25 18:16 ` Eric Dumazet
@ 2015-02-25 18:47 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-02-25 18:47 UTC (permalink / raw)
  To: ameenali023; +Cc: netdev, linux-kernel

From: Ameen Ali <ameenali023@gmail.com>
Date: Wed, 25 Feb 2015 19:50:59 +0200

> @@ -3413,7 +3413,7 @@ EXPORT_SYMBOL(netif_rx_ni);
>  
>  static void net_tx_action(struct softirq_action *h)
>  {
> -	struct softnet_data *sd = this_cpu_ptr(&softnet_data);
> +	volatile struct softnet_data *sd = &__get_cpu_var(softnet_data);

volatile is never an appropriate solution to a race condition

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-25 18:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-25 17:50 [PATCH 4/4] net/core/dev.c : Race condition in net_tx_action Ameen Ali
2015-02-25 18:16 ` Eric Dumazet
2015-02-25 18:47 ` 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).