From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Renaud Barbier <Renaud.Barbier@ametek.com>,
Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [RFT PATCH master 1/2] partitions: dos: allocate NT signature param when recreating partition
Date: Thu, 9 Jan 2025 12:24:36 +0100 [thread overview]
Message-ID: <20250109112437.3174977-1-a.fatoum@pengutronix.de> (raw)
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
next reply other threads:[~2025-01-09 11:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-09 11:24 Ahmad Fatoum [this message]
2025-01-09 11:24 ` [RFT PATCH master 2/2] partitions: efi: allocate disk GUID " Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250109112437.3174977-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=Renaud.Barbier@ametek.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox