Skip to content

Commit cc0356d

Browse files
committed
Merge tag 'x86_core_for_v5.16_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 core updates from Borislav Petkov: - Do not #GP on userspace use of CLI/STI but pretend it was a NOP to keep old userspace from breaking. Adjust the corresponding iopl selftest to that. - Improve stack overflow warnings to say which stack got overflowed and raise the exception stack sizes to 2 pages since overflowing the single page of exception stack is very easy to do nowadays with all the tracing machinery enabled. With that, rip out the custom mapping of AMD SEV's too. - A bunch of changes in preparation for FGKASLR like supporting more than 64K section headers in the relocs tool, correct ORC lookup table size to cover the whole kernel .text and other adjustments. * tag 'x86_core_for_v5.16_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: selftests/x86/iopl: Adjust to the faked iopl CLI/STI usage vmlinux.lds.h: Have ORC lookup cover entire _etext - _stext x86/boot/compressed: Avoid duplicate malloc() implementations x86/boot: Allow a "silent" kaslr random byte fetch x86/tools/relocs: Support >64K section headers x86/sev: Make the #VC exception stacks part of the default stacks storage x86: Increase exception stack sizes x86/mm/64: Improve stack overflow warnings x86/iopl: Fake iopl(3) CLI/STI usage
2 parents fc02cb2 + a72fdfd commit cc0356d

File tree

22 files changed

+284
-130
lines changed

22 files changed

+284
-130
lines changed

arch/x86/boot/compressed/kaslr.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
#include <generated/utsrelease.h>
3333
#include <asm/efi.h>
3434

35-
/* Macros used by the included decompressor code below. */
36-
#define STATIC
37-
#include <linux/decompress/mm.h>
38-
3935
#define _SETUP
4036
#include <asm/setup.h> /* For COMMAND_LINE_SIZE */
4137
#undef _SETUP

arch/x86/boot/compressed/misc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828

2929
/* Macros used by the included decompressor code below. */
3030
#define STATIC static
31+
/* Define an externally visible malloc()/free(). */
32+
#define MALLOC_VISIBLE
33+
#include <linux/decompress/mm.h>
3134

3235
/*
3336
* Provide definitions of memzero and memmove as some of the decompressors will

arch/x86/boot/compressed/misc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ extern char _head[], _end[];
4646
/* misc.c */
4747
extern memptr free_mem_ptr;
4848
extern memptr free_mem_end_ptr;
49+
void *malloc(int size);
50+
void free(void *where);
4951
extern struct boot_params *boot_params;
5052
void __putstr(const char *s);
5153
void __puthex(unsigned long value);

arch/x86/include/asm/cpu_entry_area.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010

1111
#ifdef CONFIG_X86_64
1212

13+
#ifdef CONFIG_AMD_MEM_ENCRYPT
14+
#define VC_EXCEPTION_STKSZ EXCEPTION_STKSZ
15+
#else
16+
#define VC_EXCEPTION_STKSZ 0
17+
#endif
18+
1319
/* Macro to enforce the same ordering and stack sizes */
1420
#define ESTACKS_MEMBERS(guardsize, optional_stack_size) \
1521
char DF_stack_guard[guardsize]; \
@@ -28,7 +34,7 @@
2834

2935
/* The exception stacks' physical storage. No guard pages required */
3036
struct exception_stacks {
31-
ESTACKS_MEMBERS(0, 0)
37+
ESTACKS_MEMBERS(0, VC_EXCEPTION_STKSZ)
3238
};
3339

3440
/* The effective cpu entry area mapping with guard pages. */

