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
Unified · Split
| @@ -315,6 +315,9 @@ static void account_kernel_stack(struct task_struct *tsk, int account) · 314 unmodified lines | ||
| 315 | 315 | |
| 316 | 316 | static void release_task_stack(struct task_struct *tsk) |
| 317 | 317 | { |
| 318 | + if (WARN_ON(tsk->state != TASK_DEAD)) | |
| 319 | + return; /* Better to leak the stack than to free prematurely */ | |
| 320 | + | |
| 318 | 321 | account_kernel_stack(tsk, -1); |
| 319 | 322 | arch_release_thread_stack(tsk->stack); |
| 320 | 323 | free_thread_stack(tsk); |
| @@ -1862,6 +1865,7 @@ bad_fork_cleanup_count: · 1541 unmodified lines | ||
| 1862 | 1865 | atomic_dec(&p->cred->user->processes); |
| 1863 | 1866 | exit_creds(p); |
| 1864 | 1867 | bad_fork_free: |
| 1868 | + p->state = TASK_DEAD; | |
| 1865 | 1869 | put_task_stack(p); |
| 1866 | 1870 | free_task(p); |
| 1867 | 1871 | fork_out: |
| @@ -5192,21 +5192,14 @@ void sched_show_task(struct task_struct *p) · 5191 unmodified lines | ||
| 5192 | 5192 | int ppid; |
| 5193 | 5193 | unsigned long state = p->state; |
| 5194 | 5194 | |
| 5195 | + if (!try_get_task_stack(p)) | |
| 5196 | + return; | |
| 5195 | 5197 | if (state) |
| 5196 | 5198 | state = __ffs(state) + 1; |
| 5197 | 5199 | printk(KERN_INFO "%-15.15s %c", p->comm, |
| 5198 | 5200 | 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 | |
| 5205 | 5201 | if (state == TASK_RUNNING) |
| 5206 | 5202 | printk(KERN_CONT " running task "); |
| 5207 | − else | |
| 5208 | − printk(KERN_CONT " %016lx ", thread_saved_pc(p)); | |
| 5209 | −#endif | |
| 5210 | 5203 | #ifdef CONFIG_DEBUG_STACK_USAGE |
| 5211 | 5204 | free = stack_not_used(p); |
| 5212 | 5205 | #endif |
| @@ -5221,6 +5214,7 @@ void sched_show_task(struct task_struct *p) · 8 unmodified lines | ||
| 5221 | 5214 | |
| 5222 | 5215 | print_worker_info(KERN_INFO, p); |
| 5223 | 5216 | show_stack(p, NULL); |
| 5217 | + put_task_stack(p); | |
| 5224 | 5218 | } |
| 5225 | 5219 | |
| 5226 | 5220 | void show_state_filter(unsigned long state_filter) |