From: Baoquan He <bhe@redhat.com>
To: Kees Cook <keescook@chromium.org>
Cc: Borislav Petkov <bp@suse.de>, Ingo Molnar <mingo@kernel.org>,
Yinghai Lu <yinghai@kernel.org>, Ingo Molnar <mingo@redhat.com>,
"x86@kernel.org" <x86@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Andrey Ryabinin <aryabinin@virtuozzo.com>,
Dmitry Vyukov <dvyukov@google.com>,
"H.J. Lu" <hjl.tools@gmail.com>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Andy Lutomirski <luto@kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/5] x86, KASLR: Update description for decompressor worst case size
Date: Fri, 22 Apr 2016 11:13:22 +0800 [thread overview]
Message-ID: <20160422031322.GA2478@x1.redhat.com> (raw)
In-Reply-To: <CAGXu5j+qzY=nB6JKZipWfRx_jzTyh8OnyHyFg0jYvnS6uJiAJw@mail.gmail.com>
On 04/21/16 at 01:04pm, Kees Cook wrote:
> On Thu, Apr 21, 2016 at 7:47 AM, Borislav Petkov <bp@suse.de> wrote:
> > On Wed, Apr 20, 2016 at 01:55:42PM -0700, Kees Cook wrote:
> > ...
> > What's "non compressed data overhead"?
> >
> > Does that want to say:
> >
> > "... resulting in 18 bytes overhead of uncompressed data."
> >
> > perhaps?
>
> Yeah, that reads much more clearly. I'll change it.
>
> >> +#
> >> +# Files divided into blocks
> >> +# 1 bit (last block flag)
> >> +# 2 bits (block type)
> >> +#
> >> +# 1 block occurs every 32K -1 bytes or when there 50% compression
> >> +# has been achieved. The smallest block type encoding is always used.
> >> +#
> >> +# stored:
> >> +# 32 bits length in bytes.
> >> +#
> >> +# fixed:
> >> +# magic fixed tree.
> >> +# symbols.
> >> +#
> >> +# dynamic:
> >> +# dynamic tree encoding.
> >> +# symbols.
> >> +#
> >> +#
> >> +# The buffer for decompression in place is the length of the uncompressed
> >> +# data, plus a small amount extra to keep the algorithm safe. The
> >> +# compressed data is placed at the end of the buffer. The output pointer
> >> +# is placed at the start of the buffer and the input pointer is placed
> >> +# where the compressed data starts. Problems will occur when the output
> >> +# pointer overruns the input pointer.
> >> +#
> >> +# The output pointer can only overrun the input pointer if the input
> >> +# pointer is moving faster than the output pointer. A condition only
> >> +# triggered by data whose compressed form is larger than the uncompressed
> >> +# form.
> >> +#
> >> +# The worst case at the block level is a growth of the compressed data
> >> +# of 5 bytes per 32767 bytes.
> >> +#
> >> +# The worst case internal to a compressed block is very hard to figure.
> >> +# The worst case can at least be bounded by having one bit that represents
> >> +# 32764 bytes and then all of the rest of the bytes representing the very
> >> +# very last byte.
> >> +#
> >> +# All of which is enough to compute an amount of extra data that is required
> >> +# to be safe. To avoid problems at the block level allocating 5 extra bytes
> >> +# per 32767 bytes of data is sufficient. To avoid problems internal to a
> >> +# block adding an extra 32767 bytes (the worst case uncompressed block size)
> >> +# is sufficient, to ensure that in the worst case the decompressed data for
> >> +# block will stop the byte before the compressed data for a block begins.
> >> +# To avoid problems with the compressed data's meta information an extra 18
> >> +# bytes are needed. Leading to the formula:
> >> +#
> >> +# extra_bytes = (uncompressed_size >> 12) + 32768 + 18 + decompressor_size
> >> +#
> >> +# Adding 8 bytes per 32K is a bit excessive but much easier to calculate.
> >> +# Adding 32768 instead of 32767 just makes for round numbers.
> >> +# Adding the decompressor_size is necessary as it musht live after all
> >> +# of the data as well. Last I measured the decompressor is about 14K.
> >> +# 10K of actual data and 4K of bss.
> >
> > I guess reflow the paragraphs while at it, as well?
> >
> > "Adding 8 bytes per 32K is a bit excessive but much easier to calculate.
> > Adding 32768 instead of 32767 just makes for round numbers. Adding the
> > decompressor_size is necessary as it musht live after all of the data as
~~must
There's a typo here, it should be 'must'. I didn't notice before. It
might be fixed when take Boris's paragraph reflowing. :)
> > well. Last I measured the decompressor is about 14K. 10K of actual data
> > and 4K of bss."
> >
> > and so on...
>
> Yeah, I'd been reflowing as I went and I went back and forth on that
> one. It looked like it was a list ("Adding... Adding... Adding...") so
> I'd left it, but my initial instinct matches your: it should just get
> reflowed like all the rest.
>
> I'll fix that too.
>
> Thanks for the review!
>
> -Kees
>
> --
> Kees Cook
> Chrome OS & Brillo Security
next prev parent reply other threads:[~2016-04-22 3:13 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-20 20:55 [PATCH 0/5] x86, boot: clean up KASLR code (step 2) Kees Cook
2016-04-20 20:55 ` [PATCH 1/5] x86, KASLR: Update description for decompressor worst case size Kees Cook
2016-04-21 14:47 ` Borislav Petkov
2016-04-21 20:04 ` Kees Cook
2016-04-22 3:13 ` Baoquan He [this message]
2016-04-22 7:41 ` Ingo Molnar
2016-04-22 9:45 ` [tip:x86/boot] x86/KASLR: " tip-bot for Baoquan He
2016-04-20 20:55 ` [PATCH 2/5] x86, KASLR: Drop CONFIG_RANDOMIZE_BASE_MAX_OFFSET Kees Cook
2016-04-21 17:44 ` Borislav Petkov
2016-04-21 18:13 ` Kees Cook
2016-04-22 7:16 ` Ingo Molnar
2016-04-22 9:43 ` Borislav Petkov
2016-04-22 9:45 ` [tip:x86/boot] x86/KASLR: " tip-bot for Baoquan He
2016-04-20 20:55 ` [PATCH 3/5] x86, boot: Clean up things used by decompressors Kees Cook
2016-04-22 9:46 ` [tip:x86/boot] x86/boot: " tip-bot for Kees Cook
2016-04-20 20:55 ` [PATCH 4/5] x86, boot: Make memcpy handle overlaps Kees Cook
2016-04-22 7:49 ` Ingo Molnar
2016-04-22 22:18 ` Kees Cook
2016-04-22 7:56 ` Ingo Molnar
2016-04-22 9:46 ` [tip:x86/boot] x86/boot: Make memcpy() " tip-bot for Kees Cook
2016-04-22 21:05 ` Lasse Collin
2016-04-22 22:01 ` Kees Cook
2016-04-20 20:55 ` [PATCH 5/5] x86, KASLR: Warn when KASLR is disabled Kees Cook
2016-04-22 9:47 ` [tip:x86/boot] x86/KASLR: " tip-bot for Kees Cook
2016-04-22 7:43 ` [PATCH 0/5] x86, boot: clean up KASLR code (step 2) Ingo Molnar
2016-04-22 15:39 ` Kees Cook
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=20160422031322.GA2478@x1.redhat.com \
--to=bhe@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=aryabinin@virtuozzo.com \
--cc=bp@suse.de \
--cc=dvyukov@google.com \
--cc=hjl.tools@gmail.com \
--cc=jpoimboe@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=x86@kernel.org \
--cc=yinghai@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 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.