]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - kernel/pid.c
bpf: Prevent re-mmap()'ing BPF map as writable for initially r/o mapping
[mirror_ubuntu-jammy-kernel.git] / kernel / pid.c
index 0f4ecb57214cb840d9d1d866669865316fd4a380..bc21c0fb26d8b09e564aead32d8bb8b3d8a938d9 100644 (file)
@@ -144,9 +144,6 @@ void free_pid(struct pid *pid)
                        /* Handle a fork failure of the first process */
                        WARN_ON(ns->child_reaper);
                        ns->pid_allocated = 0;
-                       /* fall through */
-               case 0:
-                       schedule_work(&ns->proc_work);
                        break;
                }
 
@@ -247,10 +244,15 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
                tmp = tmp->parent;
        }
 
-       if (unlikely(is_child_reaper(pid))) {
-               if (pid_ns_prepare_proc(ns))
-                       goto out_free;
-       }
+       /*
+        * ENOMEM is not the most obvious choice especially for the case
+        * where the child subreaper has already exited and the pid
+        * namespace denies the creation of any new processes. But ENOMEM
+        * is what we have exposed to userspace for a long time and it is
+        * documented behavior for pid namespaces. So we can't easily
+        * change it even if there were an error code better suited.
+        */
+       retval = -ENOMEM;
 
        get_pid_ns(ns);
        refcount_set(&pid->count, 1);
@@ -258,6 +260,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
                INIT_HLIST_HEAD(&pid->tasks[type]);
 
        init_waitqueue_head(&pid->wait_pidfd);
+       INIT_HLIST_HEAD(&pid->inodes);
 
        upid = pid->numbers + ns->level;
        spin_lock_irq(&pidmap_lock);
@@ -584,7 +587,7 @@ static struct file *__pidfd_fget(struct task_struct *task, int fd)
        struct file *file;
        int ret;
 
-       ret = mutex_lock_killable(&task->signal->cred_guard_mutex);
+       ret = mutex_lock_killable(&task->signal->exec_update_mutex);
        if (ret)
                return ERR_PTR(ret);
 
@@ -593,7 +596,7 @@ static struct file *__pidfd_fget(struct task_struct *task, int fd)
        else
                file = ERR_PTR(-EPERM);
 
-       mutex_unlock(&task->signal->cred_guard_mutex);
+       mutex_unlock(&task->signal->exec_update_mutex);
 
        return file ?: ERR_PTR(-EBADF);
 }