Skip to content

Commit 62f8137

Browse files
pskrgaggregkh
authored andcommitted
netfilter: nft_ct: protect nft_ct_pcpu_template_refcnt with mutex
[ Upstream commit e3245a7 ] Syzbot hit use-after-free in nf_tables_dump_sets. The problem was in missing lock protection for nft_ct_pcpu_template_refcnt. Before commit f102d66 ("netfilter: nf_tables: use dedicated mutex to guard transactions") all transactions were serialized by global mutex, but then global mutex was changed to local per netnamespace commit_mutex. This change causes use-after-free bug, when 2 netnamespaces concurently changing nft_ct_pcpu_template_refcnt without proper locking. Fix it by adding nft_ct_pcpu_mutex and protect all nft_ct_pcpu_template_refcnt changes with it. Fixes: f102d66 ("netfilter: nf_tables: use dedicated mutex to guard transactions") Reported-and-tested-by: syzbot+649e339fa6658ee623d3@syzkaller.appspotmail.com Signed-off-by: Pavel Skripkin <paskripkin@gmail.com> Acked-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1cf43a1 commit 62f8137

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎net/netfilter/nft_ct.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ struct nft_ct_helper_obj {
4141
#ifdef CONFIG_NF_CONNTRACK_ZONES
4242
static DEFINE_PER_CPU(struct nf_conn *, nft_ct_pcpu_template);
4343
static unsigned int nft_ct_pcpu_template_refcnt __read_mostly;
44+
static DEFINE_MUTEX(nft_ct_pcpu_mutex);
4445
#endif
4546

4647
static u64 nft_ct_get_eval_counter(const struct nf_conn_counter *c,
@@ -526,8 +527,10 @@ static void __nft_ct_set_destroy(const struct nft_ctx *ctx, struct nft_ct *priv)
526527
#endif
527528
#ifdef CONFIG_NF_CONNTRACK_ZONES
528529
case NFT_CT_ZONE:
530+
mutex_lock(&nft_ct_pcpu_mutex);
529531
if (--nft_ct_pcpu_template_refcnt == 0)
530532
nft_ct_tmpl_put_pcpu();
533+
mutex_unlock(&nft_ct_pcpu_mutex);
531534
break;
532535
#endif
533536
default:
@@ -565,9 +568,13 @@ static int nft_ct_set_init(const struct nft_ctx *ctx,
565568
#endif
566569
#ifdef CONFIG_NF_CONNTRACK_ZONES
567570
case NFT_CT_ZONE:
568-
if (!nft_ct_tmpl_alloc_pcpu())
571+
mutex_lock(&nft_ct_pcpu_mutex);
572+
if (!nft_ct_tmpl_alloc_pcpu()) {
573+
mutex_unlock(&nft_ct_pcpu_mutex);
569574
return -ENOMEM;
575+
}
570576
nft_ct_pcpu_template_refcnt++;
577+
mutex_unlock(&nft_ct_pcpu_mutex);
571578
len = sizeof(u16);
572579
break;
573580
#endif

0 commit comments

Comments
 (0)