mac802154: free a replaced child
Subsystems (3)
PATCH v2 1/2 mac802154: free a replaced child
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.
---
v2: Drop the added comment and move the lookup fix to patch 2/2.
v1: https://lore.kernel.org/r/[email protected]
net/mac802154/scan.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/mac802154/scan.c +3 -1
@@ -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);
Signature · 1 line
2.56.0
PATCH v2 2/2 mac802154: look up children by extended address
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.
---
v2: Drop the added comment and move the lookup fix to patch 2/2.
v1: https://lore.kernel.org/r/[email protected]
net/mac802154/scan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac802154/scan.c +1 -1
@@ -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) {
Signature · 1 line
2.56.0
Re: [PATCH net v2 2/2] mac802154: look up children by extended address
Quoted 16 lines · Lee Keon-Hyeong
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, andcfg802154_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.
Quoted 6 lines
In a separate
mac802154_hwsimtest, 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 <[email protected]>
Quoted 14 lines · Lee Keon-Hyeong
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->nchildreneven 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.
Quoted 6 lines
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 <[email protected]>
Hello Lee Keon-Hyeong.
Quoted 8 lines · Lee Keon-Hyeong
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->nchildreneven though the number of children has not changed.Free the old entry and increment nchildren only when adding a new child.
[...]
Applied to wpan/wpan.git, thanks!
[1/2] mac802154: free a replaced child
https://git.kernel.org/wpan/wpan/c/4022afee3116 [2/2] mac802154: look up children by extended address https://git.kernel.org/wpan/wpan/c/b6148aaa5eb5
regards,
Stefan Schmidt