[drivers][block][efi] Fix GPT partition entry underflow vulnerability#11275
Draft
[drivers][block][efi] Fix GPT partition entry underflow vulnerability#11275
Conversation
|
|
Co-authored-by: BernardXiong <[email protected]>
Copilot
AI
changed the title
[WIP] [Bug] Fix malformed GPT entry causing underflowed partition size
[drivers][block][efi] Fix GPT partition entry underflow vulnerability
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
is_pte_valid()accepts GPT entries whereending_lba < starting_lba. The subsequent size calculation inefi_partition()underflows:A crafted GPT image with valid CRCs can register partitions with attacker-controlled start and massive wrapped size.
Fix
Add
end < startcheck tois_pte_valid():Original prompt
This section details on the original issue you should resolve
<issue_title>[Bug] malformed GPT entry with ending_lba < starting_lba creates an underflowed partition size</issue_title>
<issue_description>### RT-Thread Version
master (verified on commit
2b58dec87b584aa7ded6e8c736498716f8d29cd0)Hardware Type/Architectures
any BSP using the new block partition probing path with EFI/GPT enabled
Develop Toolchain
GCC
Describe the bug
GPT Partition Entry Underflow in RT-Thread EFI/GPT Parser
Affected Components
components/drivers/block/partitions/efi.ccomponents/drivers/block/blk_partition.crt_inline rt_bool_t is_pte_valid(const gpt_entry *pte, const rt_size_t lastlba)rt_err_t efi_partition(struct rt_blk_disk *disk)rt_err_t blk_put_partition(struct rt_blk_disk *disk, const char *type, rt_size_t start, rt_size_t count, int partno)Vulnerability Details
1. GPT entries accepted without checking
ending_lba >= starting_lbaIn
efi.c, GPT entries are considered valid byis_pte_valid()if:partition_type_guidis notNULL_GUIDstarting_lba <= lastlbaending_lba <= lastlbaCurrent code:
There is no check that
ending_lba >= starting_lba. So a malformed GPT entry with:starting_lbainside disk boundsending_lbainside disk boundsending_lba < starting_lbais still accepted as valid.
2. Partition size calculation underflows
efi_partition()computes the partition length as:If
ending_lba < starting_lba, the subtraction underflows in unsigned arithmetic and produces a very large wrapped size.That underflowed size is then passed to
blk_put_partition():and stored into the logical partition device:
As a result, a malformed GPT entry can create a logical partition object with an attacker-controlled start and a huge wrapped size.
Trigger Condition
The bug is reached during normal GPT partition probing:
No local code changes are required. A crafted GPT image with valid headers/CRCs and a malformed partition entry is sufficient.
Proof of Concept
A PoC can be implemented with a crafted GPT disk image used by any block backend that reaches
rt_blk_disk_probe_partition().PoC Shape
Create a disk image with:
partition_type_guid != NULL_GUIDstarting_lba <= lastlbaending_lba <= lastlbaending_lba < starting_lbaFor example:
Both fields are inside disk bounds, but the end is before the start.
Expected Result
During partition probing:
is_pte_valid()accepts the entryefi_partition()computes:which underflows to a huge
rt_uint64_tvalue.blk_put_partition()registers a logical partition with that wrapped size.Minimal Reproduction Steps
rt_blk_disk_probe_partition().Impact
The immediate impact is that malformed GPT metadata can create an invalid logical partition with a huge sector count. This can break the partition abstraction and may enable later incorrect reads/writes, boundary confusion, or other follow-on faults in code that trusts the partition object's stored geometry.
So even though the trigger is a malformed GPT image, the root cause is a missing semantic validity check in the parser.
Upstream / Downstream Impact
Upstream
Verified on current
masterin the new block EFI/GPT parser implementation.Do...
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.