netfilter: xt_RATEEST: acquire xt_rateest_mutex for hash insert
commit 7dc68e98757a8eccf8ca7a53a29b896f1eef1f76 upstream.
rateest_hash is supposed to be protected by xt_rateest_mutex,
and, as suggested by Eric, lookup and insert should be atomic,
so we should acquire the xt_rateest_mutex once for both.
So introduce a non-locking helper for internal use and keep the
locking one for external.
Reported-by: <syzbot+5cb189720978275e4c75@syzkaller.appspotmail.com>
Fixes: 5859034d7e
("[NETFILTER]: x_tables: add RATEEST target")
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Reviewed-by: Florian Westphal <fw@strlen.de>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
5d27dfad3f
commit
fb13b263bc
|
@ -40,23 +40,31 @@ static void xt_rateest_hash_insert(struct xt_rateest *est)
|
||||||
hlist_add_head(&est->list, &rateest_hash[h]);
|
hlist_add_head(&est->list, &rateest_hash[h]);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct xt_rateest *xt_rateest_lookup(const char *name)
|
static struct xt_rateest *__xt_rateest_lookup(const char *name)
|
||||||
{
|
{
|
||||||
struct xt_rateest *est;
|
struct xt_rateest *est;
|
||||||
unsigned int h;
|
unsigned int h;
|
||||||
|
|
||||||
h = xt_rateest_hash(name);
|
h = xt_rateest_hash(name);
|
||||||
mutex_lock(&xt_rateest_mutex);
|
|
||||||
hlist_for_each_entry(est, &rateest_hash[h], list) {
|
hlist_for_each_entry(est, &rateest_hash[h], list) {
|
||||||
if (strcmp(est->name, name) == 0) {
|
if (strcmp(est->name, name) == 0) {
|
||||||
est->refcnt++;
|
est->refcnt++;
|
||||||
mutex_unlock(&xt_rateest_mutex);
|
|
||||||
return est;
|
return est;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mutex_unlock(&xt_rateest_mutex);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct xt_rateest *xt_rateest_lookup(const char *name)
|
||||||
|
{
|
||||||
|
struct xt_rateest *est;
|
||||||
|
|
||||||
|
mutex_lock(&xt_rateest_mutex);
|
||||||
|
est = __xt_rateest_lookup(name);
|
||||||
|
mutex_unlock(&xt_rateest_mutex);
|
||||||
|
return est;
|
||||||
|
}
|
||||||
EXPORT_SYMBOL_GPL(xt_rateest_lookup);
|
EXPORT_SYMBOL_GPL(xt_rateest_lookup);
|
||||||
|
|
||||||
void xt_rateest_put(struct xt_rateest *est)
|
void xt_rateest_put(struct xt_rateest *est)
|
||||||
|
@ -104,8 +112,10 @@ static int xt_rateest_tg_checkentry(const struct xt_tgchk_param *par)
|
||||||
rnd_inited = true;
|
rnd_inited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
est = xt_rateest_lookup(info->name);
|
mutex_lock(&xt_rateest_mutex);
|
||||||
|
est = __xt_rateest_lookup(info->name);
|
||||||
if (est) {
|
if (est) {
|
||||||
|
mutex_unlock(&xt_rateest_mutex);
|
||||||
/*
|
/*
|
||||||
* If estimator parameters are specified, they must match the
|
* If estimator parameters are specified, they must match the
|
||||||
* existing estimator.
|
* existing estimator.
|
||||||
|
@ -143,11 +153,13 @@ static int xt_rateest_tg_checkentry(const struct xt_tgchk_param *par)
|
||||||
|
|
||||||
info->est = est;
|
info->est = est;
|
||||||
xt_rateest_hash_insert(est);
|
xt_rateest_hash_insert(est);
|
||||||
|
mutex_unlock(&xt_rateest_mutex);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err2:
|
err2:
|
||||||
kfree(est);
|
kfree(est);
|
||||||
err1:
|
err1:
|
||||||
|
mutex_unlock(&xt_rateest_mutex);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue