From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ZsG2p-0001Lc-Oq for mharc-grub-devel@gnu.org; Fri, 30 Oct 2015 16:13:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZsG2l-0001J4-Ds for grub-devel@gnu.org; Fri, 30 Oct 2015 16:13:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZsG2k-0003m2-4d for grub-devel@gnu.org; Fri, 30 Oct 2015 16:12:59 -0400 Received: from mail-wi0-x22d.google.com ([2a00:1450:400c:c05::22d]:34702) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZsG2j-0003ly-QP for grub-devel@gnu.org; Fri, 30 Oct 2015 16:12:58 -0400 Received: by wikq8 with SMTP id q8so18169285wik.1 for ; Fri, 30 Oct 2015 13:12:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type; bh=TU2mDiJXKivrMHS1konC2BKNG+qSZYujBEbHLor9T9k=; b=S+X6Zw6/ZutyDwcXk0sX2kWQG4L4rrreAlfsSmay7K6U2yGCr1l20WzTJ22KiJy75h jW35d4pgbjkqRL23pfzwAj44EyrPvH63DjPikpxPrL/1shUgmQYeQjYB7rZVZaks8Jv3 ESE0ToHValfb1WN22drYnG4CqJW7hSdbFkiSkGROumgBitTDA7MPkC8rVnOc+yazliVT 8tZ1QM8AMFsawftfriA5xmkvBErFBbZ/4pNzcIU2SrDyPm7FdZu240rdGJGeR333zQhQ rkmBHKYGjst9HL3P0DHexDKNCIaCQOg+VbbJR2tSkjEFXJHnH+hySDVTWct32zp4VMRm u1XQ== X-Received: by 10.194.61.70 with SMTP id n6mr10221515wjr.81.1446235977096; Fri, 30 Oct 2015 13:12:57 -0700 (PDT) Received: from ?IPv6:2a02:1205:34c8:dc00:863a:4bff:fe50:abc4? ([2a02:1205:34c8:dc00:863a:4bff:fe50:abc4]) by smtp.gmail.com with ESMTPSA id cr5sm8646510wjb.16.2015.10.30.13.12.56 for (version=TLSv1/SSLv3 cipher=OTHER); Fri, 30 Oct 2015 13:12:56 -0700 (PDT) Subject: Re: [PATCH] mkimage: zero fill alignment space To: The development of GNU GRUB References: <1446220198-29899-1-git-send-email-arvidjaar@gmail.com> From: =?UTF-8?Q?Vladimir_'=cf=86-coder/phcoder'_Serbinenko?= Message-ID: <5633CF47.6060905@gmail.com> Date: Fri, 30 Oct 2015 21:12:55 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.3.0 MIME-Version: 1.0 In-Reply-To: <1446220198-29899-1-git-send-email-arvidjaar@gmail.com> Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="7M8fUNpAFRgMg3eRe5Wwfmg2fIGXCWawh" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22d 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, 30 Oct 2015 20:13:01 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7M8fUNpAFRgMg3eRe5Wwfmg2fIGXCWawh Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 30.10.2015 16:49, Andrei Borzenkov wrote: > This did not cause real problem but is good for reproducible builds. I = hit > it with recent bootinfoscript that displays embedded config; I was puzz= led > by random garbage at the end. >=20 > Also remove redundant zeroing code where we fill in the whole memory bl= ock > anyway. >=20 Could we just zero-out the whole block when we allocate it to have an easier code and avoid it happening again? > --- > util/mkimage.c | 29 +++++++++++++---------------- > 1 file changed, 13 insertions(+), 16 deletions(-) >=20 > diff --git a/util/mkimage.c b/util/mkimage.c > index 35df998..1c522fe 100644 > --- a/util/mkimage.c > +++ b/util/mkimage.c > @@ -992,7 +992,7 @@ grub_install_generate_image (const char *dir, const= char *prefix, > { > char *kernel_img, *core_img; > size_t kernel_size, total_module_size, core_size, exec_size; > - size_t memdisk_size =3D 0, config_size =3D 0, config_size_pure =3D 0= ; > + size_t memdisk_size =3D 0, memdisk_size_pure =3D 0, config_size =3D = 0, config_size_pure =3D 0; > size_t prefix_size =3D 0; > char *kernel_path; > size_t offset; > @@ -1035,7 +1035,8 @@ grub_install_generate_image (const char *dir, con= st char *prefix, > =20 > if (memdisk_path) > { > - memdisk_size =3D ALIGN_UP(grub_util_get_image_size (memdisk_path= ), 512); > + memdisk_size_pure =3D grub_util_get_image_size (memdisk_path); > + memdisk_size =3D ALIGN_UP(memdisk_size_pure, 512); > grub_util_info ("the size of memory disk is 0x%" GRUB_HOST_PRIxL= ONG_LONG, > (unsigned long long) memdisk_size); > total_module_size +=3D memdisk_size + sizeof (struct grub_module= _header); > @@ -1043,8 +1044,8 @@ grub_install_generate_image (const char *dir, con= st char *prefix, > =20 > if (config_path) > { > - config_size_pure =3D grub_util_get_image_size (config_path) + 1;= > - config_size =3D ALIGN_ADDR (config_size_pure); > + config_size_pure =3D grub_util_get_image_size (config_path); > + config_size =3D ALIGN_ADDR (config_size_pure + 1); > grub_util_info ("the size of config file is 0x%" GRUB_HOST_PRIxL= ONG_LONG, > (unsigned long long) config_size); > total_module_size +=3D config_size + sizeof (struct grub_module_= header); > @@ -1140,19 +1141,21 @@ grub_install_generate_image (const char *dir, c= onst char *prefix, > size_t i; > for (i =3D 0; i < npubkeys; i++) > { > - size_t curs; > struct grub_module_header *header; > + size_t key_size, orig_size; > =20 > - curs =3D grub_util_get_image_size (pubkey_paths[i]); > + orig_size =3D grub_util_get_image_size (pubkey_paths[i]); > + key_size =3D ALIGN_ADDR (orig_size); > =20 > header =3D (struct grub_module_header *) (kernel_img + offset); > memset (header, 0, sizeof (struct grub_module_header)); > header->type =3D grub_host_to_target32 (OBJ_TYPE_PUBKEY); > - header->size =3D grub_host_to_target32 (curs + sizeof (*header)); > + header->size =3D grub_host_to_target32 (key_size + sizeof (*header));= > offset +=3D sizeof (*header); > =20 > grub_util_load_image (pubkey_paths[i], kernel_img + offset); > - offset +=3D ALIGN_ADDR (curs); > + memset (kernel_img + offset + orig_size, 0, key_size - orig_size); > + offset +=3D key_size; > } > } > =20 > @@ -1167,6 +1170,7 @@ grub_install_generate_image (const char *dir, con= st char *prefix, > offset +=3D sizeof (*header); > =20 > grub_util_load_image (memdisk_path, kernel_img + offset); > + memset (kernel_img + offset + memdisk_size_pure, 0, memdisk_size= - memdisk_size_pure); > offset +=3D memdisk_size; > } > =20 > @@ -1181,7 +1185,7 @@ grub_install_generate_image (const char *dir, con= st char *prefix, > offset +=3D sizeof (*header); > =20 > grub_util_load_image (config_path, kernel_img + offset); > - *(kernel_img + offset + config_size_pure - 1) =3D 0; > + memset (kernel_img + offset + config_size_pure, 0, config_size -= config_size_pure); > offset +=3D config_size; > } > =20 > @@ -1267,17 +1271,10 @@ grub_install_generate_image (const char *dir, c= onst char *prefix, > =3D grub_host_to_target_addr (image_target->link_addr); > } > full_size =3D core_size + decompress_size; > - > full_img =3D xmalloc (full_size); > - memset (full_img, 0, full_size);=20 > - > memcpy (full_img, decompress_img, decompress_size); > - > memcpy (full_img + decompress_size, core_img, core_size); > =20 > - memset (full_img + decompress_size + core_size, 0, > - full_size - (decompress_size + core_size)); > - > free (core_img); > core_img =3D full_img; > core_size =3D full_size; >=20 --7M8fUNpAFRgMg3eRe5Wwfmg2fIGXCWawh Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iF4EAREKAAYFAlYzz0cACgkQmBXlbbo5nOseOQEAqFEIp9nehXNb4vrVD2gbkSdN 6RUpnlajBgHbb3EyBEIA+gKiNED/WlxrxZLt06W1o30XRd/N9O7hM6u2zbzDLBPZ =0Z1r -----END PGP SIGNATURE----- --7M8fUNpAFRgMg3eRe5Wwfmg2fIGXCWawh--