kmemleak: Scan all allocated, writeable and not executable module sections
authorSteven Rostedt <[email protected]>
Wed, 15 May 2013 19:33:01 +0000 (20:33 +0100)
committerCatalin Marinas <[email protected]>
Fri, 17 May 2013 08:53:07 +0000 (09:53 +0100)
Instead of just picking data sections by name (names that start
with .data, .bss or .ref.data), use the section flags and scan all
sections that are allocated, writable and not executable. Which should
cover all sections of a module that might reference data.

Signed-off-by: Steven Rostedt <[email protected]>
[[email protected]: removed unused 'name' variable]
[[email protected]: collapsed 'if' blocks]
Signed-off-by: Catalin Marinas <[email protected]>
Acked-by: Rusty Russell <[email protected]>
kernel/module.c

index b049939177f6d3a4983341b42eb4719c27b4af62..06f496a5d182ccfe54a6d2ac0db78c5764ca7e1f 100644 (file)
@@ -2431,10 +2431,10 @@ static void kmemleak_load_module(const struct module *mod,
        kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL);
 
        for (i = 1; i < info->hdr->e_shnum; i++) {
-               const char *name = info->secstrings + info->sechdrs[i].sh_name;
-               if (!(info->sechdrs[i].sh_flags & SHF_ALLOC))
-                       continue;
-               if (!strstarts(name, ".data") && !strstarts(name, ".bss"))
+               /* Scan all writable sections that's not executable */
+               if (!(info->sechdrs[i].sh_flags & SHF_ALLOC) ||
+                   !(info->sechdrs[i].sh_flags & SHF_WRITE) ||
+                   (info->sechdrs[i].sh_flags & SHF_EXECINSTR))
                        continue;
 
                kmemleak_scan_area((void *)info->sechdrs[i].sh_addr,