[PATCH] module: don't annotate ROX memory as kmemleak_not_leak()

Mike Rapoport posted 1 patch 3 weeks, 5 days ago
kernel/module/main.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] module: don't annotate ROX memory as kmemleak_not_leak()
Posted by Mike Rapoport 3 weeks, 5 days ago
From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>

The ROX memory allocations are part of a larger vmalloc allocation and
annotating them with kmemleak_not_leak() confuses kmemleak.

Skip kmemleak_not_leak() annotations for the ROX areas.

Fixes: c287c0723329 ("module: switch to execmem API for remapping as RW and restoring ROX")
Fixes: 64f6a4e10c05 ("x86: re-enable EXECMEM_ROX support")
Reported-by: "Borah, Chaitanya Kumar" <chaitanya.kumar.borah@intel.com>
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
---

Peter, can you take it via tip tree?
Or you prefer for Luis to pick this up?

 kernel/module/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/module/main.c b/kernel/module/main.c
index 974821d6e85a..3dbe23098433 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -1250,7 +1250,8 @@ static int module_memory_alloc(struct module *mod, enum mod_mem_type type)
 	 * *do* eventually get freed, but let's just keep things simple
 	 * and avoid *any* false positives.
 	 */
-	kmemleak_not_leak(ptr);
+	if (!mod->mem[type].is_rox)
+		kmemleak_not_leak(ptr);
 
 	memset(ptr, 0, size);
 	mod->mem[type].base = ptr;
-- 
2.47.2
Re: [PATCH] module: don't annotate ROX memory as kmemleak_not_leak()
Posted by Peter Zijlstra 3 weeks, 5 days ago
On Fri, Feb 14, 2025 at 10:45:31AM +0200, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
> 
> The ROX memory allocations are part of a larger vmalloc allocation and
> annotating them with kmemleak_not_leak() confuses kmemleak.
> 
> Skip kmemleak_not_leak() annotations for the ROX areas.
> 
> Fixes: c287c0723329 ("module: switch to execmem API for remapping as RW and restoring ROX")
> Fixes: 64f6a4e10c05 ("x86: re-enable EXECMEM_ROX support")
> Reported-by: "Borah, Chaitanya Kumar" <chaitanya.kumar.borah@intel.com>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> 
> Peter, can you take it via tip tree?
> Or you prefer for Luis to pick this up?

Less of a head-ache overall if these things stay together I recon.
So I'll stick it in tip/x86/mm along with the rest of those patches.

Thanks!
[tip: x86/core] module: don't annotate ROX memory as kmemleak_not_leak()
Posted by tip-bot2 for Mike Rapoport (Microsoft) 3 weeks, 4 days ago
The following commit has been merged into the x86/core branch of tip:

Commit-ID:     675204778c69c2b3e0f6a4e2dbfeb4f3e89194ba
Gitweb:        https://git.kernel.org/tip/675204778c69c2b3e0f6a4e2dbfeb4f3e89194ba
Author:        Mike Rapoport (Microsoft) <rppt@kernel.org>
AuthorDate:    Fri, 14 Feb 2025 10:45:31 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 14 Feb 2025 10:32:02 +01:00

module: don't annotate ROX memory as kmemleak_not_leak()

The ROX memory allocations are part of a larger vmalloc allocation and
annotating them with kmemleak_not_leak() confuses kmemleak.

Skip kmemleak_not_leak() annotations for the ROX areas.

Fixes: c287c0723329 ("module: switch to execmem API for remapping as RW and restoring ROX")
Fixes: 64f6a4e10c05 ("x86: re-enable EXECMEM_ROX support")
Reported-by: "Borah, Chaitanya Kumar" <chaitanya.kumar.borah@intel.com>
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20250214084531.3299390-1-rppt@kernel.org
---
 kernel/module/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/module/main.c b/kernel/module/main.c
index 5c127be..a256cc9 100644
--- a/kernel/module/main.c
+++ b/kernel/module/main.c
@@ -1260,7 +1260,8 @@ static int module_memory_alloc(struct module *mod, enum mod_mem_type type)
 	 * *do* eventually get freed, but let's just keep things simple
 	 * and avoid *any* false positives.
 	 */
-	kmemleak_not_leak(ptr);
+	if (!mod->mem[type].is_rox)
+		kmemleak_not_leak(ptr);
 
 	memset(ptr, 0, size);
 	mod->mem[type].base = ptr;