Changes in 4.9.169 x86/power: Fix some ordering bugs in __restore_processor_context() x86/power/64: Use struct desc_ptr for the IDT in struct saved_context x86/power/32: Move SYSENTER MSR restoration to fix_processor_context() x86/power: Make restore_processor_context() sane powerpc/tm: Limit TM code inside PPC_TRANSACTIONAL_MEM kbuild: clang: choose GCC_TOOLCHAIN_DIR not on LD x86: vdso: Use $LD instead of $CC to link x86/vdso: Drop implicit common-page-size linker flag lib/string.c: implement a basic bcmp powerpc: Fix invalid use of register expressions powerpc/64s: Add barrier_nospec powerpc/64s: Add support for ori barrier_nospec patching powerpc: Avoid code patching freed init sections powerpc/64s: Patch barrier_nospec in modules powerpc/64s: Enable barrier_nospec based on firmware settings powerpc: Use barrier_nospec in copy_from_user() powerpc/64: Use barrier_nospec in syscall entry powerpc/64s: Enhance the information in cpu_show_spectre_v1() powerpc64s: Show ori31 availability in spectre_v1 sysfs file not v2 powerpc/64: Disable the speculation barrier from the command line powerpc/64: Make stf barrier PPC_BOOK3S_64 specific. powerpc/64: Add CONFIG_PPC_BARRIER_NOSPEC powerpc/64: Call setup_barrier_nospec() from setup_arch() powerpc/64: Make meltdown reporting Book3S 64 specific powerpc/fsl: Add barrier_nospec implementation for NXP PowerPC Book3E powerpc/fsl: Sanitize the syscall table for NXP PowerPC 32 bit platforms powerpc/asm: Add a patch_site macro & helpers for patching instructions powerpc/64s: Add new security feature flags for count cache flush powerpc/64s: Add support for software count cache flush powerpc/pseries: Query hypervisor for count cache flush settings powerpc/powernv: Query firmware for count cache flush settings powerpc/fsl: Add infrastructure to fixup branch predictor flush powerpc/fsl: Add macro to flush the branch predictor powerpc/fsl: Fix spectre_v2 mitigations reporting powerpc/fsl: Emulate SPRN_BUCSR register powerpc/fsl: Add nospectre_v2 command line argument powerpc/fsl: Flush the branch predictor at each kernel entry (64bit) powerpc/fsl: Flush the branch predictor at each kernel entry (32 bit) powerpc/fsl: Flush branch predictor when entering KVM powerpc/fsl: Enable runtime patching if nospectre_v2 boot arg is used powerpc/fsl: Update Spectre v2 reporting powerpc/fsl: Fixed warning: orphan section `__btb_flush_fixup' powerpc/fsl: Fix the flush of branch predictor. powerpc/security: Fix spectre_v2 reporting arm64: kaslr: Reserve size of ARM64_MEMSTART_ALIGN in linear region tty: mark Siemens R3964 line discipline as BROKEN tty: ldisc: add sysctl to prevent autoloading of ldiscs ipv6: Fix dangling pointer when ipv6 fragment ipv6: sit: reset ip header pointer in ipip6_rcv kcm: switch order of device registration to fix a crash net: rds: force to destroy connection if t_sock is NULL in rds_tcp_kill_sock(). openvswitch: fix flow actions reallocation qmi_wwan: add Olicard 600 sctp: initialize _pad of sockaddr_in before copying to user memory tcp: Ensure DCTCP reacts to losses vrf: check accept_source_route on the original netdevice bnxt_en: Reset device on RX buffer errors. bnxt_en: Improve RX consumer index validity check. net/mlx5e: Add a lock on tir list netns: provide pure entropy for net_hash_mix() net: ethtool: not call vzalloc for zero sized memory request ip6_tunnel: Match to ARPHRD_TUNNEL6 for dev type ALSA: seq: Fix OOB-reads from strlcpy parisc: Detect QEMU earlier in boot process include/linux/bitrev.h: fix constant bitrev ASoC: fsl_esai: fix channel swap issue when stream starts Btrfs: do not allow trimming when a fs is mounted with the nologreplay option block: do not leak memory in bio_copy_user_iov() genirq: Respect IRQCHIP_SKIP_SET_WAKE in irq_chip_set_wake_parent() virtio: Honour 'may_reduce_num' in vring_create_virtqueue ARM: dts: at91: Fix typo in ISC_D0 on PC9 arm64: futex: Fix FUTEX_WAKE_OP atomic ops with non-zero result value parisc: Use cr16 interval timers unconditionally on qemu xen: Prevent buffer overflow in privcmd ioctl sched/fair: Do not re-read ->h_load_next during hierarchical load calculation xtensa: fix return_address PCI: Add function 1 DMA alias quirk for Marvell 9170 SATA controller Linux 4.9.169 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
290 lines
6.2 KiB
C
290 lines
6.2 KiB
C
/*
|
|
* Kernel and userspace stack tracing.
|
|
*
|
|
* This file is subject to the terms and conditions of the GNU General Public
|
|
* License. See the file "COPYING" in the main directory of this archive
|
|
* for more details.
|
|
*
|
|
* Copyright (C) 2001 - 2013 Tensilica Inc.
|
|
* Copyright (C) 2015 Cadence Design Systems Inc.
|
|
*/
|
|
#include <linux/export.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/stacktrace.h>
|
|
|
|
#include <asm/stacktrace.h>
|
|
#include <asm/traps.h>
|
|
#include <asm/uaccess.h>
|
|
|
|
#if IS_ENABLED(CONFIG_OPROFILE) || IS_ENABLED(CONFIG_PERF_EVENTS)
|
|
|
|
/* Address of common_exception_return, used to check the
|
|
* transition from kernel to user space.
|
|
*/
|
|
extern int common_exception_return;
|
|
|
|
/* A struct that maps to the part of the frame containing the a0 and
|
|
* a1 registers.
|
|
*/
|
|
struct frame_start {
|
|
unsigned long a0;
|
|
unsigned long a1;
|
|
};
|
|
|
|
void xtensa_backtrace_user(struct pt_regs *regs, unsigned int depth,
|
|
int (*ufn)(struct stackframe *frame, void *data),
|
|
void *data)
|
|
{
|
|
unsigned long windowstart = regs->windowstart;
|
|
unsigned long windowbase = regs->windowbase;
|
|
unsigned long a0 = regs->areg[0];
|
|
unsigned long a1 = regs->areg[1];
|
|
unsigned long pc = regs->pc;
|
|
struct stackframe frame;
|
|
int index;
|
|
|
|
if (!depth--)
|
|
return;
|
|
|
|
frame.pc = pc;
|
|
frame.sp = a1;
|
|
|
|
if (pc == 0 || pc >= TASK_SIZE || ufn(&frame, data))
|
|
return;
|
|
|
|
/* Two steps:
|
|
*
|
|
* 1. Look through the register window for the
|
|
* previous PCs in the call trace.
|
|
*
|
|
* 2. Look on the stack.
|
|
*/
|
|
|
|
/* Step 1. */
|
|
/* Rotate WINDOWSTART to move the bit corresponding to
|
|
* the current window to the bit #0.
|
|
*/
|
|
windowstart = (windowstart << WSBITS | windowstart) >> windowbase;
|
|
|
|
/* Look for bits that are set, they correspond to
|
|
* valid windows.
|
|
*/
|
|
for (index = WSBITS - 1; (index > 0) && depth; depth--, index--)
|
|
if (windowstart & (1 << index)) {
|
|
/* Get the PC from a0 and a1. */
|
|
pc = MAKE_PC_FROM_RA(a0, pc);
|
|
/* Read a0 and a1 from the
|
|
* corresponding position in AREGs.
|
|
*/
|
|
a0 = regs->areg[index * 4];
|
|
a1 = regs->areg[index * 4 + 1];
|
|
|
|
frame.pc = pc;
|
|
frame.sp = a1;
|
|
|
|
if (pc == 0 || pc >= TASK_SIZE || ufn(&frame, data))
|
|
return;
|
|
}
|
|
|
|
/* Step 2. */
|
|
/* We are done with the register window, we need to
|
|
* look through the stack.
|
|
*/
|
|
if (!depth)
|
|
return;
|
|
|
|
/* Start from the a1 register. */
|
|
/* a1 = regs->areg[1]; */
|
|
while (a0 != 0 && depth--) {
|
|
struct frame_start frame_start;
|
|
/* Get the location for a1, a0 for the
|
|
* previous frame from the current a1.
|
|
*/
|
|
unsigned long *psp = (unsigned long *)a1;
|
|
|
|
psp -= 4;
|
|
|
|
/* Check if the region is OK to access. */
|
|
if (!access_ok(VERIFY_READ, psp, sizeof(frame_start)))
|
|
return;
|
|
/* Copy a1, a0 from user space stack frame. */
|
|
if (__copy_from_user_inatomic(&frame_start, psp,
|
|
sizeof(frame_start)))
|
|
return;
|
|
|
|
pc = MAKE_PC_FROM_RA(a0, pc);
|
|
a0 = frame_start.a0;
|
|
a1 = frame_start.a1;
|
|
|
|
frame.pc = pc;
|
|
frame.sp = a1;
|
|
|
|
if (pc == 0 || pc >= TASK_SIZE || ufn(&frame, data))
|
|
return;
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(xtensa_backtrace_user);
|
|
|
|
void xtensa_backtrace_kernel(struct pt_regs *regs, unsigned int depth,
|
|
int (*kfn)(struct stackframe *frame, void *data),
|
|
int (*ufn)(struct stackframe *frame, void *data),
|
|
void *data)
|
|
{
|
|
unsigned long pc = regs->depc > VALID_DOUBLE_EXCEPTION_ADDRESS ?
|
|
regs->depc : regs->pc;
|
|
unsigned long sp_start, sp_end;
|
|
unsigned long a0 = regs->areg[0];
|
|
unsigned long a1 = regs->areg[1];
|
|
|
|
sp_start = a1 & ~(THREAD_SIZE - 1);
|
|
sp_end = sp_start + THREAD_SIZE;
|
|
|
|
/* Spill the register window to the stack first. */
|
|
spill_registers();
|
|
|
|
/* Read the stack frames one by one and create the PC
|
|
* from the a0 and a1 registers saved there.
|
|
*/
|
|
while (a1 > sp_start && a1 < sp_end && depth--) {
|
|
struct stackframe frame;
|
|
unsigned long *psp = (unsigned long *)a1;
|
|
|
|
frame.pc = pc;
|
|
frame.sp = a1;
|
|
|
|
if (kernel_text_address(pc) && kfn(&frame, data))
|
|
return;
|
|
|
|
if (pc == (unsigned long)&common_exception_return) {
|
|
regs = (struct pt_regs *)a1;
|
|
if (user_mode(regs)) {
|
|
if (ufn == NULL)
|
|
return;
|
|
xtensa_backtrace_user(regs, depth, ufn, data);
|
|
return;
|
|
}
|
|
a0 = regs->areg[0];
|
|
a1 = regs->areg[1];
|
|
continue;
|
|
}
|
|
|
|
sp_start = a1;
|
|
|
|
pc = MAKE_PC_FROM_RA(a0, pc);
|
|
a0 = *(psp - 4);
|
|
a1 = *(psp - 3);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(xtensa_backtrace_kernel);
|
|
|
|
#endif
|
|
|
|
void walk_stackframe(unsigned long *sp,
|
|
int (*fn)(struct stackframe *frame, void *data),
|
|
void *data)
|
|
{
|
|
unsigned long a0, a1;
|
|
unsigned long sp_end;
|
|
|
|
a1 = (unsigned long)sp;
|
|
sp_end = ALIGN(a1, THREAD_SIZE);
|
|
|
|
spill_registers();
|
|
|
|
while (a1 < sp_end) {
|
|
struct stackframe frame;
|
|
|
|
sp = (unsigned long *)a1;
|
|
|
|
a0 = *(sp - 4);
|
|
a1 = *(sp - 3);
|
|
|
|
if (a1 <= (unsigned long)sp)
|
|
break;
|
|
|
|
frame.pc = MAKE_PC_FROM_RA(a0, a1);
|
|
frame.sp = a1;
|
|
|
|
if (fn(&frame, data))
|
|
return;
|
|
}
|
|
}
|
|
|
|
#ifdef CONFIG_STACKTRACE
|
|
|
|
struct stack_trace_data {
|
|
struct stack_trace *trace;
|
|
unsigned skip;
|
|
};
|
|
|
|
static int stack_trace_cb(struct stackframe *frame, void *data)
|
|
{
|
|
struct stack_trace_data *trace_data = data;
|
|
struct stack_trace *trace = trace_data->trace;
|
|
|
|
if (trace_data->skip) {
|
|
--trace_data->skip;
|
|
return 0;
|
|
}
|
|
if (!kernel_text_address(frame->pc))
|
|
return 0;
|
|
|
|
trace->entries[trace->nr_entries++] = frame->pc;
|
|
return trace->nr_entries >= trace->max_entries;
|
|
}
|
|
|
|
void save_stack_trace_tsk(struct task_struct *task, struct stack_trace *trace)
|
|
{
|
|
struct stack_trace_data trace_data = {
|
|
.trace = trace,
|
|
.skip = trace->skip,
|
|
};
|
|
walk_stackframe(stack_pointer(task), stack_trace_cb, &trace_data);
|
|
}
|
|
EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
|
|
|
|
void save_stack_trace(struct stack_trace *trace)
|
|
{
|
|
save_stack_trace_tsk(current, trace);
|
|
}
|
|
EXPORT_SYMBOL_GPL(save_stack_trace);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_FRAME_POINTER
|
|
|
|
struct return_addr_data {
|
|
unsigned long addr;
|
|
unsigned skip;
|
|
};
|
|
|
|
static int return_address_cb(struct stackframe *frame, void *data)
|
|
{
|
|
struct return_addr_data *r = data;
|
|
|
|
if (r->skip) {
|
|
--r->skip;
|
|
return 0;
|
|
}
|
|
if (!kernel_text_address(frame->pc))
|
|
return 0;
|
|
r->addr = frame->pc;
|
|
return 1;
|
|
}
|
|
|
|
/*
|
|
* level == 0 is for the return address from the caller of this function,
|
|
* not from this function itself.
|
|
*/
|
|
unsigned long return_address(unsigned level)
|
|
{
|
|
struct return_addr_data r = {
|
|
.skip = level,
|
|
};
|
|
walk_stackframe(stack_pointer(NULL), return_address_cb, &r);
|
|
return r.addr;
|
|
}
|
|
EXPORT_SYMBOL(return_address);
|
|
|
|
#endif
|