net: make sure we never create ifindex = 0
authorJakub Kicinski <kuba@kernel.org>
Mon, 31 Jul 2023 17:11:58 +0000 (10:11 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 1 Aug 2023 22:01:29 +0000 (15:01 -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 <stephen@networkplumber.org>
Link: https://lore.kernel.org/all/20230728162350.2a6d4979@hermes.local/
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Link: https://lore.kernel.org/r/20230731171159.988962-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/dev.c

index b58674774a57b18f9c2943c5ad142812d246f775..10e5a036c706a60c6cd9de856b6a6fe7356ce94e 100644 (file)
@@ -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);