Skip to content

Commit 0ee1dd9

Browse files
jpoimboeingomolnar
authored andcommitted
x86/dumpstack: Remove raw stack dump
For mostly historical reasons, the x86 oops dump shows the raw stack values: ... [registers] Stack: ffff880079af7350 ffff880079905400 0000000000000000 ffffc900008f3ae0 ffffffffa0196610 0000000000000001 00010000ffffffff 0000000087654321 0000000000000002 0000000000000000 0000000000000000 0000000000000000 Call Trace: ... This seems to be an artifact from long ago, and probably isn't needed anymore. It generally just adds noise to the dump, and it can be actively harmful because it leaks kernel addresses. Linus says: "The stack dump actually goes back to forever, and it used to be useful back in 1992 or so. But it used to be useful mainly because stacks were simpler and we didn't have very good call traces anyway. I definitely remember having used them - I just do not remember having used them in the last ten+ years. Of course, it's still true that if you can trigger an oops, you've likely already lost the security game, but since the stack dump is so useless, let's aim to just remove it and make games like the above harder." This also removes the related 'kstack=' cmdline option and the 'kstack_depth_to_print' sysctl. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/e83bd50df52d8fe88e94d2566426ae40d813bf8f.1477405374.git.jpoimboe@redhat.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent bb5e5ce commit 0ee1dd9

8 files changed

Lines changed: 4 additions & 130 deletions

File tree

‎Documentation/kernel-parameters.txt‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,9 +1958,6 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
19581958
kmemcheck=2 (one-shot mode)
19591959
Default: 2 (one-shot mode)
19601960

1961-
kstack=N [X86] Print N words from the kernel stack
1962-
in oops dumps.
1963-
19641961
kvm.ignore_msrs=[KVM] Ignore guest accesses to unhandled MSRs.
19651962
Default is 0 (don't ignore, but inject #GP)
19661963

‎Documentation/sysctl/kernel.txt‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ show up in /proc/sys/kernel:
4040
- hung_task_warnings
4141
- kexec_load_disabled
4242
- kptr_restrict
43-
- kstack_depth_to_print [ X86 only ]
4443
- l2cr [ PPC only ]
4544
- modprobe ==> Documentation/debugging-modules.txt
4645
- modules_disabled
@@ -395,13 +394,6 @@ When kptr_restrict is set to (2), kernel pointers printed using
395394

396395
==============================================================
397396

398-
kstack_depth_to_print: (X86 only)
399-
400-
Controls the number of words to print when dumping the raw
401-
kernel stack.
402-
403-
==============================================================
404-
405397
l2cr: (PPC only)
406398

407399
This flag controls the L2 cache of G3 processor boards. If

‎Documentation/x86/x86_64/boot-options.txt‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,6 @@ IOMMU (input/output memory management unit)
277277
space might stop working. Use this option if you have devices that
278278
are accessed from userspace directly on some PCI host bridge.
279279

280-
Debugging
281-
282-
kstack=N Print N words from the kernel stack in oops dumps.
283-
284280
Miscellaneous
285281

286282
nogbpages

‎arch/x86/include/asm/stacktrace.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ static inline bool on_stack(struct stack_info *info, void *addr, size_t len)
4343
addr + len > begin && addr + len <= end);
4444
}
4545

46-
extern int kstack_depth_to_print;
47-
4846
#ifdef CONFIG_X86_32
4947
#define STACKSLOTS_PER_LINE 8
5048
#else
@@ -86,9 +84,6 @@ get_stack_pointer(struct task_struct *task, struct pt_regs *regs)
8684
void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
8785
unsigned long *stack, char *log_lvl);
8886

89-
void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
90-
unsigned long *sp, char *log_lvl);
91-
9287
extern unsigned int code_bytes;
9388

9489
/* The form of the top of the frame on the stack */

‎arch/x86/kernel/dumpstack.c‎

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
int panic_on_unrecovered_nmi;
2323
int panic_on_io_nmi;
2424
unsigned int code_bytes = 64;
25-
int kstack_depth_to_print = 3 * STACKSLOTS_PER_LINE;
2625
static int die_counter;
2726

2827
bool in_task_stack(unsigned long *stack, struct task_struct *task,
@@ -171,12 +170,12 @@ void show_stack(struct task_struct *task, unsigned long *sp)
171170
if (!sp && task == current)
172171
sp = get_stack_pointer(current, NULL);
173172

174-
show_stack_log_lvl(task, NULL, sp, KERN_DEFAULT);
173+
show_trace_log_lvl(task, NULL, sp, KERN_DEFAULT);
175174
}
176175

177176
void show_stack_regs(struct pt_regs *regs)
178177
{
179-
show_stack_log_lvl(current, regs, NULL, KERN_DEFAULT);
178+
show_trace_log_lvl(current, regs, NULL, KERN_DEFAULT);
180179
}
181180

182181
static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
@@ -295,22 +294,6 @@ void die(const char *str, struct pt_regs *regs, long err)
295294
oops_end(flags, regs, sig);
296295
}
297296

