OSDN Git Service

firmware: qemu_fw_cfg: fix sysfs information leak
authorJohan Hovold <johan@kernel.org>
Wed, 1 Dec 2021 13:25:27 +0000 (14:25 +0100)
committerMichael S. Tsirkin <mst@redhat.com>
Fri, 14 Jan 2022 23:50:52 +0000 (18:50 -0500)
Make sure to always NUL-terminate file names retrieved from the firmware
to avoid accessing data beyond the entry slab buffer and exposing it
through sysfs in case the firmware data is corrupt.

Fixes: 75f3e8e47f38 ("firmware: introduce sysfs driver for QEMU's fw_cfg device")
Cc: stable@vger.kernel.org # 4.6
Cc: Gabriel Somlo <somlo@cmu.edu>
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20211201132528.30025-4-johan@kernel.org
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/firmware/qemu_fw_cfg.c

index ccb7ed6..f08e056 100644 (file)
@@ -598,7 +598,7 @@ static int fw_cfg_register_file(const struct fw_cfg_file *f)
        /* set file entry information */
        entry->size = be32_to_cpu(f->size);
        entry->select = be16_to_cpu(f->select);
-       memcpy(entry->name, f->name, FW_CFG_MAX_FILE_PATH);
+       strscpy(entry->name, f->name, FW_CFG_MAX_FILE_PATH);
 
        /* register entry under "/sys/firmware/qemu_fw_cfg/by_key/" */
        err = kobject_init_and_add(&entry->kobj, &fw_cfg_sysfs_entry_ktype,