All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] firmware: dmi: Stop decoding on broken entry
@ 2024-04-18 12:27 Jean Delvare
  2024-04-18 13:56 ` Michael Kelley
  0 siblings, 1 reply; 2+ messages in thread
From: Jean Delvare @ 2024-04-18 12:27 UTC (permalink / raw)
  To: Michael Schierl; +Cc: linux-hyperv, linux-kernel, Michael Kelley

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: [PATCH v2] firmware: dmi: Stop decoding on broken entry
  2024-04-18 12:27 [PATCH v2] firmware: dmi: Stop decoding on broken entry Jean Delvare
@ 2024-04-18 13:56 ` Michael Kelley
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Kelley @ 2024-04-18 13:56 UTC (permalink / raw)
  To: Jean Delvare, Michael Schierl; +Cc: linux-hyperv, linux-kernel

From: Jean Delvare <jdelvare@suse.de> Sent: Thursday, April 18, 2024 5:28 AM
> 
> 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
> 

Reviewed-by: Michael Kelley <mhklinux@outlook.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-18 13:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-18 12:27 [PATCH v2] firmware: dmi: Stop decoding on broken entry Jean Delvare
2024-04-18 13:56 ` Michael Kelley

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.