From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1YnUrF-0005fU-Bg for mharc-grub-devel@gnu.org; Wed, 29 Apr 2015 12:29:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55628) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnUrD-0005fL-9t for grub-devel@gnu.org; Wed, 29 Apr 2015 12:29:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnUr9-0005cK-Mx for grub-devel@gnu.org; Wed, 29 Apr 2015 12:29:07 -0400 Received: from mail-lb0-x22d.google.com ([2a00:1450:4010:c04::22d]:34410) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnUr9-0005cD-G5 for grub-devel@gnu.org; Wed, 29 Apr 2015 12:29:03 -0400 Received: by lbcga7 with SMTP id ga7so24519426lbc.1 for ; Wed, 29 Apr 2015 09:29:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type; bh=0itG0bcSCyWTPn/cGtQa+ZDmn9atA63PO2WjHlRBjok=; b=svtBwtx3pMloLaNirPEHIambYgw3fNAlP/i3iZNPdSwI8TfaAWqSSNnuU/Df6iDOzm KGHYEk4miK1E8ejymmuo/ObZmP8aa5UToGMjk8CAccIsydqbzCJ8tTJTSCubMBtw8cj+ SEr6wyk3L7NRE/oZ6cUXhZUcvJhaZDrK+dF1BADjsMJe/wzhe9C3uP2x+Iy7nYabH7Nz DIgIxfZYfzgezpK1VlHEu5/zktsWWH+lMeVx59GtW7sCOVRtAfToaPo8f+0Hhrs2/lHG FPGd8Tkvq6d1Eih5Mke3+8Lj9a+OPN77Tl+x3p126cb+D/NsmdmJgIRZjNUGBlijQ0yZ hbqw== X-Received: by 10.152.115.205 with SMTP id jq13mr19109573lab.2.1430324942360; Wed, 29 Apr 2015 09:29:02 -0700 (PDT) Received: from opensuse.site (ppp91-76-14-38.pppoe.mtu-net.ru. [91.76.14.38]) by mx.google.com with ESMTPSA id cq3sm4608844lad.14.2015.04.29.09.29.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Apr 2015 09:29:01 -0700 (PDT) Date: Wed, 29 Apr 2015 19:28:56 +0300 From: Andrei Borzenkov To: Vladimir =?UTF-8?B?J8+GLWNvZGVyL3BoY29kZXIn?= Serbinenko Subject: Re: [syslinux] Using memdisk with grub2 and a gzip-compressed ISO Message-ID: <20150429192856.0874a506@opensuse.site> In-Reply-To: <5540E2E4.1010807@gmail.com> References: <55396F5E.7090303@zytor.com> <20150424061443.3d80329c@opensuse.site> <5539B8C1.4030401@zytor.com> <20150424064128.71489695@opensuse.site> <5539C90A.9000608@zytor.com> <553EB638.4060704@zytor.com> <5540E2E4.1010807@gmail.com> X-Mailer: Claws Mail 3.11.0 (GTK+ 2.24.27; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; boundary="Sig_/ARUP.N/WFZgg+r1lHKkLnz3"; protocol="application/pgp-signature" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::22d Cc: The development of GNU GRUB 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: Wed, 29 Apr 2015 16:29:08 -0000 --Sig_/ARUP.N/WFZgg+r1lHKkLnz3 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable =D0=92 Wed, 29 Apr 2015 15:55:48 +0200 Vladimir '=CF=86-coder/phcoder' Serbinenko =D0=BF=D0=B8= =D1=88=D0=B5=D1=82: > On 28.04.2015 00:20, H. Peter Anvin wrote: > > On 04/23/2015 11:25 PM, Andrei Borzenkov via Syslinux wrote: > >> On Fri, Apr 24, 2015 at 7:39 AM, H. Peter Anvin wrote: > >>> On 04/23/2015 08:41 PM, Andrei Borzenkov wrote: > >>>> > >>>> CRC+length (in case of gzip) are located immediately after compressed > >>>> stream. After stream is decompressed you get location where it ends = and > >>>> automatically where length is located. > >>>> > >>> > >>> I know. One could decompress it twice, > >> > >> Cannot you incrementally reallocate uncompressed buffer? > >> > >=20 > > That is very hard because of how memory is managed in MEMDISK. > >=20 > It's fine to skip padding if only one file is supplied on command line. The only reason I can think of to use trailing padding at all is this line in Documentation/early-userspace/buffer-format.txt: cpio_trailer :=3D ALGN(4) + cpio_header + "TRAILER!!!\0" + ALGN(4) which mandates final alignment. Because grub does not really know whether file is initrd or initramfs and whether content is compressed or uncompressed cpio, it is much easier to simply pad everything. If we accept this as valid reason, number of files does not really matter. In practice kernel never required trailing alignment, at least since earliest git version in 2005. So I guess we can remove it.=20 > What about: > diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c > index 117232f..a63a11a 100644 > --- a/grub-core/loader/linux.c > +++ b/grub-core/loader/linux.c > @@ -205,7 +205,8 @@ grub_initrd_init (int argc, char *argv[], > initrd_ctx->nfiles++; > initrd_ctx->components[i].size > =3D grub_file_size (initrd_ctx->components[i].file); > - initrd_ctx->size +=3D ALIGN_UP (initrd_ctx->components[i].size, 4); > + if (argc !=3D 1) > + initrd_ctx->size +=3D ALIGN_UP (initrd_ctx->components[i].size, 4= ); > } >=20 This results in out-of-bound access in grub_initrd_load. The right fix is to pad before next file instead which automatically gives correct length in case of single file. I'll commit a patch. --Sig_/ARUP.N/WFZgg+r1lHKkLnz3 Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iEYEARECAAYFAlVBBssACgkQR6LMutpd94xsHACfQuE/jyjcHf3nctdKkUZl+Nv6 ZFkAoMXvV8S8G/ftQTz+mSLeCB/V3Buq =mX7Y -----END PGP SIGNATURE----- --Sig_/ARUP.N/WFZgg+r1lHKkLnz3--