pid.c (cc46c03397c1865a181f1a4f66d4645806e5a943) | pid.c (63f818f46af9f8b3f17b9695501e8d08959feb60) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * Generic pidhash and scalable, time-bounded PID allocator 4 * 5 * (C) 2002-2003 Nadia Yvette Chambers, IBM 6 * (C) 2004 Nadia Yvette Chambers, Oracle 7 * (C) 2002-2004 Ingo Molnar, Red Hat 8 * --- 130 unchanged lines hidden (view full) --- 139 * may be sleeping in zap_pid_ns_processes(). 140 */ 141 wake_up_process(ns->child_reaper); 142 break; 143 case PIDNS_ADDING: 144 /* Handle a fork failure of the first process */ 145 WARN_ON(ns->child_reaper); 146 ns->pid_allocated = 0; | 1// SPDX-License-Identifier: GPL-2.0-only 2/* 3 * Generic pidhash and scalable, time-bounded PID allocator 4 * 5 * (C) 2002-2003 Nadia Yvette Chambers, IBM 6 * (C) 2004 Nadia Yvette Chambers, Oracle 7 * (C) 2002-2004 Ingo Molnar, Red Hat 8 * --- 130 unchanged lines hidden (view full) --- 139 * may be sleeping in zap_pid_ns_processes(). 140 */ 141 wake_up_process(ns->child_reaper); 142 break; 143 case PIDNS_ADDING: 144 /* Handle a fork failure of the first process */ 145 WARN_ON(ns->child_reaper); 146 ns->pid_allocated = 0; |
147 /* fall through */ 148 case 0: 149 schedule_work(&ns->proc_work); | |
150 break; 151 } 152 153 idr_remove(&ns->idr, upid->nr); 154 } 155 spin_unlock_irqrestore(&pidmap_lock, flags); 156 157 call_rcu(&pid->rcu, delayed_put_pid); --- 84 unchanged lines hidden (view full) --- 242 goto out_free; 243 } 244 245 pid->numbers[i].nr = nr; 246 pid->numbers[i].ns = tmp; 247 tmp = tmp->parent; 248 } 249 | 147 break; 148 } 149 150 idr_remove(&ns->idr, upid->nr); 151 } 152 spin_unlock_irqrestore(&pidmap_lock, flags); 153 154 call_rcu(&pid->rcu, delayed_put_pid); --- 84 unchanged lines hidden (view full) --- 239 goto out_free; 240 } 241 242 pid->numbers[i].nr = nr; 243 pid->numbers[i].ns = tmp; 244 tmp = tmp->parent; 245 } 246 |
250 /* 251 * ENOMEM is not the most obvious choice especially for the case 252 * where the child subreaper has already exited and the pid 253 * namespace denies the creation of any new processes. But ENOMEM 254 * is what we have exposed to userspace for a long time and it is 255 * documented behavior for pid namespaces. So we can't easily 256 * change it even if there were an error code better suited. 257 */ 258 retval = -ENOMEM; 259 260 if (unlikely(is_child_reaper(pid))) { 261 if (pid_ns_prepare_proc(ns)) 262 goto out_free; 263 } 264 | |
265 get_pid_ns(ns); 266 refcount_set(&pid->count, 1); | 247 get_pid_ns(ns); 248 refcount_set(&pid->count, 1); |
249 spin_lock_init(&pid->lock); |
|
267 for (type = 0; type < PIDTYPE_MAX; ++type) 268 INIT_HLIST_HEAD(&pid->tasks[type]); 269 270 init_waitqueue_head(&pid->wait_pidfd); | 250 for (type = 0; type < PIDTYPE_MAX; ++type) 251 INIT_HLIST_HEAD(&pid->tasks[type]); 252 253 init_waitqueue_head(&pid->wait_pidfd); |
254 INIT_HLIST_HEAD(&pid->inodes); |
|
271 272 upid = pid->numbers + ns->level; 273 spin_lock_irq(&pidmap_lock); 274 if (!(ns->pid_allocated & PIDNS_ADDING)) 275 goto out_unlock; 276 for ( ; upid >= pid->numbers; --upid) { 277 /* Make the PID visible to find_pid_ns. */ 278 idr_replace(&upid->ns->idr, pid, upid->nr); --- 310 unchanged lines hidden (view full) --- 589 SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT); 590} 591 592static struct file *__pidfd_fget(struct task_struct *task, int fd) 593{ 594 struct file *file; 595 int ret; 596 | 255 256 upid = pid->numbers + ns->level; 257 spin_lock_irq(&pidmap_lock); 258 if (!(ns->pid_allocated & PIDNS_ADDING)) 259 goto out_unlock; 260 for ( ; upid >= pid->numbers; --upid) { 261 /* Make the PID visible to find_pid_ns. */ 262 idr_replace(&upid->ns->idr, pid, upid->nr); --- 310 unchanged lines hidden (view full) --- 573 SLAB_HWCACHE_ALIGN | SLAB_PANIC | SLAB_ACCOUNT); 574} 575 576static struct file *__pidfd_fget(struct task_struct *task, int fd) 577{ 578 struct file *file; 579 int ret; 580 |
597 ret = mutex_lock_killable(&task->signal->cred_guard_mutex); | 581 ret = mutex_lock_killable(&task->signal->exec_update_mutex); |
598 if (ret) 599 return ERR_PTR(ret); 600 601 if (ptrace_may_access(task, PTRACE_MODE_ATTACH_REALCREDS)) 602 file = fget_task(task, fd); 603 else 604 file = ERR_PTR(-EPERM); 605 | 582 if (ret) 583 return ERR_PTR(ret); 584 585 if (ptrace_may_access(task, PTRACE_MODE_ATTACH_REALCREDS)) 586 file = fget_task(task, fd); 587 else 588 file = ERR_PTR(-EPERM); 589 |
606 mutex_unlock(&task->signal->cred_guard_mutex); | 590 mutex_unlock(&task->signal->exec_update_mutex); |
607 608 return file ?: ERR_PTR(-EBADF); 609} 610 611static int pidfd_getfd(struct pid *pid, int fd) 612{ 613 struct task_struct *task; 614 struct file *file; --- 66 unchanged lines hidden --- | 591 592 return file ?: ERR_PTR(-EBADF); 593} 594 595static int pidfd_getfd(struct pid *pid, int fd) 596{ 597 struct task_struct *task; 598 struct file *file; --- 66 unchanged lines hidden --- |