* [RFT PATCH master 1/2] partitions: dos: allocate NT signature param when recreating partition
@ 2025-01-09 11:24 Ahmad Fatoum
2025-01-09 11:24 ` [RFT PATCH master 2/2] partitions: efi: allocate disk GUID " Ahmad Fatoum
0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2025-01-09 11:24 UTC (permalink / raw)
To: barebox; +Cc: Renaud Barbier, Ahmad Fatoum
We used to only allocate the device parameter when parsing a MBR 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: 19f4033db59e ("partitions: dos: fix memory leaks")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/partitions/dos.c | 40 +++++++++++++++++++++++-----------------
1 file changed, 23 insertions(+), 17 deletions(-)
diff --git a/common/partitions/dos.c b/common/partitions/dos.c
index 5a055efec7d1..95b71af7ff8f 100644
--- a/common/partitions/dos.c
+++ b/common/partitions/dos.c
@@ -200,6 +200,26 @@ static void extract_flags(const struct partition_entry *p,
pentry->flags |= DEVFS_PARTITION_BOOTABLE_ESP;
}
+static void add_nt_signature_param(struct disk_signature_priv *dsp,
+ struct block_device *blk)
+{
+ dsp->blk = blk;
+
+ /*
+ * This parameter contains the NT disk signature. This allows to
+ * to specify the Linux rootfs using the following syntax:
+ *
+ * root=PARTUUID=ssssssss-pp
+ *
+ * where ssssssss is a zero-filled hex representation of the 32-bit
+ * signature and pp is a zero-filled hex representation of the 1-based
+ * partition number.
+ */
+ dsp->param = dev_add_param_uint32(blk->dev, "nt_signature",
+ dos_set_disk_signature, dos_get_disk_signature,
+ &dsp->signature, "%08x", dsp);
+}
+
/**
* Check if a DOS like partition describes this block device
* @param blk Block device to register to
@@ -216,7 +236,6 @@ static struct partition_desc *dos_partition(void *buf, struct block_device *blk)
struct partition *extended_partition = NULL;
uint8_t *buffer = buf;
int i;
- struct disk_signature_priv *dsp;
uint32_t signature = get_unaligned_le32(buf + 0x1b8);
struct dos_partition_desc *dpd;
@@ -275,22 +294,7 @@ static struct partition_desc *dos_partition(void *buf, struct block_device *blk)
if (extended_partition)
dos_extended_partition(blk, dpd, extended_partition, signature);
- dsp = &dpd->disksig;
- dsp->blk = blk;
-
- /*
- * This parameter contains the NT disk signature. This allows to
- * to specify the Linux rootfs using the following syntax:
- *
- * root=PARTUUID=ssssssss-pp
- *
- * where ssssssss is a zero-filled hex representation of the 32-bit
- * signature and pp is a zero-filled hex representation of the 1-based
- * partition number.
- */
- dsp->param = dev_add_param_uint32(blk->dev, "nt_signature",
- dos_set_disk_signature, dos_get_disk_signature,
- &dsp->signature, "%08x", dsp);
+ add_nt_signature_param(&dpd->disksig, blk);
return &dpd->pd;
}
@@ -320,6 +324,8 @@ static __maybe_unused struct partition_desc *dos_partition_create_table(struct b
dpd->signature = random32();
+ add_nt_signature_param(&dpd->disksig, blk);
+
return &dpd->pd;
}
--
2.39.5
^ permalink raw reply [flat|nested] 2+ messages in thread
* [RFT PATCH master 2/2] partitions: efi: allocate disk GUID param when recreating partition
2025-01-09 11:24 [RFT PATCH master 1/2] partitions: dos: allocate NT signature param when recreating partition Ahmad Fatoum
@ 2025-01-09 11:24 ` Ahmad Fatoum
0 siblings, 0 replies; 2+ messages in thread
From: Ahmad Fatoum @ 2025-01-09 11:24 UTC (permalink / raw)
To: barebox; +Cc: Renaud Barbier, Ahmad Fatoum
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@pengutronix.de>
---
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-01-09 11:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-09 11:24 [RFT PATCH master 1/2] partitions: dos: allocate NT signature param when recreating partition Ahmad Fatoum
2025-01-09 11:24 ` [RFT PATCH master 2/2] partitions: efi: allocate disk GUID " Ahmad Fatoum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox