]> git.ipfire.org Git - thirdparty/openwrt.git/commit
swconfig: fix portmap memory leak and hardening 24246/head
authorRosen Penev <rosenp@gmail.com>
Wed, 15 Jul 2026 22:58:06 +0000 (15:58 -0700)
committerJonas Jelonek <jelonek.jonas@gmail.com>
Tue, 21 Jul 2026 07:11:05 +0000 (09:11 +0200)
commit3978d4e5ee17e9ba0f2f6dd3fd8489a369fb4a14
treeb4a2896fd727cade15f839e880dcc2804312f399
parentce120be3619610a7457df2d5970a7701b150db51
swconfig: fix portmap memory leak and hardening

Free the per-port segment strings on unregister to avoid leaking them
across device rebind. Drop the dead (phys < 0) check and guard the
kstrdup allocation against failure.

Move swconfig_create_led_trigger() before list_add_tail() in
register_switch so a failing registration never publishes the device on
the global swdevs list with dangling portmap/portbuf pointers (a
use-after-free for any swdevs iterator). Route both the LED trigger
failure and the -ENFILE (swdev id exhaustion) failure paths through a
shared cleanup that frees portbuf, portmap, and the per-port segment
strings instead of leaking them.

Reorder the frees in unregister_switch to run after list_del so the
buffers are not freed while the device is still reachable from swdevs.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/24246
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
target/linux/generic/files/drivers/net/phy/swconfig.c