linux-stable/drivers/char/ipmi
Yi Yang 09cb2a71b2 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:43:00 +02:00
..
Kconfig ipmi: ASPEED_BT_IPMI_BMC: select REGMAP_MMIO instead of depending on it 2023-05-11 23:03:26 +09:00
Makefile ipmi:ipmb: Add initial support for IPMI over IPMB 2021-10-05 06:54:17 -05:00
bt-bmc.c ipmi: bt: Add ast2600 compatible string 2021-10-07 14:02:45 -05:00
ipmb_dev_int.c i2c: Make remove callback return void 2022-08-16 12:46:26 +02:00
ipmi_bt_sm.c ipmi: Clean up some printks 2020-09-15 09:57:45 -05:00
ipmi_devintf.c ipmi:devintf: Return a proper error when recv buffer too small 2021-10-05 06:54:16 -05:00
ipmi_dmi.c
ipmi_dmi.h
ipmi_ipmb.c ipmi: ipmb: Fix the MODULE_PARM_DESC associated to 'retry_time_ms' 2023-03-10 09:34:03 +01:00
ipmi_kcs_sm.c ipmi: Clean up some printks 2020-09-15 09:57:45 -05:00
ipmi_msghandler.c ipmi: fix use after free in _ipmi_destroy_user() 2023-01-07 11:11:52 +01:00
ipmi_plat_data.c ipmi: Handle device properties with software node API 2021-03-10 19:00:02 -06:00
ipmi_plat_data.h
ipmi_powernv.c
ipmi_poweroff.c ipmi: Add an intializer for ipmi_recv_msg struct 2022-05-12 10:00:03 -05:00
ipmi_si.h parisc: Make struct parisc_driver::remove() return void 2021-08-30 10:18:25 +02:00
ipmi_si_hardcode.c ipmi_si: Join string literals back 2021-04-02 12:53:42 -05:00
ipmi_si_hotmod.c ipmi_si: Join string literals back 2021-04-02 12:53:42 -05:00
ipmi_si_intf.c ipmi_si: fix a memleak in try_smi_init() 2023-09-13 09:43:00 +02:00
ipmi_si_mem_io.c
ipmi_si_parisc.c parisc: Make struct parisc_driver::remove() return void 2021-08-30 10:18:25 +02:00
ipmi_si_pci.c ipmi_si: Join string literals back 2021-04-02 12:53:42 -05:00
ipmi_si_platform.c parisc: Make struct parisc_driver::remove() return void 2021-08-30 10:18:25 +02:00
ipmi_si_port_io.c
ipmi_si_sm.h
ipmi_smic_sm.c ipmi: Clean up some printks 2020-09-15 09:57:45 -05:00
ipmi_ssif.c ipmi:ssif: Fix a memory leak when scanning for an adapter 2023-09-13 09:42:44 +02:00
ipmi_watchdog.c ipmi: Add an intializer for ipmi_recv_msg struct 2022-05-12 10:00:03 -05:00
kcs_bmc.c ipmi: kcs_bmc: Enable IBF on open 2021-06-21 19:50:28 -05:00
kcs_bmc.h ipmi: kcs_bmc: Allow clients to control KCS IRQ state 2021-06-21 19:50:28 -05:00
kcs_bmc_aspeed.c ipmi: kcs: Poll OBF briefly to reduce OBE latency 2022-12-31 13:32:03 +01:00
kcs_bmc_cdev_ipmi.c ipmi: Add __init/__exit annotations to module init/exit funcs 2022-09-22 10:55:46 -05:00
kcs_bmc_client.h ipmi: kcs_bmc: Allow clients to control KCS IRQ state 2021-06-21 19:50:28 -05:00
kcs_bmc_device.h ipmi: kcs_bmc: Allow clients to control KCS IRQ state 2021-06-21 19:50:28 -05:00
kcs_bmc_npcm7xx.c ipmi: kcs_bmc: Enable IBF on open 2021-06-21 19:50:28 -05:00
kcs_bmc_serio.c ipmi: Add __init/__exit annotations to module init/exit funcs 2022-09-22 10:55:46 -05:00