- Don't crash when reading a DASD disk with PV's on there (#563419)

- Don't overwrite the pmbr when merely printing a gpt table (#563211)
This commit is contained in:
Hans de Goede 2010-02-10 14:01:25 +00:00
parent 23df9b3cb9
commit 1a97476e88
3 changed files with 181 additions and 1 deletions

View File

@ -0,0 +1,26 @@
From 122bc980e27334d0f6243b74fffc8d2cefe0eb5c Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Wed, 10 Feb 2010 14:11:14 +0100
Subject: [PATCH parted] dasd: Fix NULL pointer dereference in dasd_read
* libparted/labels/dasd.c (dasd_read): Fix NULL ptr dereference.
---
libparted/labels/dasd.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/libparted/labels/dasd.c b/libparted/labels/dasd.c
index 4b5840b..516d189 100644
--- a/libparted/labels/dasd.c
+++ b/libparted/labels/dasd.c
@@ -399,7 +399,7 @@ dasd_read (PedDisk* disk)
if (strncmp(PART_TYPE_SWAP, str, 6) == 0) {
fs = ped_file_system_probe(&part->geom);
- if (is_linux_swap(fs->name)) {
+ if (fs && is_linux_swap(fs->name)) {
dasd_data->system = PARTITION_LINUX_SWAP;
PDEBUG;
}
--
1.6.6

View File

@ -0,0 +1,146 @@
From 28be933ce317f954be1e39a50d8f42197d6e3c15 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@redhat.com>
Date: Sun, 7 Feb 2010 20:31:11 +0100
Subject: [PATCH parted 01/10] gpt: read-only operation could clobber MBR part of hybrid GPT+MBR table
* libparted/labels/gpt.c (gpt_read): Fix a bug introduced by me in
commit 7f753b1b, "gpt: rewrite GPT header-reading code".
Set write_back=0 in one more code path.
* tests/Makefile.am (TESTS): Add t0205-gpt-list-clobbers-pmbr.sh.
* tests/t0205-gpt-list-clobbers-pmbr.sh: New test.
Reported by aix27249 in
http://parted.alioth.debian.org/cgi-bin/trac.cgi/ticket/250
---
libparted/labels/gpt.c | 10 ++++--
tests/Makefile.am | 1 +
tests/t0205-gpt-list-clobbers-pmbr.sh | 59 +++++++++++++++++++++++++++++++++
4 files changed, 72 insertions(+), 3 deletions(-)
create mode 100644 tests/t0205-gpt-list-clobbers-pmbr.sh
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 9d9876c..ea96a3b 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -4,7 +4,7 @@
original version by Matt Domsch <Matt_Domsch@dell.com>
Disclaimed into the Public Domain
- Portions Copyright (C) 2001-2003, 2005-2009 Free Software Foundation, Inc.
+ Portions Copyright (C) 2001-2003, 2005-2010 Free Software Foundation, Inc.
EFI GUID Partition Table handling
Per Intel EFI Specification v1.02
@@ -932,9 +932,9 @@ gpt_read (PedDisk *disk)
if (primary_gpt && backup_gpt)
{
/* Both are valid. */
+#ifndef DISCOVER_ONLY
if (PED_LE64_TO_CPU (primary_gpt->AlternateLBA) < disk->dev->length - 1)
{
-#ifndef DISCOVER_ONLY
switch (ped_exception_throw
(PED_EXCEPTION_ERROR,
(PED_EXCEPTION_FIX | PED_EXCEPTION_CANCEL
@@ -954,8 +954,12 @@ gpt_read (PedDisk *disk)
write_back = 0;
break;
}
-#endif /* !DISCOVER_ONLY */
}
+ else
+ {
+ write_back = 0;
+ }
+#endif /* !DISCOVER_ONLY */
gpt = primary_gpt;
pth_free (backup_gpt);
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7bfb22e..38922f6 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -9,6 +9,7 @@ TESTS = \
t0200-gpt.sh \
t0201-gpt.sh \
t0202-gpt-pmbr.sh \
+ t0205-gpt-list-clobbers-pmbr.sh \
t0220-gpt-msftres.sh \
t0250-gpt.sh \
t0280-gpt-corrupt.sh \
@@ -1261,6 +1261,8 @@ t0201-gpt.sh.log: t0201-gpt.sh
@p='t0201-gpt.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
t0202-gpt-pmbr.sh.log: t0202-gpt-pmbr.sh
@p='t0202-gpt-pmbr.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
+t0205-gpt-list-clobbers-pmbr.sh.log: t0205-gpt-list-clobbers-pmbr.sh
+ @p='t0205-gpt-list-clobbers-pmbr.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
t0220-gpt-msftres.sh.log: t0220-gpt-msftres.sh
@p='t0220-gpt-msftres.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
t0250-gpt.sh.log: t0250-gpt.sh
diff --git a/tests/t0205-gpt-list-clobbers-pmbr.sh b/tests/t0205-gpt-list-clobbers-pmbr.sh
new file mode 100644
index 0000000..979a15e
--- /dev/null
+++ b/tests/t0205-gpt-list-clobbers-pmbr.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+# Ensure that printing a GPT partition table does not modify the pMBR.
+# Due to a bug in parted-2.1, "parted /dev/... print" would do just that.
+# Not a problem for most, but if you have a hybrid, e.g., gptsync'd
+# GPT/MBR table, merely listing the table with Parted-2.1 would clobber
+# the MBR part.
+
+# Copyright (C) 2010 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+if test "$VERBOSE" = yes; then
+ set -x
+ parted --version
+fi
+
+: ${srcdir=.}
+. $srcdir/t-lib.sh
+
+fail=0
+
+ss=$sector_size_
+n_sectors=400
+dev=dev-file
+
+dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
+parted -s $dev mklabel gpt || fail=1
+parted -s $dev mkpart p1 101s 150s || fail=1
+parted -s $dev mkpart p2 151s 200s || fail=1
+parted -s $dev mkpart p3 201s 250s || fail=1
+
+parted -m -s $dev u s p || fail=1
+
+# Write non-NUL bytes all over the MBR, so we're likely to see any change.
+# However, be careful to leave the type of the first partition, 0xEE,
+# as well as the final two magic bytes.
+printf '%0450d\xee%059d\x55\xaa' 0 0 | dd of=$dev count=1 conv=notrunc || fail=1
+
+dd if=$dev of=before count=1 || fail=1
+
+chmod a-w $dev
+parted -m -s $dev u s p || fail=1
+
+dd if=$dev of=after count=1 || fail=1
+
+cmp before after || fail=1
+
+Exit $fail
--
1.6.6

View File

@ -4,7 +4,7 @@
Summary: The GNU disk partition manipulation program Summary: The GNU disk partition manipulation program
Name: parted Name: parted
Version: 2.1 Version: 2.1
Release: 3%{?dist} Release: 4%{?dist}
License: GPLv3+ License: GPLv3+
Group: Applications/System Group: Applications/System
URL: http://www.gnu.org/software/parted URL: http://www.gnu.org/software/parted
@ -13,6 +13,8 @@ Source0: ftp://ftp.gnu.org/gnu/%{name}/%{name}-%{version}.tar.xz
Patch1: parted-2.1-blkid_topology_get_physical_sector_size.patch Patch1: parted-2.1-blkid_topology_get_physical_sector_size.patch
Patch2: parted-2.1-mem-leak-fixes-rh556012.patch Patch2: parted-2.1-mem-leak-fixes-rh556012.patch
Patch3: parted-2.1-default-alignment.patch Patch3: parted-2.1-default-alignment.patch
Patch4: parted-2.1-gpt-clobber-pmbr-rh563211.patch
Patch5: parted-2.1-dasd-NULL-dereference-rh563419.patch
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: e2fsprogs-devel BuildRequires: e2fsprogs-devel
@ -55,6 +57,8 @@ Parted library, you need to install this package.
%patch1 -p1 %patch1 -p1
%patch2 -p1 %patch2 -p1
%patch3 -p1 %patch3 -p1
%patch4 -p1
%patch5 -p1
iconv -f ISO-8859-1 -t UTF8 AUTHORS > tmp; touch -r AUTHORS tmp; mv tmp AUTHORS iconv -f ISO-8859-1 -t UTF8 AUTHORS > tmp; touch -r AUTHORS tmp; mv tmp AUTHORS
@ -130,6 +134,10 @@ fi
%changelog %changelog
* Wed Feb 10 2010 Hans de Goede <hdegoede@redhat.com> 2.1-4
- Don't crash when reading a DASD disk with PV's on there (#563419)
- Don't overwrite the pmbr when merely printing a gpt table (#563211)
* Sun Jan 31 2010 Hans de Goede <hdegoede@redhat.com> 2.1-3 * Sun Jan 31 2010 Hans de Goede <hdegoede@redhat.com> 2.1-3
- If a drive does not have alignment information available default - If a drive does not have alignment information available default
to an alignment of 1MiB (#559639) to an alignment of 1MiB (#559639)