Kill off show_stack() NULL-implies-current idiom
Subsystems (3)
cover Kill off show_stack() NULL-implies-current idiom
Today, show_stack() accepts a NULL task parameter, which it takes to mean the current task. However, as noted in tip/x86/asm commit:
81539169f283329f ("x86/dumpstack: Remove NULL task pointer convention")
... having a NULL task parameter imply current leads to subtle bugs in stack walking code (so far seen on both 86 and arm64), makes callsites harder to read, and is unnecessary as all callers have access to current.
As a step towards removing the problematic NULL-implies-current idiom entirely, these patches ensure that generic code explictly passes current to show_stack(), rather than relying on arch code to handle NULL.
Thanks,
Mark.
Mark Rutland (3):
sched: document that show_stack() should not be passed a NULL task drivers/tty: Explicitly pass current to show_stack
lib: dump_stack: explicitly pass current to show_stack
drivers/tty/sysrq.c | 2 +- include/linux/sched.h | 3 +++ lib/dump_stack.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/3 sched: document that show_stack() should not be passed a NULL task
As noted in commit:
81539169f283329f ("x86/dumpstack: Remove NULL task pointer convention")
... having a NULL task parameter imply current leads to subtle bugs in stack walking code (so far seen on both 86 and arm64), makes callsites harder to read, and is unnecessary as all callers have access to current.
As a step towards removing the problematic NULL-implies-current idiom entirely, document that new code should pass current explicitly.
--- include/linux/sched.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/sched.h +3 -0
@@ -367,6 +367,9 @@ extern void show_regs(struct pt_regs *);* TASK is a pointer to the task whose backtrace we want to see (or NULL for current * task), SP is the stack pointer of the first frame that should be shown in the back * trace (or NULL if the entire call-chain of the task should be shown). +* +* Note: passing a NULL task is deprecated, and new code should pass current +* explicitly. */ extern void show_stack (struct task_struct *task,unsigned long *sp);
Signature · 1 line
2.7.4
PATCH 2/3 drivers/tty: Explicitly pass current to show_stack
In reply to Mark RutlandAs noted in commit:
81539169f283329f ("x86/dumpstack: Remove NULL task pointer convention")
... having a NULL task parameter imply current leads to subtle bugs in stack walking code (so far seen on both 86 and arm64), makes callsites harder to read, and is unnecessary as all callers have access to current.
As a step towards removing the problematic NULL-implies-current idiom entirely, have the sysrq code explicitly pass current to show_stack.
--- drivers/tty/sysrq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/sysrq.c +1 -1
@@ -224,7 +224,7 @@ static void showacpu(void *dummy)spin_lock_irqsave (&show_lock, flags);pr_info ("CPU%d:\n" ,smp_processor_id ()); -show_stack (NULL ,NULL ); +show_stack (current,NULL );spin_unlock_irqrestore (&show_lock, flags); }
Signature · 1 line
2.7.4
PATCH 3/3 lib: dump_stack: explicitly pass current to show_stack
In reply to Mark RutlandAs noted in commit:
81539169f283329f ("x86/dumpstack: Remove NULL task pointer convention")
... having a NULL task parameter imply current leads to subtle bugs in stack walking code (so far seen on both 86 and arm64), makes callsites harder to read, and is unnecessary as all callers have access to current.
As a step towards removing the problematic NULL-implies-current idiom entirely, have the dump_stack code explicitly pass current to show_stack.
--- lib/dump_stack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/dump_stack.c +1 -1
@@ -12,7 +12,7 @@static void __dump_stack (void ) {dump_stack_print_info (KERN_DEFAULT ); -show_stack (NULL ,NULL ); +show_stack (current,NULL ); }/**
Signature · 1 line
2.7.4
Quoted 5 lines · Mark Rutland
Today,
show_stack()accepts a NULL task parameter, which it takes to mean the current task. However, as noted in tip/x86/asm commit:
81539169f283329f("x86/dumpstack: Remove NULL task pointer convention")
Quoted 7 lines
... having a NULL task parameter imply current leads to subtle bugs in stack walking code (so far seen on both 86 and arm64), makes callsites harder to read, and is unnecessary as all callers have access to current.
As a step towards removing the problematic NULL-implies-current idiom entirely, these patches ensure that generic code explictly passes current to
show_stack(), rather than relying on arch code to handle NULL.
This is a good step, though it would be really nice to fix this tree-wide. Do you have any plans to do so?
Regardless, for the series:
Signature · 1 line
Josh
Quoted 10 lines · Josh Poimboeuf
Quoted 9 lines · Mark Rutland
Today,
show_stack()accepts a NULL task parameter, which it takes to mean the current task. However, as noted in tip/x86/asm commit:
81539169f283329f("x86/dumpstack: Remove NULL task pointer convention")... having a NULL task parameter imply current leads to subtle bugs in stack walking code (so far seen on both 86 and arm64), makes callsites harder to read, and is unnecessary as all callers have access to current.
Quoted 6 lines
Quoted 3 lines
As a step towards removing the problematic NULL-implies-current idiom entirely, these patches ensure that generic code explictly passes current to
show_stack(), rather than relying on arch code to handle NULL.This is a good step, though it would be really nice to fix this tree-wide. Do you have any plans to do so?
FWIW, I completely agree, though I have no plans to do so currently.
I'd meant to Cc linux-arch for this series in order to make people aware, though evidently I did not. I can Cc subsequent arm64 NULL-implies-current cleanup patches there, if that's helpful?
Quoted 3 lines
Regardless, for the series:
Reviewed-by Josh Poimboeuf <[email protected]>
Cheers!
Thanks,
Mark.
Quoted 10 lines · Josh Poimboeuf
Quoted 9 lines · Mark Rutland
Today,
show_stack()accepts a NULL task parameter, which it takes to mean the current task. However, as noted in tip/x86/asm commit:
81539169f283329f("x86/dumpstack: Remove NULL task pointer convention")... having a NULL task parameter imply current leads to subtle bugs in stack walking code (so far seen on both 86 and arm64), makes callsites harder to read, and is unnecessary as all callers have access to current.
Quoted 6 lines
Quoted 3 lines
As a step towards removing the problematic NULL-implies-current idiom entirely, these patches ensure that generic code explictly passes current to
show_stack(), rather than relying on arch code to handle NULL.This is a good step, though it would be really nice to fix this tree-wide. Do you have any plans to do so?
I started having a go, and in doing so I've realised that as things stand, these patches are broken, as some architectures don't handle current explicitly.
Please disregard all patches in this series.
Apologies,
Mark.