From: Ivan Abramov <i.abramov@mt-integration.ru>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: Ivan Abramov <i.abramov@mt-integration.ru>,
Kuniyuki Iwashima <kuniyu@amazon.com>,
<linux-wireless@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<lvc-project@linuxtesting.org>
Subject: [PATCH v2 1/3] cfg80211: Restore initial state on failed device_rename() in cfg80211_switch_netns()
Date: Mon, 7 Apr 2025 15:53:42 +0300 [thread overview]
Message-ID: <20250407125345.1238818-2-i.abramov@mt-integration.ru> (raw)
In-Reply-To: <20250407125345.1238818-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).
Fixes: 04600794958f ("cfg80211: support sysfs namespaces")
Suggested-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Ivan Abramov <i.abramov@mt-integration.ru>
---
net/wireless/core.c | 47 +++++++++++++++++++++++++--------------------
1 file changed, 26 insertions(+), 21 deletions(-)
diff --git a/net/wireless/core.c b/net/wireless/core.c
index 9e6b31903121..e4d353ec9436 100644
--- a/net/wireless/core.c
+++ b/net/wireless/core.c
@@ -169,27 +169,17 @@ int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
wdev->netdev->netns_immutable = true;
}
- if (err) {
- /* failed -- clean up to old netns */
- net = wiphy_net(&rdev->wiphy);
-
- list_for_each_entry_continue_reverse(wdev,
- &rdev->wiphy.wdev_list,
- list) {
- if (!wdev->netdev)
- continue;
- wdev->netdev->netns_immutable = false;
- err = dev_change_net_namespace(wdev->netdev, net,
- "wlan%d");
- WARN_ON(err);
- wdev->netdev->netns_immutable = true;
- }
-
- return err;
- }
+ if (err)
+ goto errout;
guard(wiphy)(&rdev->wiphy);
+ err = device_rename(&rdev->wiphy.dev, dev_name(&rdev->wiphy.dev));
+ WARN_ON(err);
+
+ if (err)
+ goto errout;
+
list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
if (!wdev->netdev)
continue;
@@ -200,9 +190,6 @@ int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
wiphy_net_set(&rdev->wiphy, net);
- err = device_rename(&rdev->wiphy.dev, dev_name(&rdev->wiphy.dev));
- WARN_ON(err);
-
nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY);
list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) {
@@ -212,6 +199,24 @@ int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
}
return 0;
+
+errout:
+ /* failed -- clean up to old netns */
+ net = wiphy_net(&rdev->wiphy);
+
+ list_for_each_entry_continue_reverse(wdev,
+ &rdev->wiphy.wdev_list,
+ list) {
+ if (!wdev->netdev)
+ continue;
+ wdev->netdev->netns_immutable = false;
+ err = dev_change_net_namespace(wdev->netdev, net,
+ "wlan%d");
+ WARN_ON(err);
+ wdev->netdev->netns_immutable = true;
+ }
+
+ return err;
}
static void cfg80211_rfkill_poll(struct rfkill *rfkill, void *data)
--
2.39.5
next prev parent reply other threads:[~2025-04-07 12:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-07 12:53 [PATCH v2 0/3] Avoid calling WARN_ON() on allocation failure " Ivan Abramov
2025-04-07 12:53 ` Ivan Abramov [this message]
2025-04-23 15:44 ` [PATCH v2 1/3] cfg80211: Restore initial state on failed device_rename() " Johannes Berg
2025-04-23 18:16 ` Kuniyuki Iwashima
2025-04-07 12:53 ` [PATCH v2 2/3] cfg80211: Avoid calling WARN_ON() on -ENOMEM " Ivan Abramov
2025-04-07 12:53 ` [PATCH v2 3/3] cfg80211: Remove WARN_ON() in cfg80211_pernet_exit() Ivan Abramov
2025-04-07 17:29 ` [PATCH v2 0/3] Avoid calling WARN_ON() on allocation failure in cfg80211_switch_netns() Kuniyuki Iwashima
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=20250407125345.1238818-2-i.abramov@mt-integration.ru \
--to=i.abramov@mt-integration.ru \
--cc=johannes@sipsolutions.net \
--cc=kuniyu@amazon.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=lvc-project@linuxtesting.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®