Skip to content

Commit acfa60d

Browse files
willdeaconctmarinas
authored andcommitted
arm64: mm: Fix "rodata=on" when CONFIG_RODATA_FULL_DEFAULT_ENABLED=y
When CONFIG_RODATA_FULL_DEFAULT_ENABLED=y, passing "rodata=on" on the kernel command-line (rather than "rodata=full") should turn off the "full" behaviour, leaving writable linear aliases of read-only kernel memory. Unfortunately, the option has no effect in this situation and the only way to disable the "rodata=full" behaviour is to disable rodata protection entirely by passing "rodata=off". Fix this by parsing the "on" and "off" options in the arch code, additionally enforcing that 'rodata_full' cannot be set without also setting 'rodata_enabled', allowing us to simplify a couple of checks in the process. Fixes: 2e8cff0 ("arm64: fix rodata=full") Cc: Ard Biesheuvel <[email protected]> Cc: Mark Rutland <[email protected]> Signed-off-by: Will Deacon <[email protected]> Reviewed-by: "Russell King (Oracle)" <[email protected]> Reviewed-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent b85ea95 commit acfa60d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

arch/arm64/include/asm/setup.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,22 @@ static inline bool arch_parse_debug_rodata(char *arg)
2121
extern bool rodata_enabled;
2222
extern bool rodata_full;
2323

24-
if (arg && !strcmp(arg, "full")) {
24+
if (!arg)
25+
return false;
26+
27+
if (!strcmp(arg, "full")) {
28+
rodata_enabled = rodata_full = true;
29+
return true;
30+
}
31+
32+
if (!strcmp(arg, "off")) {
33+
rodata_enabled = rodata_full = false;
34+
return true;
35+
}
36+
37+
if (!strcmp(arg, "on")) {
2538
rodata_enabled = true;
26-
rodata_full = true;
39+
rodata_full = false;
2740
return true;
2841
}
2942

arch/arm64/mm/pageattr.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ bool can_set_direct_map(void)
2929
*
3030
* KFENCE pool requires page-granular mapping if initialized late.
3131
*/
32-
return (rodata_enabled && rodata_full) || debug_pagealloc_enabled() ||
33-
arm64_kfence_can_set_direct_map();
32+
return rodata_full || debug_pagealloc_enabled() ||
33+
arm64_kfence_can_set_direct_map();
3434
}
3535

3636
static int change_page_range(pte_t *ptep, unsigned long addr, void *data)
@@ -105,8 +105,7 @@ static int change_memory_common(unsigned long addr, int numpages,
105105
* If we are manipulating read-only permissions, apply the same
106106
* change to the linear mapping of the pages that back this VM area.
107107
*/
108-
if (rodata_enabled &&
109-
rodata_full && (pgprot_val(set_mask) == PTE_RDONLY ||
108+
if (rodata_full && (pgprot_val(set_mask) == PTE_RDONLY ||
110109
pgprot_val(clear_mask) == PTE_RDONLY)) {
111110
for (i = 0; i < area->nr_pages; i++) {
112111
__change_memory_common((u64)page_address(area->pages[i]),

0 commit comments

Comments
 (0)