Skip to content

Commit 8153916

Browse files
jpoimboeingomolnar
authored andcommitted
x86/dumpstack: Remove NULL task pointer convention
show_stack_log_lvl() and friends allow a NULL pointer for the task_struct to indicate the current task. This creates confusion and can cause sneaky bugs. Instead require the caller to pass 'current' directly. This only changes the internal workings of the dumpstack code. The dump_trace() and show_stack() interfaces still allow a NULL task pointer. Those interfaces should also probably be fixed as well. Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent ac496bf commit 8153916

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
9494
if (regs)
9595
return (unsigned long *)regs->bp;
9696

97-
if (!task || task == current)
97+
if (task == current)
9898
return __builtin_frame_address(0);
9999

100100
return (unsigned long *)((struct inactive_task_frame *)task->thread.sp)->bp;
@@ -113,7 +113,7 @@ get_stack_pointer(struct task_struct *task, struct pt_regs *regs)
113113
if (regs)
114114
return (unsigned long *)kernel_stack_pointer(regs);
115115

116-
if (!task || task == current)
116+
if (task == current)
117117
return __builtin_frame_address(0);
118118

119119
return (unsigned long *)task->thread.sp;

‎arch/x86/kernel/dumpstack.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,13 @@ void show_stack(struct task_struct *task, unsigned long *sp)
175175
{
176176
unsigned long bp = 0;
177177

178+
task = task ? : current;
179+
178180
/*
179181
* Stack frames below this one aren't interesting. Don't show them
180182
* if we're printing for %current.
181183
*/
182-
if (!sp && (!task || task == current)) {
184+
if (!sp && task == current) {
183185
sp = get_stack_pointer(current, NULL);
184186
bp = (unsigned long)get_frame_pointer(current, NULL);
185187
}

‎arch/x86/kernel/dumpstack_32.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ void show_regs(struct pt_regs *regs)
205205
u8 *ip;
206206

207207
pr_emerg("Stack:\n");
208-
show_stack_log_lvl(NULL, regs, NULL, 0, KERN_EMERG);
208+
show_stack_log_lvl(current, regs, NULL, 0, KERN_EMERG);
209209

210210
pr_emerg("Code:");
211211

‎arch/x86/kernel/dumpstack_64.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void show_regs(struct pt_regs *regs)
278278
u8 *ip;
279279

280280
printk(KERN_DEFAULT "Stack:\n");
281-
show_stack_log_lvl(NULL, regs, NULL, 0, KERN_DEFAULT);
281+
show_stack_log_lvl(current, regs, NULL, 0, KERN_DEFAULT);
282282

283283
printk(KERN_DEFAULT "Code: ");
284284

0 commit comments

Comments
 (0)