linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [NETFILTER] bridge: rcu_deref outside read-lock section
@ 2012-08-13 22:47 Denis Efremov
  2012-08-13 23:36 ` Stephen Hemminger
  2012-08-14  8:08 ` [PATCH v2] " Denis Efremov
  0 siblings, 2 replies; 6+ messages in thread
From: Denis Efremov @ 2012-08-13 22:47 UTC (permalink / raw)
  To: Pablo Neira Ayuso
  Cc: Denis Efremov, Patrick McHardy, netfilter-devel, netfilter,
	coreteam, linux-kernel, ldv-project

As it noted in the comment before the br_handle_frame_finish
function, this function should be called under rcu_read_lock.

The problem callgraph:
br_dev_xmit -> br_nf_pre_routing_finish_bridge_slow ->
-> br_handle_frame_finish -> br_port_get_rcu -> rcu_dereference

And in this case there is no read-lock section.
I have put lock/unlock in br_nf_pre_routing_finish_bridge_slow,
as the only function that calls it(for now) - is br_dev_xmit.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Denis Efremov <yefremov.denis@gmail.com>
---
 include/linux/netfilter_bridge.h |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/include/linux/netfilter_bridge.h b/include/linux/netfilter_bridge.h
index 31d2844..ceb048e 100644
--- a/include/linux/netfilter_bridge.h
+++ b/include/linux/netfilter_bridge.h
@@ -79,6 +79,7 @@ extern int br_handle_frame_finish(struct sk_buff *skb);
 /* Only used in br_device.c */
 static inline int br_nf_pre_routing_finish_bridge_slow(struct sk_buff *skb)
 {
+	int res;
 	struct nf_bridge_info *nf_bridge = skb->nf_bridge;
 
 	skb_pull(skb, ETH_HLEN);
@@ -86,7 +87,10 @@ static inline int br_nf_pre_routing_finish_bridge_slow(struct sk_buff *skb)
 	skb_copy_to_linear_data_offset(skb, -(ETH_HLEN-ETH_ALEN),
 				       skb->nf_bridge->data, ETH_HLEN-ETH_ALEN);
 	skb->dev = nf_bridge->physindev;
-	return br_handle_frame_finish(skb);
+	rcu_read_lock();
+	res = br_handle_frame_finish(skb);
+	rcu_read_unlock();
+	return res;
 }
 
 /* This is called by the IP fragmenting code and it ensures there is
-- 
1.7.7


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

* Re: [PATCH] [NETFILTER] bridge: rcu_deref outside read-lock section
  2012-08-13 22:47 [PATCH] [NETFILTER] bridge: rcu_deref outside read-lock section Denis Efremov
@ 2012-08-13 23:36 ` Stephen Hemminger
  2012-08-14  7:32   ` Denis
  2012-08-14  8:08 ` [PATCH v2] " Denis Efremov
  1 sibling, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2012-08-13 23:36 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Pablo Neira Ayuso, Patrick McHardy, netfilter-devel, netfilter,
	coreteam, linux-kernel, ldv-project

On Tue, 14 Aug 2012 02:47:42 +0400
Denis Efremov <yefremov.denis@gmail.com> wrote:

> As it noted in the comment before the br_handle_frame_finish
> function, this function should be called under rcu_read_lock.
> 
> The problem callgraph:
> br_dev_xmit -> br_nf_pre_routing_finish_bridge_slow ->
> -> br_handle_frame_finish -> br_port_get_rcu -> rcu_dereference
> 
> And in this case there is no read-lock section.
> I have put lock/unlock in br_nf_pre_routing_finish_bridge_slow,
> as the only function that calls it(for now) - is br_dev_xmit.
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Denis Efremov <yefremov.denis@gmail.com>
> ---
>  include/linux/netfilter_bridge.h |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/include/linux/netfilter_bridge.h b/include/linux/netfilter_bridge.h
> index 31d2844..ceb048e 100644
> --- a/include/linux/netfilter_bridge.h
> +++ b/include/linux/netfilter_bridge.h
> @@ -79,6 +79,7 @@ extern int br_handle_frame_finish(struct sk_buff *skb);
>  /* Only used in br_device.c */
>  static inline int br_nf_pre_routing_finish_bridge_slow(struct sk_buff *skb)
>  {
> +	int res;
>  	struct nf_bridge_info *nf_bridge = skb->nf_bridge;
>  
>  	skb_pull(skb, ETH_HLEN);
> @@ -86,7 +87,10 @@ static inline int br_nf_pre_routing_finish_bridge_slow(struct sk_buff *skb)
>  	skb_copy_to_linear_data_offset(skb, -(ETH_HLEN-ETH_ALEN),
>  				       skb->nf_bridge->data, ETH_HLEN-ETH_ALEN);
>  	skb->dev = nf_bridge->physindev;
> -	return br_handle_frame_finish(skb);
> +	rcu_read_lock();
> +	res = br_handle_frame_finish(skb);
> +	rcu_read_unlock();
> +	return res;
>  }
>  
>  /* This is called by the IP fragmenting code and it ensures there is

Why not just move the rcu_read_lock() in br_dev_xmit earlier?

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

* Re: [PATCH] [NETFILTER] bridge: rcu_deref outside read-lock section
  2012-08-13 23:36 ` Stephen Hemminger
@ 2012-08-14  7:32   ` Denis
  0 siblings, 0 replies; 6+ messages in thread
From: Denis @ 2012-08-14  7:32 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Pablo Neira Ayuso, Patrick McHardy, netfilter-devel, netfilter,
	coreteam, linux-kernel, ldv-project

On 14.08.2012 3:36, Stephen Hemminger wrote:
> Why not just move the rcu_read_lock() in br_dev_xmit earlier? 

I don't know the semantics of this code, so it's difficult for me to
choose the appropriate place. I thought that the callers
of br_nf_pre_routing_finish_bridge_slow function are limited to
br_dev_xmit and we can modify header without problems.
Anyway, I will send another version of the patch.


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

* [PATCH v2] bridge: rcu_deref outside read-lock section
  2012-08-13 22:47 [PATCH] [NETFILTER] bridge: rcu_deref outside read-lock section Denis Efremov
  2012-08-13 23:36 ` Stephen Hemminger
@ 2012-08-14  8:08 ` Denis Efremov
  2012-08-14 15:19   ` [PATCH] bridge: fix rcu dereference outside of rcu_read_lock Stephen Hemminger
  1 sibling, 1 reply; 6+ messages in thread
From: Denis Efremov @ 2012-08-14  8:08 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Denis Efremov, David S. Miller, pablo, kaber, netfilter-devel,
	netfilter, coreteam, linux-kernel, ldv-project

As it noted in the comment before the br_handle_frame_finish
function, this function should be called under rcu_read_lock.

The problem callgraph:
br_dev_xmit -> br_nf_pre_routing_finish_bridge_slow ->
-> br_handle_frame_finish -> br_port_get_rcu -> rcu_dereference

And in this case there is no read-lock section.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Denis Efremov <yefremov.denis@gmail.com>
---
 net/bridge/br_device.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 3334845..f9ae07f 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -33,7 +33,9 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
 
 #ifdef CONFIG_BRIDGE_NETFILTER
 	if (skb->nf_bridge && (skb->nf_bridge->mask & BRNF_BRIDGED_DNAT)) {
+		rcu_read_lock();
 		br_nf_pre_routing_finish_bridge_slow(skb);
+		rcu_read_unlock();
 		return NETDEV_TX_OK;
 	}
 #endif
-- 
1.7.7


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

* [PATCH] bridge: fix rcu dereference outside of rcu_read_lock
  2012-08-14  8:08 ` [PATCH v2] " Denis Efremov
@ 2012-08-14 15:19   ` Stephen Hemminger
  2012-08-15 22:10     ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2012-08-14 15:19 UTC (permalink / raw)
  To: Denis Efremov
  Cc: David S. Miller, pablo, kaber, netfilter-devel, netfilter,
	coreteam, linux-kernel, ldv-project

Alternative solution for problem found by Linux Driver Verification
project (linuxtesting.org).

As it noted in the comment before the br_handle_frame_finish
function, this function should be called under rcu_read_lock.

The problem callgraph:
br_dev_xmit -> br_nf_pre_routing_finish_bridge_slow ->
 -> br_handle_frame_finish -> br_port_get_rcu -> rcu_dereference

And in this case there is no read-lock section.

Reported-by: Denis Efremov <yefremov.denis@gmail.com>
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
---
 net/bridge/br_device.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 3334845..8a3b50f 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -31,9 +31,11 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
 	struct net_bridge_mdb_entry *mdst;
 	struct br_cpu_netstats *brstats = this_cpu_ptr(br->stats);
 
+	rcu_read_lock();
 #ifdef CONFIG_BRIDGE_NETFILTER
 	if (skb->nf_bridge && (skb->nf_bridge->mask & BRNF_BRIDGED_DNAT)) {
 		br_nf_pre_routing_finish_bridge_slow(skb);
+		rcu_read_unlock();
 		return NETDEV_TX_OK;
 	}
 #endif
@@ -48,7 +50,6 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
 	skb_reset_mac_header(skb);
 	skb_pull(skb, ETH_HLEN);
 
-	rcu_read_lock();
 	if (is_broadcast_ether_addr(dest))
 		br_flood_deliver(br, skb);
 	else if (is_multicast_ether_addr(dest)) {
-- 
1.7.10.4


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

* Re: [PATCH] bridge: fix rcu dereference outside of rcu_read_lock
  2012-08-14 15:19   ` [PATCH] bridge: fix rcu dereference outside of rcu_read_lock Stephen Hemminger
@ 2012-08-15 22:10     ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2012-08-15 22:10 UTC (permalink / raw)
  To: shemminger
  Cc: yefremov.denis, pablo, kaber, netfilter-devel, netfilter,
	coreteam, linux-kernel, ldv-project

From: Stephen Hemminger <shemminger@vyatta.com>
Date: Tue, 14 Aug 2012 08:19:33 -0700

> Alternative solution for problem found by Linux Driver Verification
> project (linuxtesting.org).
> 
> As it noted in the comment before the br_handle_frame_finish
> function, this function should be called under rcu_read_lock.
> 
> The problem callgraph:
> br_dev_xmit -> br_nf_pre_routing_finish_bridge_slow ->
>  -> br_handle_frame_finish -> br_port_get_rcu -> rcu_dereference
> 
> And in this case there is no read-lock section.
> 
> Reported-by: Denis Efremov <yefremov.denis@gmail.com>
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

Applied, thanks Stephen.

Please CC: this to netdev next time.  It's in a grey area whether I or
the netfilter folks should apply this one, and here I'm deciding to
take care of it.


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

end of thread, other threads:[~2012-08-15 22:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-13 22:47 [PATCH] [NETFILTER] bridge: rcu_deref outside read-lock section Denis Efremov
2012-08-13 23:36 ` Stephen Hemminger
2012-08-14  7:32   ` Denis
2012-08-14  8:08 ` [PATCH v2] " Denis Efremov
2012-08-14 15:19   ` [PATCH] bridge: fix rcu dereference outside of rcu_read_lock Stephen Hemminger
2012-08-15 22: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).