Received: from list by lists.gnu.org with archive (Exim 4.71) id 1YYy5o-0002X8-Kq for mharc-grub-devel@gnu.org; Fri, 20 Mar 2015 10:40:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYy5l-0002Tr-Lc for grub-devel@gnu.org; Fri, 20 Mar 2015 10:40:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYy5h-0005x5-LH for grub-devel@gnu.org; Fri, 20 Mar 2015 10:40:05 -0400 Received: from che.mayfirst.org ([209.234.253.108]:37601) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYy5h-0005uS-H1 for grub-devel@gnu.org; Fri, 20 Mar 2015 10:40:01 -0400 Received: from fifthhorseman.net (unknown [38.109.115.130]) by che.mayfirst.org (Postfix) with ESMTPSA id 29848F984 for ; Fri, 20 Mar 2015 10:39:58 -0400 (EDT) Received: by fifthhorseman.net (Postfix, from userid 1000) id A5B3420404; Fri, 20 Mar 2015 07:39:42 -0700 (PDT) From: Daniel Kahn Gillmor To: Grub 2 Development List Subject: [PATCH] make grub-install on efi idempotent by omitting PE timestamp User-Agent: Notmuch/0.18.2 (http://notmuchmail.org) Emacs/24.4.1 (x86_64-pc-linux-gnu) Date: Fri, 20 Mar 2015 10:39:39 -0400 Message-ID: <877fubg2c4.fsf@alice.fifthhorseman.net> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.234.253.108 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Mar 2015 14:40:07 -0000 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable I'm using grub-efi on a debian amd64 system, with the ESP mounted at /boot/efi. when i run: grub-install the digest of /boot/efi/EFI/debian/grubx64.efi changes: root@pops:~# sha1sum /boot/efi/EFI/debian/grubx64.efi=20 eafbe63218ecb7f7e69522e55ff7bc9551002c08 /boot/efi/EFI/debian/grubx64.efi root@pops:~# grub-install Installing for x86_64-efi platform. Installation finished. No error reported. root@pops:~# sha1sum /boot/efi/EFI/debian/grubx64.efi=20 b3ec06be87d356479e652e6515814ed4fd8f35cc /boot/efi/EFI/debian/grubx64.efi root@pops:~# I compared the two versions, and it looks like they only differ in the PE timestamp: root@pops:~# cp /boot/efi/EFI/debian/grubx64.efi{,.bak} root@pops:~# grub-install Installing for x86_64-efi platform. Installation finished. No error reported. root@pops:~# sha1sum /boot/efi/EFI/debian/grubx64.efi{,.bak} a2fe7412a8fff69b033c5b11eb3a78927ea084e1 /boot/efi/EFI/debian/grubx64.efi b3ec06be87d356479e652e6515814ed4fd8f35cc /boot/efi/EFI/debian/grubx64.efi.= bak root@pops:~# diff -u <(hd < /boot/efi/EFI/debian/grubx64.efi.bak ) <(hd < /= boot/efi/EFI/debian/grubx64.efi ) =2D-- /dev/fd/63 2015-03-20 09:32:36.784878070 -0400 +++ /dev/fd/62 2015-03-20 09:32:36.784878070 -0400 @@ -6,7 +6,7 @@ 00000050 69 73 20 70 72 6f 67 72 61 6d 20 63 61 6e 6e 6f |is program ca= nno| 00000060 74 20 62 65 20 72 75 6e 20 69 6e 20 44 4f 53 20 |t be run in D= OS | 00000070 6d 6f 64 65 2e 0d 0d 0a 24 00 00 00 00 00 00 00 |mode....$....= ...| =2D00000080 50 45 00 00 64 86 04 00 30 21 0c 55 00 00 00 00 |PE..d...0!.= U....| +00000080 50 45 00 00 64 86 04 00 42 21 0c 55 00 00 00 00 |PE..d...B!.U.= ...| 00000090 00 00 00 00 f0 00 0e 02 0b 02 00 00 00 96 00 00 |.............= ...| 000000a0 00 2c 01 00 00 00 00 00 00 04 00 00 00 04 00 00 |.,...........= ...| 000000b0 00 00 00 00 00 00 00 00 00 02 00 00 00 02 00 00 |.............= ...| root@pops:~# These are definitely timestamps, as the two files were generated about 20 seconds apart, and 0x42 - 0x30 =3D 0x12 =3D 18. Here's the timestamp-to-date conversion: $ date -d \@$(printf '%d' 0x550c2130) Fri Mar 20 09:31:28 EDT 2015 $ This seems like a spurious change to me, and one that makes it harder to do things like compare checksums to make sure no one has tampered with the bootloader, or keeping a signature valid for the bootloader as blob. Is there a reason to embed the timestamps here? in practice, PE executables seem to be able to work with an all-zero timestamp (e.g. see ld's --no-insert-timestamp option). It looks like we're also embedding the timestamp for UBOOT images. This should be fixable with the following change, which covers both efi (first hunk) and uboot (second hunk): =2D--------- diff --git a/util/mkimage.c b/util/mkimage.c index 7821dc5..4b0f4de 100644 =2D-- a/util/mkimage.c +++ b/util/mkimage.c @@ -1439,7 +1439,7 @@ grub_install_generate_image (const char *dir, const c= har *prefix, c->machine =3D grub_host_to_target16 (image_target->pe_target); =20 c->num_sections =3D grub_host_to_target16 (4); =2D c->time =3D grub_host_to_target32 (time (0)); + c->time =3D grub_host_to_target32 (0); c->characteristics =3D grub_host_to_target16 (GRUB_PE32_EXECUTABLE_IMAGE | GRUB_PE32_LINE_NUMS_STRIPPED | ((image_target->voidp_sizeof =3D=3D 4) @@ -1782,7 +1782,7 @@ grub_install_generate_image (const char *dir, const c= har *prefix, =20 memset (hdr, 0, sizeof (*hdr)); hdr->ih_magic =3D grub_cpu_to_be32_compile_time (GRUB_UBOOT_IH_MAGIC= ); =2D hdr->ih_time =3D grub_cpu_to_be32 (time (0)); + hdr->ih_time =3D grub_cpu_to_be32 (0); hdr->ih_size =3D grub_cpu_to_be32 (core_size); hdr->ih_load =3D grub_cpu_to_be32 (image_target->link_addr); hdr->ih_ep =3D grub_cpu_to_be32 (image_target->link_addr); =2D--------- I notice that we're already embedding 0 for the timestamp for MIPS_ARC on util/mkimage:1859, so this isn't without precedent. If we want to get fancier, we could make an --embed-timestamp=3DSECONDS option to grub-install, which would allow the user to explicitly set the timestamp to a known value, or an --embed-current-timestamp option to actually use the output of time(0), but i wouldn't get that fancy without first hearing a strong argument for why we need an embedded timestamp in the first place. what do you think? --dkg --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQJ8BAEBCgBmBQJVDDEsXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXRFQjk2OTEyODdBN0FEREUzNzU3RDkxMUVB NTI0MDFCMTFCRkRGQTVDAAoJEKUkAbEb/fpcffcP/2dvAqneFC3w+2Ry8dYrLynp IFnNi6EQLKBmPbwvLAY1au/BRPL56d7Bw+qjMMsb1qIzK4kCtBMfhZsAp92JvrOA akzg7HqiBlZdxaF8JQqVJT7yqHkL/0DRn3xsWcfK81uS6NAPRi1/0LvdmLBz3Bsg ucRWUwnRB+1Oe+ZPxGXMabPdeZwGP2fnknRPw8/LEIQlHsKdLB6CpY1qKZvSj2vt o5r6M7G4gN9q0U0ZjLvSiPO25IXl9z/zT4mDuXN+10DkOxoi88zyWDx9Uu5I40n0 olGupFObo5gRYzrJgGloCiVEmp6LMLTcR0mtUEpvlskL+TgafrCgYsDF/fiU/J+g BIgvNgOENSA9XD6w9yfzvtgRsjtZUkMIZWxfkWOgJxxFW/seNmmeZDxvXevd/O5d IekQIBcb9UnMeJI4is8lkR3aoJHkVzShrdZuGwi4csG1ehIv37B0bby0TJQvPbOs RYulxtOM/EGC0aOgPcC0hsjbrneUhKS9V/9iNJH6Sgoq461t9sewqZeZBlL7Po59 vXscxiG2wsckuF6OkqdllDD6Z+1YKZsuazdWjY2yFsYdRyq6k+oE5MMcG6wh3A+0 BHh20/TFF9dyjUrk1zO7MrRjbciDbFKxpNLpsJ+CShFlKpTNgyJZD/Lq7sg87uze VDZoFh5GgMtNEiJDvGaE =u/QC -----END PGP SIGNATURE----- --=-=-=--