All of lore.kernel.org
 help / color / mirror / Atom feed
From: hector@marcansoft.com (Hector Martin)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] Clean up ARM compressed loader
Date: Thu, 25 Feb 2010 01:30:28 +0100	[thread overview]
Message-ID: <4B85C4A4.4060005@marcansoft.com> (raw)
In-Reply-To: <20100225000114.GB21985@n2100.arm.linux.org.uk>

Russell King - ARM Linux wrote:
> On Thu, Feb 25, 2010 at 12:57:20AM +0100, Hector Martin wrote:
>> Russell King - ARM Linux wrote:
>>> On Wed, Feb 24, 2010 at 06:34:49PM -0500, Nicolas Pitre wrote:
>>>> What about simply not compiling the decompressor with -fPIC when using 
>>>> ZBOOT_ROM=y?  That would certainly solve the problem with the only 
>>>> restriction that such kernel images won't be bootable from RAM which is 
>>>> probably an acceptable compromize.
>>> Unfortunately, that doesn't solve the stack-bashing with ZBOOT_ROM=n.
>> Yes it does, that's exactly what my first version of the patch did. Once
>> you get rid of the partial relocation used for ROM builds (with split
>> text/bss) you don't need -Dstatic=, and once you get rid of that you
>> solve the stack-bashing. The ROM build becomes a bog standard
>> non-relocatable ROM image (with the usual LMA/VMA linker script stuff to
>> copy initialized data to RAM), and the RAM build becomes a bog standard
>> relocatable image (a single contiguous blob including
>> text/rodata/data/bss) that doesn't suffer from any issues when you move
>> it around.
> 
> Did you bother to read my previous reply explaining that this is not
> a hack for the toolchain?  It sounds to me like you didn't.

Are you new to C? It looks like you are seriously still claiming that
-Dstatic= is A-OK under all circumstances. It very obviously isn't.

In your other e-mail, you're missing the point. You're arguing that
compiler behavior regarding access to data (particularly that with
static vs. global visibility) is well-defined enough that you can
guarantee that GOT-relative accesses will not happen as long as you
avoid static data. I'm still not convinced, but that's not my main point.

The problem is that -Dstatic= isn't a magical safe way of making objects
globally visible, because the 'static' keyword in C means different
things in different places. Specifically, it means a totally different
thing inside functions. Instead of turning a static file-global array
into a globally visible array, you're turning a static (as in
non-stack-allocated) array inside a function into a stack-allocated
array. And as no doubt you're aware, stack objects become undefined once
the function exits, and references to them are invalid. Welcome to our
inflate heisenbug:

static void zlib_fixedtables(struct inflate_state *state)

{

#   include "inffixed.h"  /* static blah {len,dist}fix[] = {...}; */
    state->lencode = lenfix;

    state->lenbits = 9;

    state->distcode = distfix;

    state->distbits = 5;

}

Guess what happens when you remove the static keywords there.

Long story short, -Dstatic= isn't accomplishing what you want, because
it's crude and doesn't handle all cases properly. If you want to keep
the current model, you have to be willing to manually watch changes to
the decompressor implementations so they do not violate your assumptions
(i.e. never use static inside functions and rely on it, at least),
because -Dstatic= will break valid C code. Under _all_ circumstances, no
matter what your other compiler flags are or how you link and load
stuff, -Dstatic= is guaranteed to break some valid C code, and that's
what's happening here.

Sure, you could patch up the issue by moving the #include out of the
function above, but then you'd better be willing to watch for anything
like that anywhere in decompressor code used for ARM, because other
kernel developers aren't going to know that ARM silently discards their
static keywords. I'm not even sure this is the only broken code so far,
there could be more.

-- 
Hector Martin (hector at marcansoft.com)
Public Key: http://www.marcansoft.com/marcan.asc

  reply	other threads:[~2010-02-25  0:30 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-24  2:23 [PATCH] Clean up ARM compressed loader Hector Martin
2010-02-24  8:51 ` Uwe Kleine-König
2010-02-24  9:28   ` Hector Martin
2010-02-24 22:34 ` Russell King - ARM Linux
2010-02-24 23:34   ` Nicolas Pitre
2010-02-24 23:42     ` Russell King - ARM Linux
2010-02-24 23:57       ` Hector Martin
2010-02-25  0:01         ` Russell King - ARM Linux
2010-02-25  0:30           ` Hector Martin [this message]
2010-02-25  4:28             ` Nicolas Pitre
2010-02-25  4:33               ` Nicolas Pitre
2010-02-25  9:38               ` Russell King - ARM Linux
2010-02-25 10:05                 ` Hector Martin
2010-02-25 18:35                   ` Nicolas Pitre
2010-02-25 19:21                     ` Hector Martin
2010-02-25 19:40                       ` Nicolas Pitre
2010-02-25 19:56                         ` Hector Martin
2010-02-25 20:29                           ` Nicolas Pitre
2010-02-25 21:05                             ` Russell King - ARM Linux
2010-02-25 21:25                               ` Nicolas Pitre
2010-02-25 20:30                         ` Russell King - ARM Linux
2010-02-25 12:24                 ` Russell King - ARM Linux
2010-02-25 19:24                   ` Nicolas Pitre
2010-02-25 19:34                     ` Russell King - ARM Linux
2010-02-25 23:48                     ` Russell King - ARM Linux
2010-02-25 23:55                       ` Russell King - ARM Linux
2010-02-25  9:51               ` Hector Martin
2010-02-25 18:30                 ` Nicolas Pitre
2010-02-25  8:23             ` Russell King - ARM Linux
2010-02-25  4:06         ` Nicolas Pitre
  -- strict thread matches above, loose matches on Subject: below --
2010-02-23 13:57 hector at marcansoft.com
2010-02-23 14:07 ` Russell King - ARM Linux
2010-02-24  8:42 ` Uwe Kleine-König
2010-02-24  9:27   ` Hector Martin
2010-02-24 11:03     ` Russell King - ARM Linux
2010-02-24 15:20       ` Hector Martin
2010-02-24 15:30         ` Uwe Kleine-König
2010-02-24 22:09           ` Hector Martin
2010-02-24 22:30             ` Russell King - ARM Linux
2010-02-25  0:01               ` Hector Martin
2010-02-24 16:29         ` Russell King - ARM Linux

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=4B85C4A4.4060005@marcansoft.com \
    --to=hector@marcansoft.com \
    --cc=linux-arm-kernel@lists.infradead.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.