From: Ivan Abramov <i.abramov@mt-integration.ru>
To: Alexander Aring <alex.aring@gmail.com>
Cc: Ivan Abramov <i.abramov@mt-integration.ru>,
Stefan Schmidt <stefan@datenfreihafen.org>,
Miquel Raynal <miquel.raynal@bootlin.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>, <linux-wpan@vger.kernel.org>,
<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<lvc-project@linuxtesting.org>
Subject: [PATCH 1/3] ieee802154: Restore initial state on failed device_rename() in cfg802154_switch_netns()
Date: Fri, 28 Mar 2025 04:04:25 +0300 [thread overview]
Message-ID: <20250328010427.735657-2-i.abramov@mt-integration.ru> (raw)
In-Reply-To: <20250328010427.735657-1-i.abramov@mt-integration.ru>
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>
---
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 88adb04e4072..ddde594513a0 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_local = 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_local = false;
- err = dev_change_net_namespace(wpan_dev->netdev, net,
- "wpan%d");
- WARN_ON(err);
- wpan_dev->netdev->netns_local = 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_local = false;
+ err = dev_change_net_namespace(wpan_dev->netdev, net,
+ "wpan%d");
+ WARN_ON(err);
+ wpan_dev->netdev->netns_local = true;
+ }
+
+ return err;
}
void cfg802154_dev_free(struct cfg802154_registered_device *rdev)
--
2.39.5
next prev parent reply other threads:[~2025-03-28 1:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-28 1:04 [PATCH 0/3] Avoid calling WARN_ON() on allocation failure " Ivan Abramov
2025-03-28 1:04 ` Ivan Abramov [this message]
2025-03-28 1:04 ` [PATCH 2/3] ieee802154: Avoid calling WARN_ON() on -ENOMEM " Ivan Abramov
2025-03-28 2:30 ` Kuniyuki Iwashima
2025-03-31 9:40 ` Ivan Abramov
2025-03-28 1:04 ` [PATCH 3/3] ieee802154: Remove WARN_ON() in cfg802154_pernet_exit() Ivan Abramov
2025-03-28 2:35 ` [PATCH 0/3] Avoid calling WARN_ON() on allocation failure in cfg802154_switch_netns() Kuniyuki Iwashima
2025-03-28 8:29 ` Miquel Raynal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250328010427.735657-2-i.abramov@mt-integration.ru \
--to=i.abramov@mt-integration.ru \
--cc=alex.aring@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wpan@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=miquel.raynal@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stefan@datenfreihafen.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®