ipv4: fib: fix route re-dump in inet_dump_fib() on multi-batch dump
Subsystems (3)
PATCH v2 1/1 ipv4: fib: fix route re-dump in inet_dump_fib() on multi-batch dump
inet_dump_fib() saves its progress in cb->args[1] as a positional index within the current hash chain. Between batches, a concurrent fib_new_table() can insert a new table at the chain head, shifting all existing entries. On resume the saved index lands on a different table, causing already-dumped tables to be re-dumped and the originally suspended table to restart from the beginning.
Fix by storing tb->tb_id in cb->args[1] instead of a positional index, mirroring the fix applied to inet6_dump_fib() in commit 9facb861dc6b ("ipv6: fib6: fix NULL deref in fib6_walk_continue() on multi-batch dump").
---
v2:
- Drop Fixes tag (not needed for net-next)
- Fix variable declaration order (reverse xmas tree)
- Reference IPv6 fix commit hash
v1: https://lore.kernel.org/netdev/[email protected]/
net/ipv4/fib_frontend.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
net/ipv4/fib_frontend.c +9 -9
@@ -1019,10 +1019,11 @@ static int inet_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) .dump_routes = true, .dump_exceptions = true, }; -unsigned int e =0 , s_e, h, s_h;struct hlist_head *head;int dumped =0 , err =0 ;struct fib_table *tb; +unsigned int h, s_h; +u32 s_id;rcu_read_lock ();if (cb->strict_check) {
@@ -1054,29 +1055,28 @@ static int inet_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 ]; err =0 ; -for (h = s_h; h <FIB_TABLE_HASHSZ ; h++, s_e =0 ) { - e =0 ; +for (h = s_h; h <FIB_TABLE_HASHSZ ; h++, s_id =0 ) { head = &net->ipv4.fib_table_hash[h];hlist_for_each_entry_rcu (tb, head, tb_hlist) { -if (e < s_e) - goto next; +if (s_id && tb->tb_id != s_id) +continue ; + + s_id =0 ;if (dumped)memset (&cb->args[2 ],0 ,sizeof (cb->args) -2 *sizeof (cb->args[0 ])); + cb->args[1 ] = tb->tb_id; err =fib_table_dump (tb, skb, cb, &filter);if (err <0 ) goto out; dumped =1 ; -next: - e++; } } out: - cb->args[1 ] = e; cb->args[0 ] = h; unlock:
Signature · 1 line
2.54.0
Quoted 7 lines · Pengfei Zhang
inet_dump_fib()saves its progress in cb->args[1] as a positional index within the current hash chain. Between batches, a concurrentfib_new_table()can insert a new table at the chain head, shifting all existing entries. On resume the saved index lands on a different table, causing already-dumped tables to be re-dumped and the originally suspended table to restart from the beginning.
Quoted 6 lines
Fix by storing
tb->tb_idin cb->args[1] instead of a positional index, mirroring the fix applied toinet6_dump_fib()in commit9facb861dc6b("ipv6: fib6: fix NULL deref infib6_walk_continue()on multi-batch dump").Signed-off-by Pengfei Zhang <[email protected]>
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 8 lines · On Tue, 30 Jun 2026 16:42:20 +0800 you wrote:
inet_dump_fib()saves its progress in cb->args[1] as a positional index within the current hash chain. Between batches, a concurrentfib_new_table()can insert a new table at the chain head, shifting all existing entries. On resume the saved index lands on a different table, causing already-dumped tables to be re-dumped and the originally suspended table to restart from the beginning.[...]
Here is the summary with links:
- [v2,net-next] ipv4: fib: fix route re-dump in inet_dump_fib() on multi-batch dump
https://git.kernel.org/netdev/net-next/c/2ed8d5c72488
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html