Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] pidfs: fix ERR_PTR dereference in pidfd_info()
@ 2025-10-11  7:29 Zhen Ni
  2025-10-11  9:24 ` Mateusz Guzik
  0 siblings, 1 reply; 3+ messages in thread
From: Zhen Ni @ 2025-10-11  7:29 UTC (permalink / raw)
  To: viro, brauner, jack; +Cc: linux-fsdevel, Zhen Ni, stable

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-10-13  8:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-11  7:29 [PATCH] pidfs: fix ERR_PTR dereference in pidfd_info() Zhen Ni
2025-10-11  9:24 ` Mateusz Guzik
2025-10-13  3:42   ` zhen.ni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox