]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
arm64: kprobes: check the return value of set_memory_rox()
authorYang Shi <yang@os.amperecomputing.com>
Tue, 4 Nov 2025 21:49:47 +0000 (13:49 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Nov 2025 09:35:46 +0000 (10:35 +0100)
[ Upstream commit 0ec364c0c95fc85bcbc88f1a9a06ebe83c88e18c ]

Since commit a166563e7ec3 ("arm64: mm: support large block mapping when
rodata=full"), __change_memory_common has more chance to fail due to
memory allocation failure when splitting page table. So check the return
value of set_memory_rox(), then bail out if it fails otherwise we may have
RW memory mapping for kprobes insn page.

Fixes: 195a1b7d8388 ("arm64: kprobes: call set_memory_rox() for kprobe page")
Reviewed-by: Ryan Roberts <ryan.roberts@arm.com>
Reviewed-by: Dev Jain <dev.jain@arm.com>
Signed-off-by: Yang Shi <yang@os.amperecomputing.com>
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/arm64/kernel/probes/kprobes.c

index 6e397d8dcd4c2668cc3c4a2f0e854c2cbed590dd..b0e0f0aed748a82c06616e9a4acbdd67b13d8525 100644 (file)
@@ -49,7 +49,10 @@ void *alloc_insn_page(void)
        addr = execmem_alloc(EXECMEM_KPROBES, PAGE_SIZE);
        if (!addr)
                return NULL;
-       set_memory_rox((unsigned long)addr, 1);
+       if (set_memory_rox((unsigned long)addr, 1)) {
+               execmem_free(addr);
+               return NULL;
+       }
        return addr;
 }