Skip to content

Commit

Permalink
net: make sure we never create ifindex = 0
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jakub Kicinski committed Aug 1, 2023
1 parent 005c960 commit ceaac91
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit ceaac91

Please sign in to comment.