diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2012-10-25 10:49:25 +1030 |
---|---|---|
committer | Ben Hutchings <ben@decadent.org.uk> | 2012-11-16 16:47:01 +0000 |
commit | 1d60939abd811d472171dfe714c3d25804fc2693 (patch) | |
tree | d689986e688b7c88dc1249457da098d7477e213b /kernel/module.c | |
parent | ee5e9ba331c346da00557849bbe75ba7e2be3333 (diff) | |
download | linux-stable-1d60939abd811d472171dfe714c3d25804fc2693.tar.gz linux-stable-1d60939abd811d472171dfe714c3d25804fc2693.tar.bz2 linux-stable-1d60939abd811d472171dfe714c3d25804fc2693.zip |
module: fix out-by-one error in kallsyms
commit 59ef28b1f14899b10d6b2682c7057ca00a9a3f47 upstream.
Masaki found and patched a kallsyms issue: the last symbol in a
module's symtab wasn't transferred. This is because we manually copy
the zero'th entry (which is always empty) then copy the rest in a loop
starting at 1, though from src[0]. His fix was minimal, I prefer to
rewrite the loops in more standard form.
There are two loops: one to get the size, and one to copy. Make these
identical: always count entry 0 and any defined symbol in an allocated
non-init section.
This bug exists since the following commit was introduced.
module: reduce symbol table for loaded modules (v2)
commit: 4a4962263f07d14660849ec134ee42b63e95ea9a
LKML: http://lkml.org/lkml/2012/10/24/27
Reported-by: Masaki Kimura <masaki.kimura.kz@hitachi.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
[bwh: Backported to 3.2: we're still using a bitmap to compress the string
table]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Diffstat (limited to 'kernel/module.c')
-rw-r--r-- | kernel/module.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/kernel/module.c b/kernel/module.c index 6c8fa3401833..65362d9ab783 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -2193,15 +2193,17 @@ static void layout_symtab(struct module *mod, struct load_info *info) src = (void *)info->hdr + symsect->sh_offset; nsrc = symsect->sh_size / sizeof(*src); - for (ndst = i = 1; i < nsrc; ++i, ++src) - if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) { - unsigned int j = src->st_name; + for (ndst = i = 0; i < nsrc; i++) { + if (i == 0 || + is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) { + unsigned int j = src[i].st_name; while (!__test_and_set_bit(j, info->strmap) && info->strtab[j]) ++j; ++ndst; } + } /* Append room for core symbols at end of core part. */ info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1); @@ -2238,14 +2240,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info) mod->core_symtab = dst = mod->module_core + info->symoffs; src = mod->symtab; - *dst = *src; - for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) { - if (!is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) - continue; - dst[ndst] = *src; - dst[ndst].st_name = bitmap_weight(info->strmap, - dst[ndst].st_name); - ++ndst; + for (ndst = i = 0; i < mod->num_symtab; i++) { + if (i == 0 || + is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) { + dst[ndst] = src[i]; + dst[ndst].st_name = bitmap_weight(info->strmap, + dst[ndst].st_name); + ++ndst; + } } mod->core_num_syms = ndst; |