netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net] xt_RATEEST: acquire xt_rateest_mutex for hash insert
@ 2018-02-01  0:26 Cong Wang
  2018-02-01  1:44 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Cong Wang @ 2018-02-01  0:26 UTC (permalink / raw)
  To: netdev; +Cc: netfilter-devel, Cong Wang, Pablo Neira Ayuso

rateest_hash is supposed to be protected by xt_rateest_mutex.

Reported-by: <syzbot+5cb189720978275e4c75@syzkaller.appspotmail.com>
Fixes: 5859034d7eb8 ("[NETFILTER]: x_tables: add RATEEST target")
Cc: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/netfilter/xt_RATEEST.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/netfilter/xt_RATEEST.c b/net/netfilter/xt_RATEEST.c
index 498b54fd04d7..83ec3a282755 100644
--- a/net/netfilter/xt_RATEEST.c
+++ b/net/netfilter/xt_RATEEST.c
@@ -36,7 +36,9 @@ static void xt_rateest_hash_insert(struct xt_rateest *est)
 	unsigned int h;
 
 	h = xt_rateest_hash(est->name);
+	mutex_lock(&xt_rateest_mutex);
 	hlist_add_head(&est->list, &rateest_hash[h]);
+	mutex_unlock(&xt_rateest_mutex);
 }
 
 struct xt_rateest *xt_rateest_lookup(const char *name)
-- 
2.13.0


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

* Re: [Patch net] xt_RATEEST: acquire xt_rateest_mutex for hash insert
  2018-02-01  0:26 [Patch net] xt_RATEEST: acquire xt_rateest_mutex for hash insert Cong Wang
@ 2018-02-01  1:44 ` Eric Dumazet
  2018-02-01 21:50   ` Cong Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2018-02-01  1:44 UTC (permalink / raw)
  To: Cong Wang, netdev; +Cc: netfilter-devel, Pablo Neira Ayuso

On Wed, 2018-01-31 at 16:26 -0800, Cong Wang wrote:
> rateest_hash is supposed to be protected by xt_rateest_mutex.
> 
> Reported-by: <syzbot+5cb189720978275e4c75@syzkaller.appspotmail.com>
> Fixes: 5859034d7eb8 ("[NETFILTER]: x_tables: add RATEEST target")
> Cc: Pablo Neira Ayuso <pablo@netfilter.org>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
>  net/netfilter/xt_RATEEST.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/net/netfilter/xt_RATEEST.c b/net/netfilter/xt_RATEEST.c
> index 498b54fd04d7..83ec3a282755 100644
> --- a/net/netfilter/xt_RATEEST.c
> +++ b/net/netfilter/xt_RATEEST.c
> @@ -36,7 +36,9 @@ static void xt_rateest_hash_insert(struct xt_rateest *est)
>  	unsigned int h;
>  
>  	h = xt_rateest_hash(est->name);
> +	mutex_lock(&xt_rateest_mutex);
>  	hlist_add_head(&est->list, &rateest_hash[h]);
> +	mutex_unlock(&xt_rateest_mutex);
>  }

We probably should make this module netns aware, otherwise bad things
will happen.

(It seems multiple threads could run, so getting the mutex twice 
(xt_rateest_lookup then xt_rateest_hash_insert() is racy)

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

* Re: [Patch net] xt_RATEEST: acquire xt_rateest_mutex for hash insert
  2018-02-01  1:44 ` Eric Dumazet
@ 2018-02-01 21:50   ` Cong Wang
  2018-02-01 22:36     ` Florian Westphal
  0 siblings, 1 reply; 4+ messages in thread
From: Cong Wang @ 2018-02-01 21:50 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Linux Kernel Network Developers, netfilter-devel, Pablo Neira Ayuso

On Wed, Jan 31, 2018 at 5:44 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> On Wed, 2018-01-31 at 16:26 -0800, Cong Wang wrote:
>> rateest_hash is supposed to be protected by xt_rateest_mutex.
>>
>> Reported-by: <syzbot+5cb189720978275e4c75@syzkaller.appspotmail.com>
>> Fixes: 5859034d7eb8 ("[NETFILTER]: x_tables: add RATEEST target")
>> Cc: Pablo Neira Ayuso <pablo@netfilter.org>
>> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
>> ---
>>  net/netfilter/xt_RATEEST.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/net/netfilter/xt_RATEEST.c b/net/netfilter/xt_RATEEST.c
>> index 498b54fd04d7..83ec3a282755 100644
>> --- a/net/netfilter/xt_RATEEST.c
>> +++ b/net/netfilter/xt_RATEEST.c
>> @@ -36,7 +36,9 @@ static void xt_rateest_hash_insert(struct xt_rateest *est)
>>       unsigned int h;
>>
>>       h = xt_rateest_hash(est->name);
>> +     mutex_lock(&xt_rateest_mutex);
>>       hlist_add_head(&est->list, &rateest_hash[h]);
>> +     mutex_unlock(&xt_rateest_mutex);
>>  }
>
> We probably should make this module netns aware, otherwise bad things
> will happen.

Right, both the lock and the hashtable. I can do it for net-next,
if you don't.

>
> (It seems multiple threads could run, so getting the mutex twice
> (xt_rateest_lookup then xt_rateest_hash_insert() is racy)

Yeah, need to merge these two critical sections.

Thanks.

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

* Re: [Patch net] xt_RATEEST: acquire xt_rateest_mutex for hash insert
  2018-02-01 21:50   ` Cong Wang
@ 2018-02-01 22:36     ` Florian Westphal
  0 siblings, 0 replies; 4+ messages in thread
From: Florian Westphal @ 2018-02-01 22:36 UTC (permalink / raw)
  To: Cong Wang
  Cc: Eric Dumazet, Linux Kernel Network Developers, netfilter-devel,
	Pablo Neira Ayuso

Cong Wang <xiyou.wangcong@gmail.com> wrote:
> On Wed, Jan 31, 2018 at 5:44 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> > On Wed, 2018-01-31 at 16:26 -0800, Cong Wang wrote:
> >> rateest_hash is supposed to be protected by xt_rateest_mutex.
> >>
> >> Reported-by: <syzbot+5cb189720978275e4c75@syzkaller.appspotmail.com>
> >> Fixes: 5859034d7eb8 ("[NETFILTER]: x_tables: add RATEEST target")
> >> Cc: Pablo Neira Ayuso <pablo@netfilter.org>
> >> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> >> ---
> >>  net/netfilter/xt_RATEEST.c | 2 ++
> >>  1 file changed, 2 insertions(+)
> >>
> >> diff --git a/net/netfilter/xt_RATEEST.c b/net/netfilter/xt_RATEEST.c
> >> index 498b54fd04d7..83ec3a282755 100644
> >> --- a/net/netfilter/xt_RATEEST.c
> >> +++ b/net/netfilter/xt_RATEEST.c
> >> @@ -36,7 +36,9 @@ static void xt_rateest_hash_insert(struct xt_rateest *est)
> >>       unsigned int h;
> >>
> >>       h = xt_rateest_hash(est->name);
> >> +     mutex_lock(&xt_rateest_mutex);
> >>       hlist_add_head(&est->list, &rateest_hash[h]);
> >> +     mutex_unlock(&xt_rateest_mutex);
> >>  }
> >
> > We probably should make this module netns aware, otherwise bad things
> > will happen.
> 
> Right, both the lock and the hashtable. I can do it for net-next,
> if you don't.

Note that the xtables af mutexes are not per-netns, the race is iptables
vs. ip6tables.

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

end of thread, other threads:[~2018-02-01 22:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-01  0:26 [Patch net] xt_RATEEST: acquire xt_rateest_mutex for hash insert Cong Wang
2018-02-01  1:44 ` Eric Dumazet
2018-02-01 21:50   ` Cong Wang
2018-02-01 22:36     ` Florian Westphal

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