All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrei Borzenkov <arvidjaar@gmail.com>
To: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
Cc: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: [syslinux] Using memdisk with grub2 and a gzip-compressed ISO
Date: Wed, 29 Apr 2015 19:28:56 +0300	[thread overview]
Message-ID: <20150429192856.0874a506@opensuse.site> (raw)
In-Reply-To: <5540E2E4.1010807@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2257 bytes --]

В Wed, 29 Apr 2015 15:55:48 +0200
Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com> пишет:

> 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 <hpa@zytor.com> 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?
> >>
> > 
> > That is very hard because of how memory is managed in MEMDISK.
> > 
> 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 := 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. 

> 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
>         = grub_file_size (initrd_ctx->components[i].file);
> -      initrd_ctx->size += ALIGN_UP (initrd_ctx->components[i].size, 4);
> +      if (argc != 1)
> +       initrd_ctx->size += ALIGN_UP (initrd_ctx->components[i].size, 4);
>      }
> 

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.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

  reply	other threads:[~2015-04-29 16:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-23 14:23 Using memdisk with grub2 and a gzip-compressed ISO David Shaw
2015-04-23 16:59 ` Andrei Borzenkov
2015-04-23 22:17 ` [syslinux] " H. Peter Anvin
2015-04-24  3:14   ` Andrei Borzenkov
2015-04-24  3:30     ` H. Peter Anvin
2015-04-24  3:41       ` Andrei Borzenkov
2015-04-24  4:39         ` H. Peter Anvin
2015-04-24  6:25           ` Andrei Borzenkov
2015-04-27 22:20             ` H. Peter Anvin
2015-04-29 13:55               ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-04-29 16:28                 ` Andrei Borzenkov [this message]
2015-04-29 17:45 ` Andrei Borzenkov
2015-04-29 18:35   ` Vladimir 'phcoder' Serbinenko
2015-04-30  3:36     ` Andrei Borzenkov
2015-04-29 18:42   ` David Shaw
2015-05-07 14:23   ` Vladimir 'φ-coder/phcoder' Serbinenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150429192856.0874a506@opensuse.site \
    --to=arvidjaar@gmail.com \
    --cc=grub-devel@gnu.org \
    --cc=phcoder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.