Skip to content

Commit b8902f8

Browse files
keesbroonie
authored andcommitted
x86/mm: Always enable CONFIG_DEBUG_RODATA and remove the Kconfig option
commit 9ccaf77cf05915f51231d158abfd5448aedde758 upstream. This removes the CONFIG_DEBUG_RODATA option and makes it always enabled. This simplifies the code and also makes it clearer that read-only mapped memory is just as fundamental a security feature in kernel-space as it is in user-space. Suggested-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Andy Lutomirski <luto@amacapital.net> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: David Brown <david.brown@linaro.org> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Emese Revfy <re.emese@gmail.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Mathias Krause <minipli@googlemail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: PaX Team <pageexec@freemail.hu> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: kernel-hardening@lists.openwall.com Cc: linux-arch <linux-arch@vger.kernel.org> Link: http://lkml.kernel.org/r/1455748879-21872-4-git-send-email-keescook@chromium.org Signed-off-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: David Brown <david.brown@linaro.org> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 97db577 commit b8902f8

13 files changed

Lines changed: 25 additions & 61 deletions

File tree

arch/x86/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ config ARCH_SUPPORTS_UPROBES
289289
config FIX_EARLYCON_MEM
290290
def_bool y
291291

292+
config DEBUG_RODATA
293+
def_bool y
294+
292295
config PGTABLE_LEVELS
293296
int
294297
default 4 if X86_64

arch/x86/Kconfig.debug

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,16 @@ config EFI_PGT_DUMP
9191
issues with the mapping of the EFI runtime regions into that
9292
table.
9393

94-
config DEBUG_RODATA
95-
bool "Write protect kernel read-only data structures"
96-
default y
97-
depends on DEBUG_KERNEL
98-
---help---
99-
Mark the kernel read-only data as write-protected in the pagetables,
100-
in order to catch accidental (and incorrect) writes to such const
101-
data. This is recommended so that we can catch kernel bugs sooner.
102-
If in doubt, say "Y".
103-
10494
config DEBUG_RODATA_TEST
105-
bool "Testcase for the DEBUG_RODATA feature"
106-
depends on DEBUG_RODATA
95+
bool "Testcase for the marking rodata read-only"
10796
default y
10897
---help---
109-
This option enables a testcase for the DEBUG_RODATA
110-
feature as well as for the change_page_attr() infrastructure.
98+
This option enables a testcase for the setting rodata read-only
99+
as well as for the change_page_attr() infrastructure.
111100
If in doubt, say "N"
112101

113102
config DEBUG_WX
114103
bool "Warn on W+X mappings at boot"
115-
depends on DEBUG_RODATA
116104
select X86_PTDUMP_CORE
117105
---help---
118106
Generate a warning if any W+X mappings are found at boot.

arch/x86/include/asm/cacheflush.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,10 @@ void clflush_cache_range(void *addr, unsigned int size);
9191

9292
#define mmio_flush_range(addr, size) clflush_cache_range(addr, size)
9393

94-
#ifdef CONFIG_DEBUG_RODATA
9594
extern const int rodata_test_data;
9695
extern int kernel_set_to_readonly;
9796
void set_kernel_text_rw(void);
9897
void set_kernel_text_ro(void);
99-
#else
100-
static inline void set_kernel_text_rw(void) { }
101-
static inline void set_kernel_text_ro(void) { }
102-
#endif
10398

10499
#ifdef CONFIG_DEBUG_RODATA_TEST
105100
int rodata_test(void);

arch/x86/include/asm/kvm_para.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,8 @@ static inline bool kvm_check_and_clear_guest_paused(void)
1717
}
1818
#endif /* CONFIG_KVM_GUEST */
1919

20-
#ifdef CONFIG_DEBUG_RODATA
2120
#define KVM_HYPERCALL \
2221
ALTERNATIVE(".byte 0x0f,0x01,0xc1", ".byte 0x0f,0x01,0xd9", X86_FEATURE_VMMCALL)
23-
#else
24-
/* On AMD processors, vmcall will generate a trap that we will
25-
* then rewrite to the appropriate instruction.
26-
*/
27-
#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
28-
#endif
2922

3023
/* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
3124
* instruction. The hypervisor may replace it with something else but only the

arch/x86/include/asm/sections.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
extern char __brk_base[], __brk_limit[];
88
extern struct exception_table_entry __stop___ex_table[];
99

10-
#if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
10+
#if defined(CONFIG_X86_64)
1111
extern char __end_rodata_hpage_align[];
1212
#endif
1313

arch/x86/kernel/ftrace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ within(unsigned long addr, unsigned long start, unsigned long end)
8181
static unsigned long text_ip_addr(unsigned long ip)
8282
{
8383
/*
84-
* On x86_64, kernel text mappings are mapped read-only with
85-
* CONFIG_DEBUG_RODATA. So we use the kernel identity mapping instead
86-
* of the kernel text mapping to modify the kernel text.
84+
* On x86_64, kernel text mappings are mapped read-only, so we use
85+
* the kernel identity mapping instead of the kernel text mapping
86+
* to modify the kernel text.
8787
*
8888
* For 32bit kernels, these mappings are same and we can use
8989
* kernel identity mapping to modify code.

arch/x86/kernel/kgdb.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,7 @@ void kgdb_arch_set_pc(struct pt_regs *regs, unsigned long ip)
750750
int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
751751
{
752752
int err;
753-
#ifdef CONFIG_DEBUG_RODATA
754753
char opc[BREAK_INSTR_SIZE];
755-
#endif /* CONFIG_DEBUG_RODATA */
756754

757755
bpt->type = BP_BREAKPOINT;
758756
err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
@@ -761,7 +759,6 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
761759
return err;
762760
err = probe_kernel_write((char *)bpt->bpt_addr,
763761
arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
764-
#ifdef CONFIG_DEBUG_RODATA
765762
if (!err)
766763
return err;
767764
/*
@@ -778,13 +775,12 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
778775
if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
779776
return -EINVAL;
780777
bpt->type = BP_POKE_BREAKPOINT;
781-
#endif /* CONFIG_DEBUG_RODATA */
778+
782779
return err;
783780
}
784781

785782
int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
786783
{
787-
#ifdef CONFIG_DEBUG_RODATA
788784
int err;
789785
char opc[BREAK_INSTR_SIZE];
790786

@@ -801,8 +797,8 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
801797
if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
802798
goto knl_write;
803799
return err;
800+
804801
knl_write:
805-
#endif /* CONFIG_DEBUG_RODATA */
806802
return probe_kernel_write((char *)bpt->bpt_addr,
807803
(char *)bpt->saved_instr, BREAK_INSTR_SIZE);
808804
}

arch/x86/kernel/test_nx.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ static int test_NX(void)
142142
* by the error message
143143
*/
144144

145-
#ifdef CONFIG_DEBUG_RODATA
146145
/* Test 3: Check if the .rodata section is executable */
147146
if (rodata_test_data != 0xC3) {
148147
printk(KERN_ERR "test_nx: .rodata marker has invalid value\n");
@@ -151,7 +150,6 @@ static int test_NX(void)
151150
printk(KERN_ERR "test_nx: .rodata section is executable\n");
152151
ret = -ENODEV;
153152
}
154-
#endif
155153

156154
#if 0
157155
/* Test 4: Check if the .data section of a module is executable */

arch/x86/kernel/test_rodata.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,5 @@ int rodata_test(void)
7676
}
7777

7878
MODULE_LICENSE("GPL");
79-
MODULE_DESCRIPTION("Testcase for the DEBUG_RODATA infrastructure");
79+
MODULE_DESCRIPTION("Testcase for marking rodata as read-only");
8080
MODULE_AUTHOR("Arjan van de Ven <arjan@linux.intel.com>");

arch/x86/kernel/vmlinux.lds.S

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,28 @@ ENTRY(phys_startup_64)
4141
jiffies_64 = jiffies;
4242
#endif
4343

44-
#if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
44+
#if defined(CONFIG_X86_64)
4545
/*
46-
* On 64-bit, align RODATA to 2MB so that even with CONFIG_DEBUG_RODATA
47-
* we retain large page mappings for boundaries spanning kernel text, rodata
48-
* and data sections.
46+
* On 64-bit, align RODATA to 2MB so we retain large page mappings for
47+
* boundaries spanning kernel text, rodata and data sections.
4948
*
5049
* However, kernel identity mappings will have different RWX permissions
5150
* to the pages mapping to text and to the pages padding (which are freed) the
5251
* text section. Hence kernel identity mappings will be broken to smaller
5352
* pages. For 64-bit, kernel text and kernel identity mappings are different,
54-
* so we can enable protection checks that come with CONFIG_DEBUG_RODATA,
55-
* as well as retain 2MB large page mappings for kernel text.
53+
* so we can enable protection checks as well as retain 2MB large page
54+
* mappings for kernel text.
5655
*/
57-
#define X64_ALIGN_DEBUG_RODATA_BEGIN . = ALIGN(HPAGE_SIZE);
56+
#define X64_ALIGN_RODATA_BEGIN . = ALIGN(HPAGE_SIZE);
5857

59-
#define X64_ALIGN_DEBUG_RODATA_END \
58+
#define X64_ALIGN_RODATA_END \
6059
. = ALIGN(HPAGE_SIZE); \
6160
__end_rodata_hpage_align = .;
6261

6362
#else
6463

65-
#define X64_ALIGN_DEBUG_RODATA_BEGIN
66-
#define X64_ALIGN_DEBUG_RODATA_END
64+
#define X64_ALIGN_RODATA_BEGIN
65+
#define X64_ALIGN_RODATA_END
6766

6867
#endif
6968

@@ -112,13 +111,11 @@ SECTIONS
112111

113112
EXCEPTION_TABLE(16) :text = 0x9090
114113

115-
#if defined(CONFIG_DEBUG_RODATA)
116114
/* .text should occupy whole number of pages */
117115
. = ALIGN(PAGE_SIZE);
118-
#endif
119-
X64_ALIGN_DEBUG_RODATA_BEGIN
116+
X64_ALIGN_RODATA_BEGIN
120117
RO_DATA(PAGE_SIZE)
121-
X64_ALIGN_DEBUG_RODATA_END
118+
X64_ALIGN_RODATA_END
122119

123120
/* Data */
124121
.data : AT(ADDR(.data) - LOAD_OFFSET) {

0 commit comments

Comments
 (0)