- tests: Add test for dvh with a bad checksum (bcl)
Related: RHEL-73220 - libparted: Fix dvh disklabel unhandled exception (bcl) Related: RHEL-73220 - tests: Add test for SUN disklabel handling (bcl) Related: RHEL-73220 - libparted: Fix sun disklabel unhandled exception (bcl) Resolves: RHEL-73220
This commit is contained in:
parent
6d209f9862
commit
df0cabfa08
35
0001-libparted-Fix-sun-disklabel-unhandled-exception.patch
Normal file
35
0001-libparted-Fix-sun-disklabel-unhandled-exception.patch
Normal file
@ -0,0 +1,35 @@
|
||||
From c2d04367de1c734677b3f3c4d93c50e51a8b4506 Mon Sep 17 00:00:00 2001
|
||||
From: "Brian C. Lane" <bcl@redhat.com>
|
||||
Date: Tue, 7 Jan 2025 16:50:21 -0800
|
||||
Subject: [PATCH 1/4] libparted: Fix sun disklabel unhandled exception
|
||||
|
||||
The CHS warning should only continue if ignored, not if unhandled.
|
||||
|
||||
Script mode, or exception handlers can return PED_EXCEPTION_UNHANDLED
|
||||
which should act the same as a cancel. Previously it would only exit if
|
||||
cancel was selected, allowing it to continue to use the bad CHS and
|
||||
crash later.
|
||||
|
||||
(cherry picked from commit 95b877cfa36c1571487c2a67a3902f1f5c4dc747)
|
||||
|
||||
Resolves: RHEL-73220
|
||||
---
|
||||
libparted/labels/sun.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/libparted/labels/sun.c b/libparted/labels/sun.c
|
||||
index 5ed2886..853576b 100644
|
||||
--- a/libparted/labels/sun.c
|
||||
+++ b/libparted/labels/sun.c
|
||||
@@ -284,7 +284,7 @@ _check_geometry_sanity (PedDisk* disk, SunRawLabel* label)
|
||||
PED_BE16_TO_CPU(label->pcylcount),
|
||||
PED_BE16_TO_CPU(label->ntrks),
|
||||
PED_BE16_TO_CPU(label->nsect))
|
||||
- == PED_EXCEPTION_CANCEL)
|
||||
+ != PED_EXCEPTION_IGNORE)
|
||||
return 0;
|
||||
#endif
|
||||
dev->bios_geom.sectors = PED_BE16_TO_CPU(label->nsect);
|
||||
--
|
||||
2.48.1
|
||||
|
120
0002-tests-Add-test-for-SUN-disklabel-handling.patch
Normal file
120
0002-tests-Add-test-for-SUN-disklabel-handling.patch
Normal file
@ -0,0 +1,120 @@
|
||||
From 99dd43ecbe22d69b95a322901f881db44e8a9cb9 Mon Sep 17 00:00:00 2001
|
||||
From: "Brian C. Lane" <bcl@redhat.com>
|
||||
Date: Wed, 8 Jan 2025 11:59:40 -0800
|
||||
Subject: [PATCH 2/4] tests: Add test for SUN disklabel handling
|
||||
|
||||
When fixed the output from script mode should be an unknown disklabel,
|
||||
not sun.
|
||||
|
||||
(cherry picked from commit bdb92f73112177c091a764836a9ceaa59f7e9b15)
|
||||
|
||||
Related: RHEL-73220
|
||||
---
|
||||
tests/Makefile.am | 3 ++-
|
||||
tests/sun-badlabel | 42 +++++++++++++++++++++++++++++++++++++
|
||||
tests/t4002-sun-badlabel.sh | 23 ++++++++++++++++++++
|
||||
3 files changed, 67 insertions(+), 1 deletion(-)
|
||||
create mode 100755 tests/sun-badlabel
|
||||
create mode 100644 tests/t4002-sun-badlabel.sh
|
||||
|
||||
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
||||
index fa27b44..00f4a9d 100644
|
||||
--- a/tests/Makefile.am
|
||||
+++ b/tests/Makefile.am
|
||||
@@ -67,6 +67,7 @@ TESTS = \
|
||||
t3400-whole-disk-FAT-partition.sh \
|
||||
t4000-sun-raid-type.sh \
|
||||
t4001-sun-vtoc.sh \
|
||||
+ t4002-sun-badlabel.sh \
|
||||
t4100-msdos-partition-limits.sh \
|
||||
t4100-dvh-partition-limits.sh \
|
||||
t4100-msdos-starting-sector.sh \
|
||||
@@ -103,7 +104,7 @@ TESTS = \
|
||||
EXTRA_DIST = \
|
||||
$(TESTS) t-local.sh t-lvm.sh \
|
||||
init.cfg init.sh t-lib-helpers.sh gpt-header-munge \
|
||||
- gpt-header-move msdos-overlap gpt-attrs
|
||||
+ gpt-header-move msdos-overlap gpt-attrs sun-badlabel
|
||||
|
||||
check_PROGRAMS = print-align print-flags print-max dup-clobber duplicate \
|
||||
fs-resize
|
||||
diff --git a/tests/sun-badlabel b/tests/sun-badlabel
|
||||
new file mode 100755
|
||||
index 0000000..6a28e86
|
||||
--- /dev/null
|
||||
+++ b/tests/sun-badlabel
|
||||
@@ -0,0 +1,42 @@
|
||||
+#!/usr/bin/python3
|
||||
+# Mangle the CHS values stored in a SUN disklabel
|
||||
+# This sets CHS to 1 track, 2 sectors and updates the checksum
|
||||
+# This triggers a bug in the SUN disklabel code when the CHS
|
||||
+# error is UNHANDLED (in script mode or with a custom exception
|
||||
+# handler) and it continues using a bad label which will coredump
|
||||
+# when .duplicate() is called on it.
|
||||
+
|
||||
+import array
|
||||
+from struct import unpack_from, pack_into
|
||||
+import sys
|
||||
+
|
||||
+file = open(sys.argv[1],'rb+')
|
||||
+header = file.read(512)
|
||||
+
|
||||
+# Make sure it looks like a SUN disklabel first
|
||||
+magic = unpack_from(">H", header, 0x1FC)[0]
|
||||
+if magic != 0xDABE:
|
||||
+ raise RuntimeError("Not a SUN disklabel. magic = 0x%04X" % magic)
|
||||
+csum = unpack_from(">H", header, 0x1FE)[0]
|
||||
+ntrks = unpack_from(">H", header, 0x1B4)[0]
|
||||
+nsect = unpack_from(">H", header, 0x1B6)[0]
|
||||
+
|
||||
+header = array.array('B', header)
|
||||
+# cylinders at 0x1B0
|
||||
+# modify ntrks at offset 0x1B4
|
||||
+pack_into('>H', header, 0x1B4, 1)
|
||||
+# modify nsect at offset 0x1B6
|
||||
+pack_into('>H', header, 0x1B6, 2)
|
||||
+
|
||||
+## Undo old values
|
||||
+csum ^= ntrks
|
||||
+csum ^= nsect
|
||||
+
|
||||
+## Add new
|
||||
+csum ^= 1
|
||||
+csum ^= 2
|
||||
+pack_into('>H', header, 0x1FE, csum)
|
||||
+
|
||||
+file.seek(0)
|
||||
+file.write(header)
|
||||
+file.close()
|
||||
diff --git a/tests/t4002-sun-badlabel.sh b/tests/t4002-sun-badlabel.sh
|
||||
new file mode 100644
|
||||
index 0000000..177c0e4
|
||||
--- /dev/null
|
||||
+++ b/tests/t4002-sun-badlabel.sh
|
||||
@@ -0,0 +1,23 @@
|
||||
+#!/bin/sh
|
||||
+# Test exception handling on a bad SUN disklabel
|
||||
+
|
||||
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted $srcdir
|
||||
+ss=$sector_size_
|
||||
+
|
||||
+n_sectors=2000 # number of sectors
|
||||
+dev=sun-disk-file
|
||||
+# create an empty file as a test disk
|
||||
+dd if=/dev/zero of=$dev bs=$ss count=$n_sectors 2> /dev/null || fail=1
|
||||
+
|
||||
+# label the test disk as a sun disk
|
||||
+parted -s $dev mklabel sun > out 2>&1 || fail=1
|
||||
+compare /dev/null out || fail=1
|
||||
+
|
||||
+# Mangle the disklabel to have incorrect CHS values, but a valid checksum
|
||||
+sun-badlabel $dev || fail=1
|
||||
+
|
||||
+# Check the output (this should return 1, but depend on checking the output for the test)
|
||||
+parted -m -s $dev p > out 2>&1
|
||||
+grep unknown out || { cat out; fail=1; }
|
||||
+
|
||||
+Exit $fail
|
||||
--
|
||||
2.48.1
|
||||
|
33
0003-libparted-Fix-dvh-disklabel-unhandled-exception.patch
Normal file
33
0003-libparted-Fix-dvh-disklabel-unhandled-exception.patch
Normal file
@ -0,0 +1,33 @@
|
||||
From 2293e0b0f83a31410d533087a1bf6cd4ea50305c Mon Sep 17 00:00:00 2001
|
||||
From: "Brian C. Lane" <bcl@redhat.com>
|
||||
Date: Wed, 8 Jan 2025 13:35:04 -0800
|
||||
Subject: [PATCH 3/4] libparted: Fix dvh disklabel unhandled exception
|
||||
|
||||
When an exception is using PED_EXCEPTION_IGNORE_CANCEL it should check
|
||||
for !PED_EXCEPTION_IGNORE so that an unhandled exception is treated the
|
||||
same as cancel. Otherwise it could lead to using the disklabel with
|
||||
incorrect values.
|
||||
|
||||
(cherry picked from commit 1480769f2a7071c5a251b6c69658808199e8b05b)
|
||||
|
||||
Related: RHEL-73220
|
||||
---
|
||||
libparted/labels/dvh.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/libparted/labels/dvh.c b/libparted/labels/dvh.c
|
||||
index 0f9124d..7d7dae3 100644
|
||||
--- a/libparted/labels/dvh.c
|
||||
+++ b/libparted/labels/dvh.c
|
||||
@@ -308,7 +308,7 @@ dvh_read (PedDisk* disk)
|
||||
PED_EXCEPTION_IGNORE_CANCEL,
|
||||
_("Checksum is wrong, indicating the partition "
|
||||
"table is corrupt."))
|
||||
- == PED_EXCEPTION_CANCEL)
|
||||
+ != PED_EXCEPTION_IGNORE)
|
||||
return 0;
|
||||
}
|
||||
|
||||
--
|
||||
2.48.1
|
||||
|
61
0004-tests-Add-test-for-dvh-with-a-bad-checksum.patch
Normal file
61
0004-tests-Add-test-for-dvh-with-a-bad-checksum.patch
Normal file
@ -0,0 +1,61 @@
|
||||
From bd12d12ff31bb6bee1dbcc700cdb6879ad55bf81 Mon Sep 17 00:00:00 2001
|
||||
From: "Brian C. Lane" <bcl@redhat.com>
|
||||
Date: Wed, 8 Jan 2025 14:01:39 -0800
|
||||
Subject: [PATCH 4/4] tests: Add test for dvh with a bad checksum
|
||||
|
||||
When using script mode it should return an unknown partition type, not
|
||||
dvh, because the exception is unhandled.
|
||||
|
||||
(cherry picked from commit 82b582996ce691eb635bed124603207515b92efe)
|
||||
|
||||
Related: RHEL-73220
|
||||
---
|
||||
tests/Makefile.am | 1 +
|
||||
tests/t4101-dvh-badlabel.sh | 23 +++++++++++++++++++++++
|
||||
2 files changed, 24 insertions(+)
|
||||
create mode 100644 tests/t4101-dvh-badlabel.sh
|
||||
|
||||
diff --git a/tests/Makefile.am b/tests/Makefile.am
|
||||
index 00f4a9d..5eeab08 100644
|
||||
--- a/tests/Makefile.am
|
||||
+++ b/tests/Makefile.am
|
||||
@@ -71,6 +71,7 @@ TESTS = \
|
||||
t4100-msdos-partition-limits.sh \
|
||||
t4100-dvh-partition-limits.sh \
|
||||
t4100-msdos-starting-sector.sh \
|
||||
+ t4101-dvh-badlabel.sh \
|
||||
t4200-partprobe.sh \
|
||||
t4300-nilfs2-tiny.sh \
|
||||
t4301-nilfs2-badsb2.sh \
|
||||
diff --git a/tests/t4101-dvh-badlabel.sh b/tests/t4101-dvh-badlabel.sh
|
||||
new file mode 100644
|
||||
index 0000000..075c044
|
||||
--- /dev/null
|
||||
+++ b/tests/t4101-dvh-badlabel.sh
|
||||
@@ -0,0 +1,23 @@
|
||||
+#!/bin/sh
|
||||
+# Test exception handling on a bad DVH disklabel
|
||||
+
|
||||
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted $srcdir
|
||||
+ss=$sector_size_
|
||||
+
|
||||
+n_sectors=2000 # number of sectors
|
||||
+dev=sun-disk-file
|
||||
+# create an empty file as a test disk
|
||||
+dd if=/dev/zero of=$dev bs=$ss count=$n_sectors 2> /dev/null || fail=1
|
||||
+
|
||||
+# label the test disk as a dvh disk
|
||||
+parted -s $dev mklabel dvh > out 2>&1 || fail=1
|
||||
+compare /dev/null out || fail=1
|
||||
+
|
||||
+# Mangle the disklabel to have incorrect checksum
|
||||
+dd if=/dev/zero of=$dev conv=notrunc bs=4 count=1 seek=1
|
||||
+
|
||||
+# Check the output (this should return 1, but depend on checking the output for the test)
|
||||
+parted -m -s $dev p > out 2>&1
|
||||
+grep unknown out || { cat out; fail=1; }
|
||||
+
|
||||
+Exit $fail
|
||||
--
|
||||
2.48.1
|
||||
|
17
parted.spec
17
parted.spec
@ -1,7 +1,7 @@
|
||||
Summary: The GNU disk partition manipulation program
|
||||
Name: parted
|
||||
Version: 3.6
|
||||
Release: 6%{?dist}
|
||||
Release: 7%{?dist}
|
||||
License: GPL-3.0-or-later
|
||||
URL: http://www.gnu.org/software/parted
|
||||
|
||||
@ -10,6 +10,11 @@ Source1: https://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.xz.sig
|
||||
Source2: pubkey.phillip.susi
|
||||
Source3: pubkey.brian.lane
|
||||
|
||||
Patch0001: 0001-libparted-Fix-sun-disklabel-unhandled-exception.patch
|
||||
Patch0002: 0002-tests-Add-test-for-SUN-disklabel-handling.patch
|
||||
Patch0003: 0003-libparted-Fix-dvh-disklabel-unhandled-exception.patch
|
||||
Patch0004: 0004-tests-Add-test-for-dvh-with-a-bad-checksum.patch
|
||||
|
||||
BuildRequires: gcc
|
||||
BuildRequires: e2fsprogs-devel
|
||||
BuildRequires: readline-devel
|
||||
@ -113,6 +118,16 @@ make check
|
||||
|
||||
|
||||
%changelog
|
||||
* Tue Jan 21 2025 Brian C. Lane <bcl@redhat.com> - 3.6-7
|
||||
- tests: Add test for dvh with a bad checksum (bcl)
|
||||
Related: RHEL-73220
|
||||
- libparted: Fix dvh disklabel unhandled exception (bcl)
|
||||
Related: RHEL-73220
|
||||
- tests: Add test for SUN disklabel handling (bcl)
|
||||
Related: RHEL-73220
|
||||
- libparted: Fix sun disklabel unhandled exception (bcl)
|
||||
Resolves: RHEL-73220
|
||||
|
||||
* Tue Oct 29 2024 Troy Dawson <tdawson@redhat.com> - 3.6-6
|
||||
- Bump release for October 2024 mass rebuild:
|
||||
Resolves: RHEL-64018
|
||||
|
Loading…
Reference in New Issue
Block a user