linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Penglei Jiang <superman.xpt@gmail.com>
To: brauner@kernel.org, akpm@linux-foundation.org,
	lorenzo.stoakes@oracle.com
Cc: tglx@linutronix.de, jlayton@kernel.org, viro@zeniv.linux.org.uk,
	felix.moessbauer@siemens.com, adrian.ratiu@collabora.com,
	xu.xin16@zte.com.cn, linux-kernel@vger.kernel.org,
	linux-fsdevel@vger.kernel.org,
	syzbot+f9238a0a31f9b5603fef@syzkaller.appspotmail.com,
	syzbot+02e64be5307d72e9c309@syzkaller.appspotmail.com,
	Penglei Jiang <superman.xpt@gmail.com>
Subject: [PATCH] proc: Fix the issue of proc_mem_open returning NULL
Date: Mon, 24 Mar 2025 09:23:53 -0700	[thread overview]
Message-ID: <20250324162353.72271-1-superman.xpt@gmail.com> (raw)

The following functions call proc_mem_open but do not handle the case
where it returns NULL:

  __mem_open in fs/proc/base.c
  proc_maps_open in fs/proc/task_mmu.c
  smaps_rollup_open in fs/proc/task_mmu.c
  pagemap_open in fs/proc/task_mmu.c
  maps_open in fs/proc/task_nommu.c

The following reported bugs may be related to this issue:

  https://lore.kernel.org/all/000000000000f52642060d4e3750@google.com
  https://lore.kernel.org/all/0000000000001bc4a00612d9a7f4@google.com

Fix:

Modify proc_mem_open to return an error code in case of errors, instead
of returning NULL.

Signed-off-by: Penglei Jiang <superman.xpt@gmail.com>
---
 fs/proc/base.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index cd89e956c322..b5e7317cf0dc 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -840,7 +840,7 @@ struct mm_struct *proc_mem_open(struct inode *inode, unsigned int mode)
 	put_task_struct(task);
 
 	if (IS_ERR(mm))
-		return mm == ERR_PTR(-ESRCH) ? NULL : mm;
+		return mm;
 
 	/* ensure this mm_struct can't be freed */
 	mmgrab(mm);
-- 
2.17.1


             reply	other threads:[~2025-03-24 16:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-24 16:23 Penglei Jiang [this message]
2025-03-24 17:48 ` [PATCH] proc: Fix the issue of proc_mem_open returning NULL Mateusz Guzik
2025-03-25  4:14   ` [PATCH V2] " Penglei Jiang
2025-03-27 19:24     ` Andrew Morton
2025-03-31  9:16       ` [PATCH V3] " Penglei Jiang
2025-03-31 17:06         ` [PATCH V4] " Penglei Jiang
2025-04-04  6:33           ` [PATCH V5] " Penglei Jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250324162353.72271-1-superman.xpt@gmail.com \
    --to=superman.xpt@gmail.com \
    --cc=adrian.ratiu@collabora.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=felix.moessbauer@siemens.com \
    --cc=jlayton@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=syzbot+02e64be5307d72e9c309@syzkaller.appspotmail.com \
    --cc=syzbot+f9238a0a31f9b5603fef@syzkaller.appspotmail.com \
    --cc=tglx@linutronix.de \
    --cc=viro@zeniv.linux.org.uk \
    --cc=xu.xin16@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).