Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: leegun25@proton.me
Cc: alex.aring@gmail.com, stefan@datenfreihafen.org,
	miquel.raynal@bootlin.com, linux-wpan@vger.kernel.org,
	netdev@vger.kernel.org, kuba@kernel.org
Subject: Re: [PATCH net] mac802154: fix duplicate association handling
Date: Wed, 25 Nov 2026 13:39:43 +0000	[thread overview]
Message-ID: <179561398358.3135.3017322314045036906@kernel.org> (raw)
In-Reply-To: <20261121133101.240921-1-leegun25@proton.me>

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

      parent reply	other threads:[~2026-11-25 13:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 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=179561398358.3135.3017322314045036906@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alex.aring@gmail.com \
    --cc=kuba@kernel.org \
    --cc=leegun25@proton.me \
    --cc=linux-wpan@vger.kernel.org \
    --cc=miquel.raynal@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --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