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=1796331322; b=Nd5lYzKzgDiy1ZyPDYzuxL+s5h2KrqHvvtof5MhHtNC/BwM8TzI2RWScJUf4AxQ6caCr M/TRuWUxN5qCuFqvlw9aDdv+Q+A3brGzrxEc/JVp/wv/IAd/3wVBZKofbcYi5PlydWQjF ZazT/bym4424EoyNlYEl+jfwA2UMREl43mVt1yOjLKMZ29uWjYQY7m14BrW21NhS5Vz32 4TPWYSra/1QWCbE3tHhpazwAsTkkBWLxZSquaNZKlDpTy8lw3MAR9oDJuQmtcU/hbrD5C CQtzBrU4gylAvfaV/hKJqPJ/p5aYH9pagSZluG2VxPfq/2ZbwT/THo6+SRGbIYg1RJg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796331322; h=Received:DKIM-Signature:Content-Type:MIME-Version:Message-Id: In-Reply-To:References:Subject:From:To:Cc:Date; bh=AMXfQlGT6b8+g4XrAlaBGklj/XIObIj+wj078JqJgt8=; b=V9i9m0QHVKe8YN7Dzq17ANut05knyy/oMBhPbmS51B5oUxbXJSegTiEwAcIBiYs+TrvN RJDihSNQDLpx7i+NbM+R3Iq2K+UsfTdfxrvO5ZKzRm+79xW+B85EXdfoOu2sgCTN3p95M NfrNJKaztXRjeijNDEh8Dw2Tfwv73uWCAT9JYptj94emCKNa3AxZcjxrLLeUmxFB3lrvH fn6pmlvMuQaEaggEBQ1+VYyLT50T5X6M6zI5OxxBfjhhBxeJHlDaT44Ti1N3Zd56Sy5KT dDv+3k4U9Jm1aUDI7C/H4h5yO5rbarRwry2pj1xnED/jC71KKScdVv2r3DG6yba9+dQ== 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=Dh3XIdqt; 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 B34BE606A683; Thu, 3 Dec 2026 20:55:22 +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=Dh3XIdqt Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7F4D1F00931; Thu, 3 Dec 2026 20:55:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796331322; bh=AMXfQlGT6b8+g4XrAlaBGklj/XIObIj+wj078JqJgt8=; h=In-Reply-To:References:Subject:From:To:Cc:Date; b=Dh3XIdqthBo5cjUkRyo95efZKoGt83HjLy+tuKEFs9D6XAYPM3qANsSYOkK1oVBRV c983Go3OC6R01cJPxdAofvFJ7aI5jlGjORwE1wflmTCB5u+k2t1T3nl5klCHKc4H6A uS6KrBH42uu6yaRnPfkKVWand+/vHINkllUNxCKStVGS07yoNtgdQY07x0C0TvKDPS qGSW2JpgsYPl9nJd0LvY+bAg0x3YHDE5jziDzusfF1HaiMaeyZnbXceXhhZYZMep9g +4QCKbPSN3nkM0tyrtxGgWAk1rW70L1qLGAUembkZH147IlHEKv2KxLe3K7q7JFj8D 21iH94msrsPVA== Content-Type: multipart/mixed; boundary="===============8696996266065567612==" X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Message-Id: <55fd59dbd3965f7d12b18d7fcc2011a5a87046a7310b1c08bd3ca1cbcd9b1895@mail.kernel.org> In-Reply-To: <20261203200612.26376-3-mason@kernel.org> References: <20261203200612.26376-3-mason@kernel.org> Subject: Re: [PATCH 2/3] exit: don't leave stale parent and leader pointers From: bot+bpf-ci@kernel.org To: mason@kernel.org,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,tj@kernel.org,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,mason@kernel.org,ast@kernel.org,andrii@kernel.org,daniel@iogearbox.net,martin.lau@kernel.org,eddyz87@gmail.com,yonghong.song@linux.dev,mason@kernel.org,ihor.solodrai@linux.dev Date: Thu, 3 Dec 2026 20:55:19 +0000 (UTC) --===============8696996266065567612== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit > exit: don't leave stale parent and leader pointers TL;DR: Released threads now pin their group leader, which may create a reference cycle with BPF task-storage kptrs, leaking both task_structs until the map is destroyed. The commit message omits this lifetime change. > diff --git a/kernel/exit.c b/kernel/exit.c > --- a/kernel/exit.c > +++ b/kernel/exit.c [ ... ] > @@ -262,6 +263,17 @@ void release_task(struct task_struct *p) > */ > thread_pid = get_pid(task_pid(p)); > > + /* > + * A released thread pins its leader, which lockless next_thread() > + * needs. Until @p is released its leader can neither change nor go > + * away. notify_count < 0 means mt-exec: @p is the old leader, and > + * must not pin the new one, or repeated execs could build a chain. > + */ > + leader = p->group_leader; > + pin_leader = leader != p && READ_ONCE(p->signal->notify_count) >= 0; > + if (pin_leader) > + get_task_struct(leader); > + Can this pin create a reference cycle between a thread and its leader? Previously the reference to the leader L held on behalf of a released thread T was not counted, so L's task_struct was freed once L itself was reaped. Now T holds a usage reference on L until T's own __put_task_struct(): kernel/fork.c:__put_task_struct() /* release_task() has pinned the leader of a thread */ if (tsk->group_leader != tsk) put_task_struct(tsk->group_leader); Anything whose release of T is tied to L's final free now forms a cycle. BPF task-local storage looks like one such case, since bpf_task_storage_free() is only called from free_task(), and map_check_btf() allows BPF_KPTR_REF fields in BPF_MAP_TYPE_TASK_STORAGE values. A program that stores a referenced kptr to thread T in L's task storage: v = bpf_task_storage_get(&map, L, NULL, BPF_LOCAL_STORAGE_GET_F_CREATE); old = bpf_kptr_xchg(&v->t, bpf_task_from_pid(tid_of_T)); used to be fine, because L's free released the storage and dropped T. With this patch: T exits -> exit_notify() -> release_task(T) -> get_task_struct(L) L exits and is reaped -> put_task_struct_rcu_user(L) -> delayed_put_task_struct(L) -> put_task_struct(L): usage stays >= 1 (T's pin), L is not freed free_task(L) never runs, so L's storage and its kptr to T are never released T's usage stays >= 1, so __put_task_struct(T) never drops the pin on L Both task_structs then stay allocated until the map itself is destroyed, along with what __put_task_struct() would have released: creds, signal_struct, css_set and LSM blobs. A cleanup hook on lsm/task_free for L also never runs. A long-running BPF LSM or sched_ext program could leak this way once per process. The commit message also does not mention this new lifetime dependency: holding any thread's task_struct now keeps its leader's task_struct alive. Is that intended? --- AI reviewed your patch. Please fix the bug or email reply why it's not a bug. See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md CI run summary: https://github.com/kernel-patches/bpf/actions/runs/47195022171 --===============8696996266065567612==--