Skip to content

Commit b319cea

Browse files
vdonnefortmcgrof
authored andcommitted
module: Refine kmemleak scanned areas
commit ac3b432 ("module: replace module_layout with module_memory") introduced a set of memory regions for the module layout sharing the same attributes. However, it didn't update the kmemleak scanned areas which intended to limit kmemleak scan to sections containing writable data. This means sections such as .text and .rodata are scanned by kmemleak. Refine the scanned areas for modules by limiting it to MOD_TEXT and MOD_INIT_TEXT mod_mem regions. CC: Song Liu <song@kernel.org> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Vincent Donnefort <vdonnefort@google.com> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
1 parent ce47f7c commit b319cea

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

kernel/module/debug_kmemleak.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,9 @@
1212
void kmemleak_load_module(const struct module *mod,
1313
const struct load_info *info)
1414
{
15-
unsigned int i;
16-
17-
/* only scan the sections containing data */
18-
kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL);
19-
20-
for (i = 1; i < info->hdr->e_shnum; i++) {
21-
/* Scan all writable sections that's not executable */
22-
if (!(info->sechdrs[i].sh_flags & SHF_ALLOC) ||
23-
!(info->sechdrs[i].sh_flags & SHF_WRITE) ||
24-
(info->sechdrs[i].sh_flags & SHF_EXECINSTR))
25-
continue;
26-
27-
kmemleak_scan_area((void *)info->sechdrs[i].sh_addr,
28-
info->sechdrs[i].sh_size, GFP_KERNEL);
15+
/* only scan writable, non-executable sections */
16+
for_each_mod_mem_type(type) {
17+
if (type != MOD_DATA && type != MOD_INIT_DATA)
18+
kmemleak_no_scan(mod->mem[type].base);
2919
}
3020
}

0 commit comments

Comments
 (0)