linux-stable/drivers/base/firmware_loader
Luis Chamberlain c37f9ee2bb firmware_loader: fix pre-allocated buf built-in firmware use
[ Upstream commit f7a07f7b96 ]

The firmware_loader can be used with a pre-allocated buffer
through the use of the API calls:

  o request_firmware_into_buf()
  o request_partial_firmware_into_buf()

If the firmware was built-in and present, our current check
for if the built-in firmware fits into the pre-allocated buffer
does not return any errors, and we proceed to tell the caller
that everything worked fine. It's a lie and no firmware would
end up being copied into the pre-allocated buffer. So if the
caller trust the result it may end up writing a bunch of 0's
to a device!

Fix this by making the function that checks for the pre-allocated
buffer return non-void. Since the typical use case is when no
pre-allocated buffer is provided make this return successfully
for that case. If the built-in firmware does *not* fit into the
pre-allocated buffer size return a failure as we should have
been doing before.

I'm not aware of users of the built-in firmware using the API
calls with a pre-allocated buffer, as such I doubt this fixes
any real life issue. But you never know... perhaps some oddball
private tree might use it.

In so far as upstream is concerned this just fixes our code for
correctness.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Link: https://lore.kernel.org/r/20210917182226.3532898-2-mcgrof@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-11-25 09:48:27 +01:00
..
builtin firmware_loader: remove unneeded 'comma' macro 2021-06-04 15:06:03 +02:00
fallback.c firmware_loader: fix use-after-free in firmware_fallback_sysfs 2021-07-29 17:22:15 +02:00
fallback.h firmware: Store opt_flags in fw_priv 2020-10-05 13:37:04 +02: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
firmware.h firmware_loader: fix use-after-free in firmware_fallback_sysfs 2021-07-29 17:22:15 +02:00
Kconfig drivers: base: Fix Kconfig indentation 2019-11-20 15:10:25 +01:00
main.c firmware_loader: fix pre-allocated buf built-in firmware use 2021-11-25 09:48:27 +01:00
Makefile firmware: Add new platform fallback mechanism and firmware_request_platform() 2020-03-20 14:54:04 +01:00