linux/drivers/net/netdevsim
Wang Yufen 6d463ddd01 netdevsim: Fix memory leak of nsim_dev->fa_cookie
[ Upstream commit 064bc7312b ]

kmemleak reports this issue:

unreferenced object 0xffff8881bac872d0 (size 8):
  comm "sh", pid 58603, jiffies 4481524462 (age 68.065s)
  hex dump (first 8 bytes):
    04 00 00 00 de ad be ef                          ........
  backtrace:
    [<00000000c80b8577>] __kmalloc+0x49/0x150
    [<000000005292b8c6>] nsim_dev_trap_fa_cookie_write+0xc1/0x210 [netdevsim]
    [<0000000093d78e77>] full_proxy_write+0xf3/0x180
    [<000000005a662c16>] vfs_write+0x1c5/0xaf0
    [<000000007aabf84a>] ksys_write+0xed/0x1c0
    [<000000005f1d2e47>] do_syscall_64+0x3b/0x90
    [<000000006001c6ec>] entry_SYSCALL_64_after_hwframe+0x63/0xcd

The issue occurs in the following scenarios:

nsim_dev_trap_fa_cookie_write()
  kmalloc() fa_cookie
  nsim_dev->fa_cookie = fa_cookie
..
nsim_drv_remove()

The fa_cookie allocked in nsim_dev_trap_fa_cookie_write() is not freed. To
fix, add kfree(nsim_dev->fa_cookie) to nsim_drv_remove().

Fixes: d3cbb907ae ("netdevsim: add ACL trap reporting cookie as a metadata")
Signed-off-by: Wang Yufen <wangyufen@huawei.com>
Cc: Jiri Pirko <jiri@mellanox.com>
Link: https://lore.kernel.org/r/1668504625-14698-1-git-send-email-wangyufen@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
[ The context change is due to the commit 5e388f3dc3
("netdevsim: move vfconfig to nsim_dev") in v5.16
which is irrelevant to the logic of this patch. ]
Signed-off-by: Johnny Hao <johnny_haocn@sina.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-06-01 17:35:08 +02:00
..
bpf.c netdevsim: Avoid allocation warnings triggered from user space 2022-08-17 14:23:36 +02:00
bus.c Driver core update for 5.15-rc1 2021-09-01 08:44:42 -07:00
dev.c netdevsim: Fix memory leak of nsim_dev->fa_cookie 2026-06-01 17:35:08 +02:00
ethtool.c netdevsim: don't overwrite read only ethtool parms 2021-12-22 09:32:40 +01:00
fib.c netdevsim: Add trailing zero to terminate the string in nsim_nexthop_bucket_activity_write() 2024-11-08 16:25:53 +01:00
health.c netdevsim: prevent bad user input in nsim_dev_health_break_write() 2025-01-09 13:28:31 +01:00
ipsec.c netdevsim: print human readable IP address 2025-03-13 12:50:46 +01:00
Makefile netdevsim: Add dummy psample implementation 2021-03-14 15:00:43 -07:00
netdev.c net: Use u64_stats_fetch_begin_irq() for stats fetch. 2022-09-08 12:28:07 +02:00
netdevsim.h net: netdevsim: try to close UDP port harness races 2025-03-13 12:50:12 +01:00
psample.c netdevsim: Only use sampling truncation length when valid 2021-04-22 13:23:56 -07:00
udp_tunnels.c net: netdevsim: try to close UDP port harness races 2025-03-13 12:50:12 +01:00