git: f6cbd6b6d2cc - main - smbios: Apply the v2.1's length fixup only on a 32-bit entry point

From: Olivier Certner <olce_at_FreeBSD.org>
Date: Fri, 07 Mar 2025 16:44:41 UTC
The branch main has been updated by olce:

URL: https://cgit.FreeBSD.org/src/commit/?id=f6cbd6b6d2ccd672e4807128ce0d07db333d4335

commit f6cbd6b6d2ccd672e4807128ce0d07db333d4335
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2025-03-03 09:16:14 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-03-07 16:42:46 +0000

    smbios: Apply the v2.1's length fixup only on a 32-bit entry point
    
    Only allow the length tolerance (0x1e instead of 0x1f) for a 32-bit
    entry point, as there was no 64-bit entry point in the erroneous SMBIOS
    v2.1 standard and assigning the length with 0x1f does not make sense in
    this case.
    
    While here, fix accessing the major/minor versions via 'eps' even in the
    64-bit entry point case (not causing any practical problem thus far as
    the entry point length is greater than any SMBIOS revisions in
    existence, so the comparison guarding the fixup would not pass).
    
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
---
 sys/dev/smbios/smbios.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/sys/dev/smbios/smbios.c b/sys/dev/smbios/smbios.c
index 9e942335e985..733384b3614e 100644
--- a/sys/dev/smbios/smbios.c
+++ b/sys/dev/smbios/smbios.c
@@ -141,14 +141,13 @@ smbios_identify (driver_t *driver, device_t parent)
 		}
 	}
 	if (length != map_size) {
-		u_int8_t major, minor;
-
-		major = eps->major_version;
-		minor = eps->minor_version;
-
-		/* SMBIOS v2.1 implementation might use 0x1e. */
-		if (length == 0x1e && major == 2 && minor == 1)
-			length = 0x1f;
+		/*
+		 * SMBIOS v2.1 implementations might use 0x1e because the
+		 * standard was then erroneous.
+		 */
+		if (length == 0x1e && map_size == sizeof(*eps) &&
+		    eps->major_version == 2 && eps->minor_version == 1)
+			length = map_size;
 		else
 			goto unmap_return;
 	}