* [PATCH net] mac802154: take RTNL around ASSOC RESP transmission
@ 2026-11-21 15:08 Lee Keon-Hyeong
2026-11-24 18:48 ` Miquel Raynal
2026-11-25 15:08 ` netdev-bot+sashiko
0 siblings, 2 replies; 5+ messages in thread
From: Lee Keon-Hyeong @ 2026-11-21 15:08 UTC (permalink / raw)
To: alex.aring, stefan, miquel.raynal; +Cc: linux-wpan, netdev
mac802154_process_association_req() runs from the rx_mac_cmd workqueue.
The missing RTNL was identified during an LLM-assisted code audit of the
mac802154 association handling path. The function builds the ASSOC RESP
and sends it through
mac802154_send_association_resp_locked() -> ieee802154_mlme_tx_locked(),
which asserts the RTNL and calls ieee802154_sync_queue(). The worker does
not hold the RTNL: this triggers an RTNL assertion failure whenever an
ASSOC REQ reaches the response transmission path. With panic_on_warn=1 a
single unauthenticated frame panics the kernel, even with
max_associations=0 (a rejected request still sends a response).
Take the RTNL before association_lock, matching the netlink lock order
(RTNL then association_lock), and release it after the association lock on
all exits.
Reproduced with a monitor/coordinator pair on mac802154_hwsim; the same
test is silent with this patch. On a CONFIG_PROVE_LOCKING kernel 86,891
association requests were sent while the coordinator was brought down and
up 1,200 times and recreated 71 times: no lockdep report, no hang and no
warning, and the longest down transition took about 4 ms. The
panic_on_warn run (22,941 requests, 300 down/up cycles) also completed.
There is no in-tree selftest for this path; the checks above use a
dedicated hwsim harness.
Fixes: 601f160b61b2 ("mac802154: Handle association requests from peers")
Signed-off-by: Lee Keon-Hyeong <leegun25@proton.me>
---
net/mac802154/scan.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/mac802154/scan.c b/net/mac802154/scan.c
index d393b1f4e..49bc5d29b 100644
--- a/net/mac802154/scan.c
+++ b/net/mac802154/scan.c
@@ -826,6 +826,11 @@ int mac802154_process_association_req(struct ieee802154_sub_if_data *sdata,
return -ENODEV;
}
+ /* mac802154_send_association_resp_locked() uses the MLME TX helpers,
+ * which require the RTNL. Take it before association_lock to keep the
+ * same lock order as the netlink paths (RTNL then association_lock).
+ */
+ rtnl_lock();
mutex_lock(&wpan_dev->association_lock);
memcpy(&assoc_req_pl, skb->data, sizeof(assoc_req_pl));
@@ -895,6 +900,7 @@ int mac802154_process_association_req(struct ieee802154_sub_if_data *sdata,
unlock:
mutex_unlock(&wpan_dev->association_lock);
+ rtnl_unlock();
return ret;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net] mac802154: take RTNL around ASSOC RESP transmission
2026-11-21 15:08 [PATCH net] mac802154: take RTNL around ASSOC RESP transmission Lee Keon-Hyeong
@ 2026-11-24 18:48 ` Miquel Raynal
2026-11-25 22:35 ` 이건형
2026-11-25 15:08 ` netdev-bot+sashiko
1 sibling, 1 reply; 5+ messages in thread
From: Miquel Raynal @ 2026-11-24 18:48 UTC (permalink / raw)
To: Lee Keon-Hyeong; +Cc: alex.aring, stefan, linux-wpan, netdev
On 21/11/2026 at 15:08:43 GMT, Lee Keon-Hyeong <leegun25@proton.me> wrote:
> mac802154_process_association_req() runs from the rx_mac_cmd workqueue.
> The missing RTNL was identified during an LLM-assisted code audit of the
> mac802154 association handling path. The function builds the ASSOC RESP
> and sends it through
> mac802154_send_association_resp_locked() -> ieee802154_mlme_tx_locked(),
> which asserts the RTNL and calls ieee802154_sync_queue(). The worker does
> not hold the RTNL: this triggers an RTNL assertion failure whenever an
> ASSOC REQ reaches the response transmission path. With panic_on_warn=1 a
> single unauthenticated frame panics the kernel, even with
> max_associations=0 (a rejected request still sends a response).
>
> Take the RTNL before association_lock, matching the netlink lock order
> (RTNL then association_lock), and release it after the association lock on
> all exits.
>
> Reproduced with a monitor/coordinator pair on mac802154_hwsim; the same
> test is silent with this patch. On a CONFIG_PROVE_LOCKING kernel 86,891
> association requests were sent while the coordinator was brought down and
> up 1,200 times and recreated 71 times: no lockdep report, no hang and no
> warning, and the longest down transition took about 4 ms. The
> panic_on_warn run (22,941 requests, 300 down/up cycles) also completed.
> There is no in-tree selftest for this path; the checks above use a
> dedicated hwsim harness.
Ok, we can definitely align on the observation but the approach may not
stand.
First let's approach the numbers. 4ms is on a locally run simulator. You
are fixing a subsystem that plays with radios. A physical IEEE802154
radio would probably bring the usual bad case to > 100ms, and worth case
would be above the 1s boundary. So taking the RTNL lock as you do it
there would no longer warn in dev mode, but might lead to a DoS.
Reviewing your patch makes me realize we do something even worse: up to
10s waiting with the RTNL when waiting for an association response (for
which we are ouselves the initiator). That is slightly less a problem
since it is not remotely triggerable like the approach you propose, but
still.
I don't remember why we *had* to take the RTNL in the mlme_tx path.
Alex, maybe you remember why?
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] mac802154: take RTNL around ASSOC RESP transmission
2026-11-21 15:08 [PATCH net] mac802154: take RTNL around ASSOC RESP transmission Lee Keon-Hyeong
2026-11-24 18:48 ` Miquel Raynal
@ 2026-11-25 15:08 ` netdev-bot+sashiko
1 sibling, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 15:08 UTC (permalink / raw)
To: leegun25; +Cc: alex.aring, stefan, miquel.raynal, linux-wpan, netdev, kuba
Thank you for your contribution! Sashiko AI review found 3 potential
issue(s) to consider.
Critical: 0 · High: 3 · Medium: 0 (1) · Low: 0 (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 new rtnl_lock() in mac802154_process_association_req()
(net/mac802154/scan.c:833) makes the rx_mac_cmd worker wait on the…
- [High] A remote ASSOC REQ can still reach
WARN_ON_ONCE(!netif_running(sdata->dev)) in…
- [High] mac802154: RTNL self-deadlock on same-host association in
mac802154_process_association_req()
Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but in
mac802154_process_association_req() (net/mac802154/scan.c:891-899) the…
- [Low] This problem wasn't introduced by this patch, but
mac802154_process_association_req() checks wpan_dev->pan_id,…
--
mac802154: take RTNL around ASSOC RESP transmission
This commit makes mac802154_process_association_req() take the RTNL
before association_lock. The goal is to stop the ASSOC RESP sent from the
rx_mac_cmd worker through ieee802154_mlme_tx_locked() from tripping
ASSERT_RTNL(). The RTNL is released after association_lock on every exit.
> diff --git a/net/mac802154/scan.c b/net/mac802154/scan.c
> index d393b1f4e74e4..49bc5d29b4ee0 100644
> --- a/net/mac802154/scan.c
> +++ b/net/mac802154/scan.c
> @@ -826,6 +826,11 @@ int mac802154_process_association_req(struct ieee802154_sub_if_data *sdata,
> return -ENODEV;
> }
>
> + /* mac802154_send_association_resp_locked() uses the MLME TX helpers,
> + * which require the RTNL. Take it before association_lock to keep the
> + * same lock order as the netlink paths (RTNL then association_lock).
> + */
> + rtnl_lock();
> mutex_lock(&wpan_dev->association_lock);
[Severity: High]
Does this turn every same-host association into a 10 second stall
of the global RTNL?
NL802154_CMD_ASSOCIATE is registered with NL802154_FLAG_NEED_RTNL, so
nl802154_pre_doit() takes rtnl_lock() and holds it until
nl802154_post_doit(). In between, the call chain is:
nl802154_associate()
rdev_associate()
mac802154_associate()
mac802154_perform_association()
ieee802154_mlme_tx_one_locked() /* sends ASSOC REQ */
wait_for_completion_killable_timeout(&local->assoc_done,
10 * HZ);
The coordinator may be another interface on the same kernel, such as
a second mac802154_hwsim radio or a second local transceiver. In that
case its rx_mac_cmd worker now enters
mac802154_process_association_req() and blocks in rtnl_lock().
rtnl_mutex is global, so putting the two interfaces in different
network namespaces does not help. The ASSOC RESP cannot be sent until
the associating thread gives up:
1. The node thread holds the RTNL and sleeps on assoc_done.
2. The coordinator worker sleeps in rtnl_lock() for the full
10 * HZ.
3. mac802154_perform_association() returns -ETIMEDOUT and clears
IEEE802154_IS_ASSOCIATING. nl802154_post_doit() then drops the
RTNL.
4. The worker gets the RTNL, sends the late ASSOC RESP and adds the
node to wpan_dev->children. The node has already reported failure
and will drop the response.
So the association fails every time. For those 10 seconds every other
RTNL user on the system waits behind it, including link and address
changes and other rtnetlink requests. Before this patch the same
setup worked. ASSERT_RTNL() in ieee802154_mlme_tx_locked() only
checks rtnl_is_locked(), and the node thread was holding the RTNL.
The hwsim runs in the commit message use a monitor and a coordinator
and never issue the associate command. Lockdep does not track
completions either, so none of those runs would have shown this.
Is the RTNL really what the response TX needs here? Could the TX path
used from the rx_mac_cmd worker be protected by a narrower lock
instead? Or could mac802154_perform_association() avoid holding the
RTNL while it waits on assoc_done?
[Severity: High]
Can this rtnl_lock() stall a local associate request until it times out?
The netlink associate path holds the RTNL for the whole time it waits for
the ASSOC RESP. NL802154_CMD_ASSOCIATE has NL802154_FLAG_NEED_RTNL, so
pre_doit takes the RTNL, and then:
nl802154_associate()
mutex_lock(&wpan_dev->association_lock);
rdev_associate()
mac802154_associate() /* ASSERT_RTNL() */
mac802154_perform_association()
wait_for_completion_killable_timeout(&local->assoc_done, 10 * HZ);
Take two PHYs on the same host, for example the usual two-radio
mac802154_hwsim setup. There is a coordinator interface on phy0 and a
node on phy1 running associate:
1. The node's netlink thread holds the RTNL and waits on assoc_done.
2. phy0 receives the ASSOC REQ, and its rx_mac_cmd worker enters
mac802154_process_association_req().
3. With this patch the worker blocks in rtnl_lock() until the node's
10 second timeout expires.
4. The node returns -ETIMEDOUT and clears IEEE802154_IS_ASSOCIATING.
The ASSOC RESP that phy0 sends after that is dropped by the node's
rx path because mac802154_is_associating() is false.
5. If that TX was ACKed, the coordinator still adds the node to
wpan_dev->children, so the two sides disagree about the association.
Before this patch the cross-PHY case worked. ASSERT_RTNL() only checks
the global rtnl_is_locked(), and the node's netlink thread was holding the
RTNL. Each wpan_dev also has its own association_lock.
There is also a same-PHY variant that already existed. Each PHY has a
single-threaded mac_wq. If a coordinator with parent == NULL is itself
associating, an ASSOC REQ queued ahead of the parent's ASSOC RESP blocks
the worker that has to deliver that RESP. Before this patch it blocked on
association_lock. Now it blocks on the RTNL first.
This change also invalidates an assumption stated in commit 2f37fba846c9
("mac802154: fix use-after-free of sdata via queued RX frames"): "A worker
blocked in an association TX ... does not hold rtnl". The commit message
does not mention this.
The PROVE_LOCKING runs in the commit message would not catch this
problem. Lockdep does not model completions, and the tests described
never run the associate command.
[Severity: High]
Can a remote ASSOC REQ still reach the WARN_ON_ONCE() in
ieee802154_mlme_tx_locked() with this change?
The only running-state check is done without any lock held, in
mac802154_rx_mac_cmd_worker():
if (ieee802154_sdata_running(mac_pkt->sdata))
mac802154_rx_mac_cmd(local, mac_pkt);
Nothing checks it again after the RTNL is taken here. Here is a race with
"ip link set <coord> down":
1. dev_close() holds the RTNL and calls mac802154_slave_close().
2. mac802154_slave_close() decrements local->open_count and clears
SDATA_STATE_RUNNING.
3. A monitor interface may be up on the same PHY, which
ieee802154_check_concurrent_iface() allows. If so, open_count stays
non-zero.
4. The worker passed the check before ndo_stop ran. It sleeps in
rtnl_lock() until the close completes.
5. The worker then continues:
mac802154_send_association_resp_locked()
ieee802154_mlme_tx_locked()
if (!local->open_count) /* false, monitor still open */
return -ENETDOWN;
...
if (WARN_ON_ONCE(!netif_running(sdata->dev))) /* fires */
return -ENETDOWN;
With panic_on_warn=1 this is the same panic the commit message says it
removes.
Before this patch the window was a short lockless race. Now any worker
that is waiting for the RTNL while ndo_stop runs will see the closed
state. The rx_mac_cmd_list is also not flushed on close.
Would it make sense to check ieee802154_sdata_running(sdata) and
netif_running(sdata->dev) again after rtnl_lock(), and return -ENETDOWN
if either is false?
[Severity: Low]
This isn't a bug introduced by this patch, but the checks at the top of
mac802154_process_association_req() run before rtnl_lock() and
association_lock are taken. They read wpan_dev->pan_id, extended_addr,
short_addr and parent, for example:
if (wpan_dev->parent) {
dev_dbg(&sdata->dev->dev,
"Ignoring ASSOC REQ, not the PAN coordinator\n");
return -ENODEV;
}
The writers hold those locks:
mac802154_associate() {
...
wpan_dev->pan_id = coord->pan_id;
wpan_dev->short_addr = short_addr;
wpan_dev->parent = parent;
...
}
On the same PHY, this sequence is possible:
1. The worker handles the parent's ASSOC RESP and completes assoc_done.
2. The worker picks up a later ASSOC REQ, reads parent == NULL and
blocks on rtnl_lock().
3. mac802154_associate() sets wpan_dev->parent and drops the locks.
4. The worker accepts and records a child as if it were still the PAN
coordinator. It may also answer a request addressed to the old
pan_id.
The same window existed before through association_lock. Should these
checks be done after the locks are taken?
>
> memcpy(&assoc_req_pl, skb->data, sizeof(assoc_req_pl));
[ ... ]
> @@ -895,6 +900,7 @@ int mac802154_process_association_req(struct ieee802154_sub_if_data *sdata,
>
> unlock:
> mutex_unlock(&wpan_dev->association_lock);
> + rtnl_unlock();
> return ret;
> }
[Severity: Medium]
This is a pre-existing issue, but does the duplicate-child handling just
above the unlock label leak exchild?
exchild = cfg802154_device_is_child(wpan_dev, &tmp);
if (exchild) {
dev_dbg(&sdata->dev->dev,
"Child %8phC was already known\n", &ceaddr);
list_del(&exchild->node);
}
list_add(&child->node, &wpan_dev->children);
wpan_dev->nchildren++;
With alloc_addr == 0, the lookup finds the old entry. It is unlinked but
never freed, and nchildren is still incremented. The count then overstates
the list by one per re-association.
With alloc_addr == 1, which Linux nodes always set, tmp.mode is
IEEE802154_SHORT_ADDRESSING. cfg802154_pan_device_is_matching() always
rejects that mode:
if (ext_dev->mode == IEEE802154_ADDR_SHORT)
return false;
So duplicates pile up on wpan_dev->children and nchildren keeps growing.
The other removal paths pair list_del() with kfree() and adjust
nchildren:
mac802154_process_disassociation_notif()
mac802154_disassociate_child()
cfg802154_free_peer_structures()
Repeated re-associations from one peer can push nchildren toward
max_associations. That leads to spurious IEEE802154_PAN_AT_CAPACITY
refusals.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121150835.256812-1-leegun25%40proton.me
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] mac802154: take RTNL around ASSOC RESP transmission
2026-11-24 18:48 ` Miquel Raynal
@ 2026-11-25 22:35 ` 이건형
2026-11-26 11:05 ` Miquel Raynal
0 siblings, 1 reply; 5+ messages in thread
From: 이건형 @ 2026-11-25 22:35 UTC (permalink / raw)
To: Miquel Raynal; +Cc: alex.aring, stefan, linux-wpan, netdev
Hi Miquèl,
On Wednesday, November 25th, 2026 at 03:48, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
> First let's approach the numbers. 4ms is on a locally run simulator. You
> are fixing a subsystem that plays with radios. A physical IEEE802154
> radio would probably bring the usual bad case to > 100ms, and worth case
> would be above the 1s boundary. So taking the RTNL lock as you do it
> there would no longer warn in dev mode, but might lead to a DoS.
Thanks for pointing this out. I also found that taking the RTNL in
the association response worker causes association between two PHYs
on the same host to time out in hwsim.
> Reviewing your patch makes me realize we do something even worse: up to
> 10s waiting with the RTNL when waiting for an association response (for
> which we are ouselves the initiator). That is slightly less a problem
> since it is not remotely triggerable like the approach you propose, but
> still.
>
> I don't remember why we *had* to take the RTNL in the mlme_tx path.
>
> Alex, maybe you remember why?
Commit ddd9ee7cda12 added the RTNL to prevent ndo_stop() from running
during MLME TX.
I also found your 2022 device_lock proposal:
https://lore.kernel.org/netdev/20220826144049.256134-11-miquel.raynal@bootlin.com/
I tried adding a per-PHY mutex shared by MLME TX, ndo_open() and
ndo_stop(). With this change, the association response worker uses
the new mutex without taking the RTNL. The existing MLME TX wrappers
retain their RTNL requirements.
In mac802154_hwsim, association between two PHYs on the same host
works, and I saw no warnings or hangs during 5,000 association
requests and 100 interface down/up cycles.
With an artificial TX delay of 1 second, bringing the interface
down still takes about 900 ms. ndo_stop() can still wait for an
in-flight association response TX while holding the RTNL.
As Alex pointed out in the 2022 discussion, page/channel changes
also need to be considered. These are not covered by the new mutex.
Would this be a reasonable direction for the fix? If so, I can send
a v2.
Thanks,
Lee Keon-Hyeong
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net] mac802154: take RTNL around ASSOC RESP transmission
2026-11-25 22:35 ` 이건형
@ 2026-11-26 11:05 ` Miquel Raynal
0 siblings, 0 replies; 5+ messages in thread
From: Miquel Raynal @ 2026-11-26 11:05 UTC (permalink / raw)
To: 이건형; +Cc: alex.aring, stefan, linux-wpan, netdev
On 25/11/2026 at 22:35:11 GMT, 이건형 <leegun25@proton.me> wrote:
> Hi Miquèl,
>
> On Wednesday, November 25th, 2026 at 03:48, Miquel Raynal <miquel.raynal@bootlin.com> wrote:
>
>> First let's approach the numbers. 4ms is on a locally run simulator. You
>> are fixing a subsystem that plays with radios. A physical IEEE802154
>> radio would probably bring the usual bad case to > 100ms, and worth case
>> would be above the 1s boundary. So taking the RTNL lock as you do it
>> there would no longer warn in dev mode, but might lead to a DoS.
>
> Thanks for pointing this out. I also found that taking the RTNL in
> the association response worker causes association between two PHYs
> on the same host to time out in hwsim.
>
>> Reviewing your patch makes me realize we do something even worse: up to
>> 10s waiting with the RTNL when waiting for an association response (for
>> which we are ouselves the initiator). That is slightly less a problem
>> since it is not remotely triggerable like the approach you propose, but
>> still.
>>
>> I don't remember why we *had* to take the RTNL in the mlme_tx path.
>>
>> Alex, maybe you remember why?
>
> Commit ddd9ee7cda12 added the RTNL to prevent ndo_stop() from running
> during MLME TX.
>
> I also found your 2022 device_lock proposal:
>
> https://lore.kernel.org/netdev/20220826144049.256134-11-miquel.raynal@bootlin.com/
>
> I tried adding a per-PHY mutex shared by MLME TX, ndo_open() and
> ndo_stop(). With this change, the association response worker uses
> the new mutex without taking the RTNL. The existing MLME TX wrappers
> retain their RTNL requirements.
>
> In mac802154_hwsim, association between two PHYs on the same host
> works, and I saw no warnings or hangs during 5,000 association
> requests and 100 interface down/up cycles.
>
> With an artificial TX delay of 1 second, bringing the interface
> down still takes about 900 ms. ndo_stop() can still wait for an
> in-flight association response TX while holding the RTNL.
>
> As Alex pointed out in the 2022 discussion, page/channel changes
> also need to be considered. These are not covered by the new mutex.
>
> Would this be a reasonable direction for the fix? If so, I can send
> a v2.
Yes please, let's see what it would look like.
Thanks,
Miquèl
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-26 11:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 15:08 [PATCH net] mac802154: take RTNL around ASSOC RESP transmission Lee Keon-Hyeong
2026-11-24 18:48 ` Miquel Raynal
2026-11-25 22:35 ` 이건형
2026-11-26 11:05 ` Miquel Raynal
2026-11-25 15:08 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox