]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
pidfs: fix PIDFD_INFO_COREDUMP handling
authorChristian Brauner <brauner@kernel.org>
Tue, 28 Oct 2025 08:45:47 +0000 (09:45 +0100)
committerChristian Brauner <brauner@kernel.org>
Thu, 30 Oct 2025 13:25:13 +0000 (14:25 +0100)
When PIDFD_INFO_COREDUMP is requested we raise it unconditionally in the
returned mask even if no coredump actually did take place. This was
done because we assumed that the later check whether ->coredump_mask as
non-zero detects that it is zero and then retrieves the dumpability
settings from the task's mm. This has issues though becuase there are
tasks that might not have any mm. Also it's just not very cleanly
implemented. Fix this.

Link: https://patch.msgid.link/20251028-work-coredump-signal-v1-2-ca449b7b7aa0@kernel.org
Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/pidfs.c

index c2f0b7091cd7d3582b71e2d0df60dfad6d23af0d..c0f410903c3f32beea5f1caf747c3817178138f7 100644 (file)
@@ -335,8 +335,9 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)
        }
 
        if (mask & PIDFD_INFO_COREDUMP) {
-               kinfo.mask |= PIDFD_INFO_COREDUMP;
                kinfo.coredump_mask = READ_ONCE(attr->__pei.coredump_mask);
+               if (kinfo.coredump_mask)
+                       kinfo.mask |= PIDFD_INFO_COREDUMP;
        }
 
        task = get_pid_task(pid, PIDTYPE_PID);
@@ -355,12 +356,13 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)
        if (!c)
                return -ESRCH;
 
-       if ((kinfo.mask & PIDFD_INFO_COREDUMP) && !(kinfo.coredump_mask)) {
+       if ((mask & PIDFD_INFO_COREDUMP) && !kinfo.coredump_mask) {
                guard(task_lock)(task);
                if (task->mm) {
                        unsigned long flags = __mm_flags_get_dumpable(task->mm);
 
                        kinfo.coredump_mask = pidfs_coredump_mask(flags);
+                       kinfo.mask |= PIDFD_INFO_COREDUMP;
                }
        }