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 2/2] partitions: efi: allocate disk GUID param when recreating partition
Date: Thu, 9 Jan 2025 12:24:37 +0100 [thread overview]
Message-ID: <20250109112437.3174977-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250109112437.3174977-1-a.fatoum@pengutronix.de>
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
prev parent 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 [RFT PATCH master 1/2] partitions: dos: allocate NT signature " Ahmad Fatoum
2025-01-09 11:24 ` Ahmad Fatoum [this message]
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-2-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