Netdev List
 help / color / mirror / Atom feed
* [PATCH net] mac802154: fix duplicate association handling
@ 2026-11-21 13:31 Lee Keon-Hyeong
  2026-11-21 13:31 ` netdev-bot+sinfo
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Lee Keon-Hyeong @ 2026-11-21 13:31 UTC (permalink / raw)
  To: alex.aring, stefan, miquel.raynal; +Cc: linux-wpan, netdev

A retransmitted ASSOC REQ from an already known child is supposed to
replace the old entry, but the lookup uses the new child's address mode.
With alloc_addr=1 the new child has short-address mode and
cfg802154_pan_device_is_matching() rejects short-mode queries, so the
lookup never matches and every retransmission is appended as a new child,
consuming an association slot and a short address.  With alloc_addr=0 the
lookup matches, but the old entry is only list_del()'d without kfree(),
leaking a kmalloc-32 object per retransmission, and nchildren is
incremented again for the replacement.

The ASSOC REQ source is always an extended address.  Look the existing
child up by its extended address regardless of the short-address mode
chosen for the new entry, free the replaced child, and count only
genuinely new children.

With max_associations=2, two association requests from the same peer
exhaust all available slots and prevent another peer from associating.
With alloc_addr=0, 300 repeated requests leak 300 kmalloc-32 objects and
inflate nchildren; a subsequent disassociation leaves the counter
inflated, and an interface down/up does not reset it.  Both behaviours
were reproduced with a monitor/coordinator pair on mac802154_hwsim and
are gone after this patch.

Fixes: 601f160b61b2 ("mac802154: Handle association requests from peers")
Signed-off-by: Lee Keon-Hyeong <leegun25@proton.me>
---
 net/mac802154/scan.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/net/mac802154/scan.c b/net/mac802154/scan.c
index d393b1f4e..ebef22e7e 100644
--- a/net/mac802154/scan.c
+++ b/net/mac802154/scan.c
@@ -879,19 +879,23 @@ int mac802154_process_association_req(struct ieee802154_sub_if_data *sdata,
 		"Successful association with new child %8phC\n", &ceaddr);
 
 	/* Ensure this child is not already associated (might happen due to
-	 * retransmissions), in this case drop the ex structure.
+	 * retransmissions), in this case replace the ex structure.  The ASSOC
+	 * REQ source is always an extended address, so look the child up by it
+	 * regardless of the short address mode chosen for the new entry.
 	 */
-	tmp.mode = child->mode;
+	tmp.mode = IEEE802154_EXTENDED_ADDRESSING;
 	tmp.extended_addr = child->extended_addr;
 	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);
+		kfree(exchild);
+	} else {
+		wpan_dev->nchildren++;
 	}
 
 	list_add(&child->node, &wpan_dev->children);
-	wpan_dev->nchildren++;
 
 unlock:
 	mutex_unlock(&wpan_dev->association_lock);
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH net] mac802154: fix duplicate association handling
  2026-11-21 13:31 [PATCH net] mac802154: fix duplicate association handling Lee Keon-Hyeong
@ 2026-11-21 13:31 ` netdev-bot+sinfo
  2026-11-21 14:00   ` 이건형
  2026-11-23  8:48 ` Miquel Raynal
  2026-11-25 13:39 ` netdev-bot+sashiko
  2 siblings, 1 reply; 5+ messages in thread
From: netdev-bot+sinfo @ 2026-11-21 13:31 UTC (permalink / raw)
  To: Lee Keon-Hyeong; +Cc: alex.aring, stefan, miquel.raynal, linux-wpan, netdev

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] mac802154: fix duplicate association handling
  2026-11-21 13:31 ` netdev-bot+sinfo
@ 2026-11-21 14:00   ` 이건형
  0 siblings, 0 replies; 5+ messages in thread
From: 이건형 @ 2026-11-21 14:00 UTC (permalink / raw)
  To: netdev-bot+sinfo; +Cc: alex.aring, stefan, miquel.raynal, linux-wpan, netdev

Hi,

The issue was identified during an LLM-assisted code audit of the mac802154 association handling path. I focused on this path because unauthenticated ASSOC REQs can affect the coordinator's association state.

The audit revealed an incorrect address mode used for duplicate-child lookup, a missing kfree(), and an incorrect nchildren increment.

I set up a simulated IEEE 802.15.4 environment using mac802154_hwsim and wrote a reproducer that sends repeated ASSOC REQs. The unpatched kernel exhibited association slot exhaustion and memory leaks, while neither issue was reproduced after applying the patch.

Best regards,
Lee Keon-Hyeong

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] mac802154: fix duplicate association handling
  2026-11-21 13:31 [PATCH net] mac802154: fix duplicate association handling Lee Keon-Hyeong
  2026-11-21 13:31 ` netdev-bot+sinfo
@ 2026-11-23  8:48 ` Miquel Raynal
  2026-11-25 13:39 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: Miquel Raynal @ 2026-11-23  8:48 UTC (permalink / raw)
  To: Lee Keon-Hyeong; +Cc: alex.aring, stefan, linux-wpan, netdev

Hi Lee,

On 21/11/2026 at 13:31:08 GMT, Lee Keon-Hyeong <leegun25@proton.me> wrote:

> A retransmitted ASSOC REQ from an already known child is supposed to
> replace the old entry, but the lookup uses the new child's address mode.
> With alloc_addr=1 the new child has short-address mode and
> cfg802154_pan_device_is_matching() rejects short-mode queries, so the
> lookup never matches and every retransmission is appended as a new child,
> consuming an association slot and a short address.  With alloc_addr=0 the
> lookup matches, but the old entry is only list_del()'d without kfree(),
> leaking a kmalloc-32 object per retransmission, and nchildren is
> incremented again for the replacement.
>
> The ASSOC REQ source is always an extended address.  Look the existing
> child up by its extended address regardless of the short-address mode
> chosen for the new entry, free the replaced child, and count only
> genuinely new children.
>
> With max_associations=2, two association requests from the same peer
> exhaust all available slots and prevent another peer from associating.
> With alloc_addr=0, 300 repeated requests leak 300 kmalloc-32 objects and
> inflate nchildren; a subsequent disassociation leaves the counter
> inflated, and an interface down/up does not reset it.  Both behaviours
> were reproduced with a monitor/coordinator pair on mac802154_hwsim and
> are gone after this patch.
>
> Fixes: 601f160b61b2 ("mac802154: Handle association requests from peers")
> Signed-off-by: Lee Keon-Hyeong <leegun25@proton.me>
> ---
>  net/mac802154/scan.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/net/mac802154/scan.c b/net/mac802154/scan.c
> index d393b1f4e..ebef22e7e 100644
> --- a/net/mac802154/scan.c
> +++ b/net/mac802154/scan.c
> @@ -879,19 +879,23 @@ int mac802154_process_association_req(struct ieee802154_sub_if_data *sdata,
>  		"Successful association with new child %8phC\n", &ceaddr);
>  
>  	/* Ensure this child is not already associated (might happen due to
> -	 * retransmissions), in this case drop the ex structure.
> +	 * retransmissions), in this case replace the ex structure.  The ASSOC
> +	 * REQ source is always an extended address, so look the child up by it
> +	 * regardless of the short address mode chosen for the new
>  	entry.

Did you read back this comment and thought it was in any way useful?
Please drop.

>  	 */
> -	tmp.mode = child->mode;
> +	tmp.mode = IEEE802154_EXTENDED_ADDRESSING;

This is probably fine but an orthogonal change, so a separate patch, no?

>  	tmp.extended_addr = child->extended_addr;
>  	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);
> +		kfree(exchild);
> +	} else {
> +		wpan_dev->nchildren++;
>  	}
>  
>  	list_add(&child->node, &wpan_dev->children);
> -	wpan_dev->nchildren++;
>  
>  unlock:
>  	mutex_unlock(&wpan_dev->association_lock);

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH net] mac802154: fix duplicate association handling
  2026-11-21 13:31 [PATCH net] mac802154: fix duplicate association handling Lee Keon-Hyeong
  2026-11-21 13:31 ` netdev-bot+sinfo
  2026-11-23  8:48 ` Miquel Raynal
@ 2026-11-25 13:39 ` netdev-bot+sashiko
  2 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-11-25 13:39 UTC (permalink / raw)
  To: leegun25; +Cc: alex.aring, stefan, miquel.raynal, linux-wpan, netdev, kuba

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

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

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] In mac802154_process_association_req() (net/mac802154/scan.c),
  the duplicate lookup only runs after the capacity gate at line 848.
- [Medium] mac802154_process_association_req() (net/mac802154/scan.c)
  draws a fresh random short address for every accepted REQ…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
  cfg802154_get_free_short_addr() (net/ieee802154/pan.c:86-88) does not…

--

mac802154: fix duplicate association handling

This commit changes mac802154_process_association_req() to look up an
already known child by its extended address, whatever short address mode
was chosen for the new entry. It also frees the replaced child entry.
nchildren is now incremented only for children that were not already in
the list.

> diff --git a/net/mac802154/scan.c b/net/mac802154/scan.c
> index d393b1f4e74e4..ebef22e7e8857 100644
> --- a/net/mac802154/scan.c
> +++ b/net/mac802154/scan.c
> @@ -879,19 +879,23 @@ int mac802154_process_association_req(struct ieee802154_sub_if_data *sdata,
>  		"Successful association with new child %8phC\n", &ceaddr);
>  
>  	/* Ensure this child is not already associated (might happen due to
> -	 * retransmissions), in this case drop the ex structure.
> +	 * retransmissions), in this case replace the ex structure.  The ASSOC
> +	 * REQ source is always an extended address, so look the child up by it
> +	 * regardless of the short address mode chosen for the new entry.
>  	 */
> -	tmp.mode = child->mode;
> +	tmp.mode = IEEE802154_EXTENDED_ADDRESSING;
>  	tmp.extended_addr = child->extended_addr;
>  	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);
> +		kfree(exchild);

[Severity: Medium]

With alloc_addr=1, a new short address is picked and sent in the
association response before this lookup runs:

		if (assoc_req_pl.alloc_addr) {
			assoc_resp_pl.short_addr = cfg802154_get_free_short_addr(wpan_dev);
			child->mode = IEEE802154_SHORT_ADDRESSING;

In the retransmission case named in the comment, the requester keeps
address A from the first response.
mac802154_process_association_resp() clears IEEE802154_IS_ASSOCIATING on
the first matching response and returns -ENODEV for any later ones.

Here the old entry holding A is freed and only the new entry, with address
B, is kept. Won't the coordinator then reach this child at a short address
it doesn't use? For example, mac802154_send_disassociation_notif() does:

	frame.mhr.dest.short_addr = target->short_addr;

Address A is then also treated as free for the next allocation.

Before this patch, the newest entry B was already at the head of the list
and lookups returned it first, so the mismatch is not entirely new.
Now that the patch replaces the entry on retransmissions, should it reuse
exchild->short_addr (or do the lookup before allocating)? That would avoid
handing out a new address the peer will ignore. The commit message doesn't
mention this behaviour.

> +	} else {
> +		wpan_dev->nchildren++;
>  	}

[Severity: High]

Does this count only genuinely new children while there is still room in
the table? The duplicate lookup runs only after the capacity check earlier
in mac802154_process_association_req():

	if (wpan_dev->nchildren >= wpan_dev->max_associations) {
		...
			assoc_resp_pl.status = IEEE802154_PAN_AT_CAPACITY;
		...
	}
	...
	ret = mac802154_send_association_resp_locked(sdata, child, &assoc_resp_pl);
	if (ret || assoc_resp_pl.status != IEEE802154_ASSOCIATION_SUCCESSFUL) {
		kfree(child);
		goto unlock;
	}

Suppose nchildren == max_associations and a request arrives from a child
that is already in wpan_dev->children. The request gets
IEEE802154_PAN_AT_CAPACITY, and the replace logic is never reached. The
stale entry keeps its slot, but the peer is told it is not associated.

This can happen with max_associations=2, the setup used in the commit
message, if the peer lost its state. It can also happen after
mac802154_disassociate_from_parent() runs on the peer: the peer frees its
parent even when the disassociation notification was not acked, so the
coordinator still holds the child.

For a plain MAC retransmission the refusal does no harm, because
mac802154_process_association_resp() drops later responses once
IEEE802154_IS_ASSOCIATING is cleared.

Would it make sense to do the extended address lookup before the capacity
check, and skip the check for a known child? Then these statements from
the commit message would also hold when the table is full:

  "A retransmitted ASSOC REQ from an already known child is supposed to
  replace the old entry"

  "count only genuinely new children"

>  
>  	list_add(&child->node, &wpan_dev->children);
> -	wpan_dev->nchildren++;

[Severity: High]

This isn't a bug introduced by this patch, but the replace logic relies on
cfg802154_get_free_short_addr() returning unused addresses. It does not
appear to reject addresses already used by children. In
net/ieee802154/pan.c:

	do {
		get_random_bytes(&addr, 2);
		...
		list_for_each_entry(child, &wpan_dev->children, node)
			if (child->short_addr == addr)
				continue;

		break;
	} while (1);

Since list_for_each_entry() is a for loop, the continue only advances the
list walk and does not restart the do/while loop. When the walk finishes,
the break runs and the colliding address is returned.

The kernel-doc in include/net/cfg802154.h promises "a random short address
expectedly unused on our PAN". mac802154_process_association_req() gives
this address to any remote peer that sets alloc_addr, so two children can
end up with the same short address.

max_associations defaults to SZ_16K and there are only 65534 usable
values, so collisions become likely after a few hundred associations.
Flooding the coordinator with unauthenticated association requests makes
them almost certain.

Should the child check use a flag or a goto, so that a collision restarts
the outer loop?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261121133101.240921-1-leegun25%40proton.me

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-25 13:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-21 13:31 [PATCH net] mac802154: fix duplicate association handling Lee Keon-Hyeong
2026-11-21 13:31 ` netdev-bot+sinfo
2026-11-21 14:00   ` 이건형
2026-11-23  8:48 ` Miquel Raynal
2026-11-25 13:39 ` 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