Package: dmidecode
Version: 3.0-2
Severity: normal
Tags: patch
User: ubuntu-de...@lists.ubuntu.com
Usertags: origin-ubuntu yakkety ubuntu-patch

Dear Maintainer,

The current dmidecode requires some upstream fixes to enable it
do decode SMBIOS 3.0 tables that are now appearing on the market.

This fix has been tested and fixes a SMBIOS 3.0 decode issue, and
I believe it is useful for Debian to pick up the changes that
I've applied to dmidecode in Ubuntu.

*** /tmp/tmpnZdydp/bug_body

In Ubuntu, the attached patch was applied to achieve the following:

  * Fix decoding of SMBIOS 3.0 tables (LP: #1578022)
    - Pull in upstream fixes to allow dmidecode to decode
      SMBIOS 3.0 tables, 4 upstream fixes:
      + Fix 'No SMBIOS nor DMI entry point found' on SMBIOS3
      + Let read_file return the actual data size of the entry point
      + Use read_file() to read the DMI table from sysfs
      + Use DWORD for Structure table maximum size in SMBIOS3


Thanks for considering the patch.

-- System Information:
Debian Release: stretch/sid
  APT prefers yakkety-proposed
  APT policy: (500, 'yakkety-proposed'), (500, 'yakkety')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.4.0-22-generic (SMP w/4 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
diff -Nru dmidecode-3.0/debian/patches/0001-dmidecode-Use-read_file-to-read-the-DMI-table-from-s.patch dmidecode-3.0/debian/patches/0001-dmidecode-Use-read_file-to-read-the-DMI-table-from-s.patch
--- dmidecode-3.0/debian/patches/0001-dmidecode-Use-read_file-to-read-the-DMI-table-from-s.patch	2016-05-13 13:32:16.000000000 +0100
+++ dmidecode-3.0/debian/patches/0001-dmidecode-Use-read_file-to-read-the-DMI-table-from-s.patch	1970-01-01 01:00:00.000000000 +0100
@@ -1,82 +0,0 @@
-From 364055211b1956539c6a6268e111e244e1292c8c Mon Sep 17 00:00:00 2001
-From: Jean Delvare <jdelv...@suse.de>
-Date: Mon, 2 Nov 2015 09:45:31 +0100
-Subject: [PATCH] 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
----
- CHANGELOG   |  3 +++
- dmidecode.c | 29 +++++++++++++++++++++--------
- 2 files changed, 24 insertions(+), 8 deletions(-)
-
-Index: dmidecode-3.0/CHANGELOG
-===================================================================
---- dmidecode-3.0.orig/CHANGELOG
-+++ dmidecode-3.0/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  <xiexi...@huawei.com>
- 
-Index: dmidecode-3.0/dmidecode.c
-===================================================================
---- dmidecode-3.0.orig/dmidecode.c
-+++ dmidecode-3.0/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
diff -Nru dmidecode-3.0/debian/patches/0001-Fix-No-SMBIOS-nor-DMI-entry-point-found-on-SMBIOS3.patch dmidecode-3.0/debian/patches/0001-Fix-No-SMBIOS-nor-DMI-entry-point-found-on-SMBIOS3.patch
--- dmidecode-3.0/debian/patches/0001-Fix-No-SMBIOS-nor-DMI-entry-point-found-on-SMBIOS3.patch	2016-05-13 13:27:11.000000000 +0100
+++ dmidecode-3.0/debian/patches/0001-Fix-No-SMBIOS-nor-DMI-entry-point-found-on-SMBIOS3.patch	1970-01-01 01:00:00.000000000 +0100
@@ -1,60 +0,0 @@
-From bf7bad24ce141dab5b5acc3ffb98ce5fe4a8e0f9 Mon Sep 17 00:00:00 2001
-From: Xie XiuQi <xiexi...@huawei.com>
-Date: Wed, 21 Oct 2015 15:12:50 +0200
-Subject: [PATCH] Fix 'No SMBIOS nor DMI entry point found' on SMBIOS3
-
-address_from_efi may return a SMBIOS or SMBIOS3 format entry
-point, so add this condition.
----
- AUTHORS     |  1 +
- CHANGELOG   |  4 ++++
- dmidecode.c | 12 ++++++++++--
- 3 files changed, 15 insertions(+), 2 deletions(-)
-
-Index: dmidecode-3.0/AUTHORS
-===================================================================
---- dmidecode-3.0.orig/AUTHORS
-+++ dmidecode-3.0/AUTHORS
-@@ -19,6 +19,7 @@ Jarod Wilson <ja...@redhat.com>
- Anton Arapov <an...@redhat.com>
- Roy Franz <roy.fr...@linaro.org>
- Tyler Bell <tyler.b...@hp.com>
-+Xie XiuQi <xiexi...@huawei.com>
- 
- MANY THANKS TO (IN CHRONOLOGICAL ORDER)
- Werner Heuser
-Index: dmidecode-3.0/CHANGELOG
-===================================================================
---- dmidecode-3.0.orig/CHANGELOG
-+++ dmidecode-3.0/CHANGELOG
-@@ -1,3 +1,7 @@
-+2015-10-21  Xie XiuQi  <xiexi...@huawei.com>
-+
-+	* dmidecode.c: Handle SMBIOS 3.0 entry points on EFI systems.
-+
- 2015-09-03  Jean Delvare  <jdelv...@suse.de>
- 
- 	* version.h: Set version to 3.0.
-Index: dmidecode-3.0/dmidecode.c
-===================================================================
---- dmidecode-3.0.orig/dmidecode.c
-+++ dmidecode-3.0/dmidecode.c
-@@ -4864,8 +4864,16 @@ int main(int argc, char * const argv[])
- 		goto exit_free;
- 	}
- 
--	if (smbios_decode(buf, opt.devmem, 0))
--		found++;
-+	if (memcmp(buf, "_SM3_", 5) == 0)
-+	{
-+		if (smbios3_decode(buf, opt.devmem, 0))
-+			found++;
-+	}
-+	else if (memcmp(buf, "_SM_", 4) == 0)
-+	{
-+		if (smbios_decode(buf, opt.devmem, 0))
-+			found++;
-+	}
- 	goto done;
- 
- memory_scan:
diff -Nru dmidecode-3.0/debian/patches/0001-Let-read_file-return-the-actual-data-size.patch dmidecode-3.0/debian/patches/0001-Let-read_file-return-the-actual-data-size.patch
--- dmidecode-3.0/debian/patches/0001-Let-read_file-return-the-actual-data-size.patch	2016-05-13 13:29:57.000000000 +0100
+++ dmidecode-3.0/debian/patches/0001-Let-read_file-return-the-actual-data-size.patch	1970-01-01 01:00:00.000000000 +0100
@@ -1,109 +0,0 @@
-From de9a74e1c60210bee229fcf55b1678a99d1b44dd Mon Sep 17 00:00:00 2001
-From: Jean Delvare <jdelv...@suse.de>
-Date: Mon, 2 Nov 2015 09:45:26 +0100
-Subject: [PATCH] Let read_file return the actual data size
-
-Let read_file return the actual data size to the caller. This gives
-the caller the possibility to check that the data size is as expected
-and large enough for the purpose, and report to the user if not.
----
- CHANGELOG   |  5 +++++
- dmidecode.c |  4 +++-
- util.c      | 11 +++++++----
- util.h      |  2 +-
- 4 files changed, 16 insertions(+), 6 deletions(-)
-
-Index: dmidecode-3.0/CHANGELOG
-===================================================================
---- dmidecode-3.0.orig/CHANGELOG
-+++ dmidecode-3.0/CHANGELOG
-@@ -1,3 +1,8 @@
-+2015-11-02  Jean Delvare  <jdelv...@suse.de>
-+
-+	* dmidecode.c, util.c, util.h: Let read_file return the actual data
-+	  size.
-+
- 2015-10-21  Xie XiuQi  <xiexi...@huawei.com>
- 
- 	* dmidecode.c: Handle SMBIOS 3.0 entry points on EFI systems.
-Index: dmidecode-3.0/dmidecode.c
-===================================================================
---- dmidecode-3.0.orig/dmidecode.c
-+++ dmidecode-3.0/dmidecode.c
-@@ -4748,6 +4748,7 @@ int main(int argc, char * const argv[])
- 	int ret = 0;                /* Returned value */
- 	int found = 0;
- 	off_t fp;
-+	size_t size;
- 	int efi;
- 	u8 *buf;
- 
-@@ -4817,8 +4818,9 @@ int main(int argc, char * const argv[])
- 	 * contain one of several types of entry points, so read enough for
- 	 * the largest one, then determine what type it contains.
- 	 */
-+	size = 0x20;
- 	if (!(opt.flags & FLAG_NO_SYSFS)
--	 && (buf = read_file(0x20, SYS_ENTRY_FILE)) != NULL)
-+	 && (buf = read_file(&size, SYS_ENTRY_FILE)) != NULL)
- 	{
- 		if (!(opt.flags & FLAG_QUIET))
- 			printf("Getting SMBIOS data from sysfs.\n");
-Index: dmidecode-3.0/util.c
-===================================================================
---- dmidecode-3.0.orig/util.c
-+++ dmidecode-3.0/util.c
-@@ -94,10 +94,11 @@ int checksum(const u8 *buf, size_t len)
-  * needs to be freed by the caller.
-  * This provides a similar usage model to mem_chunk()
-  *
-- * Returns pointer to buffer of max_len bytes, or NULL on error
-+ * Returns pointer to buffer of max_len bytes, or NULL on error, and
-+ * sets max_len to the length actually read.
-  *
-  */
--void *read_file(size_t max_len, const char *filename)
-+void *read_file(size_t *max_len, const char *filename)
- {
- 	int fd;
- 	size_t r2 = 0;
-@@ -115,7 +116,7 @@ void *read_file(size_t max_len, const ch
- 		return(NULL);
- 	}
- 
--	if ((p = malloc(max_len)) == NULL)
-+	if ((p = malloc(*max_len)) == NULL)
- 	{
- 		perror("malloc");
- 		return NULL;
-@@ -123,7 +124,7 @@ void *read_file(size_t max_len, const ch
- 
- 	do
- 	{
--		r = read(fd, p + r2, max_len - r2);
-+		r = read(fd, p + r2, *max_len - r2);
- 		if (r == -1)
- 		{
- 			if (errno != EINTR)
-@@ -140,6 +141,8 @@ void *read_file(size_t max_len, const ch
- 	while (r != 0);
- 
- 	close(fd);
-+	*max_len = r2;
-+
- 	return p;
- }
- 
-Index: dmidecode-3.0/util.h
-===================================================================
---- dmidecode-3.0.orig/util.h
-+++ dmidecode-3.0/util.h
-@@ -25,7 +25,7 @@
- #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
- 
- int checksum(const u8 *buf, size_t len);
--void *read_file(size_t len, const char *filename);
-+void *read_file(size_t *len, const char *filename);
- void *mem_chunk(off_t base, size_t len, const char *devmem);
- int write_dump(size_t base, size_t len, const void *data, const char *dumpfile, int add);
- u64 u64_range(u64 start, u64 end);
diff -Nru dmidecode-3.0/debian/patches/0001-Use-DWORD-for-Structure-table-maximum-size-in-SMBIOS.patch dmidecode-3.0/debian/patches/0001-Use-DWORD-for-Structure-table-maximum-size-in-SMBIOS.patch
--- dmidecode-3.0/debian/patches/0001-Use-DWORD-for-Structure-table-maximum-size-in-SMBIOS.patch	2016-05-13 13:33:06.000000000 +0100
+++ dmidecode-3.0/debian/patches/0001-Use-DWORD-for-Structure-table-maximum-size-in-SMBIOS.patch	1970-01-01 01:00:00.000000000 +0100
@@ -1,30 +0,0 @@
-From ab02b117511230e46bbef7febbd854b9c832c13c Mon Sep 17 00:00:00 2001
-From: Xie XiuQi <xiexi...@huawei.com>
-Date: Mon, 1 Feb 2016 09:30:31 +0100
-Subject: [PATCH] Use DWORD for Structure table maximum size in SMBIOS3
-
-0Ch DWORD "Structure table maximum size"
-
-Maximum size of SMBIOS Structure Table, pointed to by
-the Structure Table Address, in bytes. The actual size is
-guaranteed to be less or equal to the maximum size.
-
-Signed-off-by: Xie XiuQi <xiexi...@huawei.com>
-Signed-off-by: Jean Delvare <jdelv...@suse.de>
----
- dmidecode.c | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-Index: dmidecode-3.0/dmidecode.c
-===================================================================
---- dmidecode-3.0.orig/dmidecode.c
-+++ dmidecode-3.0/dmidecode.c
-@@ -4612,7 +4612,7 @@ static int smbios3_decode(u8 *buf, const
- 	}
- 
- 	dmi_table(((off_t)offset.h << 32) | offset.l,
--		  WORD(buf + 0x0C), 0, ver, devmem, flags | FLAG_STOP_AT_EOT);
-+		  DWORD(buf + 0x0C), 0, ver, devmem, flags | FLAG_STOP_AT_EOT);
- 
- 	if (opt.flags & FLAG_DUMP_BIN)
- 	{
diff -Nru dmidecode-3.0/debian/patches/10-Fix-No-SMBIOS-nor-DMI-entry-point-found-on-SMBIOS3.patch dmidecode-3.0/debian/patches/10-Fix-No-SMBIOS-nor-DMI-entry-point-found-on-SMBIOS3.patch
--- dmidecode-3.0/debian/patches/10-Fix-No-SMBIOS-nor-DMI-entry-point-found-on-SMBIOS3.patch	1970-01-01 01:00:00.000000000 +0100
+++ dmidecode-3.0/debian/patches/10-Fix-No-SMBIOS-nor-DMI-entry-point-found-on-SMBIOS3.patch	2016-05-13 13:27:11.000000000 +0100
@@ -0,0 +1,60 @@
+From bf7bad24ce141dab5b5acc3ffb98ce5fe4a8e0f9 Mon Sep 17 00:00:00 2001
+From: Xie XiuQi <xiexi...@huawei.com>
+Date: Wed, 21 Oct 2015 15:12:50 +0200
+Subject: [PATCH] Fix 'No SMBIOS nor DMI entry point found' on SMBIOS3
+
+address_from_efi may return a SMBIOS or SMBIOS3 format entry
+point, so add this condition.
+---
+ AUTHORS     |  1 +
+ CHANGELOG   |  4 ++++
+ dmidecode.c | 12 ++++++++++--
+ 3 files changed, 15 insertions(+), 2 deletions(-)
+
+Index: dmidecode-3.0/AUTHORS
+===================================================================
+--- dmidecode-3.0.orig/AUTHORS
++++ dmidecode-3.0/AUTHORS
+@@ -19,6 +19,7 @@ Jarod Wilson <ja...@redhat.com>
+ Anton Arapov <an...@redhat.com>
+ Roy Franz <roy.fr...@linaro.org>
+ Tyler Bell <tyler.b...@hp.com>
++Xie XiuQi <xiexi...@huawei.com>
+ 
+ MANY THANKS TO (IN CHRONOLOGICAL ORDER)
+ Werner Heuser
+Index: dmidecode-3.0/CHANGELOG
+===================================================================
+--- dmidecode-3.0.orig/CHANGELOG
++++ dmidecode-3.0/CHANGELOG
+@@ -1,3 +1,7 @@
++2015-10-21  Xie XiuQi  <xiexi...@huawei.com>
++
++	* dmidecode.c: Handle SMBIOS 3.0 entry points on EFI systems.
++
+ 2015-09-03  Jean Delvare  <jdelv...@suse.de>
+ 
+ 	* version.h: Set version to 3.0.
+Index: dmidecode-3.0/dmidecode.c
+===================================================================
+--- dmidecode-3.0.orig/dmidecode.c
++++ dmidecode-3.0/dmidecode.c
+@@ -4864,8 +4864,16 @@ int main(int argc, char * const argv[])
+ 		goto exit_free;
+ 	}
+ 
+-	if (smbios_decode(buf, opt.devmem, 0))
+-		found++;
++	if (memcmp(buf, "_SM3_", 5) == 0)
++	{
++		if (smbios3_decode(buf, opt.devmem, 0))
++			found++;
++	}
++	else if (memcmp(buf, "_SM_", 4) == 0)
++	{
++		if (smbios_decode(buf, opt.devmem, 0))
++			found++;
++	}
+ 	goto done;
+ 
+ memory_scan:
diff -Nru dmidecode-3.0/debian/patches/11-Let-read_file-return-the-actual-data-size.patch dmidecode-3.0/debian/patches/11-Let-read_file-return-the-actual-data-size.patch
--- dmidecode-3.0/debian/patches/11-Let-read_file-return-the-actual-data-size.patch	1970-01-01 01:00:00.000000000 +0100
+++ dmidecode-3.0/debian/patches/11-Let-read_file-return-the-actual-data-size.patch	2016-05-13 13:29:57.000000000 +0100
@@ -0,0 +1,109 @@
+From de9a74e1c60210bee229fcf55b1678a99d1b44dd Mon Sep 17 00:00:00 2001
+From: Jean Delvare <jdelv...@suse.de>
+Date: Mon, 2 Nov 2015 09:45:26 +0100
+Subject: [PATCH] Let read_file return the actual data size
+
+Let read_file return the actual data size to the caller. This gives
+the caller the possibility to check that the data size is as expected
+and large enough for the purpose, and report to the user if not.
+---
+ CHANGELOG   |  5 +++++
+ dmidecode.c |  4 +++-
+ util.c      | 11 +++++++----
+ util.h      |  2 +-
+ 4 files changed, 16 insertions(+), 6 deletions(-)
+
+Index: dmidecode-3.0/CHANGELOG
+===================================================================
+--- dmidecode-3.0.orig/CHANGELOG
++++ dmidecode-3.0/CHANGELOG
+@@ -1,3 +1,8 @@
++2015-11-02  Jean Delvare  <jdelv...@suse.de>
++
++	* dmidecode.c, util.c, util.h: Let read_file return the actual data
++	  size.
++
+ 2015-10-21  Xie XiuQi  <xiexi...@huawei.com>
+ 
+ 	* dmidecode.c: Handle SMBIOS 3.0 entry points on EFI systems.
+Index: dmidecode-3.0/dmidecode.c
+===================================================================
+--- dmidecode-3.0.orig/dmidecode.c
++++ dmidecode-3.0/dmidecode.c
+@@ -4748,6 +4748,7 @@ int main(int argc, char * const argv[])
+ 	int ret = 0;                /* Returned value */
+ 	int found = 0;
+ 	off_t fp;
++	size_t size;
+ 	int efi;
+ 	u8 *buf;
+ 
+@@ -4817,8 +4818,9 @@ int main(int argc, char * const argv[])
+ 	 * contain one of several types of entry points, so read enough for
+ 	 * the largest one, then determine what type it contains.
+ 	 */
++	size = 0x20;
+ 	if (!(opt.flags & FLAG_NO_SYSFS)
+-	 && (buf = read_file(0x20, SYS_ENTRY_FILE)) != NULL)
++	 && (buf = read_file(&size, SYS_ENTRY_FILE)) != NULL)
+ 	{
+ 		if (!(opt.flags & FLAG_QUIET))
+ 			printf("Getting SMBIOS data from sysfs.\n");
+Index: dmidecode-3.0/util.c
+===================================================================
+--- dmidecode-3.0.orig/util.c
++++ dmidecode-3.0/util.c
+@@ -94,10 +94,11 @@ int checksum(const u8 *buf, size_t len)
+  * needs to be freed by the caller.
+  * This provides a similar usage model to mem_chunk()
+  *
+- * Returns pointer to buffer of max_len bytes, or NULL on error
++ * Returns pointer to buffer of max_len bytes, or NULL on error, and
++ * sets max_len to the length actually read.
+  *
+  */
+-void *read_file(size_t max_len, const char *filename)
++void *read_file(size_t *max_len, const char *filename)
+ {
+ 	int fd;
+ 	size_t r2 = 0;
+@@ -115,7 +116,7 @@ void *read_file(size_t max_len, const ch
+ 		return(NULL);
+ 	}
+ 
+-	if ((p = malloc(max_len)) == NULL)
++	if ((p = malloc(*max_len)) == NULL)
+ 	{
+ 		perror("malloc");
+ 		return NULL;
+@@ -123,7 +124,7 @@ void *read_file(size_t max_len, const ch
+ 
+ 	do
+ 	{
+-		r = read(fd, p + r2, max_len - r2);
++		r = read(fd, p + r2, *max_len - r2);
+ 		if (r == -1)
+ 		{
+ 			if (errno != EINTR)
+@@ -140,6 +141,8 @@ void *read_file(size_t max_len, const ch
+ 	while (r != 0);
+ 
+ 	close(fd);
++	*max_len = r2;
++
+ 	return p;
+ }
+ 
+Index: dmidecode-3.0/util.h
+===================================================================
+--- dmidecode-3.0.orig/util.h
++++ dmidecode-3.0/util.h
+@@ -25,7 +25,7 @@
+ #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
+ 
+ int checksum(const u8 *buf, size_t len);
+-void *read_file(size_t len, const char *filename);
++void *read_file(size_t *len, const char *filename);
+ void *mem_chunk(off_t base, size_t len, const char *devmem);
+ int write_dump(size_t base, size_t len, const void *data, const char *dumpfile, int add);
+ u64 u64_range(u64 start, u64 end);
diff -Nru dmidecode-3.0/debian/patches/12-dmidecode-Use-read_file-to-read-the-DMI-table-from-s.patch dmidecode-3.0/debian/patches/12-dmidecode-Use-read_file-to-read-the-DMI-table-from-s.patch
--- dmidecode-3.0/debian/patches/12-dmidecode-Use-read_file-to-read-the-DMI-table-from-s.patch	1970-01-01 01:00:00.000000000 +0100
+++ dmidecode-3.0/debian/patches/12-dmidecode-Use-read_file-to-read-the-DMI-table-from-s.patch	2016-05-13 13:32:16.000000000 +0100
@@ -0,0 +1,82 @@
+From 364055211b1956539c6a6268e111e244e1292c8c Mon Sep 17 00:00:00 2001
+From: Jean Delvare <jdelv...@suse.de>
+Date: Mon, 2 Nov 2015 09:45:31 +0100
+Subject: [PATCH] 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
+---
+ CHANGELOG   |  3 +++
+ dmidecode.c | 29 +++++++++++++++++++++--------
+ 2 files changed, 24 insertions(+), 8 deletions(-)
+
+Index: dmidecode-3.0/CHANGELOG
+===================================================================
+--- dmidecode-3.0.orig/CHANGELOG
++++ dmidecode-3.0/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  <xiexi...@huawei.com>
+ 
+Index: dmidecode-3.0/dmidecode.c
+===================================================================
+--- dmidecode-3.0.orig/dmidecode.c
++++ dmidecode-3.0/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
diff -Nru dmidecode-3.0/debian/patches/13-Use-DWORD-for-Structure-table-maximum-size-in-SMBIOS.patch dmidecode-3.0/debian/patches/13-Use-DWORD-for-Structure-table-maximum-size-in-SMBIOS.patch
--- dmidecode-3.0/debian/patches/13-Use-DWORD-for-Structure-table-maximum-size-in-SMBIOS.patch	1970-01-01 01:00:00.000000000 +0100
+++ dmidecode-3.0/debian/patches/13-Use-DWORD-for-Structure-table-maximum-size-in-SMBIOS.patch	2016-05-13 13:33:06.000000000 +0100
@@ -0,0 +1,30 @@
+From ab02b117511230e46bbef7febbd854b9c832c13c Mon Sep 17 00:00:00 2001
+From: Xie XiuQi <xiexi...@huawei.com>
+Date: Mon, 1 Feb 2016 09:30:31 +0100
+Subject: [PATCH] Use DWORD for Structure table maximum size in SMBIOS3
+
+0Ch DWORD "Structure table maximum size"
+
+Maximum size of SMBIOS Structure Table, pointed to by
+the Structure Table Address, in bytes. The actual size is
+guaranteed to be less or equal to the maximum size.
+
+Signed-off-by: Xie XiuQi <xiexi...@huawei.com>
+Signed-off-by: Jean Delvare <jdelv...@suse.de>
+---
+ dmidecode.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+Index: dmidecode-3.0/dmidecode.c
+===================================================================
+--- dmidecode-3.0.orig/dmidecode.c
++++ dmidecode-3.0/dmidecode.c
+@@ -4612,7 +4612,7 @@ static int smbios3_decode(u8 *buf, const
+ 	}
+ 
+ 	dmi_table(((off_t)offset.h << 32) | offset.l,
+-		  WORD(buf + 0x0C), 0, ver, devmem, flags | FLAG_STOP_AT_EOT);
++		  DWORD(buf + 0x0C), 0, ver, devmem, flags | FLAG_STOP_AT_EOT);
+ 
+ 	if (opt.flags & FLAG_DUMP_BIN)
+ 	{
diff -Nru dmidecode-3.0/debian/patches/series dmidecode-3.0/debian/patches/series
--- dmidecode-3.0/debian/patches/series	2016-05-13 13:32:58.000000000 +0100
+++ dmidecode-3.0/debian/patches/series	2016-05-13 13:34:36.000000000 +0100
@@ -2,7 +2,7 @@
 02-hurd.patch
 03-build.patch
 05-dmidecode-avoid-sigbus.patch
-0001-Fix-No-SMBIOS-nor-DMI-entry-point-found-on-SMBIOS3.patch
-0001-Let-read_file-return-the-actual-data-size.patch
-0001-dmidecode-Use-read_file-to-read-the-DMI-table-from-s.patch
-0001-Use-DWORD-for-Structure-table-maximum-size-in-SMBIOS.patch
+10-Fix-No-SMBIOS-nor-DMI-entry-point-found-on-SMBIOS3.patch
+11-Let-read_file-return-the-actual-data-size.patch
+12-dmidecode-Use-read_file-to-read-the-DMI-table-from-s.patch
+13-Use-DWORD-for-Structure-table-maximum-size-in-SMBIOS.patch

Reply via email to