All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] procfs: fix missing RCU protection when reading real_parent in do_task_stat()
@ 2026-01-27 15:04 alexjlzheng
  2026-01-27 17:25 ` Oleg Nesterov
  0 siblings, 1 reply; 7+ messages in thread
From: alexjlzheng @ 2026-01-27 15:04 UTC (permalink / raw)
  To: oleg, usamaarif642, david, akpm, lorenzo.stoakes, alexjlzheng,
	mingo, ruippan
  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!
      task_pid_ptr    <--- UAF!
      rcu_read_unlock

This fix adds proper RCU protection similar to getppid() in kernel/sys.c
which correctly uses rcu_dereference() when accessing current->real_parent.

Fixes: 06fffb1267c9 ("do_task_stat: don't take rcu_read_lock()")
Signed-off-by: Jinliang Zheng <alexjlzheng@tencent.com>
---
 fs/proc/array.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 42932f88141a..3c2eea2c551a 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -528,7 +528,9 @@ 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);
+		rcu_read_lock();
+		ppid = task_tgid_nr_ns(rcu_dereference(task->real_parent), ns);
+		rcu_read_unlock();
 		pgid = task_pgrp_nr_ns(task, ns);
 
 		unlock_task_sighand(task, &flags);
-- 
2.39.3


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

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

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-27 15:04 [PATCH] procfs: fix missing RCU protection when reading real_parent in do_task_stat() alexjlzheng
2026-01-27 17:25 ` Oleg Nesterov
2026-01-27 18:49   ` Mateusz Guzik
2026-01-28  3:15     ` Jinliang Zheng
2026-01-28  8:01     ` Oleg Nesterov
2026-01-28  8:10       ` Jinliang Zheng
2026-01-28  3:10   ` Jinliang Zheng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.