hwmon: (ibmpex) Fix possible UAF when ibmpex_register_bmc() fails
authorGaosheng Cui <cuigaosheng1@huawei.com>
Thu, 17 Nov 2022 03:44:23 +0000 (11:44 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 8 Dec 2022 10:16:31 +0000 (11:16 +0100)
commit798198273bf86673b970b51acdb35e57f42b3fcb
tree8888837d2375ce3020685e00500b28b4495c3ad5
parent216b9aaf5d33b927e36a4e376b7e18d3532c20ec
hwmon: (ibmpex) Fix possible UAF when ibmpex_register_bmc() fails

[ Upstream commit e2a87785aab0dac190ac89be6a9ba955e2c634f2 ]

Smatch report warning as follows:

drivers/hwmon/ibmpex.c:509 ibmpex_register_bmc() warn:
  '&data->list' not removed from list

If ibmpex_find_sensors() fails in ibmpex_register_bmc(), data will
be freed, but data->list will not be removed from driver_data.bmc_data,
then list traversal may cause UAF.

Fix by removeing it from driver_data.bmc_data before free().

Fixes: 57c7c3a0fdea ("hwmon: IBM power meter driver")
Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
Link: https://lore.kernel.org/r/20221117034423.2935739-1-cuigaosheng1@huawei.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hwmon/ibmpex.c