Commit 59ef28b1 authored by Rusty Russell's avatar Rusty Russell

module: fix out-by-one error in kallsyms

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: 4a496226

LKML: http://lkml.org/lkml/2012/10/24/27Reported-by: default avatarMasaki Kimura <masaki.kimura.kz@hitachi.com>
Cc: stable@kernel.org
parent bc909421
...@@ -2293,12 +2293,17 @@ static void layout_symtab(struct module *mod, struct load_info *info) ...@@ -2293,12 +2293,17 @@ static void layout_symtab(struct module *mod, struct load_info *info)
src = (void *)info->hdr + symsect->sh_offset; src = (void *)info->hdr + symsect->sh_offset;
nsrc = symsect->sh_size / sizeof(*src); nsrc = symsect->sh_size / sizeof(*src);
/* strtab always starts with a nul, so offset 0 is the empty string. */
strtab_size = 1;
/* Compute total space required for the core symbols' strtab. */ /* Compute total space required for the core symbols' strtab. */
for (ndst = i = strtab_size = 1; i < nsrc; ++i, ++src) for (ndst = i = 0; i < nsrc; i++) {
if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) { if (i == 0 ||
strtab_size += strlen(&info->strtab[src->st_name]) + 1; is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
strtab_size += strlen(&info->strtab[src[i].st_name])+1;
ndst++; ndst++;
} }
}
/* Append room for core symbols at end of core part. */ /* Append room for core symbols at end of core part. */
info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1); info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
...@@ -2332,15 +2337,15 @@ static void add_kallsyms(struct module *mod, const struct load_info *info) ...@@ -2332,15 +2337,15 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
mod->core_symtab = dst = mod->module_core + info->symoffs; mod->core_symtab = dst = mod->module_core + info->symoffs;
mod->core_strtab = s = mod->module_core + info->stroffs; mod->core_strtab = s = mod->module_core + info->stroffs;
src = mod->symtab; src = mod->symtab;
*dst = *src;
*s++ = 0; *s++ = 0;
for (ndst = i = 1; i < mod->num_symtab; ++i, ++src) { for (ndst = i = 0; i < mod->num_symtab; i++) {
if (!is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) if (i == 0 ||
continue; is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
dst[ndst] = src[i];
dst[ndst] = *src;
dst[ndst++].st_name = s - mod->core_strtab; dst[ndst++].st_name = s - mod->core_strtab;
s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1; s += strlcpy(s, &mod->strtab[src[i].st_name],
KSYM_NAME_LEN) + 1;
}
} }
mod->core_num_syms = ndst; mod->core_num_syms = ndst;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment