* [PATCH net v2 1/3] ieee802154: Restore initial state on failed device_rename() in cfg802154_switch_netns()
2025-04-03 8:20 [PATCH net v2 0/3] Avoid calling WARN_ON() on allocation failure in cfg802154_switch_netns() Ivan Abramov
@ 2025-04-03 8:20 ` Ivan Abramov
2025-04-03 8:20 ` [PATCH net v2 2/3] ieee802154: Avoid calling WARN_ON() on -ENOMEM " Ivan Abramov
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Ivan Abramov @ 2025-04-03 8:20 UTC (permalink / raw)
To: Alexander Aring
Cc: Ivan Abramov, Stefan Schmidt, Miquel Raynal, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
linux-wpan, netdev, linux-kernel, lvc-project
Currently, the return value of device_rename() is not acted upon.
To avoid an inconsistent state in case of failure, roll back the changes
made before the device_rename() call.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Fixes: 66e5c2672cd1 ("ieee802154: add netns support")
Signed-off-by: Ivan Abramov <i.abramov@mt-integration.ru>
---
v2: Make sure to commit against latest netdev/net.
net/ieee802154/core.c | 45 ++++++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 20 deletions(-)
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index 89b671b12600..84d514430e45 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -233,31 +233,36 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev,
wpan_dev->netdev->netns_immutable = true;
}
- if (err) {
- /* failed -- clean up to old netns */
- net = wpan_phy_net(&rdev->wpan_phy);
-
- list_for_each_entry_continue_reverse(wpan_dev,
- &rdev->wpan_dev_list,
- list) {
- if (!wpan_dev->netdev)
- continue;
- wpan_dev->netdev->netns_immutable = false;
- err = dev_change_net_namespace(wpan_dev->netdev, net,
- "wpan%d");
- WARN_ON(err);
- wpan_dev->netdev->netns_immutable = true;
- }
-
- return err;
- }
-
- wpan_phy_net_set(&rdev->wpan_phy, net);
+ if (err)
+ goto errout;
err = device_rename(&rdev->wpan_phy.dev, dev_name(&rdev->wpan_phy.dev));
WARN_ON(err);
+ if (err)
+ goto errout;
+
+ wpan_phy_net_set(&rdev->wpan_phy, net);
+
return 0;
+
+errout:
+ /* failed -- clean up to old netns */
+ net = wpan_phy_net(&rdev->wpan_phy);
+
+ list_for_each_entry_continue_reverse(wpan_dev,
+ &rdev->wpan_dev_list,
+ list) {
+ if (!wpan_dev->netdev)
+ continue;
+ wpan_dev->netdev->netns_immutable = false;
+ err = dev_change_net_namespace(wpan_dev->netdev, net,
+ "wpan%d");
+ WARN_ON(err);
+ wpan_dev->netdev->netns_immutable = true;
+ }
+
+ return err;
}
void cfg802154_dev_free(struct cfg802154_registered_device *rdev)
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH net v2 2/3] ieee802154: Avoid calling WARN_ON() on -ENOMEM in cfg802154_switch_netns()
2025-04-03 8:20 [PATCH net v2 0/3] Avoid calling WARN_ON() on allocation failure in cfg802154_switch_netns() Ivan Abramov
2025-04-03 8:20 ` [PATCH net v2 1/3] ieee802154: Restore initial state on failed device_rename() " Ivan Abramov
@ 2025-04-03 8:20 ` Ivan Abramov
2025-04-03 8:20 ` [PATCH net v2 3/3] ieee802154: Remove WARN_ON() in cfg802154_pernet_exit() Ivan Abramov
2025-04-03 8:34 ` [PATCH net v2 0/3] Avoid calling WARN_ON() on allocation failure in cfg802154_switch_netns() Miquel Raynal
3 siblings, 0 replies; 5+ messages in thread
From: Ivan Abramov @ 2025-04-03 8:20 UTC (permalink / raw)
To: Alexander Aring
Cc: Ivan Abramov, syzbot+e0bd4e4815a910c0daa8, Stefan Schmidt,
Miquel Raynal, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Simon Horman, linux-wpan, netdev, linux-kernel,
lvc-project
It's pointless to call WARN_ON() in case of an allocation failure in
dev_change_net_namespace() and device_rename(), since it only leads to
useless splats caused by deliberate fault injections, so avoid it.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Reported-by: syzbot+e0bd4e4815a910c0daa8@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/netdev/000000000000f4a1b7061f9421de@google.com/#t
Fixes: 66e5c2672cd1 ("ieee802154: add netns support")
Signed-off-by: Ivan Abramov <i.abramov@mt-integration.ru>
---
v2: Add Reported-by and Closes tags as per Kuniyuki Iwashima's observation.
Make sure to commit against latest netdev/net.
net/ieee802154/core.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index 84d514430e45..987c633e2c54 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -228,8 +228,10 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev,
continue;
wpan_dev->netdev->netns_immutable = false;
err = dev_change_net_namespace(wpan_dev->netdev, net, "wpan%d");
- if (err)
+ if (err) {
+ WARN_ON(err && err != -ENOMEM);
break;
+ }
wpan_dev->netdev->netns_immutable = true;
}
@@ -237,7 +239,7 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev,
goto errout;
err = device_rename(&rdev->wpan_phy.dev, dev_name(&rdev->wpan_phy.dev));
- WARN_ON(err);
+ WARN_ON(err && err != -ENOMEM);
if (err)
goto errout;
@@ -258,7 +260,7 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev,
wpan_dev->netdev->netns_immutable = false;
err = dev_change_net_namespace(wpan_dev->netdev, net,
"wpan%d");
- WARN_ON(err);
+ WARN_ON(err && err != -ENOMEM);
wpan_dev->netdev->netns_immutable = true;
}
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH net v2 3/3] ieee802154: Remove WARN_ON() in cfg802154_pernet_exit()
2025-04-03 8:20 [PATCH net v2 0/3] Avoid calling WARN_ON() on allocation failure in cfg802154_switch_netns() Ivan Abramov
2025-04-03 8:20 ` [PATCH net v2 1/3] ieee802154: Restore initial state on failed device_rename() " Ivan Abramov
2025-04-03 8:20 ` [PATCH net v2 2/3] ieee802154: Avoid calling WARN_ON() on -ENOMEM " Ivan Abramov
@ 2025-04-03 8:20 ` Ivan Abramov
2025-04-03 8:34 ` [PATCH net v2 0/3] Avoid calling WARN_ON() on allocation failure in cfg802154_switch_netns() Miquel Raynal
3 siblings, 0 replies; 5+ messages in thread
From: Ivan Abramov @ 2025-04-03 8:20 UTC (permalink / raw)
To: Alexander Aring
Cc: Ivan Abramov, Stefan Schmidt, Miquel Raynal, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
linux-wpan, netdev, linux-kernel, lvc-project
There's no need to call WARN_ON() in cfg802154_pernet_exit(), since
every point of failure in cfg802154_switch_netns() is covered with
WARN_ON(), so remove it.
Found by Linux Verification Center (linuxtesting.org) with Syzkaller.
Fixes: 66e5c2672cd1 ("ieee802154: add netns support")
Signed-off-by: Ivan Abramov <i.abramov@mt-integration.ru>
---
v2: Make sure to commit against latest netdev/net.
net/ieee802154/core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index 987c633e2c54..c0b8712018a1 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -358,7 +358,7 @@ static void __net_exit cfg802154_pernet_exit(struct net *net)
rtnl_lock();
list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
if (net_eq(wpan_phy_net(&rdev->wpan_phy), net))
- WARN_ON(cfg802154_switch_netns(rdev, &init_net));
+ cfg802154_switch_netns(rdev, &init_net);
}
rtnl_unlock();
}
--
2.39.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH net v2 0/3] Avoid calling WARN_ON() on allocation failure in cfg802154_switch_netns()
2025-04-03 8:20 [PATCH net v2 0/3] Avoid calling WARN_ON() on allocation failure in cfg802154_switch_netns() Ivan Abramov
` (2 preceding siblings ...)
2025-04-03 8:20 ` [PATCH net v2 3/3] ieee802154: Remove WARN_ON() in cfg802154_pernet_exit() Ivan Abramov
@ 2025-04-03 8:34 ` Miquel Raynal
3 siblings, 0 replies; 5+ messages in thread
From: Miquel Raynal @ 2025-04-03 8:34 UTC (permalink / raw)
To: Ivan Abramov
Cc: Alexander Aring, Stefan Schmidt, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wpan, netdev,
linux-kernel, lvc-project
On 03/04/2025 at 11:20:18 +03, Ivan Abramov <i.abramov@mt-integration.ru> wrote:
> This series was inspired by Syzkaller report on warning in
> cfg802154_switch_netns().
This series has received reviews under the form of Reviewed-by tags. You
are in charge of carrying those tags over versions. Please collect and
resubmit the series with all of them (a tag on the cover letter applies
to all patches).
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 5+ messages in thread