arch/x86/include/asm/insn-eval.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ int insn_get_modrm_rm_off(struct insn *insn, struct pt_regs *regs);
2121
int insn_get_modrm_reg_off(struct insn *insn, struct pt_regs *regs);
2222
unsigned long insn_get_seg_base(struct pt_regs *regs, int seg_reg_idx);
2323
int insn_get_code_seg_params(struct pt_regs *regs);
24+
int insn_get_effective_ip(struct pt_regs *regs, unsigned long *ip);
2425
int insn_fetch_from_user(struct pt_regs *regs,
2526
unsigned char buf[MAX_INSN_SIZE]);
2627
int insn_fetch_from_user_inatomic(struct pt_regs *regs,

arch/x86/include/asm/irq_stack.h

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@
7777
* Function calls can clobber anything except the callee-saved
7878
* registers. Tell the compiler.
7979
*/
80-
#define call_on_irqstack(func, asm_call, argconstr...) \
80+
#define call_on_stack(stack, func, asm_call, argconstr...) \
8181
{ \
8282
register void *tos asm("r11"); \
8383
\
84-
tos = ((void *)__this_cpu_read(hardirq_stack_ptr)); \
84+
tos = ((void *)(stack)); \
8585
\
8686
asm_inline volatile( \
8787
"movq %%rsp, (%[tos]) \n" \
@@ -98,6 +98,25 @@
9898
); \
9999
}
100100

101+
#define ASM_CALL_ARG0 \
102+
"call %P[__func] \n"
103+
104+
#define ASM_CALL_ARG1 \
105+
"movq %[arg1], %%rdi \n" \
106+
ASM_CALL_ARG0
107+
108+
#define ASM_CALL_ARG2 \
109+
"movq %[arg2], %%rsi \n" \
110+
ASM_CALL_ARG1
111+
112+
#define ASM_CALL_ARG3 \
113+
"movq %[arg3], %%rdx \n" \
114+
ASM_CALL_ARG2
115+
116+
#define call_on_irqstack(func, asm_call, argconstr...) \
117+
call_on_stack(__this_cpu_read(hardirq_stack_ptr), \
118+
func, asm_call, argconstr)
119+
101120
/* Macros to assert type correctness for run_*_on_irqstack macros */
102121
#define assert_function_type(func, proto) \
103122
static_assert(__builtin_types_compatible_p(typeof(&func), proto))
@@ -147,8 +166,7 @@
147166
*/
148167
#define ASM_CALL_SYSVEC \
149168
"call irq_enter_rcu \n" \
150-
"movq %[arg1], %%rdi \n" \
151-
"call %P[__func] \n" \
169+
ASM_CALL_ARG1 \
152170
"call irq_exit_rcu \n"
153171

154172
#define SYSVEC_CONSTRAINTS , [arg1] "r" (regs)
@@ -168,12 +186,10 @@
168186
*/
169187
#define ASM_CALL_IRQ \
170188
"call irq_enter_rcu \n" \
171-
"movq %[arg1], %%rdi \n" \
172-
"movl %[arg2], %%esi \n" \
173-
"call %P[__func] \n" \
189+
ASM_CALL_ARG2 \
174190
"call irq_exit_rcu \n"
175191

176-
#define IRQ_CONSTRAINTS , [arg1] "r" (regs), [arg2] "r" (vector)
192+
#define IRQ_CONSTRAINTS , [arg1] "r" (regs), [arg2] "r" ((unsigned long)vector)
177193

178194
#define run_irq_on_irqstack_cond(func, regs, vector) \
179195
{ \
@@ -186,9 +202,6 @@
186202
}
187203

188204
#ifndef CONFIG_PREEMPT_RT
189-
#define ASM_CALL_SOFTIRQ \
190-
"call %P[__func] \n"
191-
192205
/*
193206
* Macro to invoke __do_softirq on the irq stack. This is only called from
194207
* task context when bottom halves are about to be reenabled and soft
@@ -198,7 +211,7 @@
198211
#define do_softirq_own_stack() \
199212
{ \
200213
__this_cpu_write(hardirq_stack_inuse, true); \
201-
call_on_irqstack(__do_softirq, ASM_CALL_SOFTIRQ); \
214+
call_on_irqstack(__do_softirq, ASM_CALL_ARG0); \
202215
__this_cpu_write(hardirq_stack_inuse, false); \
203216
}
204217

arch/x86/include/asm/page_64_types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define THREAD_SIZE_ORDER (2 + KASAN_STACK_ORDER)
1616
#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
1717

18-
#define EXCEPTION_STACK_ORDER (0 + KASAN_STACK_ORDER)
18+
#define EXCEPTION_STACK_ORDER (1 + KASAN_STACK_ORDER)
1919
#define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER)
2020

2121
#define IRQ_STACK_ORDER (2 + KASAN_STACK_ORDER)

arch/x86/include/asm/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,7 @@ struct thread_struct {
516516
*/
517517
unsigned long iopl_emul;
518518

519+
unsigned int iopl_warn:1;
519520
unsigned int sig_on_uaccess_err:1;
520521

521522
/*

arch/x86/include/asm/stacktrace.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ int get_stack_info(unsigned long *stack, struct task_struct *task,
3838
bool get_stack_info_noinstr(unsigned long *stack, struct task_struct *task,
3939
struct stack_info *info);
4040

41+
static __always_inline
42+
bool get_stack_guard_info(unsigned long *stack, struct stack_info *info)
43+
{
44+
/* make sure it's not in the stack proper */
45+
if (get_stack_info_noinstr(stack, current, info))
46+
return false;
47+
/* but if it is in the page below it, we hit a guard */
48+
return get_stack_info_noinstr((void *)stack + PAGE_SIZE, current, info);
49+
}
50+
4151
const char *stack_type_name(enum stack_type type);
4252

4353
static inline bool on_stack(struct stack_info *info, void *addr, size_t len)

arch/x86/include/asm/traps.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ void math_emulate(struct math_emu_info *);
4040
bool fault_in_kernel_space(unsigned long address);
4141

4242
#ifdef CONFIG_VMAP_STACK
43-
void __noreturn handle_stack_overflow(const char *message,
44-
struct pt_regs *regs,
45-
unsigned long fault_address);
43+
void __noreturn handle_stack_overflow(struct pt_regs *regs,
44+
unsigned long fault_address,
45+
struct stack_info *info);
4646
#endif
4747

4848
#endif /* _ASM_X86_TRAPS_H */

0 commit comments

Comments
 (0)