Skip to content

Commit 262d6a9

Browse files
committed
Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 fixes from Thomas Gleixner: "A set of fixes for x86: - Make the unwinder more robust when it encounters a NULL pointer call, so the backtrace becomes more useful - Fix the bogus ORC unwind table alignment - Prevent kernel panic during kexec on HyperV caused by a cleared but not disabled hypercall page. - Remove the now pointless stacksize increase for KASAN_EXTRA, as KASAN_EXTRA is gone. - Remove unused variables from the x86 memory management code" * 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/hyperv: Fix kernel panic when kexec on HyperV x86/mm: Remove unused variable 'old_pte' x86/mm: Remove unused variable 'cpu' Revert "x86_64: Increase stack size for KASAN_EXTRA" x86/unwind: Add hardcoded ORC entry for NULL x86/unwind: Handle NULL pointer calls better in frame unwinder x86/unwind/orc: Fix ORC unwind table alignment
2 parents b6e3cb4 + 179fb36 commit 262d6a9

File tree

7 files changed

+55
-10
lines changed

7 files changed

+55
-10
lines changed

arch/x86/hyperv/hv_init.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,13 @@ void hyperv_cleanup(void)
407407
/* Reset our OS id */
408408
wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0);
409409

410+
/*
411+
* Reset hypercall page reference before reset the page,
412+
* let hypercall operations fail safely rather than
413+
* panic the kernel for using invalid hypercall page
414+
*/
415+
hv_hypercall_pg = NULL;
416+
410417
/* Reset the hypercall page */
411418
hypercall_msr.as_uint64 = 0;
412419
wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);

arch/x86/include/asm/page_64_types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
#endif
88

99
#ifdef CONFIG_KASAN
10-
#ifdef CONFIG_KASAN_EXTRA
11-
#define KASAN_STACK_ORDER 2
12-
#else
1310
#define KASAN_STACK_ORDER 1
14-
#endif
1511
#else
1612
#define KASAN_STACK_ORDER 0
1713
#endif

arch/x86/include/asm/unwind.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ struct unwind_state {
2323
#elif defined(CONFIG_UNWINDER_FRAME_POINTER)
2424
bool got_irq;
2525
unsigned long *bp, *orig_sp, ip;
26+
/*
27+
* If non-NULL: The current frame is incomplete and doesn't contain a
28+
* valid BP. When looking for the next frame, use this instead of the
29+
* non-existent saved BP.
30+
*/
31+
unsigned long *next_bp;
2632
struct pt_regs *regs;
2733
#else
2834
unsigned long *sp;

arch/x86/kernel/unwind_frame.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,14 @@ bool unwind_next_frame(struct unwind_state *state)
320320
}
321321

322322
/* Get the next frame pointer: */
323-
if (state->regs)
323+
if (state->next_bp) {
324+
next_bp = state->next_bp;
325+
state->next_bp = NULL;
326+
} else if (state->regs) {
324327
next_bp = (unsigned long *)state->regs->bp;
325-
else
328+
} else {
326329
next_bp = (unsigned long *)READ_ONCE_TASK_STACK(state->task, *state->bp);
330+
}
327331

328332
/* Move to the next frame if it's safe: */
329333
if (!update_stack_state(state, next_bp))
@@ -398,6 +402,21 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,
398402

399403
bp = get_frame_pointer(task, regs);
400404

405+
/*
406+
* If we crash with IP==0, the last successfully executed instruction
407+
* was probably an indirect function call with a NULL function pointer.
408+
* That means that SP points into the middle of an incomplete frame:
409+
* *SP is a return pointer, and *(SP-sizeof(unsigned long)) is where we
410+
* would have written a frame pointer if we hadn't crashed.
411+
* Pretend that the frame is complete and that BP points to it, but save
412+
* the real BP so that we can use it when looking for the next frame.
413+
*/
414+
if (regs && regs->ip == 0 &&
415+
(unsigned long *)kernel_stack_pointer(regs) >= first_frame) {
416+
state->next_bp = bp;
417+
bp = ((unsigned long *)kernel_stack_pointer(regs)) - 1;
418+
}
419+
401420
/* Initialize stack info and make sure the frame data is accessible: */
402421
get_stack_info(bp, state->task, &state->stack_info,
403422
&state->stack_mask);
@@ -410,7 +429,7 @@ void __unwind_start(struct unwind_state *state, struct task_struct *task,
410429
*/
411430
while (!unwind_done(state) &&
412431
(!on_stack(&state->stack_info, first_frame, sizeof(long)) ||
413-
state->bp < first_frame))
432+
(state->next_bp == NULL && state->bp < first_frame)))
414433
unwind_next_frame(state);
415434
}
416435
EXPORT_SYMBOL_GPL(__unwind_start);

arch/x86/kernel/unwind_orc.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,30 @@ static struct orc_entry *orc_ftrace_find(unsigned long ip)
113113
}
114114
#endif
115115

116+
/*
117+
* If we crash with IP==0, the last successfully executed instruction
118+
* was probably an indirect function call with a NULL function pointer,
119+
* and we don't have unwind information for NULL.
120+
* This hardcoded ORC entry for IP==0 allows us to unwind from a NULL function
121+
* pointer into its parent and then continue normally from there.
122+
*/
123+
static struct orc_entry null_orc_entry = {
124+
.sp_offset = sizeof(long),
125+
.sp_reg = ORC_REG_SP,
126+
.bp_reg = ORC_REG_UNDEFINED,
127+
.type = ORC_TYPE_CALL
128+
};
129+
116130
static struct orc_entry *orc_find(unsigned long ip)
117131
{
118132
static struct orc_entry *orc;
119133

120134
if (!orc_init)
121135
return NULL;
122136

137+
if (ip == 0)
138+
return &null_orc_entry;
139+
123140
/* For non-init vmlinux addresses, use the fast lookup table: */
124141
if (ip >= LOOKUP_START_IP && ip < LOOKUP_STOP_IP) {
125142
unsigned int idx, start, stop;

arch/x86/mm/pageattr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ static int __should_split_large_page(pte_t *kpte, unsigned long address,
738738
{
739739
unsigned long numpages, pmask, psize, lpaddr, pfn, old_pfn;
740740
pgprot_t old_prot, new_prot, req_prot, chk_prot;
741-
pte_t new_pte, old_pte, *tmp;
741+
pte_t new_pte, *tmp;
742742
enum pg_level level;
743743

744744
/*
@@ -781,7 +781,7 @@ static int __should_split_large_page(pte_t *kpte, unsigned long address,
781781
* Convert protection attributes to 4k-format, as cpa->mask* are set
782782
* up accordingly.
783783
*/
784-
old_pte = *kpte;
784+
785785
/* Clear PSE (aka _PAGE_PAT) and move PAT bit to correct position */
786786
req_prot = pgprot_large_2_4k(old_prot);
787787

include/asm-generic/vmlinux.lds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@
733733
KEEP(*(.orc_unwind_ip)) \
734734
__stop_orc_unwind_ip = .; \
735735
} \
736-
. = ALIGN(6); \
736+
. = ALIGN(2); \
737737
.orc_unwind : AT(ADDR(.orc_unwind) - LOAD_OFFSET) { \
738738
__start_orc_unwind = .; \
739739
KEEP(*(.orc_unwind)) \

0 commit comments

Comments
 (0)