netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [FIX 0/1] sip: add missing RCU reader lock in set_expected_rtp_rtcp()
@ 2013-09-20 15:52 Holger Eitzenberger
  2013-09-20 15:52 ` [FIX 1/1] sip: add missing RCU reader lock Holger Eitzenberger
  0 siblings, 1 reply; 4+ messages in thread
From: Holger Eitzenberger @ 2013-09-20 15:52 UTC (permalink / raw)
  To: netfilter-devel; +Cc: kaber

I noticed that set_expected_rtp_rtcp() in net-next misses a 2nd
RCU reader lock when dereferencing the 2nd hook function.  Same
bug is present in kernel v3.8 at least.

It is not simply a matter of extending the RCU read protected
area because there is a conditional return in between:

    if (skip_expect)
        return NF_ACCEPT;

Please check the RCU usage.  I see e. g. that nf_ct_expect_related(),
takes nf_conntrack_lock, but my understanding of RCU is that
this is ok.

Thanks.

 /Holger


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

* [FIX 1/1] sip: add missing RCU reader lock
  2013-09-20 15:52 [FIX 0/1] sip: add missing RCU reader lock in set_expected_rtp_rtcp() Holger Eitzenberger
@ 2013-09-20 15:52 ` Holger Eitzenberger
  2013-09-20 16:55   ` Patrick McHardy
  0 siblings, 1 reply; 4+ messages in thread
From: Holger Eitzenberger @ 2013-09-20 15:52 UTC (permalink / raw)
  To: netfilter-devel; +Cc: kaber, Holger Eitzenberger

[-- Attachment #1: sip-add-missing-RCU-reader-lock.diff --]
[-- Type: text/plain, Size: 984 bytes --]

Currently set_expected_rtp_rtcp() in the SIP helper uses
rcu_dereference() two times to access two different NAT hook
functions.  However, only the first one is protected properly by
the RCU reader lock, but the 2nd isn't.

I chose to not just extend the first RCU protected area but putting
the rcu_read_unlock() down, because there is a 'return' in between.

Signed-off-by: Holger Eitzenberger <holger.eitzenberger@sophos.com>

Index: net-next/net/netfilter/nf_conntrack_sip.c
===================================================================
--- net-next.orig/net/netfilter/nf_conntrack_sip.c
+++ net-next/net/netfilter/nf_conntrack_sip.c
@@ -983,6 +983,7 @@ static int set_expected_rtp_rtcp(struct
 	if (skip_expect)
 		return NF_ACCEPT;
 
+	rcu_read_lock();
 	rtp_exp = nf_ct_expect_alloc(ct);
 	if (rtp_exp == NULL)
 		goto err1;
@@ -1012,6 +1013,7 @@ static int set_expected_rtp_rtcp(struct
 err2:
 	nf_ct_expect_put(rtp_exp);
 err1:
+	rcu_read_unlock();
 	return ret;
 }
 


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

* Re: [FIX 1/1] sip: add missing RCU reader lock
  2013-09-20 15:52 ` [FIX 1/1] sip: add missing RCU reader lock Holger Eitzenberger
@ 2013-09-20 16:55   ` Patrick McHardy
  2013-09-20 20:20     ` Holger Eitzenberger
  0 siblings, 1 reply; 4+ messages in thread
From: Patrick McHardy @ 2013-09-20 16:55 UTC (permalink / raw)
  To: Holger Eitzenberger; +Cc: netfilter-devel, Holger Eitzenberger

On Fri, Sep 20, 2013 at 05:52:18PM +0200, Holger Eitzenberger wrote:
> Currently set_expected_rtp_rtcp() in the SIP helper uses
> rcu_dereference() two times to access two different NAT hook
> functions.  However, only the first one is protected properly by
> the RCU reader lock, but the 2nd isn't.

Its more a cosmetic thing since we rely on all netfilter hooks being
rcu_read_lock()ed by nf_hook_slow() in many places anyways.

> I chose to not just extend the first RCU protected area but putting
> the rcu_read_unlock() down, because there is a 'return' in between.

I'd suggest to do that since your patch still doesn't cover the
direct_rtp nf_nat_sdp_port_hook dereference. Actually with your patch
we have unbalanced RCU locking since the direct_rtp case contains
a "goto err1".

> 
> Signed-off-by: Holger Eitzenberger <holger.eitzenberger@sophos.com>
> 
> Index: net-next/net/netfilter/nf_conntrack_sip.c
> ===================================================================
> --- net-next.orig/net/netfilter/nf_conntrack_sip.c
> +++ net-next/net/netfilter/nf_conntrack_sip.c
> @@ -983,6 +983,7 @@ static int set_expected_rtp_rtcp(struct
>  	if (skip_expect)
>  		return NF_ACCEPT;
>  
> +	rcu_read_lock();
>  	rtp_exp = nf_ct_expect_alloc(ct);
>  	if (rtp_exp == NULL)
>  		goto err1;
> @@ -1012,6 +1013,7 @@ static int set_expected_rtp_rtcp(struct
>  err2:
>  	nf_ct_expect_put(rtp_exp);
>  err1:
> +	rcu_read_unlock();
>  	return ret;
>  }
>  

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

* Re: [FIX 1/1] sip: add missing RCU reader lock
  2013-09-20 16:55   ` Patrick McHardy
@ 2013-09-20 20:20     ` Holger Eitzenberger
  0 siblings, 0 replies; 4+ messages in thread
From: Holger Eitzenberger @ 2013-09-20 20:20 UTC (permalink / raw)
  To: Patrick McHardy; +Cc: netfilter-devel


> > I chose to not just extend the first RCU protected area but putting
> > the rcu_read_unlock() down, because there is a 'return' in between.
> 
> I'd suggest to do that since your patch still doesn't cover the
> direct_rtp nf_nat_sdp_port_hook dereference. Actually with your patch
> we have unbalanced RCU locking since the direct_rtp case contains
> a "goto err1".

Sure, I'll send a 2nd patch in a new thread.

 /Holger


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

end of thread, other threads:[~2013-09-20 20:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-20 15:52 [FIX 0/1] sip: add missing RCU reader lock in set_expected_rtp_rtcp() Holger Eitzenberger
2013-09-20 15:52 ` [FIX 1/1] sip: add missing RCU reader lock Holger Eitzenberger
2013-09-20 16:55   ` Patrick McHardy
2013-09-20 20:20     ` Holger Eitzenberger

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).