summaryrefslogtreecommitdiff
path: root/debian/patches/0125-use_read_file_to_read_DMI_table_from_sysfs.patch
blob: fe01f639ef15cab79e5fc3ba8c1cd69ffbf55d41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
From 364055211b1956539c6a6268e111e244e1292c8c Mon Sep 17 00:00:00 2001
From: Jean Delvare <jdelvare@suse.de>
Date: Mon, 02 Nov 2015 08:45:31 +0000
Subject: dmidecode: Use read_file() to read the DMI table from sysfs

We shouldn't use mem_chunk() to read the DMI table from sysfs. This
will fail for SMBIOS v3 implementations which specify a maximum length
for the table rather than its exact length. The kernel will trim the
table to the actual length, so the DMI file will be shorter than the
length announced in entry point.

read_file() fits the bill in this case, as it deals with end of file
nicely.

This also helps with corrupted DMI tables, as the kernel will not
export the part of the table that it wasn't able to parse, effectively
trimming it.

This fixes bug #46176:
https://savannah.nongnu.org/bugs/?46176
Unexpected end of file error
---
Index: trunk/CHANGELOG
===================================================================
--- trunk.orig/CHANGELOG
+++ trunk/CHANGELOG
@@ -2,6 +2,9 @@
 
 	* dmidecode.c, util.c, util.h: Let read_file return the actual data
 	  size.
+	* dmidecode.c: Use read_file to read the DMI table from sysfs.
+	  This fixes Savannah bug #46176:
+	  https://savannah.nongnu.org/bugs/?46176
 
 2015-10-21  Xie XiuQi  <xiexiuqi@huawei.com>
 
Index: trunk/dmidecode.c
===================================================================
--- trunk.orig/dmidecode.c
+++ trunk/dmidecode.c
@@ -4521,16 +4521,29 @@ static void dmi_table(off_t base, u32 le
 		printf("\n");
 	}
 
-	/*
-	 * When we are reading the DMI table from sysfs, we want to print
-	 * the address of the table (done above), but the offset of the
-	 * data in the file is 0.  When reading from /dev/mem, the offset
-	 * in the file is the address.
-	 */
 	if (flags & FLAG_NO_FILE_OFFSET)
-		base = 0;
+	{
+		/*
+		 * When reading from sysfs, the file may be shorter than
+		 * announced. For SMBIOS v3 this is expcted, as we only know
+		 * the maximum table size, not the actual table size. For older
+		 * implementations (and for SMBIOS v3 too), this would be the
+		 * result of the kernel truncating the table on parse error.
+		 */
+		size_t size = len;
+		buf = read_file(&size, devmem);
+		if (!(opt.flags & FLAG_QUIET) && num && size != (size_t)len)
+		{
+			printf("Wrong DMI structures length: %u bytes "
+				"announced, only %lu bytes available.\n",
+				len, (unsigned long)size);
+		}
+		len = size;
+	}
+	else
+		buf = mem_chunk(base, len, devmem);
 
-	if ((buf = mem_chunk(base, len, devmem)) == NULL)
+	if (buf == NULL)
 	{
 		fprintf(stderr, "Table is unreachable, sorry."
 #ifndef USE_MMAP