[PATCH 1/5] block: partitions: ultrix: reject negative partition sizes

From: shao.mingyin

Date: Thu Dec 03 2026 - 09:17:18 EST


From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>

The Ultrix disklabel parser treats the signed 32-bit pi_nblocks field
as a boolean, so a negative value is accepted and passed to
put_partition() as a sector_t. It is sign-extended to
0xffffffffffffffff, the partition is created with i_size == -512, and
/sys/block/<disk>/<disk>pN/size reports 18446744073709551615 instead of
the entry being ignored.

Skip entries whose size is not positive before the existing check.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable@xxxxxxxxxx
Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
Tested on 7.4.0-rc5-next-20261130 (QEMU/TCG guest) with a 1 MiB
loop-backed disk carrying an Ultrix disklabel whose first partition
entry has pi_nblocks = 0xffffffff and pi_blkoff = 1.

The entry was accepted and the partition was created with a negative
size:

unpatched patched
loop0p1 size 18446744073709551615 no loop0p1

A second image with pi_nblocks = 8 still creates loop0p1 with start 1
and size 8 in both kernels.

block/partitions/ultrix.c | 5 +++--
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/block/partitions/ultrix.c b/block/partitions/ultrix.c
index b4b9ddc57a5d..2465b8ee47ab 100644
--- a/block/partitions/ultrix.c
+++ b/block/partitions/ultrix.c
@@ -35,3 +35,5 @@ int ultrix_partition(struct parsed_partitions *state)
if (label->pt_magic == PT_MAGIC && label->pt_valid == PT_VALID) {
- for (i=0; i<8; i++)
+ for (i = 0; i < 8; i++) {
+ if (label->pt_part[i].pi_nblocks <= 0)
+ continue;
if (label->pt_part[i].pi_nblocks)
@@ -40,2 +42,3 @@ int ultrix_partition(struct parsed_partitions *state)
label->pt_part[i].pi_nblocks);
+ }
put_dev_sector(sect);
--
2.34.1