Netdev List
 help / color / mirror / Atom feed
* [PATCH net v2 1/2] mac802154: free a replaced child
@ 2026-11-24  8:59 Lee Keon-Hyeong
  2026-11-24  8:59 ` [PATCH net v2 2/2] mac802154: look up children by extended address Lee Keon-Hyeong
  2026-11-25 13:47 ` [PATCH net v2 1/2] mac802154: free a replaced child Miquel Raynal
  0 siblings, 2 replies; 4+ messages in thread
From: Lee Keon-Hyeong @ 2026-11-24  8:59 UTC (permalink / raw)
  To: alex.aring, stefan, miquel.raynal; +Cc: linux-wpan, netdev

When an associated child retransmits an ASSOC REQ, the coordinator
removes the old entry from the list but never frees it.  It also
increments wpan_dev->nchildren even though the number of children
has not changed.

Free the old entry and increment nchildren only when adding a new child.

With alloc_addr=0 the lookup in cfg802154_device_is_child() matches:
300 retransmissions from one peer leak 300 kmalloc-32 objects and make
the association table look full.

I found this during an LLM-assisted code review and reproduced it with
mac802154_hwsim.

After 501 retransmissions, the kmalloc-32 object count stayed at 840
with the series applied.  On the unpatched kernel it rose from 780 to
1260.  Kernel selftests were not run.

Fixes: 601f160b61b2 ("mac802154: Handle association requests from peers")
Signed-off-by: Lee Keon-Hyeong <leegun25@proton.me>
---
v2: Drop the added comment and move the lookup fix to patch 2/2.
v1: https://lore.kernel.org/r/20261121133101.240921-1-leegun25@proton.me

 net/mac802154/scan.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/mac802154/scan.c b/net/mac802154/scan.c
index d393b1f4e74e..943641702646 100644
--- a/net/mac802154/scan.c
+++ b/net/mac802154/scan.c
@@ -888,10 +888,12 @@ int mac802154_process_association_req(struct ieee802154_sub_if_data *sdata,
 		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.56.0



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

* [PATCH net v2 2/2] mac802154: look up children by extended address
  2026-11-24  8:59 [PATCH net v2 1/2] mac802154: free a replaced child Lee Keon-Hyeong
@ 2026-11-24  8:59 ` Lee Keon-Hyeong
  2026-11-25 13:45   ` Miquel Raynal
  2026-11-25 13:47 ` [PATCH net v2 1/2] mac802154: free a replaced child Miquel Raynal
  1 sibling, 1 reply; 4+ messages in thread
From: Lee Keon-Hyeong @ 2026-11-24  8:59 UTC (permalink / raw)
  To: alex.aring, stefan, miquel.raynal; +Cc: linux-wpan, netdev

The source address of an ASSOC REQ is always an extended address, but
mac802154_process_association_req() builds the lookup key with the
address mode chosen for the new child.  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.  Every retransmission
is then appended as a new child, consuming an association slot and a
short address.

Look up the existing child by its extended address.

With max_associations=2, two association requests from the same peer
exhaust all available slots and prevent another peer from associating.

I found this during an LLM-assisted code review and reproduced it with
mac802154_hwsim.

In a separate mac802154_hwsim test, 64 requests from the same peer
left 64 child entries on the unpatched kernel.  With both patches
applied, the same test left one entry.  Kernel selftests were not run.

Fixes: 601f160b61b2 ("mac802154: Handle association requests from peers")
Signed-off-by: Lee Keon-Hyeong <leegun25@proton.me>
---
v2: Drop the added comment and move the lookup fix to patch 2/2.
v1: https://lore.kernel.org/r/20261121133101.240921-1-leegun25@proton.me

 net/mac802154/scan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/mac802154/scan.c b/net/mac802154/scan.c
index 943641702646..6158ef41c0e0 100644
--- a/net/mac802154/scan.c
+++ b/net/mac802154/scan.c
@@ -881,7 +881,7 @@ int mac802154_process_association_req(struct ieee802154_sub_if_data *sdata,
 	/* Ensure this child is not already associated (might happen due to
 	 * retransmissions), in this case drop the ex structure.
 	 */
-	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) {
-- 
2.56.0



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

* Re: [PATCH net v2 2/2] mac802154: look up children by extended address
  2026-11-24  8:59 ` [PATCH net v2 2/2] mac802154: look up children by extended address Lee Keon-Hyeong
@ 2026-11-25 13:45   ` Miquel Raynal
  0 siblings, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2026-11-25 13:45 UTC (permalink / raw)
  To: Lee Keon-Hyeong; +Cc: alex.aring, stefan, linux-wpan, netdev

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

> The source address of an ASSOC REQ is always an extended address, but
> mac802154_process_association_req() builds the lookup key with the
> address mode chosen for the new child.  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.  Every retransmission
> is then appended as a new child, consuming an association slot and a
> short address.
>
> Look up the existing child by its extended address.
>
> With max_associations=2, two association requests from the same peer
> exhaust all available slots and prevent another peer from associating.
>
> I found this during an LLM-assisted code review and reproduced it with
> mac802154_hwsim.
>
> In a separate mac802154_hwsim test, 64 requests from the same peer
> left 64 child entries on the unpatched kernel.  With both patches
> applied, the same test left one entry.  Kernel selftests were not run.
>
> Fixes: 601f160b61b2 ("mac802154: Handle association requests from peers")
> Signed-off-by: Lee Keon-Hyeong <leegun25@proton.me>

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

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

* Re: [PATCH net v2 1/2] mac802154: free a replaced child
  2026-11-24  8:59 [PATCH net v2 1/2] mac802154: free a replaced child Lee Keon-Hyeong
  2026-11-24  8:59 ` [PATCH net v2 2/2] mac802154: look up children by extended address Lee Keon-Hyeong
@ 2026-11-25 13:47 ` Miquel Raynal
  1 sibling, 0 replies; 4+ messages in thread
From: Miquel Raynal @ 2026-11-25 13:47 UTC (permalink / raw)
  To: Lee Keon-Hyeong; +Cc: alex.aring, stefan, linux-wpan, netdev

On 24/11/2026 at 08:59:12 GMT, Lee Keon-Hyeong <leegun25@proton.me> wrote:

> When an associated child retransmits an ASSOC REQ, the coordinator
> removes the old entry from the list but never frees it.  It also
> increments wpan_dev->nchildren even though the number of children
> has not changed.
>
> Free the old entry and increment nchildren only when adding a new child.
>
> With alloc_addr=0 the lookup in cfg802154_device_is_child() matches:
> 300 retransmissions from one peer leak 300 kmalloc-32 objects and make
> the association table look full.
>
> I found this during an LLM-assisted code review and reproduced it with
> mac802154_hwsim.
>
> After 501 retransmissions, the kmalloc-32 object count stayed at 840
> with the series applied.  On the unpatched kernel it rose from 780 to
> 1260.  Kernel selftests were not run.
>
> Fixes: 601f160b61b2 ("mac802154: Handle association requests from peers")
> Signed-off-by: Lee Keon-Hyeong <leegun25@proton.me>

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

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

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

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24  8:59 [PATCH net v2 1/2] mac802154: free a replaced child Lee Keon-Hyeong
2026-11-24  8:59 ` [PATCH net v2 2/2] mac802154: look up children by extended address Lee Keon-Hyeong
2026-11-25 13:45   ` Miquel Raynal
2026-11-25 13:47 ` [PATCH net v2 1/2] mac802154: free a replaced child Miquel Raynal

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