]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
proc: proc_maps_open allow proc_mem_open to return NULL
authorJialin Wang <wjl.linux@gmail.com>
Thu, 7 Aug 2025 16:54:55 +0000 (00:54 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:34:26 +0000 (16:34 +0200)
commit c0e1b774f68bdbea1618e356e30672c7f1e32509 upstream.

The commit 65c66047259f ("proc: fix the issue of proc_mem_open returning
NULL") caused proc_maps_open() to return -ESRCH when proc_mem_open()
returns NULL.  This breaks legitimate /proc/<pid>/maps access for kernel
threads since kernel threads have NULL mm_struct.

The regression causes perf to fail and exit when profiling a kernel
thread:

  # perf record -v -g -p $(pgrep kswapd0)
  ...
  couldn't open /proc/65/task/65/maps

This patch partially reverts the commit to fix it.

Link: https://lkml.kernel.org/r/20250807165455.73656-1-wjl.linux@gmail.com
Fixes: 65c66047259f ("proc: fix the issue of proc_mem_open returning NULL")
Signed-off-by: Jialin Wang <wjl.linux@gmail.com>
Cc: Penglei Jiang <superman.xpt@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/proc/task_mmu.c

index 0102ab3aaec1627b25c258ef5ca2f07abc74ef0c..bdc3c2e9334ad577b0a95df6dd7f8f03d7041738 100644 (file)
@@ -212,8 +212,8 @@ static int proc_maps_open(struct inode *inode, struct file *file,
 
        priv->inode = inode;
        priv->mm = proc_mem_open(inode, PTRACE_MODE_READ);
-       if (IS_ERR_OR_NULL(priv->mm)) {
-               int err = priv->mm ? PTR_ERR(priv->mm) : -ESRCH;
+       if (IS_ERR(priv->mm)) {
+               int err = PTR_ERR(priv->mm);
 
                seq_release_private(inode, file);
                return err;