* [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* Re: [PATCH] pidfs: fix ERR_PTR dereference in pidfd_info()
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
0 siblings, 1 reply; 3+ messages in thread
From: Mateusz Guzik @ 2025-10-11 9:24 UTC (permalink / raw)
To: Zhen Ni; +Cc: viro, brauner, jack, linux-fsdevel, stable
On Sat, Oct 11, 2025 at 03:29:27PM +0800, Zhen Ni wrote:
> 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);
> +
Is that something you ran into or perhaps you are going off of reading
the code?
The only way that I see to get here requires a file with
pidfs_file_operations, so AFAICS this shouuld never trigger.
In the worst case perhaps this can WARN_ON?
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] pidfs: fix ERR_PTR dereference in pidfd_info()
2025-10-11 9:24 ` Mateusz Guzik
@ 2025-10-13 3:42 ` zhen.ni
0 siblings, 0 replies; 3+ messages in thread
From: zhen.ni @ 2025-10-13 3:42 UTC (permalink / raw)
To: Mateusz Guzik; +Cc: viro, brauner, jack, linux-fsdevel, stable
在 2025/10/11 17:24, Mateusz Guzik 写道:
>
> Is that something you ran into or perhaps you are going off of reading
> the code?
>
> The only way that I see to get here requires a file with
> pidfs_file_operations, so AFAICS this shouuld never trigger.
>
> In the worst case perhaps this can WARN_ON?
>
>
Thanks for the review.
I did not hit this in real testing, but only inferred the potential
issue from reading the code context. After taking another look at the
call paths into pidfd_info(), I agree this is indeed an over-defensive
check and not actually reachable.
I'll drop this patch. Thanks for the clarification.
Zhen
^ permalink raw reply [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