]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - kernel/pid.c
kernel/pid.c: implement additional checks upon pidfd_create() parameters
[mirror_ubuntu-jammy-kernel.git] / kernel / pid.c
index d3cd95b8b080f68a2f780cf99732c38d80d4a1f5..efe87db4468364f8d2650d0b517aa2b567048f2c 100644 (file)
@@ -559,6 +559,12 @@ int pidfd_create(struct pid *pid, unsigned int flags)
 {
        int fd;
 
+       if (!pid || !pid_has_task(pid, PIDTYPE_TGID))
+               return -EINVAL;
+
+       if (flags & ~(O_NONBLOCK | O_RDWR | O_CLOEXEC))
+               return -EINVAL;
+
        fd = anon_inode_getfd("[pidfd]", &pidfd_fops, get_pid(pid),
                              flags | O_RDWR | O_CLOEXEC);
        if (fd < 0)
@@ -598,10 +604,7 @@ SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
        if (!p)
                return -ESRCH;
 
-       if (pid_has_task(p, PIDTYPE_TGID))
-               fd = pidfd_create(p, flags);
-       else
-               fd = -EINVAL;
+       fd = pidfd_create(p, flags);
 
        put_pid(p);
        return fd;