Linux-HyperV List
 help / color / mirror / Atom feed
From: Jean Delvare <jdelvare@suse.de>
To: Michael Schierl <schierlm@gmx.de>
Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
	Michael  Kelley <mhklinux@outlook.com>
Subject: [PATCH v2] firmware: dmi: Stop decoding on broken entry
Date: Thu, 18 Apr 2024 14:27:34 +0200	[thread overview]
Message-ID: <20240418142734.56e1db4b@endymion.delvare> (raw)

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>
Reported-by: Michael Schierl <schierlm@gmx.de>
Link: https://lore.kernel.org/linux-kernel/Zh2K3-HLXOesT_vZ@liuwe-devbox-debian-v2/T/
Tested-by: Michael Schierl <schierlm@gmx.de>
---
Changes since v1:
 * Also log the offset of the corrupted entry (suggested by Michael Kelley)

 drivers/firmware/dmi_scan.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

--- linux-6.8.orig/drivers/firmware/dmi_scan.c
+++ linux-6.8/drivers/firmware/dmi_scan.c
@@ -102,6 +102,17 @@ static void dmi_decode_table(u8 *buf,
 		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 %ld (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
 		 *  table in dmi_decode or dmi_string


-- 
Jean Delvare
SUSE L3 Support

             reply	other threads:[~2024-04-18 12:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-18 12:27 Jean Delvare [this message]
2024-04-18 13:56 ` [PATCH v2] firmware: dmi: Stop decoding on broken entry Michael Kelley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240418142734.56e1db4b@endymion.delvare \
    --to=jdelvare@suse.de \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhklinux@outlook.com \
    --cc=schierlm@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox