Re: [ 11/83] module: fix out-by-one error in kallsyms

2012-12-02 Thread Rusty Russell
satoru takeuchi  writes:
> Hi,

Hi!

>> --- a/kernel/module.c
>> +++ b/kernel/module.c
>> @@ -2273,12 +2273,17 @@ static void layout_symtab(struct module
>> src = (void *)info->hdr + symsect->sh_offset;
>> nsrc = symsect->sh_size / sizeof(*src);
>>
>> +   /* strtab always starts with a nul, so offset 0 is the empty string. 
>> */
>> +   strtab_size = 1;
>> +
>
> I suspect above code sniped is not needed since the size of src[0](always 1) 
> is
> counted at the following code("strtab_size += strlen(..) + 1;").

You are correct, on both counts.  This was a remnant of the previous
1-based looping.

Here's the fix I have pending.

Thanks!
Rusty.

module: fix one byte kallsyms overallocation.

Since we fixed our kallsyms strtab expansion code in
59ef28b1f14899b10d6b2682c7057ca00a9a3f47 (module: fix out-by-one error
in kallsyms) we now loop from zero, so we don't need to add an extra
byte for the first empty string.

Reported-by: satoru takeuchi 
Signed-off-by: Rusty Russell 

diff --git a/kernel/module.c b/kernel/module.c
index a1d2ed8..79a526d 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2285,7 +2285,7 @@ static void layout_symtab(struct module *mod, struct 
load_info *info)
Elf_Shdr *symsect = info->sechdrs + info->index.sym;
Elf_Shdr *strsect = info->sechdrs + info->index.str;
const Elf_Sym *src;
-   unsigned int i, nsrc, ndst, strtab_size;
+   unsigned int i, nsrc, ndst, strtab_size = 0;
 
/* Put symbol section at end of init part of module. */
symsect->sh_flags |= SHF_ALLOC;
@@ -2296,9 +2296,6 @@ static void layout_symtab(struct module *mod, struct 
load_info *info)
src = (void *)info->hdr + symsect->sh_offset;
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. */
for (ndst = i = 0; i < nsrc; i++) {
if (i == 0 ||
@@ -2340,7 +2337,6 @@ static void add_kallsyms(struct module *mod, const struct 
load_info *info)
mod->core_symtab = dst = mod->module_core + info->symoffs;
mod->core_strtab = s = mod->module_core + info->stroffs;
src = mod->symtab;
-   *s++ = 0;
for (ndst = i = 0; i < mod->num_symtab; i++) {
if (i == 0 ||
is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [ 11/83] module: fix out-by-one error in kallsyms

2012-12-02 Thread Rusty Russell
satoru takeuchi satoru.takeu...@gmail.com writes:
 Hi,

Hi!

 --- a/kernel/module.c
 +++ b/kernel/module.c
 @@ -2273,12 +2273,17 @@ static void layout_symtab(struct module
 src = (void *)info-hdr + symsect-sh_offset;
 nsrc = symsect-sh_size / sizeof(*src);

 +   /* strtab always starts with a nul, so offset 0 is the empty string. 
 */
 +   strtab_size = 1;
 +

 I suspect above code sniped is not needed since the size of src[0](always 1) 
 is
 counted at the following code(strtab_size += strlen(..) + 1;).

You are correct, on both counts.  This was a remnant of the previous
1-based looping.

Here's the fix I have pending.

Thanks!
Rusty.

module: fix one byte kallsyms overallocation.

Since we fixed our kallsyms strtab expansion code in
59ef28b1f14899b10d6b2682c7057ca00a9a3f47 (module: fix out-by-one error
in kallsyms) we now loop from zero, so we don't need to add an extra
byte for the first empty string.

Reported-by: satoru takeuchi satoru.takeu...@gmail.com
Signed-off-by: Rusty Russell ru...@rustcorp.com.au

diff --git a/kernel/module.c b/kernel/module.c
index a1d2ed8..79a526d 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2285,7 +2285,7 @@ static void layout_symtab(struct module *mod, struct 
load_info *info)
Elf_Shdr *symsect = info-sechdrs + info-index.sym;
Elf_Shdr *strsect = info-sechdrs + info-index.str;
const Elf_Sym *src;
-   unsigned int i, nsrc, ndst, strtab_size;
+   unsigned int i, nsrc, ndst, strtab_size = 0;
 
/* Put symbol section at end of init part of module. */
symsect-sh_flags |= SHF_ALLOC;
@@ -2296,9 +2296,6 @@ static void layout_symtab(struct module *mod, struct 
load_info *info)
src = (void *)info-hdr + symsect-sh_offset;
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. */
for (ndst = i = 0; i  nsrc; i++) {
if (i == 0 ||
@@ -2340,7 +2337,6 @@ static void add_kallsyms(struct module *mod, const struct 
load_info *info)
mod-core_symtab = dst = mod-module_core + info-symoffs;
mod-core_strtab = s = mod-module_core + info-stroffs;
src = mod-symtab;
-   *s++ = 0;
for (ndst = i = 0; i  mod-num_symtab; i++) {
if (i == 0 ||
is_core_symbol(src+i, info-sechdrs, info-hdr-e_shnum)) {
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [ 11/83] module: fix out-by-one error in kallsyms

2012-11-26 Thread Greg Kroah-Hartman
On Fri, Nov 23, 2012 at 07:35:36PM +0900, satoru takeuchi wrote:
> Hi,
> 
> 2012/11/22 Greg Kroah-Hartman :
> > 3.6-stable review patch.  If anyone has any objections, please let me know.
> >
> > --
> >
> > From: Rusty Russell 
> >
> > 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 
> > Signed-off-by: Rusty Russell 
> > Signed-off-by: Greg Kroah-Hartman 
> >
> > ---
> >  kernel/module.c |   27 ---
> >  1 file changed, 16 insertions(+), 11 deletions(-)
> >
> > --- a/kernel/module.c
> > +++ b/kernel/module.c
> > @@ -2273,12 +2273,17 @@ static void layout_symtab(struct module
> > src = (void *)info->hdr + symsect->sh_offset;
> > nsrc = symsect->sh_size / sizeof(*src);
> >
> > +   /* strtab always starts with a nul, so offset 0 is the empty 
> > string. */
> > +   strtab_size = 1;
> > +
> 
> I suspect above code sniped is not needed since the size of src[0](always 1) 
> is
> counted at the following code("strtab_size += strlen(..) + 1;").
> 
> > /* Compute total space required for the core symbols' strtab. */
> > -   for (ndst = i = strtab_size = 1; i < nsrc; ++i, ++src)
> > -   if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) 
> > {
> > -   strtab_size += strlen(>strtab[src->st_name]) 
> > + 1;
> > +   for (ndst = i = 0; i < nsrc; i++) {
> > +   if (i == 0 ||
> > +   is_core_symbol(src+i, info->sechdrs, 
> > info->hdr->e_shnum)) {
> 
> src[i] rather than src+1 is better as kallsyms();
> 
> > +   strtab_size += 
> > strlen(>strtab[src[i].st_name])+1;
> > ndst++;
> > }
> > +   }
> >
> > /* Append room for core symbols at end of core part. */
> > info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
> > @@ -2312,15 +2317,15 @@ static void add_kallsyms(struct module *
> > mod->core_symtab = dst = mod->module_core + info->symoffs;
> > mod->core_strtab = s = mod->module_core + info->stroffs;
> > src = mod->symtab;
> > -   *dst = *src;
> > *s++ = 0;
> 
> This "*s++"line is also not needed since the content of src[0] is copied in 
> the
> following loop.
> 
> If my understanding is correct, the allsym table becomes as follows by
> applying this patch.
> 
> ==
> \0\0\0\0... # "\0" means null
> character in this case
> ==
> 
> It should be as follows.
> 
> 
> \0\0\0...
> 
> 
> This patch would work, but need extra one byte per module. Olease let
> us know if I misunderstand something.
> I didn't confirm with real machine.

Please confirm with a real machine, and if the problem is there, please
submit a patch to get it changed in Linus's tree, which is where this
patch came from.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [ 11/83] module: fix out-by-one error in kallsyms

2012-11-26 Thread Greg Kroah-Hartman
On Fri, Nov 23, 2012 at 07:35:36PM +0900, satoru takeuchi wrote:
 Hi,
 
 2012/11/22 Greg Kroah-Hartman gre...@linuxfoundation.org:
  3.6-stable review patch.  If anyone has any objections, please let me know.
 
  --
 
  From: Rusty Russell ru...@rustcorp.com.au
 
  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...@hitachi.com
  Signed-off-by: Rusty Russell ru...@rustcorp.com.au
  Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org
 
  ---
   kernel/module.c |   27 ---
   1 file changed, 16 insertions(+), 11 deletions(-)
 
  --- a/kernel/module.c
  +++ b/kernel/module.c
  @@ -2273,12 +2273,17 @@ static void layout_symtab(struct module
  src = (void *)info-hdr + symsect-sh_offset;
  nsrc = symsect-sh_size / sizeof(*src);
 
  +   /* strtab always starts with a nul, so offset 0 is the empty 
  string. */
  +   strtab_size = 1;
  +
 
 I suspect above code sniped is not needed since the size of src[0](always 1) 
 is
 counted at the following code(strtab_size += strlen(..) + 1;).
 
  /* Compute total space required for the core symbols' strtab. */
  -   for (ndst = i = strtab_size = 1; i  nsrc; ++i, ++src)
  -   if (is_core_symbol(src, info-sechdrs, info-hdr-e_shnum)) 
  {
  -   strtab_size += strlen(info-strtab[src-st_name]) 
  + 1;
  +   for (ndst = i = 0; i  nsrc; i++) {
  +   if (i == 0 ||
  +   is_core_symbol(src+i, info-sechdrs, 
  info-hdr-e_shnum)) {
 
 src[i] rather than src+1 is better as kallsyms();
 
  +   strtab_size += 
  strlen(info-strtab[src[i].st_name])+1;
  ndst++;
  }
  +   }
 
  /* Append room for core symbols at end of core part. */
  info-symoffs = ALIGN(mod-core_size, symsect-sh_addralign ?: 1);
  @@ -2312,15 +2317,15 @@ static void add_kallsyms(struct module *
  mod-core_symtab = dst = mod-module_core + info-symoffs;
  mod-core_strtab = s = mod-module_core + info-stroffs;
  src = mod-symtab;
  -   *dst = *src;
  *s++ = 0;
 
 This *s++line is also not needed since the content of src[0] is copied in 
 the
 following loop.
 
 If my understanding is correct, the allsym table becomes as follows by
 applying this patch.
 
 ==
 \0\0first core symbol\0second core symbol\0... # \0 means null
 character in this case
 ==
 
 It should be as follows.
 
 
 \0first core symbol\0second core symbol\0...
 
 
 This patch would work, but need extra one byte per module. Olease let
 us know if I misunderstand something.
 I didn't confirm with real machine.

Please confirm with a real machine, and if the problem is there, please
submit a patch to get it changed in Linus's tree, which is where this
patch came from.

thanks,

greg k-h
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [ 11/83] module: fix out-by-one error in kallsyms

2012-11-23 Thread satoru takeuchi
Hi,

2012/11/22 Greg Kroah-Hartman :
> 3.6-stable review patch.  If anyone has any objections, please let me know.
>
> --
>
> From: Rusty Russell 
>
> 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 
> Signed-off-by: Rusty Russell 
> Signed-off-by: Greg Kroah-Hartman 
>
> ---
>  kernel/module.c |   27 ---
>  1 file changed, 16 insertions(+), 11 deletions(-)
>
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -2273,12 +2273,17 @@ static void layout_symtab(struct module
> src = (void *)info->hdr + symsect->sh_offset;
> nsrc = symsect->sh_size / sizeof(*src);
>
> +   /* strtab always starts with a nul, so offset 0 is the empty string. 
> */
> +   strtab_size = 1;
> +

I suspect above code sniped is not needed since the size of src[0](always 1) is
counted at the following code("strtab_size += strlen(..) + 1;").

> /* Compute total space required for the core symbols' strtab. */
> -   for (ndst = i = strtab_size = 1; i < nsrc; ++i, ++src)
> -   if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) {
> -   strtab_size += strlen(>strtab[src->st_name]) + 
> 1;
> +   for (ndst = i = 0; i < nsrc; i++) {
> +   if (i == 0 ||
> +   is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) 
> {

src[i] rather than src+1 is better as kallsyms();

> +   strtab_size += 
> strlen(>strtab[src[i].st_name])+1;
> ndst++;
> }
> +   }
>
> /* Append room for core symbols at end of core part. */
> info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
> @@ -2312,15 +2317,15 @@ static void add_kallsyms(struct module *
> mod->core_symtab = dst = mod->module_core + info->symoffs;
> mod->core_strtab = s = mod->module_core + info->stroffs;
> src = mod->symtab;
> -   *dst = *src;
> *s++ = 0;

This "*s++"line is also not needed since the content of src[0] is copied in the
following loop.

If my understanding is correct, the allsym table becomes as follows by
applying this patch.

==
\0\0\0\0... # "\0" means null
character in this case
==

It should be as follows.


\0\0\0...


This patch would work, but need extra one byte per module. Olease let
us know if I misunderstand something.
I didn't confirm with real machine.

Thanks,
Satoru

> -   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 = s - mod->core_strtab;
> -   s += strlcpy(s, >strtab[src->st_name], KSYM_NAME_LEN) + 
> 1;
> +   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 = s - mod->core_strtab;
> +   s += strlcpy(s, >strtab[src[i].st_name],
> +KSYM_NAME_LEN) + 1;
> +   }
> }
> mod->core_num_syms = ndst;
>  }
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe stable" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [ 11/83] module: fix out-by-one error in kallsyms

2012-11-23 Thread satoru takeuchi
Hi,

2012/11/22 Greg Kroah-Hartman gre...@linuxfoundation.org:
 3.6-stable review patch.  If anyone has any objections, please let me know.

 --

 From: Rusty Russell ru...@rustcorp.com.au

 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...@hitachi.com
 Signed-off-by: Rusty Russell ru...@rustcorp.com.au
 Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org

 ---
  kernel/module.c |   27 ---
  1 file changed, 16 insertions(+), 11 deletions(-)

 --- a/kernel/module.c
 +++ b/kernel/module.c
 @@ -2273,12 +2273,17 @@ static void layout_symtab(struct module
 src = (void *)info-hdr + symsect-sh_offset;
 nsrc = symsect-sh_size / sizeof(*src);

 +   /* strtab always starts with a nul, so offset 0 is the empty string. 
 */
 +   strtab_size = 1;
 +

I suspect above code sniped is not needed since the size of src[0](always 1) is
counted at the following code(strtab_size += strlen(..) + 1;).

 /* Compute total space required for the core symbols' strtab. */
 -   for (ndst = i = strtab_size = 1; i  nsrc; ++i, ++src)
 -   if (is_core_symbol(src, info-sechdrs, info-hdr-e_shnum)) {
 -   strtab_size += strlen(info-strtab[src-st_name]) + 
 1;
 +   for (ndst = i = 0; i  nsrc; i++) {
 +   if (i == 0 ||
 +   is_core_symbol(src+i, info-sechdrs, info-hdr-e_shnum)) 
 {

src[i] rather than src+1 is better as kallsyms();

 +   strtab_size += 
 strlen(info-strtab[src[i].st_name])+1;
 ndst++;
 }
 +   }

 /* Append room for core symbols at end of core part. */
 info-symoffs = ALIGN(mod-core_size, symsect-sh_addralign ?: 1);
 @@ -2312,15 +2317,15 @@ static void add_kallsyms(struct module *
 mod-core_symtab = dst = mod-module_core + info-symoffs;
 mod-core_strtab = s = mod-module_core + info-stroffs;
 src = mod-symtab;
 -   *dst = *src;
 *s++ = 0;

This *s++line is also not needed since the content of src[0] is copied in the
following loop.

If my understanding is correct, the allsym table becomes as follows by
applying this patch.

==
\0\0first core symbol\0second core symbol\0... # \0 means null
character in this case
==

It should be as follows.


\0first core symbol\0second core symbol\0...


This patch would work, but need extra one byte per module. Olease let
us know if I misunderstand something.
I didn't confirm with real machine.

Thanks,
Satoru

 -   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 = s - mod-core_strtab;
 -   s += strlcpy(s, mod-strtab[src-st_name], KSYM_NAME_LEN) + 
 1;
 +   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 = s - mod-core_strtab;
 +   s += strlcpy(s, mod-strtab[src[i].st_name],
 +KSYM_NAME_LEN) + 1;
 +   }
 }
 mod-core_num_syms = ndst;
  }


 --
 To unsubscribe from this list: send the line unsubscribe stable in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[ 11/83] module: fix out-by-one error in kallsyms

2012-11-22 Thread Greg Kroah-Hartman
3.6-stable review patch.  If anyone has any objections, please let me know.

--

From: Rusty Russell 

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 
Signed-off-by: Rusty Russell 
Signed-off-by: Greg Kroah-Hartman 

---
 kernel/module.c |   27 ---
 1 file changed, 16 insertions(+), 11 deletions(-)

--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2273,12 +2273,17 @@ static void layout_symtab(struct module
src = (void *)info->hdr + symsect->sh_offset;
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. */
-   for (ndst = i = strtab_size = 1; i < nsrc; ++i, ++src)
-   if (is_core_symbol(src, info->sechdrs, info->hdr->e_shnum)) {
-   strtab_size += strlen(>strtab[src->st_name]) + 1;
+   for (ndst = i = 0; i < nsrc; i++) {
+   if (i == 0 ||
+   is_core_symbol(src+i, info->sechdrs, info->hdr->e_shnum)) {
+   strtab_size += strlen(>strtab[src[i].st_name])+1;
ndst++;
}
+   }
 
/* Append room for core symbols at end of core part. */
info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
@@ -2312,15 +2317,15 @@ static void add_kallsyms(struct module *
mod->core_symtab = dst = mod->module_core + info->symoffs;
mod->core_strtab = s = mod->module_core + info->stroffs;
src = mod->symtab;
-   *dst = *src;
*s++ = 0;
-   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 = s - mod->core_strtab;
-   s += strlcpy(s, >strtab[src->st_name], KSYM_NAME_LEN) + 1;
+   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 = s - mod->core_strtab;
+   s += strlcpy(s, >strtab[src[i].st_name],
+KSYM_NAME_LEN) + 1;
+   }
}
mod->core_num_syms = ndst;
 }


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[ 11/83] module: fix out-by-one error in kallsyms

2012-11-22 Thread Greg Kroah-Hartman
3.6-stable review patch.  If anyone has any objections, please let me know.

--

From: Rusty Russell ru...@rustcorp.com.au

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...@hitachi.com
Signed-off-by: Rusty Russell ru...@rustcorp.com.au
Signed-off-by: Greg Kroah-Hartman gre...@linuxfoundation.org

---
 kernel/module.c |   27 ---
 1 file changed, 16 insertions(+), 11 deletions(-)

--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2273,12 +2273,17 @@ static void layout_symtab(struct module
src = (void *)info-hdr + symsect-sh_offset;
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. */
-   for (ndst = i = strtab_size = 1; i  nsrc; ++i, ++src)
-   if (is_core_symbol(src, info-sechdrs, info-hdr-e_shnum)) {
-   strtab_size += strlen(info-strtab[src-st_name]) + 1;
+   for (ndst = i = 0; i  nsrc; i++) {
+   if (i == 0 ||
+   is_core_symbol(src+i, info-sechdrs, info-hdr-e_shnum)) {
+   strtab_size += strlen(info-strtab[src[i].st_name])+1;
ndst++;
}
+   }
 
/* Append room for core symbols at end of core part. */
info-symoffs = ALIGN(mod-core_size, symsect-sh_addralign ?: 1);
@@ -2312,15 +2317,15 @@ static void add_kallsyms(struct module *
mod-core_symtab = dst = mod-module_core + info-symoffs;
mod-core_strtab = s = mod-module_core + info-stroffs;
src = mod-symtab;
-   *dst = *src;
*s++ = 0;
-   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 = s - mod-core_strtab;
-   s += strlcpy(s, mod-strtab[src-st_name], KSYM_NAME_LEN) + 1;
+   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 = s - mod-core_strtab;
+   s += strlcpy(s, mod-strtab[src[i].st_name],
+KSYM_NAME_LEN) + 1;
+   }
}
mod-core_num_syms = ndst;
 }


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/