diff options
author | Vincent Donnefort <vdonnefort@google.com> | 2024-09-10 09:31:23 +0200 |
---|---|---|
committer | Luis Chamberlain <mcgrof@kernel.org> | 2024-09-13 18:55:17 +0200 |
commit | b319cea80539df9bea0ad98cb5e4b2fcb7e1a34b (patch) | |
tree | 735522d9b3962ff31660e72dda8451e157d9cc5a /kernel/module | |
parent | module: abort module loading when sysfs setup suffer errors (diff) | |
download | linux-b319cea80539df9bea0ad98cb5e4b2fcb7e1a34b.tar.xz linux-b319cea80539df9bea0ad98cb5e4b2fcb7e1a34b.zip |
module: Refine kmemleak scanned areas
commit ac3b43283923 ("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>
Diffstat (limited to 'kernel/module')
-rw-r--r-- | kernel/module/debug_kmemleak.c | 18 |
1 files changed, 4 insertions, 14 deletions
diff --git a/kernel/module/debug_kmemleak.c b/kernel/module/debug_kmemleak.c index 12a569d361e8..b4cc03842d70 100644 --- a/kernel/module/debug_kmemleak.c +++ b/kernel/module/debug_kmemleak.c @@ -12,19 +12,9 @@ void kmemleak_load_module(const struct module *mod, const struct load_info *info) { - unsigned int i; - - /* only scan the sections containing data */ - kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL); - - for (i = 1; i < info->hdr->e_shnum; i++) { - /* 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, - info->sechdrs[i].sh_size, GFP_KERNEL); + /* only scan writable, non-executable sections */ + for_each_mod_mem_type(type) { + if (type != MOD_DATA && type != MOD_INIT_DATA) + kmemleak_no_scan(mod->mem[type].base); } } |