Commit b319cea8 authored by Vincent Donnefort's avatar Vincent Donnefort Committed by Luis Chamberlain

module: Refine kmemleak scanned areas

commit ac3b4328 ("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: default avatarCatalin Marinas <catalin.marinas@arm.com>
Signed-off-by: default avatarVincent Donnefort <vdonnefort@google.com>
Signed-off-by: default avatarLuis Chamberlain <mcgrof@kernel.org>
parent ce47f7cb
...@@ -12,19 +12,9 @@ ...@@ -12,19 +12,9 @@
void kmemleak_load_module(const struct module *mod, void kmemleak_load_module(const struct module *mod,
const struct load_info *info) const struct load_info *info)
{ {
unsigned int i; /* only scan writable, non-executable sections */
for_each_mod_mem_type(type) {
/* only scan the sections containing data */ if (type != MOD_DATA && type != MOD_INIT_DATA)
kmemleak_scan_area(mod, sizeof(struct module), GFP_KERNEL); kmemleak_no_scan(mod->mem[type].base);
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);
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment