[PATCH] kernel/sys.c: use RCU when accessing task_struct->real_parent

From: Alex Elder

Date: Tue Aug 11 2026 - 15:06:40 EST


In the setpgid() syscall definition, a check is made to determine
whether the target process is in the same thread group as the
current process. The check accesses the target process's real_parent
pointer directly, however that field is supposed to be accessed via
RCU. Use rcu_dereference() to avoid this C=1 build warning:

kernel/sys.c:1144:32: warning: incorrect type in argument 1 (different address spaces)

Signed-off-by: Alex Elder <elder@xxxxxxxxxxxx>
---
kernel/sys.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/sys.c b/kernel/sys.c
index df69bd71de032..434fe6ad30e13 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1114,6 +1114,7 @@ COMPAT_SYSCALL_DEFINE1(times, struct compat_tms __user *, tbuf)
SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid)
{
struct task_struct *p;
+ struct task_struct *real_parent;
struct task_struct *group_leader = current->group_leader;
struct pid *pids[PIDTYPE_MAX] = { 0 };
struct pid *pgrp;
@@ -1141,7 +1142,8 @@ SYSCALL_DEFINE2(setpgid, pid_t, pid, pid_t, pgid)
if (!thread_group_leader(p))
goto out;

- if (same_thread_group(p->real_parent, group_leader)) {
+ real_parent = rcu_dereference(p->real_parent);
+ if (same_thread_group(real_parent, group_leader)) {
err = -EPERM;
if (task_session(p) != task_session(group_leader))
goto out;

base-commit: 6b8c8af514d739d0335f5579b585e02babe8a727
--
2.53.0