History

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

Linus Torvalds committed 10 years ago

Commit ffbcbfc3 parents 6c286e8 8243d55 405c0752 files · +7 −9Browse files

Unified · Split

2 files
  1. kernel/fork.c +4 −0
  2. kernel/sched/core.c +3 −9
kernel/fork.c+4−0
@@ -315,6 +315,9 @@ static void account_kernel_stack(struct task_struct *tsk, int account) · 314 unmodified lines
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 @@ bad_fork_cleanup_count: · 1541 unmodified lines
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+3−9
@@ -5192,21 +5192,14 @@ void sched_show_task(struct task_struct *p) · 5191 unmodified lines
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) · 8 unmodified lines
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)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t