Netdev List
 help / color / mirror / Atom feed
* [PATCH net] net: netns: fix INT_MAX nsid cleanup
@ 2026-11-11  3:35 Zhao Gongyi
  2026-11-12 18:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Zhao Gongyi @ 2026-11-11  3:35 UTC (permalink / raw)
  To: netdev
  Cc: davem, edumazet, kuba, pabeni, horms, kuniyu, realwujing, stable,
	Zhao Gongyi

A syzkaller reproducer assigning INT_MAX as a peer nsid triggers an
idr_get_next() warning during netns cleanup. With panic_on_warn, this
panics the kernel.

alloc_netid() also overflows reqid + 1 for this nsid. Use
idr_alloc_u32() for requested IDs and idr_get_next_ul() for cleanup so
the cursor can advance past INT_MAX.

QEMU/KVM reproduced the warning without kernel changes or fault
injection. The same reproducer ran without warnings after this change.
Kernel selftests were not run.

Fixes: 7acee67a6bce ("netns: optimize netns cleaning by batching unhash_nsid calls")
Cc: stable@vger.kernel.org
Signed-off-by: Zhao Gongyi <zhaogongyi@bytedance.com>
---
 net/core/net_namespace.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 52c2bd447..9d530ac41 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -270,14 +270,19 @@ static void ops_undo_single(struct pernet_operations *ops,
 /* should be called with nsid_lock held */
 static int alloc_netid(struct net *net, struct net *peer, int reqid)
 {
-	int min = 0, max = 0;
+	u32 id;
+	int ret;
 
 	if (reqid >= 0) {
-		min = reqid;
-		max = reqid + 1;
+		id = reqid;
+		ret = idr_alloc_u32(&net->netns_ids, peer, &id, id,
+				    GFP_ATOMIC);
+		if (ret)
+			return ret;
+		return id;
 	}
 
-	return idr_alloc(&net->netns_ids, peer, min, max, GFP_ATOMIC);
+	return idr_alloc(&net->netns_ids, peer, 0, 0, GFP_ATOMIC);
 }
 
 /* This function is used by idr_for_each(). If net is equal to peer, the
@@ -639,10 +644,10 @@ static void unhash_nsid(struct net *last)
 	 * use for_each_net_rcu() or net_rwsem.
 	 */
 	for_each_net(tmp) {
-		int id = 0;
+		unsigned long id = 0;
 
 		spin_lock(&tmp->nsid_lock);
-		while ((peer = idr_get_next(&tmp->netns_ids, &id))) {
+		while ((peer = idr_get_next_ul(&tmp->netns_ids, &id))) {
 			int curr_id = id;
 
 			id++;

base-commit: 070411c1590c8172eb4d86f045d99c372f22fe23
-- 
2.39.5 (Apple Git-154)

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] net: netns: fix INT_MAX nsid cleanup
  2026-11-11  3:35 [PATCH net] net: netns: fix INT_MAX nsid cleanup Zhao Gongyi
@ 2026-11-12 18:50 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-11-12 18:50 UTC (permalink / raw)
  To: Zhao Gongyi
  Cc: netdev, davem, edumazet, kuba, pabeni, horms, kuniyu, realwujing,
	stable

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 11 Nov 2026 11:35:25 +0800 you wrote:
> A syzkaller reproducer assigning INT_MAX as a peer nsid triggers an
> idr_get_next() warning during netns cleanup. With panic_on_warn, this
> panics the kernel.
> 
> alloc_netid() also overflows reqid + 1 for this nsid. Use
> idr_alloc_u32() for requested IDs and idr_get_next_ul() for cleanup so
> the cursor can advance past INT_MAX.
> 
> [...]

Here is the summary with links:
  - [net] net: netns: fix INT_MAX nsid cleanup
    https://git.kernel.org/netdev/net/c/dd6f1e7582f0

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-12 18:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11  3:35 [PATCH net] net: netns: fix INT_MAX nsid cleanup Zhao Gongyi
2026-11-12 18:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox