Commit 10b465aaf9536ee5a16652fa0700740183d48ec9
Committed by
Linus Torvalds
1 parent
74d2e4f8d7
Exists in
master
and in
20 other branches
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> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 10 additions and 7 deletions Side-by-side Diff
kernel/module.c
... | ... | @@ -1010,6 +1010,12 @@ |
1010 | 1010 | * J. Corbet <corbet@lwn.net> |
1011 | 1011 | */ |
1012 | 1012 | #if defined(CONFIG_KALLSYMS) && defined(CONFIG_SYSFS) |
1013 | + | |
1014 | +static inline bool sect_empty(const Elf_Shdr *sect) | |
1015 | +{ | |
1016 | + return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0; | |
1017 | +} | |
1018 | + | |
1013 | 1019 | struct module_sect_attr |
1014 | 1020 | { |
1015 | 1021 | struct module_attribute mattr; |
... | ... | @@ -1051,8 +1057,7 @@ |
1051 | 1057 | |
1052 | 1058 | /* Count loaded sections and allocate structures */ |
1053 | 1059 | for (i = 0; i < nsect; i++) |
1054 | - if (sechdrs[i].sh_flags & SHF_ALLOC | |
1055 | - && sechdrs[i].sh_size) | |
1060 | + if (!sect_empty(&sechdrs[i])) | |
1056 | 1061 | nloaded++; |
1057 | 1062 | size[0] = ALIGN(sizeof(*sect_attrs) |
1058 | 1063 | + nloaded * sizeof(sect_attrs->attrs[0]), |
1059 | 1064 | |
... | ... | @@ -1070,10 +1075,8 @@ |
1070 | 1075 | sattr = §_attrs->attrs[0]; |
1071 | 1076 | gattr = §_attrs->grp.attrs[0]; |
1072 | 1077 | for (i = 0; i < nsect; i++) { |
1073 | - if (! (sechdrs[i].sh_flags & SHF_ALLOC)) | |
1078 | + if (sect_empty(&sechdrs[i])) | |
1074 | 1079 | continue; |
1075 | - if (!sechdrs[i].sh_size) | |
1076 | - continue; | |
1077 | 1080 | sattr->address = sechdrs[i].sh_addr; |
1078 | 1081 | sattr->name = kstrdup(secstrings + sechdrs[i].sh_name, |
1079 | 1082 | GFP_KERNEL); |
... | ... | @@ -1156,7 +1159,7 @@ |
1156 | 1159 | /* Count notes sections and allocate structures. */ |
1157 | 1160 | notes = 0; |
1158 | 1161 | for (i = 0; i < nsect; i++) |
1159 | - if ((sechdrs[i].sh_flags & SHF_ALLOC) && | |
1162 | + if (!sect_empty(&sechdrs[i]) && | |
1160 | 1163 | (sechdrs[i].sh_type == SHT_NOTE)) |
1161 | 1164 | ++notes; |
1162 | 1165 | |
... | ... | @@ -1172,7 +1175,7 @@ |
1172 | 1175 | notes_attrs->notes = notes; |
1173 | 1176 | nattr = ¬es_attrs->attrs[0]; |
1174 | 1177 | for (loaded = i = 0; i < nsect; ++i) { |
1175 | - if (!(sechdrs[i].sh_flags & SHF_ALLOC)) | |
1178 | + if (sect_empty(&sechdrs[i])) | |
1176 | 1179 | continue; |
1177 | 1180 | if (sechdrs[i].sh_type == SHT_NOTE) { |
1178 | 1181 | nattr->attr.name = mod->sect_attrs->attrs[loaded].name; |