firmware: qemu_fw_cfg: reject overflowing file directories
Subsystems (2)
PATCH 1/1 firmware: qemu_fw_cfg: reject overflowing file directories
The fw_cfg file count is supplied by the VMM. On 32-bit systems, multiplying a large count by the directory entry size can wrap, resulting in a short allocation and an out-of-bounds walk of the directory.
Reject counts whose directory size cannot be represented by size_t before allocating or reading the directory.
Fixes 75f3e8e47f38 ("firmware: introduce sysfs driver for QEMU's fw_cfg device")
Signed-off-by Yousef Alhouseen <[email protected]>
--- drivers/firmware/qemu_fw_cfg.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/firmware/qemu_fw_cfg.c +3 -1
@@ -34,6 +34,7 @@#include <linux/slab.h> #include <linux/io.h> #include <linux/ioport.h> +#include <linux/overflow.h> #include <uapi/linux/qemu_fw_cfg.h> #include <linux/delay.h> #include <linux/crash_dump.h>
@@ -642,7 +643,8 @@ static int fw_cfg_register_dir_entries(void)return ret; count =be32_to_cpu (files_count); - dir_size = count *sizeof (struct fw_cfg_file ); +if (check_mul_overflow ((size_t )count,sizeof (*dir), &dir_size)) +return -EOVERFLOW ; dir =kmalloc (dir_size,GFP_KERNEL );if (!dir)
Signature · 1 line
2.54.0