All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Helge Deller <deller@gmx.de>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>,
	ben@decadent.org.uk, tbm@cyrius.com,
	Kalle Valo <kalle.valo@iki.fi>,
	linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org,
	linux-omap@vger.kernel.org, rusty@rustcorp.com.au,
	roland@redhat.com, dave@hiauly1.hia.nrc.ca,
	Parisc List <linux-parisc@vger.kernel.org>
Subject: Re: regression: crash from 'ls /sys/modules/wl1251_spi/notes'
Date: Tue, 5 Jan 2010 17:15:50 -0800	[thread overview]
Message-ID: <20100105171550.8aef9b15.akpm@linux-foundation.org> (raw)
In-Reply-To: <4B3D145C.2080106@gmx.de>

On Thu, 31 Dec 2009 22:15:08 +0100
Helge Deller <deller@gmx.de> wrote:

> On 12/30/2009 04:49 PM, James Bottomley wrote:
> > A better, and more comprehensive patch would be to try not to count the
> > empty text sections when we're building the notes section (and actually
> > anywhere else in the file).  This patch actually relies on the fact that
> > if sh_size is zero for the text section it should be for the
> > corresponding notes section.  If that doesn't work, we'd actually have
> > to do the matching in the construction piece.
> >
> > Can you try it to see if it works for you?  If it doesn't, I'll try
> > matching notes to text.  It works fine on parisc, but as we don't have a
> > notes section, that's not saying much ...
> >
> > Thanks,
> >
> > James
> 
> 
> Ben Hutchings already sent a similar patch.
> See: http://patchwork.kernel.org/patch/68925/
> 
> IMHO James patch below seems better since it
> checks if a section will be allocated at a few more
> places...
> 

Ben's patch (which is below) is currently in linux-next, via a Rusty
tree.  It is marked for -stable backporting.

If James's patch is preferable then there's an opportunity to do the
swap if we move promptly.




commit 9e9b48a89ed43c73d7355ff999b8e87b0628e1cd
Author:     Ben Hutchings <ben@decadent.org.uk>
AuthorDate: Sat Dec 19 14:43:01 2009 +0000
Commit:     Stephen Rothwell <sfr@canb.auug.org.au>
CommitDate: Tue Jan 5 08:44:50 2010 +1100

    modules: Skip empty sections when exporting section notes
    
    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: Rusty Russell <rusty@rustcorp.com.au>

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;


  reply	other threads:[~2010-01-06  1:15 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-30 11:41 regression: crash from 'ls /sys/modules/wl1251_spi/notes' Kalle Valo
2009-12-30 15:49 ` James Bottomley
2009-12-30 17:20   ` Kalle Valo
     [not found]   ` <1262188157.2749.21.camel-0iu6Cu4xQGLYCGPCin2YbQ@public.gmane.org>
2009-12-31 21:15     ` Helge Deller
2009-12-31 21:15       ` Helge Deller
2010-01-06  1:15       ` Andrew Morton [this message]
2010-01-01  3:08   ` Américo Wang
2010-01-01  3:08     ` Américo Wang
2010-01-02 16:34     ` James Bottomley
2010-01-02 16:34       ` James Bottomley
2010-01-02 16:34       ` James Bottomley
2010-01-04 18:23   ` Roland McGrath

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100105171550.8aef9b15.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=ben@decadent.org.uk \
    --cc=dave@hiauly1.hia.nrc.ca \
    --cc=deller@gmx.de \
    --cc=kalle.valo@iki.fi \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-parisc@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=roland@redhat.com \
    --cc=rusty@rustcorp.com.au \
    --cc=tbm@cyrius.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.