mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michal Marek <mmarek@suse.cz>
To: Olof Johansson <olof@lixom.net>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
	Sam Ravnborg <sam@ravnborg.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, raymes@google.com
Subject: Re: [PATCH] modpost: Fix address calculation in reloc_location()
Date: Tue, 28 Dec 2010 00:53:05 +0100	[thread overview]
Message-ID: <20101227235305.GG21436@pobox.suse.cz> (raw)
In-Reply-To: <20101210080923.GA13474@lixom.net>

On Fri, Dec 10, 2010 at 02:09:23AM -0600, Olof Johansson wrote:
> This patch fixes a segfault in modpost that is observed when the gold
> linker is used to link the input objects.
> 
> The problem is that reloc_location (modpost.c) is computing the
> address of the relocation target incorrectly. Here, elf->hdr points
> to the beginning of the ELF file in memory, sechdr points to the
> relocation section header, section is the index of the section
> being relocated, and sechdrs[section].sh_offset would be the offset
> of that section, relative to the beginning of the ELF file. Adding
> elf->hdr + sechdrs[section].sh_offset gives you the address of the
> beginning of the section, and adding r->r_offset to that gives you the
> address of the location to be relocated. You do not need to subtract
> sechdrs[section].sh_addr from that -- the result of this is an address
> outside the file, and causes the segfault when addend_386_rel tries to
> dereference it.
> 
> This bug is not observed when GNU ld is used to link the inputs. The
> object file ubuntu/omnibook/omnibook.o is the result of an ld -r of
> several other files.  When GNU ld does an ld -r, it sets the vaddr
> field for each section to 0, but gold lays out the section addresses
> sequentially instead:
> 
> Section Headers:
>  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
>  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
>  [ 1] .text             PROGBITS        00000000 000034 004794 00  AX  0   0  4
>  [ 2] .data             PROGBITS        0000b9d0 0047c8 0009c0 00  WA  0   0  4
>  [ 3] .bss              NOBITS          000162f8 005188 00013c 00  WA  0   0  4
>  [ 4] .rodata.str1.1    PROGBITS        00004f2d 0052c4 001b1a 01 AMS  0   0  1
>  [ 5] .init.text        PROGBITS        00004794 006dde 0005fa 00  AX  0   0  1
>  [ 6] .exit.text        PROGBITS        00004d8e 0073d8 00018a 00  AX  0   0  1
>   ...
> 
> So the bug in the tool remained undiscovered because the section's vaddr
> always happened to be 0.
> 
> Signed-off-by: Raymes Khoury <raymes@google.com>
> Signed-off-by: Olof Johansson <olof@lixom.net>
> 
> ---
>  scripts/mod/modpost.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)

Thanks, applied to kbuild-2.6.git#kbuild.

Michal

      reply	other threads:[~2010-12-27 23:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-10  8:09 Olof Johansson
2010-12-27 23:53 ` Michal Marek [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=20101227235305.GG21436@pobox.suse.cz \
    --to=mmarek@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olof@lixom.net \
    --cc=raymes@google.com \
    --cc=rusty@rustcorp.com.au \
    --cc=sam@ravnborg.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®