Forwarded: [PATCH] netfilter: nf_tables: add missing RCU read lock in nf_tables_getsetelem

syzbot posted 1 patch 1 week, 2 days ago
net/netfilter/nf_tables_api.c | 2 ++
1 file changed, 2 insertions(+)
Forwarded: [PATCH] netfilter: nf_tables: add missing RCU read lock in nf_tables_getsetelem
Posted by syzbot 1 week, 2 days ago
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: [PATCH] netfilter: nf_tables: add missing RCU read lock in nf_tables_getsetelem
Author: kartikey406@gmail.com

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git main

Add RCU read-side critical section in nf_tables_getsetelem() to protect
against concurrent element deletion by garbage collection.

The function nf_tables_getsetelem() calls nft_get_set_elem() which
eventually dereferences set elements through the rbtree lookup path.
These elements can be freed by nft_trans_gc_trans_free() running in an
RCU callback context while the lookup is in progress, leading to a
use-after-free.

The function nf_tables_getsetelem_reset() already has proper RCU
protection around the same code path. This patch adds the missing RCU
read lock to nf_tables_getsetelem() to match.

Reported-by: syzbot+d417922a3e7935517ef6@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=d417922a3e7935517ef6
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
 net/netfilter/nf_tables_api.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index be4924aeaf0e..00af242b1e62 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -6628,6 +6628,7 @@ static int nf_tables_getsetelem(struct sk_buff *skb,
 	if (err)
 		return err;
 
+	rcu_read_lock();
 	nla_for_each_nested(attr, nla[NFTA_SET_ELEM_LIST_ELEMENTS], rem) {
 		err = nft_get_set_elem(&dump_ctx.ctx, dump_ctx.set, attr, false);
 		if (err < 0) {
@@ -6635,6 +6636,7 @@ static int nf_tables_getsetelem(struct sk_buff *skb,
 			break;
 		}
 	}
+	rcu_read_unlock();
 
 	return err;
 }
-- 
2.43.0