[PATCH for stable] kbuild: Fix modpost segfault

From: Michal Marek
Date: Tue Jun 29 2010 - 05:43:59 EST


Hi Greg,

please add this to stable, it's a bug that started showing up with newer
gcc. The upstream commit is 1c938663d58b5b2965976a6f54cc51b5d6f691aa.

Thanks,
Michal

From: Krzysztof Halasa <khc@xxxxxxxxx>

Alan <alan@xxxxxxxxxxxxxx> writes:

> program: /home/alan/GitTrees/linux-2.6-mid-ref/scripts/mod/modpost -o
> Module.symvers -S vmlinux.o
>
> Program received signal SIGSEGV, Segmentation fault.

It just hit me.
It's the offset calculation in reloc_location() which overflows:
return (void *)elf->hdr + sechdrs[section].sh_offset +
(r->r_offset - sechdrs[section].sh_addr);

E.g. for the first rodata r entry:
r->r_offset < sechdrs[section].sh_addr
and the expression in the parenthesis produces 0xFFFFFFE0 or something
equally wise.

Reported-by: Alan <alan@xxxxxxxxxxxxxx>
Signed-off-by: Krzysztof HaÅasa <khc@xxxxxxxxx>
Tested-by: Alan <alan@xxxxxxxxxxxxxx>
Signed-off-by: Michal Marek <mmarek@xxxxxxx>


diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 3318692..f877900 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1342,7 +1342,7 @@ static unsigned int *reloc_location(struct elf_info *elf,
int section = sechdr->sh_info;

return (void *)elf->hdr + sechdrs[section].sh_offset +
- (r->r_offset - sechdrs[section].sh_addr);
+ r->r_offset - sechdrs[section].sh_addr;
}

static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/