Revision 1022623842cb72ee4d0dbf02f6937f38c92c3f41 authored by Robert Richter on 03 September 2012, 18:54:48 UTC, committed by H. Peter Anvin on 21 November 2012, 06:23:20 UTC
In 32 bit the stack address provided by kernel_stack_pointer() may
point to an invalid range causing NULL pointer access or page faults
while in NMI (see trace below). This happens if called in softirq
context and if the stack is empty. The address at &regs->sp is then
out of range.

Fixing this by checking if regs and &regs->sp are in the same stack
context. Otherwise return the previous stack pointer stored in struct
thread_info. If that address is invalid too, return address of regs.

 BUG: unable to handle kernel NULL pointer dereference at 0000000a
 IP: [<c1004237>] print_context_stack+0x6e/0x8d
 *pde = 00000000
 Oops: 0000 [#1] SMP
 Modules linked in:
 Pid: 4434, comm: perl Not tainted 3.6.0-rc3-oprofile-i386-standard-g4411a05 #4 Hewlett-Packard HP xw9400 Workstation/0A1Ch
 EIP: 0060:[<c1004237>] EFLAGS: 00010093 CPU: 0
 EIP is at print_context_stack+0x6e/0x8d
 EAX: ffffe000 EBX: 0000000a ECX: f4435f94 EDX: 0000000a
 ESI: f4435f94 EDI: f4435f94 EBP: f5409ec0 ESP: f5409ea0
  DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068
 CR0: 8005003b CR2: 0000000a CR3: 34ac9000 CR4: 000007d0
 DR0: 00000000 DR1: 00000000 DR2: 00000000 DR3: 00000000
 DR6: ffff0ff0 DR7: 00000400
 Process perl (pid: 4434, ti=f5408000 task=f5637850 task.ti=f4434000)
 Stack:
  000003e8 ffffe000 00001ffc f4e39b00 00000000 0000000a f4435f94 c155198c
  f5409ef0 c1003723 c155198c f5409f04 00000000 f5409edc 00000000 00000000
  f5409ee8 f4435f94 f5409fc4 00000001 f5409f1c c12dce1c 00000000 c155198c
 Call Trace:
  [<c1003723>] dump_trace+0x7b/0xa1
  [<c12dce1c>] x86_backtrace+0x40/0x88
  [<c12db712>] ? oprofile_add_sample+0x56/0x84
  [<c12db731>] oprofile_add_sample+0x75/0x84
  [<c12ddb5b>] op_amd_check_ctrs+0x46/0x260
  [<c12dd40d>] profile_exceptions_notify+0x23/0x4c
  [<c1395034>] nmi_handle+0x31/0x4a
  [<c1029dc5>] ? ftrace_define_fields_irq_handler_entry+0x45/0x45
  [<c13950ed>] do_nmi+0xa0/0x2ff
  [<c1029dc5>] ? ftrace_define_fields_irq_handler_entry+0x45/0x45
  [<c13949e5>] nmi_stack_correct+0x28/0x2d
  [<c1029dc5>] ? ftrace_define_fields_irq_handler_entry+0x45/0x45
  [<c1003603>] ? do_softirq+0x4b/0x7f
  <IRQ>
  [<c102a06f>] irq_exit+0x35/0x5b
  [<c1018f56>] smp_apic_timer_interrupt+0x6c/0x7a
  [<c1394746>] apic_timer_interrupt+0x2a/0x30
 Code: 89 fe eb 08 31 c9 8b 45 0c ff 55 ec 83 c3 04 83 7d 10 00 74 0c 3b 5d 10 73 26 3b 5d e4 73 0c eb 1f 3b 5d f0 76 1a 3b 5d e8 73 15 <8b> 13 89 d0 89 55 e0 e8 ad 42 03 00 85 c0 8b 55 e0 75 a6 eb cc
 EIP: [<c1004237>] print_context_stack+0x6e/0x8d SS:ESP 0068:f5409ea0
 CR2: 000000000000000a
 ---[ end trace 62afee3481b00012 ]---
 Kernel panic - not syncing: Fatal exception in interrupt

V2:
* add comments to kernel_stack_pointer()
* always return a valid stack address by falling back to the address
  of regs

Reported-by: Yang Wei <wei.yang@windriver.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Robert Richter <robert.richter@amd.com>
Link: http://lkml.kernel.org/r/20120912135059.GZ8285@erda.amd.com
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Jun Zhang <jun.zhang@intel.com>
1 parent c1ddb48
History
File Mode Size
ABI
DocBook
EDID
PCI
RCU
accounting
acpi
aoe
arm
arm64
auxdisplay
backlight
blackfin
block
blockdev
cdrom
cgroups
connector
console
cpu-freq
cpuidle
cris
crypto
development-process
device-mapper
devicetree
driver-model
dvb
early-userspace
extcon
fault-injection
fb
filesystems
firmware_class
frv
hid
hwmon
i2c
i2o
ia64
ide
infiniband
input
ioctl
isdn
ja_JP
kbuild
kdump
ko_KR
laptops
leds
m68k
make
memory-devices
mips
misc-devices
mmc
mn10300
mtd
namespaces
netlabel
networking
nfc
parisc
pcmcia
power
powerpc
pps
prctl
pti
ptp
rapidio
s390
scheduler
scsi
security
serial
sh
sound
spi
sysctl
target
telephony
thermal
timers
trace
usb
vDSO
video4linux
virtual
vm
w1
watchdog
wimax
x86
zh_CN
.gitignore -rw-r--r-- 107 bytes
00-INDEX -rw-r--r-- 11.8 KB
BUG-HUNTING -rw-r--r-- 8.1 KB
Changes -rw-r--r-- 11.7 KB
CodingStyle -rw-r--r-- 30.9 KB
DMA-API-HOWTO.txt -rw-r--r-- 28.0 KB
DMA-API.txt -rw-r--r-- 26.7 KB
DMA-ISA-LPC.txt -rw-r--r-- 5.2 KB
DMA-attributes.txt -rw-r--r-- 4.1 KB
HOWTO -rw-r--r-- 27.2 KB
IPMI.txt -rw-r--r-- 25.9 KB
IRQ-affinity.txt -rw-r--r-- 2.5 KB
IRQ-domain.txt -rw-r--r-- 5.3 KB
IRQ.txt -rw-r--r-- 962 bytes
Intel-IOMMU.txt -rw-r--r-- 3.8 KB
Makefile -rw-r--r-- 174 bytes
ManagementStyle -rw-r--r-- 12.9 KB
SAK.txt -rw-r--r-- 2.8 KB
SM501.txt -rw-r--r-- 2.8 KB
SecurityBugs -rw-r--r-- 1.8 KB
SubmitChecklist -rw-r--r-- 4.4 KB
SubmittingDrivers -rw-r--r-- 6.3 KB
SubmittingPatches -rw-r--r-- 28.6 KB
VGA-softcursor.txt -rw-r--r-- 2.0 KB
applying-patches.txt -rw-r--r-- 19.5 KB
atomic_ops.txt -rw-r--r-- 21.6 KB
bad_memory.txt -rw-r--r-- 1.1 KB
basic_profiling.txt -rw-r--r-- 1.7 KB
binfmt_misc.txt -rw-r--r-- 5.9 KB
braille-console.txt -rw-r--r-- 1.4 KB
bt8xxgpio.txt -rw-r--r-- 4.3 KB
btmrvl.txt -rw-r--r-- 2.9 KB
bus-virt-phys-mapping.txt -rw-r--r-- 7.9 KB
cachetlb.txt -rw-r--r-- 17.1 KB
circular-buffers.txt -rw-r--r-- 7.6 KB
clk.txt -rw-r--r-- 8.5 KB
coccinelle.txt -rw-r--r-- 8.1 KB
cpu-hotplug.txt -rw-r--r-- 14.6 KB
cpu-load.txt -rw-r--r-- 3.0 KB
cputopology.txt -rw-r--r-- 3.8 KB
crc32.txt -rw-r--r-- 8.5 KB
dcdbas.txt -rw-r--r-- 3.6 KB
debugging-modules.txt -rw-r--r-- 954 bytes
debugging-via-ohci1394.txt -rw-r--r-- 7.4 KB
dell_rbu.txt -rw-r--r-- 4.9 KB
devices.txt -rw-r--r-- 116.0 KB
digsig.txt -rw-r--r-- 2.8 KB
dma-buf-sharing.txt -rw-r--r-- 19.5 KB
dmaengine.txt -rw-r--r-- 7.6 KB
dontdiff -rw-r--r-- 2.5 KB
dynamic-debug-howto.txt -rw-r--r-- 11.8 KB
edac.txt -rw-r--r-- 24.3 KB
eisa.txt -rw-r--r-- 7.1 KB
email-clients.txt -rw-r--r-- 8.6 KB
flexible-arrays.txt -rw-r--r-- 5.5 KB
futex-requeue-pi.txt -rw-r--r-- 5.0 KB
gcov.txt -rw-r--r-- 7.5 KB
gpio.txt -rw-r--r-- 32.4 KB
highuid.txt -rw-r--r-- 2.4 KB
hw_random.txt -rw-r--r-- 3.5 KB
hwspinlock.txt -rw-r--r-- 12.1 KB
init.txt -rw-r--r-- 2.5 KB
initrd.txt -rw-r--r-- 14.1 KB
intel_txt.txt -rw-r--r-- 10.2 KB
io-mapping.txt -rw-r--r-- 3.2 KB
io_ordering.txt -rw-r--r-- 1.9 KB
iostats.txt -rw-r--r-- 7.9 KB
irqflags-tracing.txt -rw-r--r-- 2.6 KB
isapnp.txt -rw-r--r-- 433 bytes
java.txt -rw-r--r-- 10.7 KB
kernel-doc-nano-HOWTO.txt -rw-r--r-- 11.4 KB
kernel-docs.txt -rw-r--r-- 33.1 KB
kernel-parameters.txt -rw-r--r-- 107.8 KB
kmemcheck.txt -rw-r--r-- 29.8 KB
kmemleak.txt -rw-r--r-- 7.9 KB
kobject.txt -rw-r--r-- 17.8 KB
kprobes.txt -rw-r--r-- 29.5 KB
kref.txt -rw-r--r-- 6.1 KB
ldm.txt -rw-r--r-- 3.8 KB
local_ops.txt -rw-r--r-- 6.1 KB
lockdep-design.txt -rw-r--r-- 11.6 KB
lockstat.txt -rw-r--r-- 10.7 KB
lockup-watchdogs.txt -rw-r--r-- 3.1 KB
logo.gif -rw-r--r-- 16.0 KB
logo.txt -rw-r--r-- 563 bytes
magic-number.txt -rw-r--r-- 9.7 KB
md.txt -rw-r--r-- 25.4 KB
media-framework.txt -rw-r--r-- 14.7 KB
memory-barriers.txt -rw-r--r-- 82.3 KB
memory-hotplug.txt -rw-r--r-- 15.0 KB
mono.txt -rw-r--r-- 2.5 KB
mutex-design.txt -rw-r--r-- 5.8 KB
nommu-mmap.txt -rw-r--r-- 12.7 KB
numastat.txt -rw-r--r-- 836 bytes
oops-tracing.txt -rw-r--r-- 12.5 KB
padata.txt -rw-r--r-- 7.3 KB
parport-lowlevel.txt -rw-r--r-- 32.2 KB
parport.txt -rw-r--r-- 8.8 KB
percpu-rw-semaphore.txt -rw-r--r-- 1.1 KB
pi-futex.txt -rw-r--r-- 5.7 KB
pinctrl.txt -rw-r--r-- 40.0 KB
pnp.txt -rw-r--r-- 6.8 KB
preempt-locking.txt -rw-r--r-- 5.2 KB
printk-formats.txt -rw-r--r-- 5.4 KB
pwm.txt -rw-r--r-- 2.9 KB
ramoops.txt -rw-r--r-- 4.6 KB
rbtree.txt -rw-r--r-- 13.3 KB
remoteproc.txt -rw-r--r-- 12.3 KB
rfkill.txt -rw-r--r-- 4.7 KB
robust-futex-ABI.txt -rw-r--r-- 8.7 KB
robust-futexes.txt -rw-r--r-- 9.4 KB
rpmsg.txt -rw-r--r-- 13.6 KB
rt-mutex-design.txt -rw-r--r-- 32.8 KB
rt-mutex.txt -rw-r--r-- 3.5 KB
rtc.txt -rw-r--r-- 15.5 KB
serial-console.txt -rw-r--r-- 4.0 KB
sgi-ioc4.txt -rw-r--r-- 2.0 KB
sgi-visws.txt -rw-r--r-- 678 bytes
smsc_ece1099.txt -rw-r--r-- 2.4 KB
sparse.txt -rw-r--r-- 3.0 KB
spinlocks.txt -rw-r--r-- 6.5 KB
stable_api_nonsense.txt -rw-r--r-- 9.2 KB
stable_kernel_rules.txt -rw-r--r-- 4.4 KB
static-keys.txt -rw-r--r-- 11.9 KB
svga.txt -rw-r--r-- 14.1 KB
sysfs-rules.txt -rw-r--r-- 8.1 KB
sysrq.txt -rw-r--r-- 11.6 KB
unaligned-memory-access.txt -rw-r--r-- 10.0 KB
unicode.txt -rw-r--r-- 6.5 KB
unshare.txt -rw-r--r-- 13.1 KB
vfio.txt -rw-r--r-- 13.6 KB
vgaarbiter.txt -rw-r--r-- 8.1 KB
video-output.txt -rw-r--r-- 1.1 KB
vme_api.txt -rw-r--r-- 13.1 KB
volatile-considered-harmful.txt -rw-r--r-- 5.6 KB
workqueue.txt -rw-r--r-- 14.9 KB
xz.txt -rw-r--r-- 5.7 KB
zorro.txt -rw-r--r-- 2.8 KB

back to top