public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] procfs: fix missing RCU protection when reading real_parent in do_task_stat()
@ 2026-01-28  8:30 alexjlzheng
  2026-01-28  8:48 ` Oleg Nesterov
  0 siblings, 1 reply; 2+ messages in thread
From: alexjlzheng @ 2026-01-28  8:30 UTC (permalink / raw)
  To: oleg, usamaarif642, david, akpm, lorenzo.stoakes, mingo,
	alexjlzheng, ruippan, mjguzik
  Cc: linux-kernel, linux-fsdevel

From: Jinliang Zheng <alexjlzheng@tencent.com>

When reading /proc/[pid]/stat, do_task_stat() accesses task->real_parent
without proper RCU protection, which leads:

  cpu 0                               cpu 1
  -----                               -----
  do_task_stat
    var = task->real_parent
                                      release_task
                                        call_rcu(delayed_put_task_struct)
    task_tgid_nr_ns(var)
      rcu_read_lock   <--- Too late to protect task->real_parent!
      task_pid_ptr    <--- UAF!
      rcu_read_unlock

This patch use task_ppid_nr_ns() instead of task_tgid_nr_ns() to adds
proper RCU protection for accessing task->real_parent.

Fixes: 06fffb1267c9 ("do_task_stat: don't take rcu_read_lock()")
Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
---
changelog:

v2: - use task_ppid_nr_ns(), suggested by Oleg Nesterov
    - clear commit message

v1: https://lore.kernel.org/linux-fsdevel/20260127150450.2073236-1-alexjlzheng@tencent.com/
---
 fs/proc/array.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 42932f88141a..5571177e0435 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -528,7 +528,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
 		}
 
 		sid = task_session_nr_ns(task, ns);
-		ppid = task_tgid_nr_ns(task->real_parent, ns);
+		ppid = task_ppid_nr_ns(task, ns);
 		pgid = task_pgrp_nr_ns(task, ns);
 
 		unlock_task_sighand(task, &flags);
-- 
2.49.0


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

* Re: [PATCH v2] procfs: fix missing RCU protection when reading real_parent in do_task_stat()
  2026-01-28  8:30 [PATCH v2] procfs: fix missing RCU protection when reading real_parent in do_task_stat() alexjlzheng
@ 2026-01-28  8:48 ` Oleg Nesterov
  0 siblings, 0 replies; 2+ messages in thread
From: Oleg Nesterov @ 2026-01-28  8:48 UTC (permalink / raw)
  To: alexjlzheng
  Cc: usamaarif642, david, akpm, lorenzo.stoakes, mingo, alexjlzheng,
	ruippan, mjguzik, linux-kernel, linux-fsdevel

On 01/28, alexjlzheng@gmail.com wrote:
>
> From: Jinliang Zheng <alexjlzheng@tencent.com>
>
> When reading /proc/[pid]/stat, do_task_stat() accesses task->real_parent
> without proper RCU protection, which leads:
>
>   cpu 0                               cpu 1
>   -----                               -----
>   do_task_stat
>     var = task->real_parent
>                                       release_task
>                                         call_rcu(delayed_put_task_struct)
>     task_tgid_nr_ns(var)
>       rcu_read_lock   <--- Too late to protect task->real_parent!
>       task_pid_ptr    <--- UAF!
>       rcu_read_unlock
>
> This patch use task_ppid_nr_ns() instead of task_tgid_nr_ns() to adds
> proper RCU protection for accessing task->real_parent.
>
> Fixes: 06fffb1267c9 ("do_task_stat: don't take rcu_read_lock()")
> Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>

Acked-by: Oleg Nesterov <oleg@redhat.com>


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

end of thread, other threads:[~2026-01-28  8:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-28  8:30 [PATCH v2] procfs: fix missing RCU protection when reading real_parent in do_task_stat() alexjlzheng
2026-01-28  8:48 ` Oleg Nesterov

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