x86/dumpstack: Remove NULL task pointer convention
authorJosh Poimboeuf <jpoimboe@redhat.com>
Fri, 16 Sep 2016 13:05:20 +0000 (08:05 -0500)
committerIngo Molnar <mingo@kernel.org>
Fri, 16 Sep 2016 14:21:39 +0000 (16:21 +0200)
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>
arch/x86/include/asm/stacktrace.h
arch/x86/kernel/dumpstack.c
arch/x86/kernel/dumpstack_32.c
arch/x86/kernel/dumpstack_64.c

index 780a83efcfd307d704c671748661e662a3604261..ed2be1b5ada867fe6c4ee241b1332e7f3c6554c1 100644 (file)
@@ -94,7 +94,7 @@ get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
        if (regs)
                return (unsigned long *)regs->bp;
 
-       if (!task || task == current)
+       if (task == current)
                return __builtin_frame_address(0);
 
        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)
        if (regs)
                return (unsigned long *)kernel_stack_pointer(regs);
 
-       if (!task || task == current)
+       if (task == current)
                return __builtin_frame_address(0);
 
        return (unsigned long *)task->thread.sp;
index aa208e565b03c9c3b0a0b4d0c56f947bb8d8bbe6..e0648f755158774932525348f43965daea6835b4 100644 (file)
@@ -175,11 +175,13 @@ void show_stack(struct task_struct *task, unsigned long *sp)
 {
        unsigned long bp = 0;
 
+       task = task ? : current;
+
        /*
         * Stack frames below this one aren't interesting.  Don't show them
         * if we're printing for %current.
         */
-       if (!sp && (!task || task == current)) {
+       if (!sp && task == current) {
                sp = get_stack_pointer(current, NULL);
                bp = (unsigned long)get_frame_pointer(current, NULL);
        }
index 122f37d7bb7ec6fab44f93130cbfc9f911b156f3..4ff000811e033477db7b382a401c891e2c0d07b1 100644 (file)
@@ -205,7 +205,7 @@ void show_regs(struct pt_regs *regs)
                u8 *ip;
 
                pr_emerg("Stack:\n");
-               show_stack_log_lvl(NULL, regs, NULL, 0, KERN_EMERG);
+               show_stack_log_lvl(current, regs, NULL, 0, KERN_EMERG);
 
                pr_emerg("Code:");
 
index 16c0d5f89b5e11a8d08a6e3bbf44968416f25f29..008a29837cabb140502858edbe29a7d11ee00bdc 100644 (file)
@@ -278,7 +278,7 @@ void show_regs(struct pt_regs *regs)
                u8 *ip;
 
                printk(KERN_DEFAULT "Stack:\n");
-               show_stack_log_lvl(NULL, regs, NULL, 0, KERN_DEFAULT);
+               show_stack_log_lvl(current, regs, NULL, 0, KERN_DEFAULT);
 
                printk(KERN_DEFAULT "Code: ");