linux_dsm_epyc7002/drivers/base/firmware_loader
Zhen Lei 80b0967597 firmware: fix theoretical UAF race with firmware cache and resume
[ Upstream commit 3ecc8cb7c092b2f50e21d2aaaae35b8221ee7214 ]

This race was discovered when I carefully analyzed the code to locate
another firmware-related UAF issue. It can be triggered only when the
firmware load operation is executed during suspend. This possibility is
almost impossible because there are few firmware load and suspend actions
in the actual environment.

		CPU0			CPU1
__device_uncache_fw_images():		assign_fw():
					fw_cache_piggyback_on_request()
					<----- P0
	spin_lock(&fwc->name_lock);
	...
	list_del(&fce->list);
	spin_unlock(&fwc->name_lock);

	uncache_firmware(fce->name);
					<----- P1
					kref_get(&fw_priv->ref);

If CPU1 is interrupted at position P0, the new 'fce' has been added to the
list fwc->fw_names by the fw_cache_piggyback_on_request(). In this case,
CPU0 executes __device_uncache_fw_images() and will be able to see it when
it traverses list fwc->fw_names. Before CPU1 executes kref_get() at P1, if
CPU0 further executes uncache_firmware(), the count of fw_priv->ref may
decrease to 0, causing fw_priv to be released in advance.

Move kref_get() to the lock protection range of fwc->name_lock to fix it.

Fixes: ac39b3ea73 ("firmware loader: let caching firmware piggyback on loading firmware")
Acked-by: Luis Chamberlain <mcgrof@kernel.org>
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Link: https://lore.kernel.org/r/20210719064531.3733-2-thunder.leizhen@huawei.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-07-05 19:10:52 +02:00
..
builtin Fix built-in early-load Intel microcode alignment 2020-01-15 11:50:37 -08:00
fallback_platform.c firmware: Store opt_flags in fw_priv 2020-10-05 13:37:04 +02:00
fallback_table.c firmware_loader: move fw_fallback_config to a private kernel symbol namespace 2020-04-28 21:05:42 +02:00
fallback.c firmware_loader: fix use-after-free in firmware_fallback_sysfs 2024-07-05 18:52:10 +02:00
fallback.h firmware: Store opt_flags in fw_priv 2020-10-05 13:37:04 +02:00
firmware.h firmware_loader: fix use-after-free in firmware_fallback_sysfs 2024-07-05 18:52:10 +02:00
Kconfig drivers: base: Fix Kconfig indentation 2019-11-20 15:10:25 +01:00
main.c firmware: fix theoretical UAF race with firmware cache and resume 2024-07-05 19:10:52 +02:00
Makefile firmware: Add new platform fallback mechanism and firmware_request_platform() 2020-03-20 14:54:04 +01:00