mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Aaro Koskinen <aaro.koskinen@iki.fi>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Aaro Koskinen <aaro.koskinen@iki.fi>,
	linux-kernel@vger.kernel.org, hsweeten@visionengravers.com,
	hpa@zytor.com, eric.piel@tremplin-utc.net,
	stable <stable@kernel.org>
Subject: Re: [PATCH] initramfs: prevent buffer overflow when unpacking to rootfs
Date: Sat, 3 Apr 2010 23:41:18 +0300 (EEST)	[thread overview]
Message-ID: <alpine.DEB.1.10.1004032332520.22263@loser> (raw)
In-Reply-To: <20100402145702.fb9ccfdc.akpm@linux-foundation.org>

On Fri, 2 Apr 2010, Andrew Morton wrote:
> On Thu,  1 Apr 2010 12:45:46 +0300
> Aaro Koskinen <aaro.koskinen@iki.fi> wrote:
>
>> Garbage in the initrd memory area may result in the unpack routine
>> accessing memory outside the buffer. The patch adds a check that the
>> specified area size is not exceeded.
>>
>> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
>> Cc: stable <stable@kernel.org>
>> ---
>>
>> The patch prevents the following kernel panic on Amstrad E3:
>>
>> 	Unpacking initramfs...
>> 	Unable to handle kernel paging request at virtual address c20121a7
>>
>> ...
>>
>> --- a/init/initramfs.c
>> +++ b/init/initramfs.c
>> @@ -460,6 +460,8 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len)
>>  		}
>>  		if (state != Reset)
>>  			error("junk in compressed archive");
>> +		if (my_inptr >= len)
>> +			break;
>>  		this_header = saved_offset + my_inptr;
>>  		buf += my_inptr;
>>  		len -= my_inptr;
>
> OK, so if I'm understanding this right, the call to
>
> 	decompress(buf, len, NULL, flush_buffer, NULL, &my_inptr, error);
>
> has gone and generated more output data than it was asked to generate?
>
> If so, isn't that a bug in the decompressor?  Which one is your system using?

The decompressor is gzip, and it returned correct buffer position.

The problem was that the loop in unpack_to_rootfs() continued
to process the remaining buffer. my_inptr was never again updated
(decompress_method() did not recognize the remaining garbage data, so
there was no further calls to decompressor). The loop kept subtracting
my_inptr from len eventually exceeding it. Perhaps there should be some
better logic to give up earlier.

A.

      reply	other threads:[~2010-04-03 20:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-01  9:45 Aaro Koskinen
2010-04-02 21:57 ` Andrew Morton
2010-04-03 20:41   ` Aaro Koskinen [this message]

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=alpine.DEB.1.10.1004032332520.22263@loser \
    --to=aaro.koskinen@iki.fi \
    --cc=akpm@linux-foundation.org \
    --cc=eric.piel@tremplin-utc.net \
    --cc=hpa@zytor.com \
    --cc=hsweeten@visionengravers.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®