From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1YnW2t-0004SZ-GH for mharc-grub-devel@gnu.org; Wed, 29 Apr 2015 13:45:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnW2n-0004Q7-Vx for grub-devel@gnu.org; Wed, 29 Apr 2015 13:45:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YnW2i-0000NV-QM for grub-devel@gnu.org; Wed, 29 Apr 2015 13:45:09 -0400 Received: from mail-la0-x229.google.com ([2a00:1450:4010:c03::229]:35727) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YnW2i-0000MC-JS for grub-devel@gnu.org; Wed, 29 Apr 2015 13:45:04 -0400 Received: by labbd9 with SMTP id bd9so25918160lab.2 for ; Wed, 29 Apr 2015 10:45:03 -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:content-transfer-encoding; bh=Pa0Zvh+ftUVh3mwkOWoh9xqnTQaVdczoi+N1yHnNSFE=; b=Z14JETJQRsYCgsmdSi4MXmVFfvV1GW56RYyvYdGJVu8AqDCxz5orfmLcGj/nHclF1X gw4TrF94AJcTijAxx5siKAdegQ6RJyMRBbQCQiZL0Sioa0w9TahwGDqi4rjZPukFuark 87lO4ozvE7Ib3dgE37HLkoQVIeLmbBTHdxd07xUMQWQNGeWcwd6w2r/I3xAO3oxQqrc8 ESBKKf+Gv0r0wcrg+68u2d3cBmFypepQVev9mAF1tuzqvfDmZFfHGQ9Rp7mRX1Yc7vWM yqkgCHz5QMj9PHdB76uHsMKvFRdf2QCI717x38LCk4cigKD3ppSyPKje8Qq+DRk7as4v S9Cg== X-Received: by 10.152.2.227 with SMTP id 3mr160379lax.73.1430329503759; Wed, 29 Apr 2015 10:45:03 -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 ra7sm6527235lbb.27.2015.04.29.10.45.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 29 Apr 2015 10:45:02 -0700 (PDT) Date: Wed, 29 Apr 2015 20:45:01 +0300 From: Andrei Borzenkov To: David Shaw Subject: Re: Using memdisk with grub2 and a gzip-compressed ISO Message-ID: <20150429204501.1d3e1021@opensuse.site> In-Reply-To: References: X-Mailer: Claws Mail 3.11.0 (GTK+ 2.24.27; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::229 Cc: grub-devel@gnu.org, syslinux@zytor.com 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 17:45:14 -0000 =D0=92 Thu, 23 Apr 2015 10:23:09 -0400 David Shaw =D0=BF=D0=B8=D1=88=D0=B5=D1=82: >=20 > When booting the box with grub2 2.02, it does not work. The error is: >=20 > Ramdisk at 0x37979000, length 0x0033b290 > gzip image: decompressed addr 0xbfff7000, len 0x00008f58: failed > Decompression error: output buffer overrun >=20 Could you test attached patch? While I'm past this message using your archive, in qemu-kvm it hangs after "... booting ..." and in qemu-system-i386 I get something that looks like memory corruption with occasional crash when initrd is uncompressed. From: Andrei Borzenkov Subject: [PATCH] loader/linux: do not pad initrd with zeroes at the end Syslinux memdisk is using initrd image and needs to know uncompressed size in advance. For gzip uncompressed size is at the end of compressed stream. Grub padded each input file to 4 bytes at the end, which means syslinux got wrong size. Linux initramfs loader apparently does not care about trailing alignment. So change code to align beginning of each file instead which automatically gives us the correct size for single file. Reported-By: David Shaw --- grub-core/loader/linux.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c index 117232f..35b858e 100644 --- a/grub-core/loader/linux.c +++ b/grub-core/loader/linux.c @@ -161,6 +161,9 @@ grub_initrd_init (int argc, char *argv[], for (i =3D 0; i < argc; i++) { const char *fname =3D argv[i]; + + initrd_ctx->size =3D ALIGN_UP (initrd_ctx->size, 4); + if (grub_memcmp (argv[i], "newc:", 5) =3D=3D 0) { const char *ptr, *eptr; @@ -205,7 +208,7 @@ 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); + initrd_ctx->size +=3D initrd_ctx->components[i].size; } =20 if (newc) @@ -253,6 +256,9 @@ grub_initrd_load (struct grub_linux_initrd_context *ini= trd_ctx, { grub_ssize_t cursize; =20 + grub_memset (ptr, 0, ALIGN_UP_OVERHEAD ((grub_addr_t)ptr, 4)); + ptr +=3D ALIGN_UP_OVERHEAD ((grub_addr_t)ptr, 4); + if (initrd_ctx->components[i].newc_name) { ptr +=3D insert_dir (initrd_ctx->components[i].newc_name, @@ -283,8 +289,6 @@ grub_initrd_load (struct grub_linux_initrd_context *ini= trd_ctx, return grub_errno; } ptr +=3D cursize; - grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); - ptr +=3D ALIGN_UP_OVERHEAD (cursize, 4); } if (newc) ptr =3D make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, = 0); --=20 tg: (104dff3..) u/initrd-pad (depends on: master)