From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7100606A339 for ; Sat, 5 Dec 2026 13:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aNQ5LByw Received: by kanga.kvack.org (Postfix) id 191EB6B05C0; Sat, 5 Dec 2026 08:13:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 169696B05C1; Sat, 5 Dec 2026 08:13:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0571D6B05C2; Sat, 5 Dec 2026 08:13:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C44D56B05C0 for ; Sat, 5 Dec 2026 08:13:27 -0500 (EST) Received: from smtpin25.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5A2CCC04E4 for ; Sat, 5 Dec 2026 13:13:27 +0000 (UTC) X-FDA: 85509970854.25.A26A1E9 Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf19.hostedemail.com (Postfix) with ESMTP id 437AA1A0017 for ; Sat, 5 Dec 2026 13:13:25 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=aNQ5LByw; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of mason@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=mason@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796476405; b=RfT5VC8J4ZHnev6DmHLIZsvtBySt31lYJ39Slb+aanB07VR2owx95u9Z8gyawkAjMnR9+X Jkls/IdPte3/wvFDGFXFmElB6UfGso1yeBIdvfk2xVM2zktWgsF5ogvvfB8Qe5523zWUga rKhg7sVkAOsAP2EhIBWtFNxkBowiY4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796476405; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2dQlVgF94Ny/eGpf+2JJu/+y0dhCrl6/5VGxSf2DEbs=; b=UFsAUSnCUvkP4fWPXMJIdZ38AFHFIWgsfPbtv3/Wf4cwLi3fR7EkF0WJIQdtEi1pdBQ6YC 19/V7tXxg+XyhHgi9+7GLGz7NJllWt1UbRXUwN0Tn8eKg0P7JGcYhkmKNlMQ/+4xchuzSJ WYU6ON46OYAAYtgej2EkyA3UR5f4y78= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=aNQ5LByw; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf19.hostedemail.com: domain of mason@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=mason@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id A146B45C28; Sat, 5 Dec 2026 13:13:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 064E91F00A11; Sat, 5 Dec 2026 13:13:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796476404; bh=2dQlVgF94Ny/eGpf+2JJu/+y0dhCrl6/5VGxSf2DEbs=; h=Date:From:To:Cc:In-Reply-To:References:Subject; b=aNQ5LBywwAP2YmRE0cuq555FhYRlX8jDnkjBQLGI7wlWtGT8nlXvAx4FvjjzKUGkh zn1FIQ1FcbtV//n3fLFNedK0O+wprW8mygYJaUU9nyINtaH4sZvWqmuGkw+5Ky37h8 wYnIEacBQeYKBfxqMN3RbWxml+n0WqS6L1Bf1hPOPiYit0Y8lygXFM3/mYsQvRRggP yoSlW9mHU1W/k/1WV7e+Y3PRmPKjrAFoNx5YYII6P7Azh0u9ckJ45sjI4Am9kRfFW1 9jdEiI7CKeSXJn2KX5WBG+0j+nB7cQcDnkdKf7pHNoBg4ExOErRZGN7AjxW71BxAAh gqJrqBad4Nk1g== Received: from stl-compute-04.internal (stl-compute-04.internal [10.204.2.64]) by mailfauth.stl.internal (Postfix) with ESMTP id 8FC96780043; Sat, 5 Dec 2026 08:13:23 -0500 (EST) Received: from stl-imap-13 ([10.204.2.104]) by stl-compute-04.internal (MEProxy); Sat, 05 Dec 2026 08:13:23 -0500 X-ME-Sender: X-ME-Proxy-Cause: dmFkZTEAfa//g8D9PGg4bwm8fXfx0P9itzNCvvFgSvt4HSpzs1NkAb9q/DrdrmIbiwd0ra b+wJXCY8tRUZuWKbLu7vUl91xOFqrKejqo3DcCvucNQQCrxn2ZBSfpDZF9+T4No+02GKzo R9nlc0LBwEK92S9hCMjZHH9oIkHRPyHgBjpyvSTopmFr4/XrUPwFs682jLopN433U2Gof9 AFHezZqXtggx7Kk4pcTFQvRobiSsUGsVw9w6Vz+8IPlz+UDbrc11vYQEA87z7L9YN8muZN SSxQ38jvEh9eHPdj4oMWgShQSf5D77QDUQZsfY1XkoSsJ9LdcITRM5Mf8yovOW+LePrrte 5tvdmcgs+mxTwLSTRBy9F2elagmQ50UhHC9pkMZMKZp+BVy2B2J1tBGDC067BE2yVZ2Lxo GF5PgR4nkxM44EaSlXFRr2b+aTWEFZceB7QynQAwoiUecSNibAtRJyl6m3atomKuLUCr9K pldf8ddzA1UwVDP/AuLagJulowTVASh5i5e0eNqcrqtufni7wapSrehu0tmMtnu5PbSFx5 3gjT3ELXWHJyNZQhon4F+XuQYTZJPg4eC46CBg9PXlfGn7/AjkBPE+tjFR1GaSHi/m7ibb 6WDY82mbr4h/IwSnVS0iF6HDw48FdODvdQu+0OXClDWIxvVh5mHE5YjInTdw X-ME-Proxy: Feedback-ID: iccae4b50:Fastmail Received: by mailuser.stl.internal (Postfix, from userid 501) id 55940F60088; Sat, 5 Dec 2026 08:13:23 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface X-Archived-By: MIME-Version: 1.0 X-ThreadId: AuvvtD4j5FdZ Date: Sat, 05 Dec 2026 08:13:02 -0500 From: "Chris Mason" To: brauner@kernel.org, oleg@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, peterz@infradead.org, mingo@redhat.com, kees@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz, tj@kernel.org, hannes@cmpxchg.org, mkoutny@suse.com, bsingharora@gmail.com, eddyz87@gmail.com, memxor@gmail.com, yonghong.song@linux.dev, martin.lau@linux.dev, song@kernel.org, jolsa@kernel.org, emil@etsalapatis.com, ihor.solodrai@linux.dev, sched-ext@lists.linux.dev, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, mason@kernel.org Message-Id: <20261204233428.14861-8-mason@kernel.org> In-Reply-To: <20261204233428.14861-1-mason@kernel.org> References: <20261204233428.14861-1-mason@kernel.org> Subject: [RFC PATCH v2 7/8] signal: add task_group_leader() Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Stat-Signature: 6okag5fur5qc1mf4qthgcs7xes3ar3kc X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-Rspamd-Queue-Id: 437AA1A0017 X-Rspamd-Server: rspam07 X-HE-Tag: 1796476405-22348 X-HE-Meta: U2FsdGVkX1+bKzYv9rlq42/1U49c17Ea1kWMr50GxbmfrQ9G0l83AtfQy/E6963fBjmQooYTXGGQ46DfJcFuROn+Whr3IlZNdgXDZuyR5LB21bsPDhFPpTDCtWVnh02aTmL860uafg3RQJN4yqZFUumVgeJooXBPYuuHdKKpb7dvrdWszEgYu1kjhv3VkDNhnLpVsszu8O8pCa3fSzacPtXs6lrJqW0zjOi8vIIkLtUM7Mzu0VdGZkLg5qFNrnK87Pa+mF7r2GBjnmaB5CmHKVz8mDI9xoPOySmVM5GfxjWCFyd1aCloZ1/FlVplarBqzNVbUor5DP25dBPfnUKr8/ki/kDv1J++AcgmBFQ01iPtUx8RQmfoxnzBDeuK/3RKNWyvL7kJCreAP9CjqXYIlW6yQ/DwlMG6T1I50+yMXFKSoYmlVTqux6sZMNQGS45ln/6sTBYsdklMbEwczscv/b+O7RtEDQYhsTQDwEayVEvBu9iFGq98z97m+7kw3WlBQlgpZ6ad/olzFiY58CoHIq7CKy/1U316HN4nfOgg/rBEUxy0E818YryNDprFjsCIx0QNYpHuu7fEOPx3qbZ90Eke6ouOklm7wVyEopSUfTKSqQAWI5FFjYFc9pf1eUoekaBA6Wx+90LFOWqkH5x60q3Veabq3N9D/6U+quyqkJOlIiODNWFtr5viwn7l76LvKGaky0JxtKdJ4tvYOA5RbsgNWs49CL0+jMgNhiUXIWnXyv8GrrGY1hZH52bvdf+2t+VfnIzt6TdKvMmEaaCYXdVt62YlWH1A2DR2YFgY+dpSKgbCBOlOmK/8zpydMRqjhCvqS3okA8/yLu2K1Q7ThNd9EqwtLhhE5ViYkJp+Ukie/fPiUjYxp6NSPCetVYlnJpJsPwUp5nNRrMngScXmCxpVlYdvicOE2jPcyPZKkTZAf5vEqRzNiMZRCus7rOg/WGrHF39Z8JPskZDkhCr tmL2A/lB B2KpbY3klq1VSM45M8ypAiqJ/OZfp0+P5SUvcvv57dDyNNFZNRyNLCbXAIlYzVtyth4l7u1XZCMs9JQx3vvIQJzhmG7ln0PHG5xbTN9Di76WrYhPYS8nnIkP07kf/I2N9D5lO89kcTvj7GO9fTRrGxO4D9sU6REPwu/b9ez2kaBT55AMAiaSLIjwWlrtqk8ZbbrJjIOFiGv1gwdWMeumb8gdwPq0ylGpjOBf12lSlyQ54gMyQrPY7OUuMyPPFKdau/Wk/7zv05UNMwXQIJXgHdGWe6qymZ5m8XGUL4nGW35Umt7N/pqQPvu9OUZGgWAqcYDOJ+I0pizQnSR7AIXc00J7juP1NDz9qp3BKO8nQdJ7110wJJBYIWNtl2Rwf0rfU2qU2IIWJg+wrdhv7Mopq9IpIeXpVVaJpD31ue/jMkwa9oCWnHS2Uv0vRpUFyhR/c+5L1Br2biYgslDaA/hIlUPDQ5y7Ygklx/Ct64LRnc9YpH+Nu4e6OzRwXbrL4p+liDmo6a5Jew8I7YngplBsXU0YSHN2Ml0CKJacQaI9ktuolNCkLXIpEipKwLqpdutFNFBFM4GzHe2zE8xp53aRdTqRpUVzEIBlfA9rAM744jeUW8hM= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 This is a prep patch that allows us to move group_leader into signal_struct. As Oleg Nesterov suggested, it adds a helper to read the field, which warns if another process's leader is read without RCU or tasklist_lock. cgroup, cpuset, Yama and current_is_single_threaded() now use thread_group_leader() or same_thread_group() instead of comparing with the leader. Signed-off-by: Chris Mason --- arch/x86/kernel/fpu/core.c | 4 ++-- arch/x86/kernel/fpu/xstate.c | 6 +++--- arch/x86/kernel/fpu/xstate.h | 4 +++- arch/x86/kernel/signal.c | 4 ++-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 ++-- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 2 +- drivers/gpu/drm/panfrost/panfrost_gem.c | 2 +- drivers/gpu/drm/panthor/panthor_gem.c | 2 +- drivers/gpu/drm/panthor/panthor_sched.c | 8 ++++---- drivers/gpu/drm/scheduler/sched_entity.c | 9 +++++---- drivers/iommu/iommufd/ioas.c | 4 ++-- drivers/iommu/iommufd/pages.c | 4 ++-- drivers/vfio/vfio_iommu_type1.c | 6 +++--- fs/binfmt_elf.c | 2 +- fs/binfmt_elf_fdpic.c | 2 +- fs/exec.c | 10 +++++----- include/linux/cgroup.h | 2 +- include/linux/sched/signal.h | 21 ++++++++++++++++++--- kernel/acct.c | 2 +- kernel/bpf/task_iter.c | 4 ++-- kernel/cgroup/cgroup.c | 2 +- kernel/cgroup/cpuset.c | 4 ++-- kernel/debug/kdb/kdb_main.c | 2 +- kernel/exit.c | 4 ++-- kernel/fork.c | 10 +++++----- kernel/signal.c | 6 +++--- kernel/sys.c | 20 ++++++++++---------- kernel/tsacct.c | 2 +- lib/is_single_threaded.c | 2 +- rust/helpers/task.c | 7 +++++++ rust/kernel/task.rs | 9 +++++---- security/apparmor/resource.c | 2 +- security/yama/yama_lsm.c | 10 ++++------ 35 files changed, 105 insertions(+), 81 deletions(-) diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index 80a7f41cf3ad9..edbb18810d720 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -243,7 +243,7 @@ static void fpu_lock_guest_permissions(void) return; spin_lock_irq(¤t->sighand->siglock); - fpuperm = &x86_task_fpu(current->group_leader)->guest_perm; + fpuperm = &x86_task_fpu(task_group_leader(current))->guest_perm; perm = fpuperm->__state_perm; /* First fpstate allocation locks down permissions. */ @@ -636,7 +636,7 @@ void fpstate_reset(struct fpu *fpu) static inline void fpu_inherit_perms(struct fpu *dst_fpu) { if (fpu_state_size_dynamic()) { - struct fpu *src_fpu = x86_task_fpu(current->group_leader); + struct fpu *src_fpu = x86_task_fpu(task_group_leader(current)); spin_lock_irq(¤t->sighand->siglock); /* Fork also inherits the permissions of the parent */ diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index da303714379cd..4c805e09225c7 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -1689,7 +1689,7 @@ static int fpstate_realloc(u64 xfeatures, unsigned int ksize, static int validate_sigaltstack(unsigned int usize) { - struct task_struct *thread, *leader = current->group_leader; + struct task_struct *thread, *leader = task_group_leader(current); unsigned long framesize = get_sigframe_size(); lockdep_assert_held(¤t->sighand->siglock); @@ -1713,7 +1713,7 @@ static int __xstate_request_perm(u64 permitted, u64 requested, bool guest) * AVX512. */ bool compacted = cpu_feature_enabled(X86_FEATURE_XCOMPACTED); - struct fpu *fpu = x86_task_fpu(current->group_leader); + struct fpu *fpu = x86_task_fpu(task_group_leader(current)); struct fpu_state_perm *perm; unsigned int ksize, usize; u64 mask; @@ -1820,7 +1820,7 @@ int __xfd_enable_feature(u64 xfd_err, struct fpu_guest *guest_fpu) return -EPERM; } - fpu = x86_task_fpu(current->group_leader); + fpu = x86_task_fpu(task_group_leader(current)); perm = guest_fpu ? &fpu->guest_perm : &fpu->perm; ksize = perm->__state_size; usize = perm->__user_state_size; diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h index 1ea762e930866..676f4db6caf63 100644 --- a/arch/x86/kernel/fpu/xstate.h +++ b/arch/x86/kernel/fpu/xstate.h @@ -2,6 +2,8 @@ #ifndef __X86_KERNEL_FPU_XSTATE_H #define __X86_KERNEL_FPU_XSTATE_H +#include + #include #include #include @@ -23,7 +25,7 @@ static inline void xstate_init_xcomp_bv(struct xregs_state *xsave, u64 mask) static inline u64 xstate_get_group_perm(bool guest) { - struct fpu *fpu = x86_task_fpu(current->group_leader); + struct fpu *fpu = x86_task_fpu(task_group_leader(current)); struct fpu_state_perm *perm; /* Pairs with WRITE_ONCE() in xstate_request_perm() */ diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c index 2404233336ab6..4fdc5b9af9916 100644 --- a/arch/x86/kernel/signal.c +++ b/arch/x86/kernel/signal.c @@ -423,14 +423,14 @@ bool sigaltstack_size_valid(size_t ss_size) if (!fpu_state_size_dynamic() && !strict_sigaltstack_size) return true; - fsize += x86_task_fpu(current->group_leader)->perm.__user_state_size; + fsize += x86_task_fpu(task_group_leader(current))->perm.__user_state_size; if (likely(ss_size > fsize)) return true; if (strict_sigaltstack_size) return ss_size > fsize; - mask = x86_task_fpu(current->group_leader)->perm.__state_perm; + mask = x86_task_fpu(task_group_leader(current))->perm.__state_perm; if (mask & XFEATURE_MASK_USER_DYNAMIC) return ss_size > fsize; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c index 326abc9b7f690..ea872eed0fcfd 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c @@ -1362,7 +1362,7 @@ int amdgpu_ttm_tt_set_userptr(struct ttm_buffer_object *bo, if (gtt->usertask) put_task_struct(gtt->usertask); - gtt->usertask = current->group_leader; + gtt->usertask = task_group_leader(current); get_task_struct(gtt->usertask); return 0; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 45f0f6aca754c..e9d64fc337d91 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -2595,7 +2595,7 @@ void amdgpu_vm_set_task_info(struct amdgpu_vm *vm) get_task_comm(vm->task_info->task.comm, current); vm->task_info->tgid = current->tgid; - get_task_comm(vm->task_info->process_name, current->group_leader); + get_task_comm(vm->task_info->process_name, task_group_leader(current)); } /** diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c index a46a4e498ac51..cab536027ec16 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c @@ -3670,7 +3670,7 @@ static long kfd_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) ptrace_attached = true; rcu_read_unlock(); - if (process->lead_thread != current->group_leader + if (process->lead_thread != task_group_leader(current) && !ptrace_attached) { dev_dbg(kfd_device, "Using KFD FD in wrong process\n"); retcode = -EBADF; @@ -3794,7 +3794,7 @@ static int kfd_mmap(struct file *filep, struct vm_area_struct *vma) if (!process) return -ESRCH; - if (process->lead_thread != current->group_leader) + if (process->lead_thread != task_group_leader(current)) return -EBADF; mmap_offset = vma->vm_pgoff << PAGE_SHIFT; diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index 458637a81f66c..1a72d9a206038 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -1701,7 +1701,7 @@ struct kfd_process *create_process(const struct task_struct *thread, */ rcu_read_lock(); if (pid_alive(thread)) - process->lead_thread = get_task_struct(thread->group_leader); + process->lead_thread = get_task_struct(task_group_leader(thread)); rcu_read_unlock(); if (!process->lead_thread) { err = -ESRCH; diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c index 518f24549b9de..219f94540068c 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -48,7 +48,7 @@ static void panfrost_gem_debugfs_bo_add(struct panfrost_device *pfdev, struct panfrost_gem_object *bo) { bo->debugfs.creator.tgid = current->tgid; - get_task_comm(bo->debugfs.creator.process_name, current->group_leader); + get_task_comm(bo->debugfs.creator.process_name, task_group_leader(current)); mutex_lock(&pfdev->debugfs.gems_lock); list_add_tail(&bo->debugfs.node, &pfdev->debugfs.gems_list); diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c index 22b57ab6f9291..df3119b5fb39b 100644 --- a/drivers/gpu/drm/panthor/panthor_gem.c +++ b/drivers/gpu/drm/panthor/panthor_gem.c @@ -54,7 +54,7 @@ static void panthor_gem_debugfs_bo_add(struct panthor_gem_object *bo) struct panthor_device, base); bo->debugfs.creator.tgid = current->tgid; - get_task_comm(bo->debugfs.creator.process_name, current->group_leader); + get_task_comm(bo->debugfs.creator.process_name, task_group_leader(current)); mutex_lock(&ptdev->gems.lock); list_add_tail(&bo->debugfs.node, &ptdev->gems.node); diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c index a343c5180e01e..0fd46bf8a6531 100644 --- a/drivers/gpu/drm/panthor/panthor_sched.c +++ b/drivers/gpu/drm/panthor/panthor_sched.c @@ -647,12 +647,12 @@ struct panthor_group { size_t kbo_sizes; } fdinfo; - /** @task_info: Info of current->group_leader that created the group. */ + /** @task_info: Info of the process that created the group. */ struct { - /** @task_info.pid: pid of current->group_leader */ + /** @task_info.pid: pid of its thread group leader */ pid_t pid; - /** @task_info.comm: comm of current->group_leader */ + /** @task_info.comm: comm of its thread group leader */ char comm[TASK_COMM_LEN]; } task_info; @@ -3592,7 +3592,7 @@ group_create_queue(struct panthor_group *group, static void group_init_task_info(struct panthor_group *group) { - struct task_struct *task = current->group_leader; + struct task_struct *task = task_group_leader(current); group->task_info.pid = task->pid; get_task_comm(group->task_info.comm, task); diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c index 03e68b4102d50..7e6227803226a 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -130,7 +131,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, INIT_LIST_HEAD(&entity->list); entity->guilty = guilty; - entity->last_user = current->group_leader; + entity->last_user = task_group_leader(current); entity->num_sched_list = num_sched_list; entity->sched_list = num_sched_list > 1 ? sched_list : NULL; RB_CLEAR_NODE(&entity->rb_tree_node); @@ -374,8 +375,8 @@ long drm_sched_entity_flush(struct drm_sched_entity *entity, long timeout) } /* For a killed process disallow further enqueueing of jobs. */ - last_user = cmpxchg(&entity->last_user, current->group_leader, NULL); - if (last_user == current->group_leader && + last_user = cmpxchg(&entity->last_user, task_group_leader(current), NULL); + if (last_user == task_group_leader(current) && (current->flags & PF_EXITING) && (current->exit_code == SIGKILL)) drm_sched_entity_kill(entity); @@ -632,7 +633,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job) trace_drm_sched_job_add_dep(sched_job, entry); } atomic_inc(entity->rq->sched->score); - WRITE_ONCE(entity->last_user, current->group_leader); + WRITE_ONCE(entity->last_user, task_group_leader(current)); /* * After the sched_job is pushed into the entity queue, it may be diff --git a/drivers/iommu/iommufd/ioas.c b/drivers/iommu/iommufd/ioas.c index 8fb5271a95060..8a163ddb7ed24 100644 --- a/drivers/iommu/iommufd/ioas.c +++ b/drivers/iommu/iommufd/ioas.c @@ -497,7 +497,7 @@ static int charge_current(unsigned long *npinned) { struct iopt_pages tmp = { .source_mm = current->mm, - .source_task = current->group_leader, + .source_task = task_group_leader(current), .source_user = current_user(), }; unsigned int account_mode; @@ -538,7 +538,7 @@ static void change_mm(struct iopt_pages *pages) mmgrab(pages->source_mm); mmdrop(old_mm); - pages->source_task = current->group_leader; + pages->source_task = task_group_leader(current); get_task_struct(pages->source_task); put_task_struct(old_task); diff --git a/drivers/iommu/iommufd/pages.c b/drivers/iommu/iommufd/pages.c index fcdbde007a9ab..ff1b8cd85a22b 100644 --- a/drivers/iommu/iommufd/pages.c +++ b/drivers/iommu/iommufd/pages.c @@ -1401,8 +1401,8 @@ static struct iopt_pages *iopt_alloc_pages(unsigned long start_byte, pages->account_mode = IOPT_PAGES_ACCOUNT_NONE; else pages->account_mode = IOPT_PAGES_ACCOUNT_USER; - pages->source_task = current->group_leader; - get_task_struct(current->group_leader); + pages->source_task = task_group_leader(current); + get_task_struct(task_group_leader(current)); pages->source_user = get_uid(current_user()); return pages; } diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index f7addfbe1aab4..83929ff28c0d7 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1651,7 +1651,7 @@ static bool vfio_iommu_iova_dma_valid(struct vfio_iommu *iommu, static int vfio_change_dma_owner(struct vfio_dma *dma) { - struct task_struct *task = current->group_leader; + struct task_struct *task = task_group_leader(current); struct mm_struct *mm = current->mm; long npage = dma->locked_vm; bool lock_cap; @@ -1776,8 +1776,8 @@ static int vfio_dma_do_map(struct vfio_iommu *iommu, * the same task, to make debugging easier. VM locked pages requires * an mm_struct, so grab the mm in case the task dies. */ - get_task_struct(current->group_leader); - dma->task = current->group_leader; + get_task_struct(task_group_leader(current)); + dma->task = task_group_leader(current); dma->lock_cap = capable(CAP_IPC_LOCK); dma->mm = current->mm; mmgrab(dma->mm); diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index bf7f8f47548d3..5e96c9a7bfa6f 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1895,7 +1895,7 @@ static int fill_note_info(struct elfhdr *elf, int phdrs, /* * Fill in the two process-wide notes. */ - fill_psinfo(psinfo, dump_task->group_leader, dump_task->mm); + fill_psinfo(psinfo, task_group_leader(dump_task), dump_task->mm); info->size += notesize(&info->psinfo); fill_siginfo_note(&info->signote, &info->csigdata, cprm->siginfo); diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index d3872169f55e5..e4e43b1a5e738 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -1542,7 +1542,7 @@ static bool elf_fdpic_core_dump(struct coredump_params *cprm) * with info from their /proc. */ - fill_psinfo(psinfo, current->group_leader, current->mm); + fill_psinfo(psinfo, task_group_leader(current), current->mm); fill_note(&psinfo_note, PRPSINFO, sizeof(*psinfo), psinfo); thread_status_size += notesize(&psinfo_note); diff --git a/fs/exec.c b/fs/exec.c index b3b80a47fb657..3bae1a6dc62c3 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -269,9 +269,9 @@ static int bprm_mm_init(struct linux_binprm *bprm) bprm->user_ns = get_user_ns(current_user_ns()); /* Save current stack limit for all calculations made during exec. */ - task_lock(current->group_leader); + task_lock(task_group_leader(current)); bprm->rlim_stack = current->signal->rlim[RLIMIT_STACK]; - task_unlock(current->group_leader); + task_unlock(task_group_leader(current)); #ifndef CONFIG_MMU bprm->p = PAGE_SIZE * MAX_ARG_PAGES - sizeof(void *); @@ -963,7 +963,7 @@ static int de_thread(struct task_struct *tsk) * and to assume its PID: */ if (!thread_group_leader(tsk)) { - struct task_struct *leader = tsk->group_leader; + struct task_struct *leader = task_group_leader(tsk); for (;;) { cgroup_threadgroup_change_begin(tsk); @@ -1402,9 +1402,9 @@ EXPORT_SYMBOL(setup_new_exec); void finalize_exec(struct linux_binprm *bprm) { /* Store any stack rlimit changes before starting thread. */ - task_lock(current->group_leader); + task_lock(task_group_leader(current)); current->signal->rlim[RLIMIT_STACK] = bprm->rlim_stack; - task_unlock(current->group_leader); + task_unlock(task_group_leader(current)); } EXPORT_SYMBOL(finalize_exec); diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 2afb4cb2bb4fa..0a1a5b09d0d50 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -377,7 +377,7 @@ void css_task_iter_end(struct css_task_iter *it); for ((leader) = cgroup_taskset_first((tset), &(dst_css)); \ (leader); \ (leader) = cgroup_taskset_next((tset), &(dst_css))) \ - if ((leader) != (leader)->group_leader) \ + if (!thread_group_leader(leader)) \ ; \ else diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h index cf73f4dd6946a..802e264c323d3 100644 --- a/include/linux/sched/signal.h +++ b/include/linux/sched/signal.h @@ -211,8 +211,8 @@ struct signal_struct { * because there is no reader checking a limit that actually needs * to get both rlim_cur and rlim_max atomically, and either one * alone is a single word that can safely be read normally. - * getrlimit/setrlimit use task_lock(current->group_leader) to - * protect this instead of the siglock, because they really + * getrlimit/setrlimit use task_lock(task_group_leader(current)) + * to protect this instead of the siglock, because they really * have no need to disable irqs. */ struct rlimit rlim[RLIM_NLIMITS]; @@ -745,6 +745,21 @@ static inline bool thread_group_leader(struct task_struct *p) return p->exit_signal >= 0; } +/* + * Another process's leader can exit, or be replaced by exec, at any time. So + * hold RCU or tasklist_lock while you use it, and check pid_alive(@p) before + * you take a reference on it. + */ +static inline struct task_struct *task_group_leader(const struct task_struct *p) +{ + RCU_LOCKDEP_WARN(p->signal != current->signal && + !rcu_read_lock_any_held() && + !lockdep_tasklist_lock_is_held(), + "another process's leader needs RCU or tasklist_lock"); + + return READ_ONCE(p->group_leader); +} + static inline bool same_thread_group(struct task_struct *p1, struct task_struct *p2) { @@ -764,7 +779,7 @@ static inline struct task_struct *__next_thread(struct task_struct *p) static inline struct task_struct *next_thread(struct task_struct *p) { - return __next_thread(p) ?: p->group_leader; + return __next_thread(p) ?: task_group_leader(p); } static inline int thread_group_empty(struct task_struct *p) diff --git a/kernel/acct.c b/kernel/acct.c index c440d43479ca5..710ae0e65555a 100644 --- a/kernel/acct.c +++ b/kernel/acct.c @@ -459,7 +459,7 @@ static void fill_ac(struct bsd_acct_struct *acct) /* calculate run_time in nsec*/ run_time = ktime_get_ns(); - run_time -= current->group_leader->start_time; + run_time -= task_group_leader(current)->start_time; /* convert nsec -> AHZ */ elapsed = nsec_to_AHZ(run_time); #if ACCT_VERSION == 3 diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c index a5f0849500715..b17c5f9a50d4e 100644 --- a/kernel/bpf/task_iter.c +++ b/kernel/bpf/task_iter.c @@ -79,7 +79,7 @@ static struct task_struct *task_group_seq_get_next(struct bpf_iter_seq_task_comm if (!next_tid) goto retry; - if (skip_if_dup_files && task->files == task->group_leader->files) + if (skip_if_dup_files && task->files == task_group_leader(task)->files) goto retry; *tid = common->pid_visiting = next_tid; @@ -126,7 +126,7 @@ static struct task_struct *task_seq_get_next(struct bpf_iter_seq_task_common *co ++*tid; goto retry; } else if (skip_if_dup_files && !thread_group_leader(task) && - task->files == task->group_leader->files) { + task->files == task_group_leader(task)->files) { put_task_struct(task); task = NULL; ++*tid; diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 640af2d4551d1..61f88297de431 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3146,7 +3146,7 @@ struct task_struct *cgroup_procs_write_start(char *buf, bool threadgroup, } if (threadgroup) - tsk = tsk->group_leader; + tsk = task_group_leader(tsk); /* * kthreads may acquire PF_NO_SETAFFINITY during initialization. diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c index db32d330cfbc2..fbb0c1e27b348 100644 --- a/kernel/cgroup/cpuset.c +++ b/kernel/cgroup/cpuset.c @@ -3252,7 +3252,7 @@ static int cpuset_can_attach(struct cgroup_taskset *tset) goto out_unlock; /* Update attach_ctx.old_cs to the latest group leader */ - if (task == task->group_leader) + if (thread_group_leader(task)) attach_ctx.old_cs = task_cs(task); if (setsched_check) { @@ -3343,7 +3343,7 @@ static void cpuset_attach_task(struct cpuset *cs, struct task_struct *task) cpuset_change_task_nodemask(task, &attach_ctx.nodemask_to); cpuset1_update_task_spread_flags(cs, task); - if ((task != task->group_leader) || !attach_ctx.mems_updated) + if (!thread_group_leader(task) || !attach_ctx.mems_updated) return; /* diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c index 40c332d2179d8..31c592761eb56 100644 --- a/kernel/debug/kdb/kdb_main.c +++ b/kernel/debug/kdb/kdb_main.c @@ -2351,7 +2351,7 @@ static int kdb_kill(int argc, const char **argv) kdb_printf("The specified process isn't found.\n"); return 0; } - p = p->group_leader; + p = task_group_leader(p); kdb_send_sig(p, sig); return 0; } diff --git a/kernel/exit.c b/kernel/exit.c index 8a5985821e17d..5046360b8a6a4 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -272,7 +272,7 @@ void release_task(struct task_struct *p) * group leader's parent process. (if it wants notification.) */ zap_leader = 0; - leader = p->group_leader; + leader = task_group_leader(p); if (leader != p && thread_group_empty(leader) && leader->exit_state == EXIT_ZOMBIE) { /* for pidfs_exit() and do_notify_parent() */ @@ -750,7 +750,7 @@ static void exit_notify(struct task_struct *tsk, int group_dead) forget_original_parent(tsk, &dead); if (group_dead) - kill_orphaned_pgrp(tsk->group_leader, NULL); + kill_orphaned_pgrp(task_group_leader(tsk), NULL); tsk->exit_state = EXIT_ZOMBIE; diff --git a/kernel/fork.c b/kernel/fork.c index c99d7147f1f1d..ff0e367b2a81d 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1795,9 +1795,9 @@ static int copy_signal(u64 clone_flags, struct task_struct *tsk) hrtimer_setup(&sig->real_timer, it_real_fn, CLOCK_MONOTONIC, HRTIMER_MODE_REL); #endif - task_lock(current->group_leader); + task_lock(task_group_leader(current)); memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim); - task_unlock(current->group_leader); + task_unlock(task_group_leader(current)); posix_cpu_timers_init_group(sig); @@ -2492,7 +2492,7 @@ __latent_entropy struct task_struct *copy_process( if (clone_flags & CLONE_THREAD) p->exit_signal = -1; else - p->exit_signal = current->group_leader->exit_signal; + p->exit_signal = task_group_leader(current)->exit_signal; } else { p->parent_exec_id = current->self_exec_id; p->exit_signal = args->exit_signal; @@ -3135,7 +3135,7 @@ void walk_process_tree(struct task_struct *top, proc_visitor visitor, void *data int res; read_lock(&tasklist_lock); - leader = top = top->group_leader; + leader = top = task_group_leader(top); down: for_each_thread(leader, parent) { list_for_each_entry(child, &parent->children, sibling) { @@ -3154,7 +3154,7 @@ void walk_process_tree(struct task_struct *top, proc_visitor visitor, void *data if (leader != top) { child = leader; parent = child->real_parent; - leader = parent->group_leader; + leader = task_group_leader(parent); goto up; } out: diff --git a/kernel/signal.c b/kernel/signal.c index dd770e68faee0..f5e77076ca2a8 100644 --- a/kernel/signal.c +++ b/kernel/signal.c @@ -2366,7 +2366,7 @@ static void do_notify_parent_cldstop(struct task_struct *tsk, if (for_ptracer) { parent = tsk->parent; } else { - tsk = tsk->group_leader; + tsk = task_group_leader(tsk); parent = tsk->real_parent; } @@ -2929,8 +2929,8 @@ bool get_signal(struct ksignal *ksig) read_lock(&tasklist_lock); do_notify_parent_cldstop(current, false, why); - if (ptrace_reparented(current->group_leader)) - do_notify_parent_cldstop(current->group_leader, + if (ptrace_reparented(task_group_leader(current))) + do_notify_parent_cldstop(task_group_leader(current), true, why); read_unlock(&tasklist_lock); diff --git a/kernel/sys.c b/kernel/sys.c index 9cb8eac08b7d2..bfa0a7b5420e7 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -1117,7 +1117,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 *group_leader = current->group_leader; + struct task_struct *group_leader = task_group_leader(current); struct pid *pids[PIDTYPE_MAX] = { 0 }; struct pid *pgrp; int err; @@ -1259,7 +1259,7 @@ SYSCALL_DEFINE1(getsid, pid_t, pid) static void set_special_pids(struct pid **pids, struct pid *pid) { - struct task_struct *curr = current->group_leader; + struct task_struct *curr = task_group_leader(current); if (task_session(curr) != pid) change_pid(pids, curr, PIDTYPE_SID, pid); @@ -1270,7 +1270,7 @@ static void set_special_pids(struct pid **pids, struct pid *pid) int ksys_setsid(void) { - struct task_struct *group_leader = current->group_leader; + struct task_struct *group_leader = task_group_leader(current); struct pid *sid = task_pid(group_leader); struct pid *pids[PIDTYPE_MAX] = { 0 }; pid_t session = pid_vnr(sid); @@ -1520,7 +1520,7 @@ static int do_prlimit(struct task_struct *tsk, unsigned int resource, /* Holding a refcount on tsk protects tsk->signal from disappearing. */ rlim = tsk->signal->rlim + resource; - task_lock(tsk->group_leader); + task_lock(task_group_leader(tsk)); if (new_rlim) { /* * Keep the capable check against init_user_ns until cgroups can @@ -1538,7 +1538,7 @@ static int do_prlimit(struct task_struct *tsk, unsigned int resource, if (new_rlim) *rlim = *new_rlim; } - task_unlock(tsk->group_leader); + task_unlock(task_group_leader(tsk)); /* * RLIMIT_CPU handling. Arm the posix CPU timer if the limit is not @@ -1557,7 +1557,7 @@ static int do_prlimit(struct task_struct *tsk, unsigned int resource, * cannot update_rlimit_cpu on it, then the entire process is * exiting and we do not need to update at all. */ - update_rlimit_cpu(tsk->group_leader, new_rlim->rlim_cur); + update_rlimit_cpu(task_group_leader(tsk), new_rlim->rlim_cur); } return retval; @@ -1636,9 +1636,9 @@ SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource, return -EINVAL; resource = array_index_nospec(resource, RLIM_NLIMITS); - task_lock(current->group_leader); + task_lock(task_group_leader(current)); x = current->signal->rlim[resource]; - task_unlock(current->group_leader); + task_unlock(task_group_leader(current)); if (x.rlim_cur > 0x7FFFFFFF) x.rlim_cur = 0x7FFFFFFF; if (x.rlim_max > 0x7FFFFFFF) @@ -1656,9 +1656,9 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource, return -EINVAL; resource = array_index_nospec(resource, RLIM_NLIMITS); - task_lock(current->group_leader); + task_lock(task_group_leader(current)); r = current->signal->rlim[resource]; - task_unlock(current->group_leader); + task_unlock(task_group_leader(current)); if (r.rlim_cur > 0x7FFFFFFF) r.rlim_cur = 0x7FFFFFFF; if (r.rlim_max > 0x7FFFFFFF) diff --git a/kernel/tsacct.c b/kernel/tsacct.c index d8e941674fb13..7fb6d9fff3b60 100644 --- a/kernel/tsacct.c +++ b/kernel/tsacct.c @@ -32,7 +32,7 @@ void bacct_add_tsk(struct user_namespace *user_ns, now_ns = ktime_get_ns(); /* store whole group time first, or tsk's own if it's been released */ rcu_read_lock(); - delta = now_ns - (pid_alive(tsk) ? tsk->group_leader : tsk)->start_time; + delta = now_ns - (pid_alive(tsk) ? task_group_leader(tsk) : tsk)->start_time; rcu_read_unlock(); /* Convert to micro seconds */ do_div(delta, NSEC_PER_USEC); diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c index 8c98b20bfc414..efe9b6b35c55c 100644 --- a/lib/is_single_threaded.c +++ b/lib/is_single_threaded.c @@ -30,7 +30,7 @@ bool current_is_single_threaded(void) for_each_process(p) { if (unlikely(p->flags & PF_KTHREAD)) continue; - if (unlikely(p == task->group_leader)) + if (unlikely(same_thread_group(p, task))) continue; for_each_thread(p, t) { diff --git a/rust/helpers/task.c b/rust/helpers/task.c index b46b1433a67e8..e62daa6067038 100644 --- a/rust/helpers/task.c +++ b/rust/helpers/task.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include __rust_helper void rust_helper_might_resched(void) @@ -23,6 +24,12 @@ __rust_helper void rust_helper_put_task_struct(struct task_struct *t) put_task_struct(t); } +__rust_helper struct task_struct * +rust_helper_task_group_leader(const struct task_struct *p) +{ + return task_group_leader(p); +} + __rust_helper kuid_t rust_helper_task_uid(struct task_struct *task) { return task_uid(task); diff --git a/rust/kernel/task.rs b/rust/kernel/task.rs index 3336df493decc..b83971543d5c9 100644 --- a/rust/kernel/task.rs +++ b/rust/kernel/task.rs @@ -334,14 +334,15 @@ pub fn active_pid_ns(&self) -> Option<&PidNamespace> { } /// Returns the group leader of the current task. + #[inline] pub fn group_leader(&self) -> &Task { // SAFETY: The group leader of a task never changes while the task is running, and `self` // is the current task, which is guaranteed running. - let ptr = unsafe { (*self.as_ptr()).group_leader }; + let ptr = unsafe { bindings::task_group_leader(self.as_ptr()) }; - // SAFETY: `current->group_leader` stays valid for at least the duration in which `current` - // is running, and the signature of this function ensures that the returned `&Task` can - // only be used while `current` is still valid, thus still running. + // SAFETY: The group leader stays valid for at least the duration in which `current` is + // running, and the signature of this function ensures that the returned `&Task` can only be + // used while `current` is still valid, thus still running. unsafe { &*ptr.cast() } } } diff --git a/security/apparmor/resource.c b/security/apparmor/resource.c index 64212b39ba4bb..76892a1e66bd5 100644 --- a/security/apparmor/resource.c +++ b/security/apparmor/resource.c @@ -199,7 +199,7 @@ void __aa_transition_rlimits(struct aa_label *old_l, struct aa_label *new_l) if (j == RLIMIT_CPU && rlim->rlim_cur != RLIM_INFINITY && IS_ENABLED(CONFIG_POSIX_TIMERS)) - (void) update_rlimit_cpu(current->group_leader, + (void) update_rlimit_cpu(task_group_leader(current), rlim->rlim_cur); } } diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c index cef3776cf3b2d..c71588e237213 100644 --- a/security/yama/yama_lsm.c +++ b/security/yama/yama_lsm.c @@ -232,7 +232,7 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3, * leader checking is handled later when walking the ancestry * at the time of PTRACE_ATTACH check. */ - myself = current->group_leader; + myself = task_group_leader(current); if (arg2 == 0) { yama_ptracer_del(NULL, myself); @@ -274,12 +274,10 @@ static int task_is_descendant(struct task_struct *parent, return 0; rcu_read_lock(); - if (!thread_group_leader(parent)) - parent = rcu_dereference(parent->group_leader); while (walker->pid > 0) { if (!thread_group_leader(walker)) - walker = rcu_dereference(walker->group_leader); - if (walker == parent) { + walker = task_group_leader(walker); + if (same_thread_group(walker, parent)) { rc = 1; break; } @@ -319,7 +317,7 @@ static int ptracer_exception_found(struct task_struct *tracer, /* Look for a PR_SET_PTRACER relationship. */ if (!thread_group_leader(tracee)) - tracee = rcu_dereference(tracee->group_leader); + tracee = task_group_leader(tracee); list_for_each_entry_rcu(relation, &ptracer_relations, node) { if (relation->invalid) continue;