From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796478035; b=4jRZQ5gmZyVkV0GdQ3ysOmIeS/53+8MB7bJuTBsZNnpIazWiodhNPvjYKY7Jnnmp53hS 9ET9xdGIAVkgIZLuqzzbDzcS7aiy5i7mrE8y7X6mZukQmJd/C8AgFkxvWaullhPBQwQGS Q4wSYUFDBSER1Dg5oUeH5Qvrx325wDbLP/JlRHlaB7dUeOnpCcaueL2CnfUMk6TX28CxH JFR002OQhFdcdG/0O9jKkEr1dPIZlPBYDk7a1tUdbC/OqSPeaRvQU6z6Zhzt+xLbOHpco NrHiGkyE7rA5GjsAb9JcgI7uG4D9NB00x1kAFMTYZ2hA78rX724Fj6QHgIrmjGIqfcQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796478035; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=F2EQbb6F/s/juBKaKb7p+1hpTgxsEc7MIK4yu253yQg=; b=IvClsqcGoxKgkswX7P8F8AuSIBjmjIDVD/IFr2hb+DC992KKUW6BPHh8DWIgAZUCfAkS SCA5q0qBFNkDGY5e9WIMT9w8v/cLxRQB7ZwZ2qE+8cCoAtWNXBpQrBepyxhypQIo+2aJE ZOSb3F8KNAAhYxzTmDP3k1nMUFyG9B3bN5WC/Q6Ujt6/Rnmmr3i43jlhCN4ok7p8ACKls ZINBs4TKXDPZqwL0gh+Qj4yuC5S++Q29IuUwBsAUADY5C6Y7imXA34xRnm6TiJ2BK+wLs UFyUp+85gtmO7ov5LdwSkbxQ7UKDT4ik/YOU93BVNaIhCf3ucYP1/7yiuK+gxG8cfaA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dWzOVGkS; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35CE3606A322; Sat, 5 Dec 2026 13:40:35 +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=dWzOVGkS Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19D9D1F0092B; Sat, 5 Dec 2026 13:40:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796478035; bh=F2EQbb6F/s/juBKaKb7p+1hpTgxsEc7MIK4yu253yQg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=dWzOVGkSi+cgP/+MmHMOjZKIilEXc1pIgIg1/uBA/TCwbuxIr4QhU/UBHtFgD6Lfp nhJLGiwy9IeoLo0LAw6a3vWclknsFp9RIr2JWJRtDSBFTAFeIwuCvsRQJ8Pi7JIxrW JKZPvawVa1NvLwVIsmDZwmNvj7oDd1stUT2p7/5PgWI4FsqtKaImp+n9/ILmbe1c35 SE8YnwLz1dHIbHH0wBTJVPRGwuJ0YRMWEfvQ5gpzcEW0h7m+h+IAzhTEjGIeMiXNGz VrGHkoFvdNQgnpSa/UjC4V8UQ2Fl5FeohY1h0CQcQ0emUuDUoVRblxfcaYJKYxiJRo GYMjKkKRDqrjQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2 6/8] drm/amdkfd: fix crashes if a debugged process exits Reply-To: sashiko-reviews@lists.linux.dev To: "Chris Mason" , brauner@kernel.org, oleg@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, bpf@vger.kernel.org Cc: "Felix Kuehling" , amd-gfx@lists.freedesktop.org, 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, linux-mm@kvack.org In-Reply-To: <20261204233428.14861-7-mason@kernel.org> References: <20261204233428.14861-1-mason@kernel.org> <20261204233428.14861-7-mason@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 13:40:33 +0000 X-Mailing-List: bpf@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/amdkfd: missing READ_ONCE() on thread->group_leader in create_process() -- commit f69fe80acbca9fdd8995442c66a399acab3c12dc Author: Chris Mason drm/amdkfd: fix crashes if a debugged process exits This commit caches the target task's mm via get_task_mm() in kfd_create_process() and takes the group_leader reference under RCU after checking pid_alive() in create_process(). > diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/a= md/amdkfd/kfd_process.c > index 336c66d9c5a73..458637a81f66c 100644 > --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c > +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c [ ... ] > @@ -1692,13 +1693,20 @@ struct kfd_process *create_process(const struct t= ask_struct *thread, bool primar > =20 > kref_init(&process->ref); > mutex_init(&process->mutex); > - process->mm =3D thread->mm; > - process->lead_thread =3D thread->group_leader; > + process->mm =3D mm; > /* > * Take the reference on the lead thread before the process can be > * released through kfd_process_wq_release(), which drops it again. > + * A process that's being debugged can exit meanwhile. > */ > - get_task_struct(process->lead_thread); > + rcu_read_lock(); > + if (pid_alive(thread)) > + process->lead_thread =3D get_task_struct(thread->group_leader); > + rcu_read_unlock(); [Severity: Medium] Can passing thread->group_leader without READ_ONCE() into get_task_struct() cause a refcount mismatch and use-after-free? get_task_struct() is an inline helper that calls refcount_inc(&t->usage) (atomic_fetch_add_relaxed()) and returns t. On architectures where atomic_fetch_add_relaxed() has no compiler memory clobber (such as arm64 LSE), the compiler can reload the unmarked thread->group_leader across refcount_inc(): CPU0 CPU1 kfd_ioctl_set_debug_trap() ... create_process(thread, ...) pid_alive(thread) =3D=3D true t =3D thread->group_leader refcount_inc(&t->usage) release_task(thread) reset_parent_and_leader(thread) WRITE_ONCE(thread->group_leader, thread) process->lead_thread =3D thread->group_leader <-- reloaded without refcount With commit "exit: reset a released task's parent and leader" updating group_leader concurrently, a reload leaks the old leader's reference and stores the new one without a reference. kfd_process_wq_release() then underflows the refcount, leading to a use-after-free (and a KCSAN data race= ). Using READ_ONCE(thread->group_leader) here prevents both the reload and the data race. Although the follow-up RFC commit "signal: add task_group_leader()" later wraps this access in READ_ONCE(), this non-RFC fix should use it directly in case it is merged or backported on its own. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204233428.1486= 1-1-mason@kernel.org?part=3D6