linux-stable/drivers/char
Yi Yang 1bfcfea0fa ipmi_si: fix a memleak in try_smi_init()
commit 6cf1a126de upstream.

Kmemleak reported the following leak info in try_smi_init():

unreferenced object 0xffff00018ecf9400 (size 1024):
  comm "modprobe", pid 2707763, jiffies 4300851415 (age 773.308s)
  backtrace:
    [<000000004ca5b312>] __kmalloc+0x4b8/0x7b0
    [<00000000953b1072>] try_smi_init+0x148/0x5dc [ipmi_si]
    [<000000006460d325>] 0xffff800081b10148
    [<0000000039206ea5>] do_one_initcall+0x64/0x2a4
    [<00000000601399ce>] do_init_module+0x50/0x300
    [<000000003c12ba3c>] load_module+0x7a8/0x9e0
    [<00000000c246fffe>] __se_sys_init_module+0x104/0x180
    [<00000000eea99093>] __arm64_sys_init_module+0x24/0x30
    [<0000000021b1ef87>] el0_svc_common.constprop.0+0x94/0x250
    [<0000000070f4f8b7>] do_el0_svc+0x48/0xe0
    [<000000005a05337f>] el0_svc+0x24/0x3c
    [<000000005eb248d6>] el0_sync_handler+0x160/0x164
    [<0000000030a59039>] el0_sync+0x160/0x180

The problem was that when an error occurred before handlers registration
and after allocating `new_smi->si_sm`, the variable wouldn't be freed in
the error handling afterwards since `shutdown_smi()` hadn't been
registered yet. Fix it by adding a `kfree()` in the error handling path
in `try_smi_init()`.

Cc: stable@vger.kernel.org # 4.19+
Fixes: 7960f18a56 ("ipmi_si: Convert over to a shutdown handler")
Signed-off-by: Yi Yang <yiyang13@huawei.com>
Co-developed-by: GONG, Ruiqi <gongruiqi@huaweicloud.com>
Signed-off-by: GONG, Ruiqi <gongruiqi@huaweicloud.com>
Message-Id: <20230629123328.2402075-1-gongruiqi@huaweicloud.com>
Signed-off-by: Corey Minyard <minyard@acm.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-09-13 09:48:38 +02:00
..
agp parisc: Flush gatt writes and adjust gatt mask in parisc_agp_mask_memory() 2023-05-22 18:30:52 +02:00
hw_random hwrng: iproc-rng200 - Implement suspend and resume calls 2023-09-13 09:48:05 +02:00
ipmi ipmi_si: fix a memleak in try_smi_init() 2023-09-13 09:48:38 +02:00
mwave
tpm tpm: Enable hwrng only for Pluton on AMD CPUs 2023-09-13 09:47:56 +02:00
xilinx_hwicap driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
xillybus driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
Kconfig char: pcmcia: remove all the drivers 2023-03-09 17:30:27 +01:00
Makefile char: pcmcia: remove all the drivers 2023-03-09 17:30:27 +01:00
adi.c
apm-emulation.c
applicom.c applicom: Fix PCI device refcount leak in applicom_init() 2023-01-20 13:05:39 +01:00
applicom.h
bsr.c driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
ds1620.c
dsp56k.c driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
dtlk.c
hangcheck-timer.c
hpet.c
lp.c driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
mem.c driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
misc.c driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
mspec.c mm: replace vma->vm_flags direct modifications with modifier calls 2023-02-09 16:51:39 -08:00
nsc_gpio.c
nvram.c
nwbutton.c
nwbutton.h
nwflash.c
pc8736x_gpio.c
powernv-op-panel.c
ppdev.c driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
ps3flash.c
random.c cpumask: fix incorrect cpumask scanning result checks 2023-03-06 12:15:13 -08:00
scx200_gpio.c
sonypi.c ACPI: make remove callback of ACPI driver void 2022-11-23 19:11:22 +01:00
tlclk.c
toshiba.c
ttyprintk.c
uv_mmtimer.c
virtio_console.c driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00