From d829f9ff9ae039ca25f22244c36066ba47be3b72 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Thu, 25 Nov 2021 10:49:54 +0100 Subject: [PATCH] daemon/listfs: don't call "sgdisk -i" on bogus MBR partition table entry The "is_partition_can_hold_filesystem" function calls "Parted.part_get_gpt_type" on the partition if: - the partition table type is GPT, - or the partition table type is MBR, and the partition is primary or logical. The one entry in the fake MBR partition table described in the previous patch passes the second branch of this check, therefore "Parted.part_get_gpt_type" is reached, and it invokes "sgdisk -i 1" on the disk. Surprisingly (not), while "sgdisk -i" copes fine with valid MBR partition tables, it chokes on the fake one. The output does not contain the "Partition GUID code" line, and so "sgdisk_info_extract_field" throws an exception. Prevent calling "Parted.part_get_gpt_type" on a bogus MBR partition table, similarly to the "extended entry in MBR partition table" case; the difference is that the bogus primary entry, unlike a valid extended entry, *can* hold a filesystem. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1931821 Signed-off-by: Laszlo Ersek Acked-by: Richard W.M. Jones Message-Id: <20211125094954.9713-6-lersek@redhat.com> --- daemon/listfs.ml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/daemon/listfs.ml b/daemon/listfs.ml index d8add5005..63ced260a 100644 --- a/daemon/listfs.ml +++ b/daemon/listfs.ml @@ -109,6 +109,8 @@ and is_partition_can_hold_filesystem partition = if is_gpt_or_mbr then ( if is_mbr_extended parttype device partnum then false + else if is_mbr_bogus parttype device partnum then + true else ( (* MBR partition id will be converted into corresponding GPT type. *) let gpt_type = Parted.part_get_gpt_type device partnum in @@ -130,6 +132,9 @@ and is_mbr_extended parttype device partnum = parttype = "msdos" && Parted.part_get_mbr_part_type device partnum = "extended" +and is_mbr_bogus parttype device partnum = + parttype = "msdos" && partnum = 1 && Utils.has_bogus_mbr device + (* Use vfs-type to check for a filesystem of some sort of [device]. * Appends (device, vfs_type) to the ret parameter (there may be * multiple devices found in the case of btrfs).