Skip to content

Commit

Permalink
module: fix kmemleak annotations for non init ELF sections
Browse files Browse the repository at this point in the history
Commit ac3b432 ("module: replace module_layout with module_memory")
reworked the way to handle memory allocations to make it clearer. But it
lost in translation how we handled kmemleak_ignore() or kmemleak_not_leak()
for different ELF sections.

Fix this and clarify the comments a bit more. Contrary to the old way
of using kmemleak_ignore() for init.* ELF sections we stick now only to
kmemleak_not_leak() as per suggestion by Catalin Marinas so to avoid
any false positives and simplify the code.

Fixes: ac3b432 ("module: replace module_layout with module_memory")
Reported-by: Jim Cromie <jim.cromie@gmail.com>
Acked-by: Song Liu <song@kernel.org>
Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
  • Loading branch information
mcgrof committed Apr 14, 2023
1 parent 0a3bf86 commit 430bb0d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions kernel/module/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2231,13 +2231,18 @@ static int move_module(struct module *mod, struct load_info *info)
}
mod->mem[type].size = PAGE_ALIGN(mod->mem[type].size);
ptr = module_memory_alloc(mod->mem[type].size, type);

/*
* The pointer to this block is stored in the module structure
* which is inside the block. Just mark it as not being a
* leak.
* The pointer to these blocks of memory are stored on the module
* structure and we keep that around so long as the module is
* around. We only free that memory when we unload the module.
* Just mark them as not being a leak then. The .init* ELF
* sections *do* get freed after boot so we *could* treat them
* slightly differently with kmemleak_ignore() and only grey
* them out as they work as typical memory allocations which
* *do* eventually get freed, but let's just keep things simple
* and avoid *any* false positives.
*/
kmemleak_ignore(ptr);
kmemleak_not_leak(ptr);
if (!ptr) {
t = type;
goto out_enomem;
Expand Down

0 comments on commit 430bb0d

Please sign in to comment.