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 --- 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