From patchwork Wed Dec 30 15:49:17 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Bottomley X-Patchwork-Id: 70260 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.2) with ESMTP id nBUFncZ4032285 for ; Wed, 30 Dec 2009 15:49:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752149AbZL3Pt0 (ORCPT ); Wed, 30 Dec 2009 10:49:26 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751670AbZL3PtZ (ORCPT ); Wed, 30 Dec 2009 10:49:25 -0500 Received: from bedivere.hansenpartnership.com ([66.63.167.143]:46166 "EHLO bedivere.hansenpartnership.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751529AbZL3PtY (ORCPT ); Wed, 30 Dec 2009 10:49:24 -0500 Received: from localhost (localhost [127.0.0.1]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id F01E28EE0E7; Wed, 30 Dec 2009 07:49:23 -0800 (PST) Received: from bedivere.hansenpartnership.com ([127.0.0.1]) by localhost (bedivere.hansenpartnership.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EN0nnTjaf2LL; Wed, 30 Dec 2009 07:49:23 -0800 (PST) Received: from [192.168.10.224] (newmulgrave.ext.hansenpartnership.com [192.168.10.224]) by bedivere.hansenpartnership.com (Postfix) with ESMTP id D8C088EE0DC; Wed, 30 Dec 2009 07:49:20 -0800 (PST) Subject: Re: regression: crash from 'ls /sys/modules/wl1251_spi/notes' From: James Bottomley To: Kalle Valo Cc: linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, linux-omap@vger.kernel.org, Helge Deller , rusty@rustcorp.com.au, akpm@linux-foundation.org, roland@redhat.com, dave@hiauly1.hia.nrc.ca, Parisc List In-Reply-To: <87k4w4wux9.fsf@purkki.valot.fi> References: <87k4w4wux9.fsf@purkki.valot.fi> Date: Wed, 30 Dec 2009 09:49:17 -0600 Message-Id: <1262188157.2749.21.camel@mulgrave.site> Mime-Version: 1.0 X-Mailer: Evolution 2.28.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org diff --git a/kernel/module.c b/kernel/module.c index e96b8ed..957f912 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -132,6 +132,11 @@ void __module_put_and_exit(struct module *mod, long code) } EXPORT_SYMBOL(__module_put_and_exit); +static inline int section_allocated(Elf_Shdr hdr) +{ + return (hdr.sh_flags & SHF_ALLOC) && hdr.sh_size != 0; +} + /* Find a module section: 0 means not found. */ static unsigned int find_sec(Elf_Ehdr *hdr, Elf_Shdr *sechdrs, @@ -142,7 +147,7 @@ static unsigned int find_sec(Elf_Ehdr *hdr, for (i = 1; i < hdr->e_shnum; i++) /* Alloc bit cleared means "ignore it." */ - if ((sechdrs[i].sh_flags & SHF_ALLOC) + if (section_allocated(sechdrs[i]) && strcmp(secstrings+sechdrs[i].sh_name, name) == 0) return i; return 0; @@ -1051,8 +1056,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 (section_allocated(sechdrs[i])) nloaded++; size[0] = ALIGN(sizeof(*sect_attrs) + nloaded * sizeof(sect_attrs->attrs[0]), @@ -1070,9 +1074,7 @@ static void add_sect_attrs(struct module *mod, unsigned int nsect, sattr = §_attrs->attrs[0]; gattr = §_attrs->grp.attrs[0]; for (i = 0; i < nsect; i++) { - if (! (sechdrs[i].sh_flags & SHF_ALLOC)) - continue; - if (!sechdrs[i].sh_size) + if (!section_allocated(sechdrs[i])) continue; sattr->address = sechdrs[i].sh_addr; sattr->name = kstrdup(secstrings + sechdrs[i].sh_name, @@ -1156,7 +1158,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 (section_allocated(sechdrs[i]) && (sechdrs[i].sh_type == SHT_NOTE)) ++notes; @@ -1172,7 +1174,7 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect, notes_attrs->notes = notes; nattr = ¬es_attrs->attrs[0]; for (loaded = i = 0; i < nsect; ++i) { - if (!(sechdrs[i].sh_flags & SHF_ALLOC)) + if (!section_allocated(sechdrs[i])) continue; if (sechdrs[i].sh_type == SHT_NOTE) { nattr->attr.name = mod->sect_attrs->attrs[loaded].name; @@ -1720,7 +1722,7 @@ static char elf_type(const Elf_Sym *sym, return '?'; if (sechdrs[sym->st_shndx].sh_flags & SHF_EXECINSTR) return 't'; - if (sechdrs[sym->st_shndx].sh_flags & SHF_ALLOC + if (section_allocated(sechdrs[sym->st_shndx]) && sechdrs[sym->st_shndx].sh_type != SHT_NOBITS) { if (!(sechdrs[sym->st_shndx].sh_flags & SHF_WRITE)) return 'r'; @@ -1751,7 +1753,7 @@ static bool is_core_symbol(const Elf_Sym *src, const Elf_Shdr *sechdrs, return false; sec = sechdrs + src->st_shndx; - if (!(sec->sh_flags & SHF_ALLOC) + if (!section_allocated(*sec) #ifndef CONFIG_KALLSYMS_ALL || !(sec->sh_flags & SHF_EXECINSTR) #endif @@ -1913,7 +1915,7 @@ static void kmemleak_load_module(struct module *mod, Elf_Ehdr *hdr, kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL); for (i = 1; i < hdr->e_shnum; i++) { - if (!(sechdrs[i].sh_flags & SHF_ALLOC)) + if (!section_allocated(sechdrs[i])) continue; if (strncmp(secstrings + sechdrs[i].sh_name, ".data", 5) != 0 && strncmp(secstrings + sechdrs[i].sh_name, ".bss", 4) != 0) @@ -2139,7 +2141,7 @@ static noinline struct module *load_module(void __user *umod, for (i = 0; i < hdr->e_shnum; i++) { void *dest; - if (!(sechdrs[i].sh_flags & SHF_ALLOC)) + if (!section_allocated(sechdrs[i])) continue; if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) @@ -2287,7 +2289,7 @@ static noinline struct module *load_module(void __user *umod, continue; /* Don't bother with non-allocated sections */ - if (!(sechdrs[info].sh_flags & SHF_ALLOC)) + if (!section_allocated(sechdrs[info])) continue; if (sechdrs[i].sh_type == SHT_REL)