Patchwork [Karmic] SRU: Upstream detected regression in 2.6.31.7

login
register
mail settings
Submitter Stefan Bader
Date Dec. 21, 2009, 5:06 p.m.
Message ID <1261415196-15326-1-git-send-email-stefan.bader@canonical.com>
Download mbox | patch
Permalink /patch/41560/
State Superseded
Delegated to: Stefan Bader
Headers show

Comments

Stefan Bader - Dec. 21, 2009, 5:06 p.m.
SRU Justification:

Impact: Upstream stable patch apparently introduced a regression with
2.6.31.7 (missed to change one of the affected places).

Fix: This fix was sent to upstream (cc: stable). It is not (yet)
integrated in upstream, but as soon as it does I'd like to pull
that in together with the 2.6.31.7 we are reviewing.

Testcase: see below

---


Subject: [PATCH] modules: Skip empty sections when exporting section notes
From: Ben Hutchings <ben@decadent.org.uk>
Date: Sat, 19 Dec 2009 14:43:01 +0000
To: Rusty Russell <rusty@rustcorp.com.au>
CC: Helge Deller <deller@gmx.de>, Martin Michlmayr <tbm@cyrius.com>, LKML <linux-kernel@vger.kernel.org>

Commit 35dead4 "modules: don't export section names of empty sections
via sysfs" changed the set of sections that have attributes, but did
not change the iteration over these attributes in add_notes_attrs().
This can lead to add_notes_attrs() creating attributes with the wrong
names or with null name pointers.

Introduce a sect_empty() function and use it in both add_sect_attrs()
and add_notes_attrs().

Reported-by: Martin Michlmayr <tbm@cyrius.com>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Tested-by: Martin Michlmayr <tbm@cyrius.com>
Cc: stable@kernel.org
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
---
 kernel/module.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

--
Leann Ogasawara - Dec. 21, 2009, 5:26 p.m.
On Mon, 2009-12-21 at 18:06 +0100, Stefan Bader wrote:
> SRU Justification:
> 
> Impact: Upstream stable patch apparently introduced a regression with
> 2.6.31.7 (missed to change one of the affected places).
> 
> Fix: This fix was sent to upstream (cc: stable). It is not (yet)
> integrated in upstream, but as soon as it does I'd like to pull
> that in together with the 2.6.31.7 we are reviewing.
> 
> Testcase: see below

Acked-by: Leann Ogasawara <leann.ogasawara@canonical.com>

> ---
> 
> 
> Subject: [PATCH] modules: Skip empty sections when exporting section notes
> From: Ben Hutchings <ben@decadent.org.uk>
> Date: Sat, 19 Dec 2009 14:43:01 +0000
> To: Rusty Russell <rusty@rustcorp.com.au>
> CC: Helge Deller <deller@gmx.de>, Martin Michlmayr <tbm@cyrius.com>, LKML <linux-kernel@vger.kernel.org>
> 
> Commit 35dead4 "modules: don't export section names of empty sections
> via sysfs" changed the set of sections that have attributes, but did
> not change the iteration over these attributes in add_notes_attrs().
> This can lead to add_notes_attrs() creating attributes with the wrong
> names or with null name pointers.
> 
> Introduce a sect_empty() function and use it in both add_sect_attrs()
> and add_notes_attrs().
> 
> Reported-by: Martin Michlmayr <tbm@cyrius.com>
> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
> Tested-by: Martin Michlmayr <tbm@cyrius.com>
> Cc: stable@kernel.org
> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
> ---
>  kernel/module.c |   17 ++++++++++-------
>  1 files changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/kernel/module.c b/kernel/module.c
> index e96b8ed..f82386b 100644
> --- a/kernel/module.c
> +++ b/kernel/module.c
> @@ -1010,6 +1010,12 @@ static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
>   * J. Corbet <corbet@lwn.net>
>   */
>  #if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
> +
> +static inline bool sect_empty(const Elf_Shdr *sect)
> +{
> +	return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
> +}
> +
>  struct module_sect_attr
>  {
>  	struct module_attribute mattr;
> @@ -1051,8 +1057,7 @@ static void add_sect_attrs(struct module *mod, unsigned int nsect,
>  
>  	/* Count loaded sections and allocate structures */
>  	for (i = 0; i < nsect; i++)
> -		if (sechdrs[i].sh_flags & SHF_ALLOC
> -		    && sechdrs[i].sh_size)
> +		if (!sect_empty(&sechdrs[i]))
>  			nloaded++;
>  	size[0] = ALIGN(sizeof(*sect_attrs)
>  			+ nloaded * sizeof(sect_attrs->attrs[0]),
> @@ -1070,9 +1075,7 @@ static void add_sect_attrs(struct module *mod, unsigned int nsect,
>  	sattr = &sect_attrs->attrs[0];
>  	gattr = &sect_attrs->grp.attrs[0];
>  	for (i = 0; i < nsect; i++) {
> -		if (! (sechdrs[i].sh_flags & SHF_ALLOC))
> -			continue;
> -		if (!sechdrs[i].sh_size)
> +		if (sect_empty(&sechdrs[i]))
>  			continue;
>  		sattr->address = sechdrs[i].sh_addr;
>  		sattr->name = kstrdup(secstrings + sechdrs[i].sh_name,
> @@ -1156,7 +1159,7 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect,
>  	/* Count notes sections and allocate structures.  */
>  	notes = 0;
>  	for (i = 0; i < nsect; i++)
> -		if ((sechdrs[i].sh_flags & SHF_ALLOC) &&
> +		if (!sect_empty(&sechdrs[i]) &&
>  		    (sechdrs[i].sh_type == SHT_NOTE))
>  			++notes;
>  
> @@ -1172,7 +1175,7 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect,
>  	notes_attrs->notes = notes;
>  	nattr = &notes_attrs->attrs[0];
>  	for (loaded = i = 0; i < nsect; ++i) {
> -		if (!(sechdrs[i].sh_flags & SHF_ALLOC))
> +		if (sect_empty(&sechdrs[i]))
>  			continue;
>  		if (sechdrs[i].sh_type == SHT_NOTE) {
>  			nattr->attr.name = mod->sect_attrs->attrs[loaded].name;
> --
>

Patch

diff --git a/kernel/module.c b/kernel/module.c
index e96b8ed..f82386b 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -1010,6 +1010,12 @@  static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
  * J. Corbet <corbet@lwn.net>
  */
 #if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
+
+static inline bool sect_empty(const Elf_Shdr *sect)
+{
+	return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
+}
+
 struct module_sect_attr
 {
 	struct module_attribute mattr;
@@ -1051,8 +1057,7 @@  static void add_sect_attrs(struct module *mod, unsigned int nsect,
 
 	/* Count loaded sections and allocate structures */
 	for (i = 0; i < nsect; i++)
-		if (sechdrs[i].sh_flags & SHF_ALLOC
-		    && sechdrs[i].sh_size)
+		if (!sect_empty(&sechdrs[i]))
 			nloaded++;
 	size[0] = ALIGN(sizeof(*sect_attrs)
 			+ nloaded * sizeof(sect_attrs->attrs[0]),
@@ -1070,9 +1075,7 @@  static void add_sect_attrs(struct module *mod, unsigned int nsect,
 	sattr = &sect_attrs->attrs[0];
 	gattr = &sect_attrs->grp.attrs[0];
 	for (i = 0; i < nsect; i++) {
-		if (! (sechdrs[i].sh_flags & SHF_ALLOC))
-			continue;
-		if (!sechdrs[i].sh_size)
+		if (sect_empty(&sechdrs[i]))
 			continue;
 		sattr->address = sechdrs[i].sh_addr;
 		sattr->name = kstrdup(secstrings + sechdrs[i].sh_name,
@@ -1156,7 +1159,7 @@  static void add_notes_attrs(struct module *mod, unsigned int nsect,
 	/* Count notes sections and allocate structures.  */
 	notes = 0;
 	for (i = 0; i < nsect; i++)
-		if ((sechdrs[i].sh_flags & SHF_ALLOC) &&
+		if (!sect_empty(&sechdrs[i]) &&
 		    (sechdrs[i].sh_type == SHT_NOTE))
 			++notes;
 
@@ -1172,7 +1175,7 @@  static void add_notes_attrs(struct module *mod, unsigned int nsect,
 	notes_attrs->notes = notes;
 	nattr = &notes_attrs->attrs[0];
 	for (loaded = i = 0; i < nsect; ++i) {
-		if (!(sechdrs[i].sh_flags & SHF_ALLOC))
+		if (sect_empty(&sechdrs[i]))
 			continue;
 		if (sechdrs[i].sh_type == SHT_NOTE) {
 			nattr->attr.name = mod->sect_attrs->attrs[loaded].name;