CVE-2025-37786

Severity CVSS v4.0:
Pending analysis
Type:
CWE-416 Use After Free
Publication date:
01/05/2025
Last modified:
17/03/2026

Description

In the Linux kernel, the following vulnerability has been resolved:<br /> <br /> net: dsa: free routing table on probe failure<br /> <br /> If complete = true in dsa_tree_setup(), it means that we are the last<br /> switch of the tree which is successfully probing, and we should be<br /> setting up all switches from our probe path.<br /> <br /> After "complete" becomes true, dsa_tree_setup_cpu_ports() or any<br /> subsequent function may fail. If that happens, the entire tree setup is<br /> in limbo: the first N-1 switches have successfully finished probing<br /> (doing nothing but having allocated persistent memory in the tree&amp;#39;s<br /> dst-&gt;ports, and maybe dst-&gt;rtable), and switch N failed to probe, ending<br /> the tree setup process before anything is tangible from the user&amp;#39;s PoV.<br /> <br /> If switch N fails to probe, its memory (ports) will be freed and removed<br /> from dst-&gt;ports. However, the dst-&gt;rtable elements pointing to its ports,<br /> as created by dsa_link_touch(), will remain there, and will lead to<br /> use-after-free if dereferenced.<br /> <br /> If dsa_tree_setup_switches() returns -EPROBE_DEFER, which is entirely<br /> possible because that is where ds-&gt;ops-&gt;setup() is, we get a kasan<br /> report like this:<br /> <br /> ==================================================================<br /> BUG: KASAN: slab-use-after-free in mv88e6xxx_setup_upstream_port+0x240/0x568<br /> Read of size 8 at addr ffff000004f56020 by task kworker/u8:3/42<br /> <br /> Call trace:<br /> __asan_report_load8_noabort+0x20/0x30<br /> mv88e6xxx_setup_upstream_port+0x240/0x568<br /> mv88e6xxx_setup+0xebc/0x1eb0<br /> dsa_register_switch+0x1af4/0x2ae0<br /> mv88e6xxx_register_switch+0x1b8/0x2a8<br /> mv88e6xxx_probe+0xc4c/0xf60<br /> mdio_probe+0x78/0xb8<br /> really_probe+0x2b8/0x5a8<br /> __driver_probe_device+0x164/0x298<br /> driver_probe_device+0x78/0x258<br /> __device_attach_driver+0x274/0x350<br /> <br /> Allocated by task 42:<br /> __kasan_kmalloc+0x84/0xa0<br /> __kmalloc_cache_noprof+0x298/0x490<br /> dsa_switch_touch_ports+0x174/0x3d8<br /> dsa_register_switch+0x800/0x2ae0<br /> mv88e6xxx_register_switch+0x1b8/0x2a8<br /> mv88e6xxx_probe+0xc4c/0xf60<br /> mdio_probe+0x78/0xb8<br /> really_probe+0x2b8/0x5a8<br /> __driver_probe_device+0x164/0x298<br /> driver_probe_device+0x78/0x258<br /> __device_attach_driver+0x274/0x350<br /> <br /> Freed by task 42:<br /> __kasan_slab_free+0x48/0x68<br /> kfree+0x138/0x418<br /> dsa_register_switch+0x2694/0x2ae0<br /> mv88e6xxx_register_switch+0x1b8/0x2a8<br /> mv88e6xxx_probe+0xc4c/0xf60<br /> mdio_probe+0x78/0xb8<br /> really_probe+0x2b8/0x5a8<br /> __driver_probe_device+0x164/0x298<br /> driver_probe_device+0x78/0x258<br /> __device_attach_driver+0x274/0x350<br /> <br /> The simplest way to fix the bug is to delete the routing table in its<br /> entirety. dsa_tree_setup_routing_table() has no problem in regenerating<br /> it even if we deleted links between ports other than those of switch N,<br /> because dsa_link_touch() first checks whether the port pair already<br /> exists in dst-&gt;rtable, allocating if not.<br /> <br /> The deletion of the routing table in its entirety already exists in<br /> dsa_tree_teardown(), so refactor that into a function that can also be<br /> called from the tree setup error path.<br /> <br /> In my analysis of the commit to blame, it is the one which added<br /> dsa_link elements to dst-&gt;rtable. Prior to that, each switch had its own<br /> ds-&gt;rtable which is freed when the switch fails to probe. But the tree<br /> is potentially persistent memory.

Vulnerable products and versions

CPE From Up to
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* 5.5 (including) 6.6.88 (excluding)
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* 6.7 (including) 6.12.25 (excluding)
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:* 6.13 (including) 6.14.4 (excluding)
cpe:2.3:o:linux:linux_kernel:6.15:rc1:*:*:*:*:*:*
cpe:2.3:o:linux:linux_kernel:6.15:rc2:*:*:*:*:*:*