Subject: [PATCH net-next v2] net: make sure we never create ifindex = 0

From: Jakub Kicinski <[email-masked]>
Date: Mon, 31 Jul 2023 10:11:58 -0700

Instead of allocating from 1 use proper xa_init flag,
to protect ourselves from IDs wrapping back to 0.

Fixes: 759ab1edb56c ("net: store netdevs in an xarray")
Reported-by: Stephen Hemminger <[email-masked]>
Link: https://lore.kernel.org/all/[email-masked]/
Signed-off-by: Jakub Kicinski <[email-masked]>
---
CC: [email-masked]
---
 net/core/dev.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index b58674774a57..10e5a036c706 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -11271,8 +11271,7 @@ static int __net_init netdev_init(struct net *net)
 	if (net->dev_index_head == NULL)
 		goto err_idx;
 
-	net->ifindex = 1;
-	xa_init_flags(&net->dev_by_index, XA_FLAGS_ALLOC);
+	xa_init_flags(&net->dev_by_index, XA_FLAGS_ALLOC1);
 
 	RAW_INIT_NOTIFIER_HEAD(&net->netdev_chain);
 
-- 
2.41.0