Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: amisiurov@cloudlinux.com
Cc: alex.aring@gmail.com, stefan@datenfreihafen.org,
	miquel.raynal@bootlin.com, linux-wpan@vger.kernel.org,
	netdev@vger.kernel.org, davem@davemloft.net, edumazet@kernel.org,
	kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net v2] ieee802154: keep the original error after a netns rollback
Date: Tue, 24 Nov 2026 07:10:36 +0000	[thread overview]
Message-ID: <179550423672.3135.14967631079444652354@kernel.org> (raw)
In-Reply-To: <20261120065750.3274661-1-amisiurov@cloudlinux.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 1 (2) · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The rollback loop in cfg802154_switch_netns()
  (net/ieee802154/core.c, lines 255-267) walks rdev->wpan_dev_list…
- [Low] The commit message suggests that any failed move in
  cfg802154_switch_netns() ends with 'err' overwritten to 0.

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it sits on the
  exact path the commit message describes (-EEXIST on the forward move).
- [High] This problem wasn't introduced by this patch, but
  cfg802154_pernet_exit() (net/ieee802154/core.c, around line 361) calls…

--

ieee802154: keep the original error after a netns rollback

This patch shadows 'err' inside the rollback loop of
cfg802154_switch_netns(). A failed netns switch then returns the original
error instead of the result of the last move-back. Without it, a failed
switch can be reported to userspace as a success through
nl802154_wpan_phy_netns().

> That rollback loop overwrites the same 'err' variable with the result of
> each move-back. The move-backs succeed, so 'err' ends up 0 and the function
> returns 0 -- success -- even though nothing moved and the phy stayed in the
> old netns.

[Severity: Low]
This isn't a bug, but could the commit message say more precisely when the
overwrite happens?

Suppose the first entry in rdev->wpan_dev_list that has a netdev is the one
that fails. list_for_each_entry_continue_reverse() starts at
list_prev_entry(pos), which is the list head. The rollback body never runs,
so the unpatched code already returns the original error in that case.

The overwrite only happens in two cases:

  - at least one earlier netdev moved before a later one failed, or
  - every netdev moved and then device_rename() failed.

The message doesn't mention the device_rename() path, which this patch
also fixes.

The reproduction note below the --- line ("phy0 and its wpan0 interface",
-EEXIST internally, 0 returned) only fits if phy0 had another interface
that moved before wpan0 failed.

Would stating these conditions help backporters decide whether they are
affected?

> diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
> index c0b8712018a16..f471744175182 100644
> --- a/net/ieee802154/core.c
> +++ b/net/ieee802154/core.c
> @@ -255,6 +255,8 @@ int cfg802154_switch_netns(struct cfg802154_registered_device *rdev,
>  	list_for_each_entry_continue_reverse(wpan_dev,
>  					     &rdev->wpan_dev_list,
>  					     list) {

[Severity: High]
Does this rollback really move all of the already-moved netdevs back?

Each dev_change_net_namespace() call runs the NETDEV_UNREGISTER and then
the NETDEV_REGISTER notifier. cfg802154_netdev_notifier_call() changes
rdev->wpan_dev_list while that happens:

net/ieee802154/core.c:cfg802154_netdev_notifier_call() {
    ...
	case NETDEV_REGISTER:
		...
		list_add_rcu(&wpan_dev->list, &rdev->wpan_dev_list);
    ...
	case NETDEV_UNREGISTER:
		...
		if (!list_empty(&wpan_dev->list)) {
			list_del_rcu(&wpan_dev->list);
		...
		INIT_LIST_HEAD(&wpan_dev->list);
    ...
}

So every successful move puts the moved wpan_dev at the head of the list.
Take a list of [A, B, C] where C fails:

  forward loop:  move A        -> [A, B, C]
                 move B        -> [B, A, C]
                 A again, net_eq() no-op
                 C fails, break with pos = C

  rollback:      pos = prev(C) = A
                 move A back   -> [A, B, C]
                 prev(A) is the list head, loop ends

B is never moved back. On the device_rename() failure path pos is the list
head, so only prev(head) is moved back.

With this patch the function returns the original error (for example
-EEXIST from an altname clash in the target netns). Userspace is told the
switch failed, but B stays in the new netns while the phy stays in the old
one.

The commit message says the error path "moves the already-moved netdevs
back to the old netns" and that "nothing moved". That doesn't seem to hold
when two or more netdevs had already moved.

The stranded netdev also keeps netns_immutable = true. When its netns is
torn down, default_device_exit_net() skips it. default_device_exit_batch()
then unregisters it with unregister_netdevice_queue(), because mac802154
netdevs have no rtnl_link_ops.

That path bypasses ieee802154_if_remove(), so sdata->list stays on
local->interfaces after the netdev and its sdata are freed. Can that then
be dereferenced in __ieee802154_rx_handle_packet():

	list_for_each_entry_rcu(sdata, &local->interfaces, list) {

or by the list_del_rcu() in ieee802154_remove_interfaces()?

> +		int err;
> +
>  		if (!wpan_dev->netdev)
>  			continue;
>  		wpan_dev->netdev->netns_immutable = false;

[Severity: High]
This isn't a bug introduced by this patch, but it is on the same -EEXIST
forward-move path the commit message describes. Is the netns_immutable
flag of the failing netdev ever restored?

In the forward loop of cfg802154_switch_netns():

		wpan_dev->netdev->netns_immutable = false;
		err = dev_change_net_namespace(wpan_dev->netdev, net, "wpan%d");
		if (err) {
			WARN_ON(err && err != -ENOMEM);
			break;
		}
		wpan_dev->netdev->netns_immutable = true;

The break skips the restore. The rollback starts at list_prev_entry() of
the failing entry, so it never visits that netdev either. That leaves the
only guard in __dev_change_net_namespace() disabled:

	if (dev->netns_immutable) {
		NL_SET_ERR_MSG(extack, "The interface netns is immutable");
		goto out;
	}

A later "ip link set wpanX netns Y" can then move the netdev away from its
phy. NETDEV_REGISTER sets the flag back to true in Y. When Y is destroyed,
the same default_device_exit_batch() path described above unregisters the
netdev without ieee802154_if_remove(). That leaves a freed sdata on
local->interfaces.

cfg80211_switch_wdev_netns() in net/wireless/core.c always restores the
flag, whatever the result:

	wdev->netdev->netns_immutable = false;
	err = dev_change_net_namespace(wdev->netdev, net, "wlan%d");
	wdev->netdev->netns_immutable = true;

Should the 802.15.4 version also set the flag back before the break?

[Severity: High]
This is a pre-existing issue, but what happens if cfg802154_switch_netns()
fails when it is called from cfg802154_pernet_exit()?

net/ieee802154/core.c:cfg802154_pernet_exit() {
    ...
		if (net_eq(wpan_phy_net(&rdev->wpan_phy), net))
			cfg802154_switch_netns(rdev, &init_net);
    ...
}

The return value is ignored. Altname clashes don't apply during teardown,
because __dev_change_net_namespace() destroys conflicting altnames when
!check_net(net_old). The trigger here is an allocation failure in
dev_change_net_namespace() or device_rename().

On such a failure the errout path does:

	net = wpan_phy_net(&rdev->wpan_phy);

That is the dying netns. The rolled-back netdevs are moved back into a
namespace that is about to be freed, possibly only some of them given the
list reordering above. wpan_phy_net_set() is never called, so the phy
keeps pointing at the freed struct net.

The immutable netdevs left in the dying netns are then unregistered by
default_device_exit_batch() without ieee802154_if_remove(). That leaves
dangling sdata entries on local->interfaces, which ieee802154_rx() and
ieee802154_remove_interfaces() later use.

cfg80211_pernet_exit() handles this with force mode and a WARN_ON():

			WARN_ON(__cfg80211_switch_netns(rdev, &init_net, true));

Force mode unregisters the interfaces that cannot be moved. Is a similar
fallback needed for 802.15.4?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261120065750.3274661-1-amisiurov%40cloudlinux.com

      parent reply	other threads:[~2026-11-24  7:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  6:57 [PATCH net v2] ieee802154: keep the original error after a netns rollback Andrey Misiurov
2026-11-20  8:25 ` Miquel Raynal
2026-11-24  7:10 ` netdev-bot+sashiko [this message]

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=179550423672.3135.14967631079444652354@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alex.aring@gmail.com \
    --cc=amisiurov@cloudlinux.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wpan@vger.kernel.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