Skip to content

Commit ffbcbfc

Browse files
committed
Merge branches 'sched-urgent-for-linus' and 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull stack vmap fixups from Thomas Gleixner: "Two small patches related to sched_show_task(): - make sure to hold a reference on the task stack while accessing it - remove the thread_saved_pc printout .. and add a sanity check into release_task_stack() to catch problems with task stack references" * 'sched-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: sched/core: Remove pointless printout in sched_show_task() sched/core: Fix oops in sched_show_task() * 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: fork: Add task stack refcounting sanity check and prevent premature task stack freeing
3 parents 6c286e8 + 8243d55 + 405c075 commit ffbcbfc

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

kernel/fork.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ static void account_kernel_stack(struct task_struct *tsk, int account)
315315

316316
static void release_task_stack(struct task_struct *tsk)
317317
{
318+
if (WARN_ON(tsk->state != TASK_DEAD))
319+
return; /* Better to leak the stack than to free prematurely */
320+
318321
account_kernel_stack(tsk, -1);
319322
arch_release_thread_stack(tsk->stack);
320323
free_thread_stack(tsk);
@@ -1862,6 +1865,7 @@ static __latent_entropy struct task_struct *copy_process(
18621865
atomic_dec(&p->cred->user->processes);
18631866
exit_creds(p);
18641867
bad_fork_free:
1868+
p->state = TASK_DEAD;
18651869
put_task_stack(p);
18661870
free_task(p);
18671871
fork_out:

kernel/sched/core.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5192,21 +5192,14 @@ void sched_show_task(struct task_struct *p)
51925192
int ppid;
51935193
unsigned long state = p->state;
51945194

5195+
if (!try_get_task_stack(p))
5196+
return;
51955197
if (state)
51965198
state = __ffs(state) + 1;
51975199
printk(KERN_INFO "%-15.15s %c", p->comm,
51985200
state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?');
5199-
#if BITS_PER_LONG == 32
5200-
if (state == TASK_RUNNING)
5201-
printk(KERN_CONT " running ");
5202-
else
5203-
printk(KERN_CONT " %08lx ", thread_saved_pc(p));
5204-
#else
52055201
if (state == TASK_RUNNING)
52065202
printk(KERN_CONT " running task ");
5207-
else
5208-
printk(KERN_CONT " %016lx ", thread_saved_pc(p));
5209-
#endif
52105203
#ifdef CONFIG_DEBUG_STACK_USAGE
52115204
free = stack_not_used(p);
52125205
#endif
@@ -5221,6 +5214,7 @@ void sched_show_task(struct task_struct *p)
52215214

52225215
print_worker_info(KERN_INFO, p);
52235216
show_stack(p, NULL);
5217+
put_task_stack(p);
52245218
}
52255219

52265220
void show_state_filter(unsigned long state_filter)

0 commit comments

Comments
 (0)