Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Zhen Ni <zhen.ni@easystack.cn>
To: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz
Cc: linux-fsdevel@vger.kernel.org, Zhen Ni <zhen.ni@easystack.cn>,
	stable@vger.kernel.org
Subject: [PATCH] pidfs: fix ERR_PTR dereference in pidfd_info()
Date: Sat, 11 Oct 2025 15:29:27 +0800	[thread overview]
Message-ID: <20251011072927.342302-1-zhen.ni@easystack.cn> (raw)

pidfd_pid() may return an ERR_PTR() when the file does not refer to a
valid pidfs file. Currently pidfd_info() calls pid_in_current_pidns()
directly on the returned value, which risks dereferencing an ERR_PTR.

Fix it by explicitly checking IS_ERR(pid) and returning PTR_ERR(pid)
before further use.

Fixes: 7477d7dce48a ("pidfs: allow to retrieve exit information")
Cc: stable@vger.kernel.org
Signed-off-by: Zhen Ni <zhen.ni@easystack.cn>
---
 fs/pidfs.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/pidfs.c b/fs/pidfs.c
index 0ef5b47d796a..16670648bb09 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -314,6 +314,9 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)
 	if (copy_from_user(&mask, &uinfo->mask, sizeof(mask)))
 		return -EFAULT;
 
+	if (IS_ERR(pid))
+		return PTR_ERR(pid);
+
 	/*
 	 * Restrict information retrieval to tasks within the caller's pid
 	 * namespace hierarchy.
-- 
2.20.1


             reply	other threads:[~2025-10-11  7:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-11  7:29 Zhen Ni [this message]
2025-10-11  9:24 ` [PATCH] pidfs: fix ERR_PTR dereference in pidfd_info() Mateusz Guzik
2025-10-13  3:42   ` zhen.ni

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=20251011072927.342302-1-zhen.ni@easystack.cn \
    --to=zhen.ni@easystack.cn \
    --cc=brauner@kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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