[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#851815: efivar: Bogus output for MBR partitions (disk signature)



Source: efivar
Version: 30-1
Severity: normal
Tags: patch upstream

format_media_dn() produces bogus media device paths for MBR partitions. Instead of displaying the MBR disk signature, the current logic apparently sign-extends its least-significant byte and returns a decimal number, still prefixed with "0x". The result is nonsense like this:

   # blkid -o value -s PTUUID /dev/sdb
   927a7490
   # efibootmgr -v | grep debian
   Boot0002* debian    HD(3,MBR,0x4294967184,0xe89c0000,0x100000)/File(\EFI\debian\grubx64.efi)

The "0x4294967184" returned by efibootmgr is really *decimal* 4294967184, which is just 0xffffff90. The correct output for this field would be "0x927a7490":

   # blkid -o value -s PTUUID /dev/sdb
   927a7490
   # efibootmgr -v | grep debian
   Boot0002* debian    HD(3,MBR,0x927a7490,0xe89c0000,0x100000)/File(\EFI\debian\grubx64.efi)

Upstream pull request: https://github.com/rhinstaller/efivar/pull/79

-- System Information:
Debian Release: stretch/sid
 APT prefers unstable
 APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386, armhf

Kernel: Linux 4.8.0-2-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
>From e5dd44155fd91d9c3e8b31f897b0dc6ac4635742 Mon Sep 17 00:00:00 2001
From: Dwayne Litzenberger <dlitz@dlitz.net>
Date: Wed, 18 Jan 2017 16:35:46 -0800
Subject: [PATCH] format_media_dn: Fix formatting of disk signature for MBR
 partitions

The previous logic sign-extended the least-significant byte of the disk
signature and returned a decimal number prefixed with "0x", producing
nonsense like this:

    # blkid -o value -s PTUUID /dev/sdb
    927a7490
    # efibootmgr -v | grep debian
    Boot0002* debian HD(3,MBR,0x4294967184,0xe89c0000,0x100000)/File(\EFI\debian\grubx64.efi)
    # python -c 'print hex(4294967184)'
    0xffffff90

With this change, it works properly:

    Boot0002* debian HD(3,MBR,0x927a7490,0xe89c0000,0x100000)/File(\EFI\debian\grubx64.efi)

Signed-off-by: Dwayne Litzenberger <dlitz@dlitz.net>
---
 src/dp-media.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/dp-media.c b/src/dp-media.c
index cde2ad8..6fd8dcf 100644
--- a/src/dp-media.c
+++ b/src/dp-media.c
@@ -36,8 +36,11 @@ _format_media_dn(char *buf, size_t size, const_efidp dp)
 		switch (dp->hd.signature_type) {
 		case EFIDP_HD_SIGNATURE_MBR:
 			format(buf, size, off, "HD",
-			       "MBR,0x%"PRIu32",0x%"PRIx64",0x%"PRIx64")",
-			       *(char *)dp->hd.signature,
+			       "MBR,0x%"PRIx32",0x%"PRIx64",0x%"PRIx64")",
+			       (uint32_t)dp->hd.signature[0] |
+			       ((uint32_t)dp->hd.signature[1] << 8) |
+			       ((uint32_t)dp->hd.signature[2] << 16) |
+			       ((uint32_t)dp->hd.signature[3] << 24),
 			       dp->hd.start, dp->hd.size);
 			break;
 		case EFIDP_HD_SIGNATURE_GUID:
-- 
2.11.0


Reply to: