From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Cc: Sascha Hauer <sascha@saschahauer.de>
Subject: [PATCH 3/6] partitions: gpt: validate mkpart range against GPT usable LBAs
Date: Wed, 01 Jul 2026 11:27:36 +0200 [thread overview]
Message-ID: <20260701-gpt-size-fixes-v1-3-aec2e5641a19@pengutronix.de> (raw)
In-Reply-To: <20260701-gpt-size-fixes-v1-0-aec2e5641a19@pengutronix.de>
efi_partition_mkpart() validated the requested partition range against
hardcoded device geometry: start_lba against a fixed 34 and end_lba
against last_lba(blk) - 33. These offsets assume the default layout of
128 partition entries (32 sectors) plus the backup GPT header.
The authoritative bounds are first_usable_lba and last_usable_lba stored
in the GPT header being modified. They can differ from the hardcoded
values, e.g. when a table is read from disk that was created for a
smaller device (last_usable_lba retains the smaller value until the GPT
is rewritten) or that reserves a differently sized partition entry
array. In those cases the old check allowed a partition to extend past
last_usable_lba, overlapping the reserved backup entry array and GPT
header.
Check start_lba/end_lba against the header's first_usable_lba and
last_usable_lba instead.
Signed-off-by: Sascha Hauer <sascha@saschahauer.de>
---
common/partitions/efi.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/common/partitions/efi.c b/common/partitions/efi.c
index 98172672ff..59b9fa9b55 100644
--- a/common/partitions/efi.c
+++ b/common/partitions/efi.c
@@ -764,15 +764,18 @@ static __maybe_unused int efi_partition_mkpart(struct partition_desc *pd,
gpt_entry *pte;
int i;
const guid_t *guid;
+ uint64_t first_usable_lba = le64_to_cpu(gpt->first_usable_lba);
+ uint64_t last_usable_lba = le64_to_cpu(gpt->last_usable_lba);
- if (start_lba < 34) {
- pr_err("invalid start LBA %lld, minimum is 34\n", start_lba);
+ if (start_lba < first_usable_lba) {
+ pr_err("invalid start LBA %lld, minimum is %lld\n", start_lba,
+ first_usable_lba);
return -EINVAL;
}
- if (end_lba >= last_lba(pd->blk) - 33) {
+ if (end_lba > last_usable_lba) {
pr_err("invalid end LBA %lld, maximum is %lld\n", end_lba,
- last_lba(pd->blk) - 34);
+ last_usable_lba);
return -EINVAL;
}
--
2.47.3
next prev parent reply other threads:[~2026-07-01 9:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-01 9:27 [PATCH 0/6] GPT: fixes around last_usable_lba Sascha Hauer
2026-07-01 9:27 ` [PATCH 1/6] partitions: gpt: Adjust last_usable_lba to real device size when writing Sascha Hauer
2026-07-01 9:27 ` [PATCH 2/6] partitions: gpt: refresh also when primary or alternate is invalid Sascha Hauer
2026-07-01 9:27 ` Sascha Hauer [this message]
2026-07-01 9:27 ` [PATCH 4/6] partitions: check new partitions against usable LBAs, not device size Sascha Hauer
2026-07-01 9:27 ` [PATCH 5/6] partitions: gpt: fix wrong error messages Sascha Hauer
2026-07-01 9:27 ` [PATCH 6/6] partitions: gpt: log a message when partition table refreshed Sascha Hauer
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=20260701-gpt-size-fixes-v1-3-aec2e5641a19@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=sascha@saschahauer.de \
/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