Bug#751704: libparted ped_disk_clobber() overwrites firmware on some arm systems
Hello,
as libparted upstream has now confirmed that modifying
PedDisk.needs_clobber from within the calling application is
ok, I would like to apply the following patch to partman-base
unless somebody has further objections against it.
Functionally it is the same patch that I had posted earlier
already, just with some coding style cleanups.
Regards,
Karsten
>From bd3e4f79ea620fefb48c768dec22a3f7d1ad31a2 Mon Sep 17 00:00:00 2001
From: Karsten Merker <merker@debian.org>
Date: Thu, 28 Aug 2014 20:38:12 +0200
Subject: [PATCH] Take care of the firmware area on sunxi-based systems
By default partman calls ped_disk_clobber when writing a new
partition table, but on the MMC device of sunxi-based systems this
would overwrite the firmware area, resulting in an unbootable system
(see bug #751704). Handle this as a special case in command_commit().
---
parted_server.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/parted_server.c b/parted_server.c
index 55cf151..a6283f6 100644
--- a/parted_server.c
+++ b/parted_server.c
@@ -1330,6 +1330,25 @@ command_dump()
oprintf("OK\n");
}
+/* Check whether we are running on a sunxi-based system. */
+int
+is_sunxi_system()
+{
+ int cpuinfo_handle;
+ int result = 0;
+ char buf[4096];
+ int length;
+
+ if ((cpuinfo_handle = open("/proc/cpuinfo", O_RDONLY)) != -1) {
+ length = read(cpuinfo_handle, buf, sizeof(buf)-1);
+ buf[length]='\0';
+ if (strstr(buf, "Allwinner") != NULL)
+ result = 1;
+ close(cpuinfo_handle);
+ }
+ return result;
+}
+
void
command_commit()
{
@@ -1337,6 +1356,20 @@ command_commit()
if (dev == NULL)
critical_error("The device %s is not opened.", device_name);
log("command_commit()");
+
+ /* The boot device on sunxi-based systems needs special handling.
+ * By default partman calls ped_disk_clobber when writing the
+ * partition table, but on sunxi-based systems this would overwrite
+ * the firmware area, resulting in an unbootable system (see
+ * bug #751704).
+ */
+ if (is_sunxi_system() && !strcmp(disk->dev->path, "/dev/mmcblk0")) {
+ disk->needs_clobber = 0;
+ log("Sunxi platform detected. Disabling ped_disk_clobber " \
+ "for the boot device %s to protect the firmware " \
+ "area.", disk->dev->path);
+ }
+
open_out();
if (disk != NULL && named_is_changed(device_name))
ped_disk_commit(disk);
--
2.1.0
--
Gem. Par. 28 Abs. 4 Bundesdatenschutzgesetz widerspreche ich der Nutzung
sowie der Weitergabe meiner personenbezogenen Daten für Zwecke der
Werbung sowie der Markt- oder Meinungsforschung.
Reply to: