Received: (at 35714) by debbugs.gnu.org; 16 May 2019 13:14:05 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu May 16 09:14:05 2019 Received: from localhost ([127.0.0.1]:54670 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1hRGCy-00022J-Or for submit <at> debbugs.gnu.org; Thu, 16 May 2019 09:14:04 -0400 Received: from ec2-34-202-238-73.compute-1.amazonaws.com ([34.202.238.73]:47384 helo=vps.thesusis.net) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <psusi@HIDDEN>) id 1hRGCx-00021i-9C for 35714 <at> debbugs.gnu.org; Thu, 16 May 2019 09:14:03 -0400 Received: from localhost (localhost [127.0.0.1]) by vps.thesusis.net (Postfix) with ESMTP id 59A3A26000; Thu, 16 May 2019 09:13:56 -0400 (EDT) Received: from vps.thesusis.net ([127.0.0.1]) by localhost (ip-172-26-1-203.ec2.internal [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5cT6-3KuOIqg; Thu, 16 May 2019 09:13:55 -0400 (EDT) Received: by vps.thesusis.net (Postfix, from userid 1000) id D83EA26016; Thu, 16 May 2019 09:13:55 -0400 (EDT) References: <20190513085212.gtsiqnazw3jx5kvk@HIDDEN> User-agent: mu4e 0.9.18; emacs 25.2.2 From: Phillip Susi <phill@HIDDEN> To: Matthijs Kooijman <matthijs@HIDDEN> Subject: Re: bug#35714: Parted destroys mbr_signature (Disk Identifier) when adding MBR bootcode In-reply-to: <20190513085212.gtsiqnazw3jx5kvk@HIDDEN> Date: Thu, 16 May 2019 09:13:55 -0400 Message-ID: <87woiqy224.fsf@HIDDEN> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.4 (/) X-Debbugs-Envelope-To: 35714 Cc: 35714 <at> debbugs.gnu.org X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -0.6 (/) Matthijs Kooijman writes: > Hi folks, > > I believe I found a bug in the dos partition table writer. Let me start > with the cause. There's this bit of code: > > if (!table->boot_code[0]) { > memset (table->boot_code, 0, 512); > memcpy (table->boot_code, MBR_BOOT_CODE, sizeof (MBR_BOOT_CODE)); > } Yikes! Clearly this should have been sizeof( table->boot_code ) rather than 512.
bug-parted@HIDDEN
:bug#35714
; Package parted
.
Full text available.Received: (at 35714) by debbugs.gnu.org; 13 May 2019 15:11:58 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon May 13 11:11:58 2019 Received: from localhost ([127.0.0.1]:45944 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1hQCcP-0006qi-JU for submit <at> debbugs.gnu.org; Mon, 13 May 2019 11:11:58 -0400 Received: from tika.stderr.nl ([94.142.244.14]:52840) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <matthijs@HIDDEN>) id 1hQByS-0003fi-UO for 35714 <at> debbugs.gnu.org; Mon, 13 May 2019 10:30:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.tikatika.nl; s=201709.tika; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:To:From:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=xhnj8l39BeZfO5IesBcnLFV0X3esNGWTejgNfZsWphc=; b=YkyZzaVeE+gG6FIadYUrW4j0F d7g3AOBBg+2JY3H9aCsA6S5ARbTxm8eO4p271O56jFsYKY/arLh4qwBZk7JgzviEK3yekDcPpIc/a z9iixK/4dZycuq63aZc21C0QfhsVj6+tGzLpRkxGx97/5uzHTu9jyXwGxCalQIPpQDyv4=; X-Preliminary-Spam-Score: -2.9 (--) Received: from [10.42.0.16] (helo=login.tika.stderr.nl) by tika.stderr.nl with smtp (Exim 4.89) (envelope-from <matthijs@HIDDEN>) id 1hQByK-00040C-Re for 35714 <at> debbugs.gnu.org; Mon, 13 May 2019 16:30:34 +0200 Received: (nullmailer pid 11157 invoked by uid 2001); Mon, 13 May 2019 14:30:32 -0000 Date: Mon, 13 May 2019 16:30:32 +0200 From: Matthijs Kooijman <matthijs@HIDDEN> To: 35714 <at> debbugs.gnu.org Subject: Re: Parted destroys mbr_signature (Disk Identifier) when adding MBR bootcode Message-ID: <20190513143031.buygnjkgc2qr547v@HIDDEN> References: <20190513085212.gtsiqnazw3jx5kvk@HIDDEN> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="affhqhr54u2qqup3" Content-Disposition: inline In-Reply-To: <20190513085212.gtsiqnazw3jx5kvk@HIDDEN> X-PGP-Fingerprint: E7D0 C6A7 5BEE 6D84 D638 F60A 3798 AF15 A156 5658 X-PGP-Key: http://www.stderr.nl/static/files/gpg_pubkey.asc User-Agent: NeoMutt/20170113 (1.7.2) X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 35714 X-Mailman-Approved-At: Mon, 13 May 2019 11:11:55 -0400 X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) --affhqhr54u2qqup3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi folks, one more addition: Below is an example of reproducing this problem on an Ubuntu Disco system running parted 3.2-25. I haven't tried git master, but looking at the code, I'm pretty sure the problem stil exists there. Gr. Matthijs # Use fdisk to create an empty partition table without any boot code matthijs@grubby:~$ truncate -s 8M tmp.img matthijs@grubby:~$ echo -e 'o\nw' | fdisk tmp.img Welcome to fdisk (util-linux 2.33.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0x0298967f. Command (m for help): Created a new DOS disklabel with disk identifier 0x94bfb6ca. Command (m for help): The partition table has been altered. Syncing disks. matthijs@grubby:~$ fdisk -l tmp.img | grep identifier Disk identifier: 0x94bfb6ca matthijs@grubby:~$ head -c 512 tmp.img | hd 00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 000001b0 00 00 00 00 00 00 00 00 ca b6 bf 94 00 00 00 00 |................| 000001c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.| 00000200 # Then use parted to add a partition matthijs@grubby:~$ parted tmp.img mkpart p fat32 4096s 8191s /sys/firmware/dmi/tables/smbios_entry_point: Permission denied /dev/mem: Permission denied WARNING: You are not superuser. Watch out for permissions. # This has changed the disk identifier (and added bootcode) matthijs@grubby:~$ fdisk -l tmp.img | grep identifier Disk identifier: 0x5d7de418 matthijs@grubby:~$ head -c 512 tmp.img | hd 00000000 fa b8 00 10 8e d0 bc 00 b0 b8 00 00 8e d8 8e c0 |................| 00000010 fb be 00 7c bf 00 06 b9 00 02 f3 a4 ea 21 06 00 |...|.........!..| 00000020 00 be be 07 38 04 75 0b 83 c6 10 81 fe fe 07 75 |....8.u........u| 00000030 f3 eb 16 b4 02 b0 01 bb 00 7c b2 80 8a 74 01 8b |.........|...t..| 00000040 4c 02 cd 13 ea 00 7c 00 00 eb fe 00 00 00 00 00 |L.....|.........| 00000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 000001b0 00 00 00 00 00 00 00 00 18 e4 7d 5d 00 00 00 00 |..........}]....| 000001c0 01 20 0c 03 20 3f 00 10 00 00 00 10 00 00 00 00 |. .. ?..........| 000001d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| * 000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.| 00000200 --affhqhr54u2qqup3 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEMyF3AetYrDfGJ9el6ZMxy91tJYwFAlzZf4QACgkQ6ZMxy91t JYzLPhAAinbPImRnYrVU5pKQj9s/XFwJpechcb4KtTklFzdKO8+EAz1/JqLcotCp kpnpWYPd6k+UXD5fom4rDDJ0PHUVfT8F+XmJIEwcWBfA8BXTz+OypZrvZFb+zAdy huAzMsbuW9JDn8XmfjJgel3F7c92PgMZJJrVUxzcQG1L8+eSEriUw7Zs6otuFHms GKEmVscx5k4eLgWJoZFj48XPzIITDw1InbUjSftMihNgaVsgzUwfgV2jmL1mr4oe Lvru11Cccx45rwmu3yyZYHgAI21ZYNzU92kKjrSkjLNOZ3bhOJdM6q0zP+PrYJjf F4BhTQ7F/Vc/pz+WT8mKsycNfZFgB0DfZiRjRIgwvs2tHopJfTT+pL8F3cPq6Hz4 UhOQgYQ1SWXQjtEioe0YksA2q1z1uWeMIIBm0rzspq3ud+rn9+SSU9NU7jF0ZBN6 1zV9mj6ggkGzRVbr0I/EGrqbNNccoRhn0PgCfMmNyT0DbC3IN1dT9u2TlK5GkhA/ 2do/i/OcsX8VOg1nIp2p6cX2+tf9aXVCNoluOMnspM6aehwHrXii+4YXF3VhT+kz DLG9vTO26guOLxEVO28TbFr121t9KdQBAjC7u2VgvJXSEl3YODKjtyX4yGl56nku 9OsJA2K4P6XAEACW/v/pltNsfCDpn9zqQKQXmfiVrbW3+vdLIDw= =31ft -----END PGP SIGNATURE----- --affhqhr54u2qqup3--
bug-parted@HIDDEN
:bug#35714
; Package parted
.
Full text available.Received: (at submit) by debbugs.gnu.org; 13 May 2019 14:20:59 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Mon May 13 10:20:59 2019 Received: from localhost ([127.0.0.1]:45841 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1hQBp5-0003N0-3j for submit <at> debbugs.gnu.org; Mon, 13 May 2019 10:20:59 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47289) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <matthijs@HIDDEN>) id 1hQ6nb-0005rV-Fx for submit <at> debbugs.gnu.org; Mon, 13 May 2019 04:59:08 -0400 Received: from lists.gnu.org ([209.51.188.17]:50202) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <matthijs@HIDDEN>) id 1hQ6nW-0002rp-7q for submit <at> debbugs.gnu.org; Mon, 13 May 2019 04:59:02 -0400 Received: from eggs.gnu.org ([209.51.188.92]:33403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <matthijs@HIDDEN>) id 1hQ6nU-0006Vu-Ss for bug-parted@HIDDEN; Mon, 13 May 2019 04:59:02 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,RCVD_IN_DNSWL_NONE, URIBL_BLOCKED autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <matthijs@HIDDEN>) id 1hQ6h0-0007RC-Mn for bug-parted@HIDDEN; Mon, 13 May 2019 04:52:19 -0400 Received: from tika.stderr.nl ([94.142.244.14]:60278) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <matthijs@HIDDEN>) id 1hQ6h0-0007Qk-35 for bug-parted@HIDDEN; Mon, 13 May 2019 04:52:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.tikatika.nl; s=201709.tika; h=Content-Type:MIME-Version:Message-ID: Subject:To:From:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=HrVao4lsfSVsMBr07FyCntiEzt0eZxsO+XVYRvhyar4=; b=Egdth9gb68vwWRpvtPPOwpG6No zRTqA6B6P8ydtLs4gDwr6dIuuEWy+w08s2AErF612zdLinBF+He73pk08OAb7lr3ZGt8b+C+dT2Dq 3ghO8lSk3FAI5WAHodBO2GOpR8hAt18B2x4I96DBh/jPUIUJuIk17JzGiP2/dfK5H51A=; X-Preliminary-Spam-Score: -2.9 (--) Received: from [10.42.0.16] (helo=login.tika.stderr.nl) by tika.stderr.nl with smtp (Exim 4.89) (envelope-from <matthijs@HIDDEN>) id 1hQ6gv-0002zJ-9i for bug-parted@HIDDEN; Mon, 13 May 2019 10:52:14 +0200 Received: (nullmailer pid 8390 invoked by uid 2001); Mon, 13 May 2019 08:52:13 -0000 Date: Mon, 13 May 2019 10:52:12 +0200 From: Matthijs Kooijman <matthijs@HIDDEN> To: bug-parted@HIDDEN Subject: Parted destroys mbr_signature (Disk Identifier) when adding MBR bootcode Message-ID: <20190513085212.gtsiqnazw3jx5kvk@HIDDEN> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="k3gah2ffcnrfl5sy" Content-Disposition: inline X-PGP-Fingerprint: E7D0 C6A7 5BEE 6D84 D638 F60A 3798 AF15 A156 5658 X-PGP-Key: http://www.stderr.nl/static/files/gpg_pubkey.asc User-Agent: NeoMutt/20170113 (1.7.2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 94.142.244.14 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 13 May 2019 10:20:58 -0400 X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) --k3gah2ffcnrfl5sy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi folks, I believe I found a bug in the dos partition table writer. Let me start with the cause. There's this bit of code: if (!table->boot_code[0]) { memset (table->boot_code, 0, 512); memcpy (table->boot_code, MBR_BOOT_CODE, sizeof (MBR_BOOT_CODE)); } When a disk has no MBR bootcode, this adds some. However, it also starts with clearing the *entire* MBR sector. I believe this should just clear the bootcode, e.g. - memset (table->boot_code, 0, 512); + memset (table->boot_code, 0, sizeof(table->boot_code)); The current code clears the mbr_signature, partition table and magic at the end. The partition table is rewritten from the table in memory, the magic value is simply replaced with a fixed value, but the mbr_signature is replaced by newly randomly generated value. Effectively, this means that when modifying a partition table without any boot code, the mbr_signature will be changed. I've noticed this problem on a Raspberry pi. The default raspbian images are generated using fdisk, without any boot code (which is not needed on a pi). Modifying the partition table using parted then generates a new mbr_signature. Since this signature (called Disk Identifier by fdisk) is used to generate the PARTUUID for partitions [1], and the PARTUUID is used to locate the root filesystem, this effectively makes the system unbootable. It seems this has been known for a while, since a workaround [2] has been (silently, without mentioning it in the commend message) introduced two years ago [3] in the raspberry pi resizing code (probably at the same time they started using PARTUUID I suspect). Also note that the disk identifier is only changes once, since then the MBR has bootcode and parted no longer needs to clear things. Gr. Matthijs [1]: https://raspberrypi.stackexchange.com/a/95436/70022 [2]: https://github.com/RPi-Distro/raspi-config/blob/master/init_resize.sh#L77-L82 [3]: https://github.com/RPi-Distro/raspi-config/commit/44a2e6188c004de50b6c25c8bace2872d672cdd1 --k3gah2ffcnrfl5sy Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEMyF3AetYrDfGJ9el6ZMxy91tJYwFAlzZMDkACgkQ6ZMxy91t JYxtnhAAvC6YkCNIBEVrLZRzpqKfy5jRbDUBXZQ+P78utrPkOcmhIyPqdoG0G7SK bO+++51aDIbhJ1d/dpApiQqUkx0WHYloo2YI1sISOflBvP6+fRc5YP9OMqwINQyt CahL+gMFaVztf6IlDsMEN8TGFoqIAK0BP2wVW06kUvV5VOuzZ5BV+qiNGZ2nF3Dh 0zN6baoCz/uU7z3KP7tQ5+7kVIG7i4hghOtRqL9/HnCbBON41W9Dv6sgEnj/Zj+I sMUSgoA7uX2xJAAqJq6PsTswpN53sHeNmi/Du+1EwckuyPM8gutD8Ij2hG2akJYj 63ZweuJbmW3vYl8VO24XDOU/UiZOA5qOeeosdT9uJqYL7VPTKNMBKXjto2v8qwcP lb6Ygv3he4m1WhwyA4axAt9do0UqVgU3fNhX4MfvKFXgk9pD1e4D/i0dnfjxB71Y UYK1RP/Irj6a0G/pUNux61SvujZUz9bVwIuDHrypH2HPmsZpofiZKF8NmDP5kneN hGOVAObhJGmj9KgPOOqAw+qapkgXyMb7iFKIjOpC9SEPS/q9/votzfL8wPs3Z0rv O3gCgtwBQIDOI311dJT27RQB42q5BgOju2Qy/jFxJmKipo3WPteHNNarVAzvHISx vevHnuzh0NjfdOlLcGoSWB9MR+OGWlB2A1VS3Xs3K4XbQ3GDSi8= =YCga -----END PGP SIGNATURE----- --k3gah2ffcnrfl5sy--
Matthijs Kooijman <matthijs@HIDDEN>
:bug-parted@HIDDEN
.
Full text available.bug-parted@HIDDEN
:bug#35714
; Package parted
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.