firmware: dmi: Stop decoding on broken entry
authorJean Delvare <jdelvare@suse.de>
Tue, 30 Apr 2024 16:29:32 +0000 (18:29 +0200)
committerJean Delvare <jdelvare@suse.de>
Tue, 30 Apr 2024 16:29:32 +0000 (18:29 +0200)
If a DMI table entry is shorter than 4 bytes, it is invalid. Due to
how DMI table parsing works, it is impossible to safely recover from
such an error, so we have to stop decoding the table.

Signed-off-by: Jean Delvare <jdelvare@suse.de>
Link: https://lore.kernel.org/linux-kernel/Zh2K3-HLXOesT_vZ@liuwe-devbox-debian-v2/T/
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
drivers/firmware/dmi_scan.c

index 015c95a825d315e02b586ece662d8c43cd484428..ac2a5d2d47463f121a4a13e2cc3b7894bce64d4c 100644 (file)
@@ -101,6 +101,17 @@ static void dmi_decode_table(u8 *buf,
               (data - buf + sizeof(struct dmi_header)) <= dmi_len) {
                const struct dmi_header *dm = (const struct dmi_header *)data;
 
+               /*
+                * If a short entry is found (less than 4 bytes), not only it
+                * is invalid, but we cannot reliably locate the next entry.
+                */
+               if (dm->length < sizeof(struct dmi_header)) {
+                       pr_warn(FW_BUG
+                               "Corrupted DMI table, offset %zd (only %d entries processed)\n",
+                               data - buf, i);
+                       break;
+               }
+
                /*
                 *  We want to know the total length (formatted area and
                 *  strings) before decoding to make sure we won't run off the