ipv6: fib6: fix NULL deref in fib6_walk_continue() on multi-batch dump
Subsystems (3)
PATCH v2 1/1 ipv6: fib6: fix NULL deref in fib6_walk_continue() on multi-batch dump
From: Pengfei Zhang <[email protected]>
inet6_dump_fib() saves its progress in cb->args[1] as a positional index within the current hash chain. Between batches the RTNL lock is released, so a concurrent fib6_new_table() can insert a new table at the chain head, shifting all existing entries. The saved index then lands on a different table, causing fib6_dump_table() to set w->root to the wrong table while w->node still points into the previous one. fib6_walk_continue() dereferences w->node->parent (NULL) and panics:
BUG: kernel NULL pointer dereference, address: 0000000000000008 RIP: 0010:fib6_walk_continue+0x6e/0x170 Call Trace: <TASK> fib6_dump_table.isra.0+0xc5/0x240 inet6_dump_fib+0xf6/0x420 rtnl_dumpit+0x30/0xa0 netlink_dump+0x15b/0x460 netlink_recvmsg+0x1d6/0x2a0 ____sys_recvmsg+0x17a/0x190
Fix by storing tb->tb6_id in cb->args[1] instead of a positional index. On resume, skip entries until the id matches; a concurrent head-insert can never match the saved id, so the walker always resumes on the correct table.
--- net/ipv6/ip6_fib.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
net/ipv6/ip6_fib.c +8 -9
@@ -636,11 +636,11 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) };const struct nlmsghdr *nlh = cb->nlh;struct net *net =sock_net (skb->sk); -unsigned int e =0 , s_e;struct hlist_head *head;struct fib6_walker *w;struct fib6_table *tb;unsigned int h, s_h; +u32 s_id;int err =0 ;rcu_read_lock ();
@@ -701,23 +701,22 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) } s_h = cb->args[0 ]; - s_e = cb->args[1 ]; + s_id = cb->args[1 ]; -for (h = s_h; h <FIB6_TABLE_HASHSZ ; h++, s_e =0 ) { - e =0 ; +for (h = s_h; h <FIB6_TABLE_HASHSZ ; h++, s_id =0 ) { head = &net->ipv6.fib_table_hash[h];hlist_for_each_entry_rcu (tb, head, tb6_hlist) { -if (e < s_e) - goto next; +if (s_id && tb->tb6_id != s_id) +continue ; + s_id =0 ; + + cb->args[1 ] = tb->tb6_id; err =fib6_dump_table (tb, skb, cb);if (err !=0 ) goto out; -next: - e++; } } out: - cb->args[1 ] = e; cb->args[0 ] = h; unlock:
Signature · 1 line
2.34.1
From: Pengfei Zhang <[email protected]>
Date: Thu, 25 Jun 2026 12:41:01 +0800
Quoted 5 lines
From: Pengfei Zhang <[email protected]>
inet6_dump_fib()saves its progress in cb->args[1] as a positional index within the current hash chain. Between batches the RTNL lock is released,
nit: RTNL has been removed from IPv6 FIB, simply say like
Between batches, a concurrent fib6_new_table() can insert ...
Quoted 18 lines
so a concurrent
fib6_new_table()can insert a new table at the chain head, shifting all existing entries. The saved index then lands on a different table, causingfib6_dump_table()to setw->rootto the wrong table whilew->nodestill points into the previous one.fib6_walk_continue()dereferencesw->node->parent(NULL) and panics:BUG: kernel NULL pointer dereference, address: 0000000000000008 RIP: 0010:fib6_walk_continue+0x6e/0x170 Call Trace: <TASK> fib6_dump_table.isra.0+0xc5/0x240 inet6_dump_fib+0xf6/0x420 rtnl_dumpit+0x30/0xa0 netlink_dump+0x15b/0x460 netlink_recvmsg+0x1d6/0x2a0 ____sys_recvmsg+0x17a/0x190
Quoted 7 lines
Fix by storing
tb->tb6_idin cb->args[1] instead of a positional index. On resume, skip entries until the id matches; a concurrent head-insert can never match the saved id, so the walker always resumes on the correct table.Fixes 1b43af5480c3 ("[IPV6]: Increase number of possible routing tables to 2^32")Signed-off-by Pengfei Zhang <[email protected]>
SOB does not match the Author of the patch (the first From: line).
Quoted 9 lines
--- net/ipv6/ip6_fib.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)net/ipv6/ip6_fib.c +0
-0
net/ipv6/ip6_fib.c static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) · line 643
Quoted 9 lines
net/ipv6/ip6_fib.c +1
-1@@ -636,11 +636,11 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) };const struct nlmsghdr *nlh = cb->nlh;struct net *net =sock_net (skb->sk); -unsigned int e =0 , s_e;struct hlist_head *head;struct fib6_walker *w;struct fib6_table *tb;unsigned int h, s_h; +u32 s_id;
nit: please keep the reverse xmas tree order.
https://docs.kernel.org/7.1/process/maintainer-netdev.html#local-variable-ordering-reverse-xmas-tree-rcs
Quoted 36 lines
net/ipv6/ip6_fib.c +7
-8int err =0 ;rcu_read_lock ();@@ -701,23 +701,22 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) } s_h = cb->args[0 ]; - s_e = cb->args[1 ]; + s_id = cb->args[1 ]; -for (h = s_h; h <FIB6_TABLE_HASHSZ ; h++, s_e =0 ) { - e =0 ; +for (h = s_h; h <FIB6_TABLE_HASHSZ ; h++, s_id =0 ) { head = &net->ipv6.fib_table_hash[h];hlist_for_each_entry_rcu (tb, head, tb6_hlist) { -if (e < s_e) - goto next; +if (s_id && tb->tb6_id != s_id) +continue ; + s_id =0 ; + + cb->args[1 ] = tb->tb6_id; err =fib6_dump_table (tb, skb, cb);if (err !=0 ) goto out; -next: - e++; } } out: - cb->args[1 ] = e; cb->args[0 ] = h; unlock:Signature · 1 line
2.34.1