From: Oleg Nesterov Date: Sun, 26 Oct 2025 14:31:40 +0000 (+0100) Subject: release_task: kill unnecessary rcu_read_lock() around dec_rlimit_ucounts() X-Git-Tag: v6.19-rc1~70^2~108 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c25d24d0f4c6c0954f2b0eb1fc69d293e88192bf;p=thirdparty%2Fkernel%2Flinux.git release_task: kill unnecessary rcu_read_lock() around dec_rlimit_ucounts() rcu_read_lock() was added to shut RCU-lockdep up when this code used __task_cred()->rcu_dereference(), but after the commit 21d1c5e386bc ("Reimplement RLIMIT_NPROC on top of ucounts") it is no longer needed: task_ucounts()->task_cred_xxx() takes rcu_read_lock() itself. NOTE: task_ucounts() returns the pointer to another rcu-protected data, struct ucounts. So it should either be used when task->real_cred and thus task->real_cred->ucounts is stable (release_task, copy_process, copy_creds), or it should be called under rcu_read_lock(). In both cases it is pointless to take rcu_read_lock() to read the cred->ucounts pointer. Link: https://lkml.kernel.org/r/20251026143140.GA22463@redhat.com Signed-off-by: Oleg Nesterov Acked-by: Alexey Gladkov Cc: David Howells Cc: Mateusz Guzik Cc: "Paul E . McKenney" Cc: Kees Cook Signed-off-by: Andrew Morton --- diff --git a/kernel/exit.c b/kernel/exit.c index 9f74e8f1c431b..f041f0c05ebbf 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -251,10 +251,8 @@ repeat: memset(&post, 0, sizeof(post)); /* don't need to get the RCU readlock here - the process is dead and - * can't be modifying its own credentials. But shut RCU-lockdep up */ - rcu_read_lock(); + * can't be modifying its own credentials. */ dec_rlimit_ucounts(task_ucounts(p), UCOUNT_RLIMIT_NPROC, 1); - rcu_read_unlock(); pidfs_exit(p); cgroup_release(p);