Skip to content

Commit ceaac91

Browse files
committed
net: make sure we never create ifindex = 0
Instead of allocating from 1 use proper xa_init flag, to protect ourselves from IDs wrapping back to 0. Fixes: 759ab1e ("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>
1 parent 005c960 commit ceaac91

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

net/core/dev.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11271,8 +11271,7 @@ static int __net_init netdev_init(struct net *net)
1127111271
if (net->dev_index_head == NULL)
1127211272
goto err_idx;
1127311273

11274-
net->ifindex = 1;
11275-
xa_init_flags(&net->dev_by_index, XA_FLAGS_ALLOC);
11274+
xa_init_flags(&net->dev_by_index, XA_FLAGS_ALLOC1);
1127611275

1127711276
RAW_INIT_NOTIFIER_HEAD(&net->netdev_chain);
1127811277

0 commit comments

Comments
 (0)