[RFT PATCH master 2/2] partitions: efi: allocate disk GUID param when recreating partition

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

 



We used to only allocate the device parameter when parsing a GPT from
disk, but not when creating the partition dynamically at runtime.

This didn't cause acute problems until we started freeing the parameter
again and triggering a NULL pointer dereference when removing dynamically
created partitions.

Fix this by always allocating the parameter.

Fixes: 834cddeb4e91 ("partitions: efi: remove guid device parameter on free")
Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
---
 common/partitions/efi.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index e3db586b98dc..43e292d71da8 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -500,6 +500,13 @@ static void part_get_efi_name(gpt_entry *pte, const char *src)
 	}
 }
 
+static void add_gpt_diskuuid_param(struct efi_partition_desc *epd,
+				   struct block_device *blk)
+{
+	epd->param_guid = dev_add_param_string_fixed(blk->dev,
+						     "guid", blk->cdev.diskuuid);
+}
+
 static struct partition_desc *efi_partition(void *buf, struct block_device *blk)
 {
 	gpt_header *gpt = NULL;
@@ -530,8 +537,7 @@ static struct partition_desc *efi_partition(void *buf, struct block_device *blk)
 	epd->ptes = ptes;
 
 	snprintf(blk->cdev.diskuuid, sizeof(blk->cdev.diskuuid), "%pUl", &gpt->disk_guid);
-	epd->param_guid = dev_add_param_string_fixed(blk->dev,
-						     "guid", blk->cdev.diskuuid);
+	add_gpt_diskuuid_param(epd, blk);
 
 	for (i = 0; i < nb_part; i++) {
 		if (!is_pte_valid(&ptes[i], last_lba(blk))) {
@@ -595,6 +601,8 @@ static __maybe_unused struct partition_desc *efi_partition_create_table(struct b
 	gpt->num_partition_entries = cpu_to_le32(128);
 	gpt->sizeof_partition_entry = cpu_to_le32(sizeof(gpt_entry));
 
+	add_gpt_diskuuid_param(epd, blk);
+
 	pr_info("Created new disk label with GUID %pU\n", &gpt->disk_guid);
 
 	epd->ptes = xzalloc(128 * sizeof(gpt_entry));
-- 
2.39.5





[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux