Linux IEEE 802.15.4 and 6LoWPAN development
 help / color / mirror / Atom feed
* [PATCH net] mac802154: take RTNL around ASSOC RESP transmission
@ 2026-11-21 15:08 Lee Keon-Hyeong
  2026-11-24 18:48 ` Miquel Raynal
  0 siblings, 1 reply; 2+ 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] 2+ 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
  0 siblings, 0 replies; 2+ 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] 2+ messages in thread

end of thread, other threads:[~2026-11-24 18:48 UTC | newest]

Thread overview: 2+ 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox