1 From 412656ce83a2605119dc1a7bc5492a13240dc666 Mon Sep 17 00:00:00 2001
2 From: Ben Hutchings <ben@decadent.org.uk>
3 Date: Sat, 19 Dec 2009 14:43:01 +0000
4 Subject: [PATCH 6/9] modules: Skip empty sections when exporting section notes
6 Commit 35dead4 "modules: don't export section names of empty sections
7 via sysfs" changed the set of sections that have attributes, but did
8 not change the iteration over these attributes in add_notes_attrs().
9 This can lead to add_notes_attrs() creating attributes with the wrong
10 names or with null name pointers.
12 Introduce a sect_empty() function and use it in both add_sect_attrs()
13 and add_notes_attrs().
15 Reported-by: Martin Michlmayr <tbm@cyrius.com>
16 Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
17 Tested-by: Martin Michlmayr <tbm@cyrius.com>
19 Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
20 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
21 Signed-off-by: Sanjeev Premi <premi@ti.com>
23 kernel/module.c | 17 ++++++++++-------
24 1 files changed, 10 insertions(+), 7 deletions(-)
26 diff --git a/kernel/module.c b/kernel/module.c
27 index 12afc5a..a1b4a43 100644
30 @@ -996,6 +996,12 @@ static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs,
31 * J. Corbet <corbet@lwn.net>
33 #if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS)
35 +static inline bool sect_empty(const Elf_Shdr *sect)
37 + return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
40 struct module_sect_attr
42 struct module_attribute mattr;
43 @@ -1037,8 +1043,7 @@ static void add_sect_attrs(struct module *mod, unsigned int nsect,
45 /* Count loaded sections and allocate structures */
46 for (i = 0; i < nsect; i++)
47 - if (sechdrs[i].sh_flags & SHF_ALLOC
48 - && sechdrs[i].sh_size)
49 + if (!sect_empty(&sechdrs[i]))
51 size[0] = ALIGN(sizeof(*sect_attrs)
52 + nloaded * sizeof(sect_attrs->attrs[0]),
53 @@ -1056,9 +1061,7 @@ static void add_sect_attrs(struct module *mod, unsigned int nsect,
54 sattr = §_attrs->attrs[0];
55 gattr = §_attrs->grp.attrs[0];
56 for (i = 0; i < nsect; i++) {
57 - if (! (sechdrs[i].sh_flags & SHF_ALLOC))
59 - if (!sechdrs[i].sh_size)
60 + if (sect_empty(&sechdrs[i]))
62 sattr->address = sechdrs[i].sh_addr;
63 sattr->name = kstrdup(secstrings + sechdrs[i].sh_name,
64 @@ -1142,7 +1145,7 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect,
65 /* Count notes sections and allocate structures. */
67 for (i = 0; i < nsect; i++)
68 - if ((sechdrs[i].sh_flags & SHF_ALLOC) &&
69 + if (!sect_empty(&sechdrs[i]) &&
70 (sechdrs[i].sh_type == SHT_NOTE))
73 @@ -1158,7 +1161,7 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect,
74 notes_attrs->notes = notes;
75 nattr = ¬es_attrs->attrs[0];
76 for (loaded = i = 0; i < nsect; ++i) {
77 - if (!(sechdrs[i].sh_flags & SHF_ALLOC))
78 + if (sect_empty(&sechdrs[i]))
80 if (sechdrs[i].sh_type == SHT_NOTE) {
81 nattr->attr.name = mod->sect_attrs->attrs[loaded].name;