Re: [PATCH net v3] mac802154: validate pinned interface before beacon transmission

From: Miquel Raynal

Date: Mon Nov 16 2026 - 11:09:46 EST


Hi,

> Changes in v3:
> - revalidate the request and pinned interface under RTNL
> - serialize beacon template access with request replacement
> - free the skb on every failure before the transmit-path handoff

I think on this point we should have something a bit unified with the
scan worker, because both handle similar situations. This is worth
fixing in another patch.

> --- a/net/mac802154/scan.c
> +++ b/net/mac802154/scan.c
> @@ -354,35 +354,31 @@ static int mac802154_transmit_beacon(struct ieee802154_local *local,
> struct wpan_dev *wpan_dev)
> {

...

> + rtnl_lock();
> + beacon_req = rtnl_dereference(local->beacon_req);
> + if (unlikely(!beacon_req || beacon_req->wpan_dev != wpan_dev ||
> + !ieee802154_sdata_running(sdata) ||
> + !netif_running(sdata->dev))) {
> + ret = -ECANCELED;

Since this is not an error, the caller should maybe not amit a log at
the error level. Again, not worth a change in this patch, but would be a
good follow-up.

> + goto out_free;
> }
>
> - sdata = IEEE802154_WPAN_DEV_TO_SUB_IF(beacon_req->wpan_dev);
> + /* Update the sequence number */
> + local->beacon.mhr.seq = atomic_inc_return(&wpan_dev->bsn) & 0xFF;
> skb->dev = sdata->dev;
>
> - rcu_read_unlock();
> -
> ret = ieee802154_beacon_push(skb, &local->beacon);
> - if (ret) {
> - kfree_skb(skb);
> - return ret;
> - }
> + if (ret)
> + goto out_free;
>
> /* Using the MLME transmission helper for sending beacons is a bit
> * overkill because we do not really care about the final outcome.
> @@ -402,7 +398,16 @@ static int mac802154_transmit_beacon(struct ieee802154_local *local,
> * transmissions, wich anyway does not have a huge impact on the
> * performances given the current design of the stack.
> */
> - return ieee802154_mlme_tx(local, sdata, skb);
> + ret = ieee802154_mlme_tx_locked(local, sdata, skb);
> + rtnl_unlock();
> +
> + return ret;
> +
> +out_free:
> + rtnl_unlock();
> + kfree_skb(skb);
> +
> + return ret;
> }
>
> void mac802154_beacon_worker(struct work_struct *work)

Again, not related to this patch, but existing issue: since you are
fixing the beacon path that is very close to the scan path that has
already been fixed, there may be a missing cancel_delayed_work_sync() in
mac802154_stop_beacons_locked() (the timer may still be pending when the
PHY is freed).

So for me the patch is correct, but follow-ups are needed.

Reviewed-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx>

Thanks,
Miquèl