Skip to contentSkip to conversation

xt_RATEEST: acquire xt_rateest_mutex for hash insert

PATCH Superseded Cong Wang 3 participants 4 messages Feb 1, 2018

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 xt_RATEEST: acquire xt_rateest_mutex for hash insert

rateest_hash is supposed to be protected by xt_rateest_mutex.

Fixes 5859034d7eb8 ("[NETFILTER]: x_tables: add RATEEST target")
Cc Pablo Neira Ayuso <[email protected]>
---
 net/netfilter/xt_RATEEST.c | 2 ++
 1 file changed, 2 insertions(+)
net/netfilter/xt_RATEEST.c +2 -0
index 498b54fd04d7..83ec3a282755 100644
@@ -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)
Signature · 1 line
2.13.0
#1 lore raw
Quoted 15 lines · Cong Wang

rateest_hash is supposed to be protected by xt_rateest_mutex.

Fixes 5859034d7eb8 ("[NETFILTER]: x_tables: add RATEEST target")
Cc Pablo Neira Ayuso <[email protected]>
---
 net/netfilter/xt_RATEEST.c | 2 ++
 1 file changed, 2 insertions(+)
net/netfilter/xt_RATEEST.c +0 -0
index 498b54fd04d7..83ec3a282755 100644

net/netfilter/xt_RATEEST.c static void xt_rateest_hash_insert(struct xt_rateest *est) · line 42

Quoted 7 lines
net/netfilter/xt_RATEEST.c +2 -0
@@ -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)

author
#2 lore raw
Quoted 18 lines · Eric Dumazet
Quoted 17 lines · Cong Wang

rateest_hash is supposed to be protected by xt_rateest_mutex.

Fixes 5859034d7eb8 ("[NETFILTER]: x_tables: add RATEEST target")
Cc Pablo Neira Ayuso <[email protected]>
---
 net/netfilter/xt_RATEEST.c | 2 ++
 1 file changed, 2 insertions(+)
net/netfilter/xt_RATEEST.c +0 -0
index 498b54fd04d7..83ec3a282755 100644
@@ -36,7 +36,9 @@ static void xt_rateest_hash_insert(struct xt_rateest *est)
      unsigned int h;
 
Quoted 8 lines

net/netfilter/xt_RATEEST.c static void xt_rateest_hash_insert(struct xt_rateest *est) · line 42

Quoted 5 lines
net/netfilter/xt_RATEEST.c +2 -0
      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.

Quoted 3 lines

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

maintainer
#3 lore raw
Quoted 28 lines · Cong Wang
Quoted 18 lines · Eric Dumazet
Quoted 17 lines · Cong Wang

rateest_hash is supposed to be protected by xt_rateest_mutex.

Fixes 5859034d7eb8 ("[NETFILTER]: x_tables: add RATEEST target")
Cc Pablo Neira Ayuso <[email protected]>
---
 net/netfilter/xt_RATEEST.c | 2 ++
 1 file changed, 2 insertions(+)
net/netfilter/xt_RATEEST.c +0 -0
index 498b54fd04d7..83ec3a282755 100644
@@ -36,7 +36,9 @@ static void xt_rateest_hash_insert(struct xt_rateest *est)
      unsigned int h;
 
Quoted 8 lines

net/netfilter/xt_RATEEST.c static void xt_rateest_hash_insert(struct xt_rateest *est) · line 42

Quoted 5 lines
net/netfilter/xt_RATEEST.c +2 -0
      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.

Quoted 2 lines

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.