Patchwork [NETFILTER] bridge: rcu_deref outside read-lock section

login
register
mail settings
Submitter Denis Efremov
Date Aug. 13, 2012, 10:47 p.m.
Message ID <1344898062-23633-1-git-send-email-yefremov.denis@gmail.com>
Download mbox | patch
Permalink /patch/177143/
State Not Applicable
Headers show

Comments

Denis Efremov - Aug. 13, 2012, 10:47 p.m.
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(-)
stephen hemminger - Aug. 13, 2012, 11:36 p.m.
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?
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Denis Efremov - Aug. 14, 2012, 7:32 a.m.
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.

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

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