298-
static int __init kstack_setup(char *s)
299-
{
300-
ssize_t ret;
301-
unsigned long val;
302-
303-
if (!s)
304-
return -EINVAL;
305-
306-
ret = kstrtoul(s, 0, &val);
307-
if (ret)
308-
return ret;
309-
kstack_depth_to_print = val;
310-
return 0;
311-
}
312-
early_param("kstack", kstack_setup);
313-
314297
static int __init code_bytes_setup(char *s)
315298
{
316299
ssize_t ret;

‎arch/x86/kernel/dumpstack_32.c‎

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -121,36 +121,6 @@ int get_stack_info(unsigned long *stack, struct task_struct *task,
121121
return -EINVAL;
122122
}
123123

124-
void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
125-
unsigned long *sp, char *log_lvl)
126-
{
127-
unsigned long *stack;
128-
int i;
129-
130-
if (!try_get_task_stack(task))
131-
return;
132-
133-
sp = sp ? : get_stack_pointer(task, regs);
134-
135-
stack = sp;
136-
for (i = 0; i < kstack_depth_to_print; i++) {
137-
if (kstack_end(stack))
138-
break;
139-
if ((i % STACKSLOTS_PER_LINE) == 0) {
140-
if (i != 0)
141-
pr_cont("\n");
142-
printk("%s %08lx", log_lvl, *stack++);
143-
} else
144-
pr_cont(" %08lx", *stack++);
145-
touch_nmi_watchdog();
146-
}
147-
pr_cont("\n");
148-
show_trace_log_lvl(task, regs, sp, log_lvl);
149-
150-
put_task_stack(task);
151-
}
152-
153-
154124
void show_regs(struct pt_regs *regs)
155125
{
156126
int i;
@@ -168,8 +138,7 @@ void show_regs(struct pt_regs *regs)
168138
unsigned char c;
169139
u8 *ip;
170140

171-
pr_emerg("Stack:\n");
172-
show_stack_log_lvl(current, regs, NULL, KERN_EMERG);
141+
show_trace_log_lvl(current, regs, NULL, KERN_EMERG);
173142

174143
pr_emerg("Code:");
175144

‎arch/x86/kernel/dumpstack_64.c‎

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -140,56 +140,6 @@ int get_stack_info(unsigned long *stack, struct task_struct *task,
140140
return -EINVAL;
141141
}
142142

143-
void show_stack_log_lvl(struct task_struct *task, struct pt_regs *regs,
144-
unsigned long *sp, char *log_lvl)
145-
{
146-
unsigned long *irq_stack_end;
147-
unsigned long *irq_stack;
148-
unsigned long *stack;
149-
int i;
150-
151-
if (!try_get_task_stack(task))
152-
return;
153-
154-
irq_stack_end = (unsigned long *)this_cpu_read(irq_stack_ptr);
155-
irq_stack = irq_stack_end - (IRQ_STACK_SIZE / sizeof(long));
156-
157-
sp = sp ? : get_stack_pointer(task, regs);
158-
159-
stack = sp;
160-
for (i = 0; i < kstack_depth_to_print; i++) {
161-
unsigned long word;
162-
163-
if (stack >= irq_stack && stack <= irq_stack_end) {
164-
if (stack == irq_stack_end) {
165-
stack = (unsigned long *) (irq_stack_end[-1]);
166-
pr_cont(" <EOI> ");
167-
}
168-
} else {
169-
if (kstack_end(stack))
170-
break;
171-
}
172-
173-
if (probe_kernel_address(stack, word))
174-
break;
175-
176-
if ((i % STACKSLOTS_PER_LINE) == 0) {
177-
if (i != 0)
178-
pr_cont("\n");
179-
printk("%s %016lx", log_lvl, word);
180-
} else
181-
pr_cont(" %016lx", word);
182-
183-
stack++;
184-
touch_nmi_watchdog();
185-
}
186-
187-
pr_cont("\n");
188-
show_trace_log_lvl(task, regs, sp, log_lvl);
189-
190-
put_task_stack(task);
191-
}
192-
193143
void show_regs(struct pt_regs *regs)
194144
{
195145
int i;
@@ -207,8 +157,7 @@ void show_regs(struct pt_regs *regs)
207157
unsigned char c;
208158
u8 *ip;
209159

210-
printk(KERN_DEFAULT "Stack:\n");
211-
show_stack_log_lvl(current, regs, NULL, KERN_DEFAULT);
160+
show_trace_log_lvl(current, regs, NULL, KERN_DEFAULT);
212161

213162
printk(KERN_DEFAULT "Code: ");
214163

‎kernel/sysctl.c‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -989,13 +989,6 @@ static struct ctl_table kern_table[] = {
989989
.mode = 0444,
990990
.proc_handler = proc_dointvec,
991991
},
992-
{
993-
.procname = "kstack_depth_to_print",
994-
.data = &kstack_depth_to_print,
995-
.maxlen = sizeof(int),
996-
.mode = 0644,
997-
.proc_handler = proc_dointvec,
998-
},
999992
{
1000993
.procname = "io_delay_type",
1001994
.data = &io_delay_type,

0 commit comments

Comments
 (0)