[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230729015623.17373-1-kuba@kernel.org>
Date: Fri, 28 Jul 2023 18:56:23 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: davem@...emloft.net
Cc: netdev@...r.kernel.org,
edumazet@...gle.com,
pabeni@...hat.com,
Jakub Kicinski <kuba@...nel.org>,
Stephen Hemminger <stephen@...workplumber.org>,
leon@...nel.org
Subject: [PATCH net-next] net: make sure we never create ifindex = 0
Instead of allocating from 1 use proper xa_limit, to protect
ourselves from IDs wrapping back to 0.
Fixes: 759ab1edb56c ("net: store netdevs in an xarray")
Reported-by: Stephen Hemminger <stephen@...workplumber.org>
Link: https://lore.kernel.org/all/20230728162350.2a6d4979@hermes.local/
Signed-off-by: Jakub Kicinski <kuba@...nel.org>
---
CC: leon@...nel.org
---
net/core/dev.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/core/dev.c b/net/core/dev.c
index b58674774a57..2312ca67b95e 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -9587,7 +9587,8 @@ static int dev_index_reserve(struct net *net, u32 ifindex)
if (!ifindex)
err = xa_alloc_cyclic(&net->dev_by_index, &ifindex, NULL,
- xa_limit_31b, &net->ifindex, GFP_KERNEL);
+ XA_LIMIT(1, INT_MAX), &net->ifindex,
+ GFP_KERNEL);
else
err = xa_insert(&net->dev_by_index, ifindex, NULL, GFP_KERNEL);
if (err < 0)
@@ -11271,7 +11272,6 @@ 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);
RAW_INIT_NOTIFIER_HEAD(&net->netdev_chain);
--
2.41.0
Powered by blists - more mailing lists