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=1796476284; b=yKWt1GDJXXPbUfMDrk6UMsJUl9QaUSBbXLSeh0rF2aXQM70rHWjSASt3HWUdIhivjEZc rUz1tkmYgxcsKk7o8VKD9Ryr9mOHqH2RGmSfQyIgu56uAtq6AT9BNQkWjdl6+IhTor2wa pkI0F70IPFUxx9FA4eaJkG2BQx7V3RlGn77Co6+O7Gpu0SCVS8PxIOgOnPxzFmAc4tWTV 5dQAv93nXHFyIAX4KXGQE0gEyPFmaLRorJf5Xmy/zANfVxTZQBp3p2+GXUOWZNdrspaAM gkmOUVIAh0cm8llIugK+q7Wz5kXgT6PiPjEpOE9fFSuIoHt+WQnAmGmsPvYknI085Pw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796476284; h=Received:DKIM-Signature:Received:Received:X-ME-Sender: X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID:Received:X-Mailer: MIME-Version:X-ThreadId:Date:From:To:Cc:Message-Id:Subject: Content-Type:Content-Transfer-Encoding; bh=nrOKAi54/rB0kWo/CSQ6sDGljXA3pjxbd3RlSonp8gI=; b=suMYdzj2cHg2HuW4fgG5FyoCItCdNV5vrOVXcFhiUvy1sDk+wJcuUMTaYS8dfrhG5x8j Yu9RwkNYR85z6/WztxOMQRm7lK6UO0FrtmY3MVX7+TCj45eF8TNh6yVkjyhC3VXLVoD66 9VcViXMyZA4JCtn6SrkbyL8ePsTY0defK5me3bonx4Sd7fzyybjzbW9gOBLFWizDYFff7 tF1fKo9tXbLAbg3peUwpTeHIHc2WeJnfoNdpyG2pmvq0mWk1jWAXhA5yeAeHyBgHVAJ7V HV0KzODls5+/+aS0vgVFe3qJ030rLJAnFVtJKafRP+u5iH+kEqjcyEZKkpuLr2OjjWQ== 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="X/EDrun+"; 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 28FA0606A330 for ; Sat, 5 Dec 2026 13:11:24 +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=X/EDrun+ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80E641F0092B; Sat, 5 Dec 2026 13:11:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796476284; bh=nrOKAi54/rB0kWo/CSQ6sDGljXA3pjxbd3RlSonp8gI=; h=Date:From:To:Cc:Subject; b=X/EDrun+CziwW9w09NezeSdLSyHlypMpLEqwmqEyXn+KilrjaeISV67658bmsKQJ1 6CrRU/58ybFuyScjk1Y1DR15KUalqLNdRUf7BmK0UaRCnGUbv2++yFjXS+zOSWWlAH 9wtAIlQgG6GK7g2H3VL7+1ykxT4QCPknu1zuO0xeRSSFVOaQ9+H3/t9JMqBBw7uVd9 6wMiN3w6H786CtwNTvEh+bFmscaDgw2unkZptLgK0Xw/dpSGFBwiOgpA8GCCX4Wrl/ ll9dHeY+knO4U3yWfrzGIg2TQzwy2BYtH10O4ftlWHUwV3bttCPClsP/VDx59hdtBp oAGmbU6c+uV2Q== Received: from stl-compute-04.internal (stl-compute-04.internal [10.204.2.64]) by mailfauth.stl.internal (Postfix) with ESMTP id 0F7DF780043; Sat, 5 Dec 2026 08:11:23 -0500 (EST) Received: from stl-imap-13 ([10.204.2.104]) by stl-compute-04.internal (MEProxy); Sat, 05 Dec 2026 08:11:23 -0500 X-ME-Sender: X-ME-Proxy-Cause: dmFkZTEmtzdTuURZ9uancifEIsG68ynPikjm1tBrk390ubDJpqat8Yi6k2j42oiIjoyr/5 BqhpyZywoGQcpWZcnahhvx1SWIISxuuDywQIh0Ql9/N/LVMclQMQYmkuqaUC0L5ZCUepcS 54f2qH4Rh3vmvhPjMQR6626N766Cg0xLC9p9y8C+N9d5tlFFb9JGZnsvnImOyN0uA410e0 J6MOr9sQF6NRU1HP6GM5bipuknPl7DdbhKBZEe7uiNUynI99G3l3+RPQdz1a+SFVxqcqTe yafz9eOpTdmn6sfd5w6geeBpdIf9qJlGz2D+ERxMPlThOy39OyWOHRO+MLoeKAbqDKiFNk FDI0v0sAtLF/nL5IzbsQcGTWXorupzQjvolIya8SkirWj7jFmM+bw8fgja7oj6xvj8yYDv Klz/OMFK0PJbIAqnr1ii7gZI5DvDQ9qhGipPd1m2oPHc3jQKQ5Bh9b8hyhckhRpRdJ6K6U +BcH/va1uSrTQgGRJaQgYv4J4+7cAny7o2WTFKmTXp81c+s0Gq9ClACJFjU36ZNDenCFkR kswHHab7hxmVVAO1Ete53krfEnrr4T2RU5iimMDx1rwsljZrNVBbSJDPmZr2BQzONEKNOk QfHCRqQb/PCfFSJY617S15P68K2Fw3LI+FmzfF++6RKccPhn02/kRhYCuBkg X-ME-Proxy: Feedback-ID: iccae4b50:Fastmail Received: by mailuser.stl.internal (Postfix, from userid 501) id 9855AF60088; Sat, 5 Dec 2026 08:11:22 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-ThreadId: AuvvtD4j5FdZ Date: Sat, 05 Dec 2026 08:11: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: "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, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, mason@kernel.org Message-Id: <20261204233428.14861-1-mason@kernel.org> Subject: [PATCH v2 0/8] fork, exit: fix use-after-frees on task pointers Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi everyone, This is v2 of the AI generated fixes for stale pointers in task_struct. The kernel only updates real_parent, parent and group_leader while a task is in the process tree. BPF programs can find it before that, during the fork, and after that, once it's been released. These pointers can lead to freed memory then. In v1, a released thread held a reference on its group leader, which I didn't love. v2 takes no references. Instead, a task outside of the process tree only points at tasks that can't go away: the forking task during the fork, and init_task or itself after release_task(). - Patch 1: taskstats has the same bug without BPF, as Alexei spotted. It checks pid_alive() now. - Patch 2: a prep patch for patch 3. - Patch 3: release_task() resets the pointers. - Patch 4: the same for tasks that are still being forked, and for idle tasks. - Patch 5: the BPF thread iterator doesn't start outside of the process tree. - Patch 6: amdkfd can use a freed group leader too, without any BPF. - Patches 7 and 8: an optional RFC for Oleg's idea to move group_leader into signal_struct. BPF programs then see the right leader of a released thread, but have to read it from the new place. Patch 7/8 aren't required for my series but I had the bots look at Oleg's suggestion. The downside of patches 1-5 is that BPF programs see PID 0 as the parent of a released task. Without patch 8, they also see a released thread as its own leader. AI generated tests reproduce the BPF bugs with KASAN on v7.4-rc5, and none of them shows up with patches 1-5. Patch 6 isn't tested on hardware. Changes since v1: - Patches 1, 2 and 6-8: new. - Patch 3: no reference on the leader any more, because it leaked (sashiko, bpf-ci). - Patch 4: pid_alive() now fails during a fork (Oleg), so patch 5 also catches tasks that are still being forked (bpf-ci). The pointers are reset after a failed fork too (sashiko). New changelog (Oleg). - Patches 3 and 4: no Fixes: lines, because BPF programs could hit these bugs before the commits that v1 named. - The title doesn't blame BPF any more (Alexei). v1: https://lore.kernel.org/all/20261203200612.26376-1-mason@kernel.org/ This is on top of v7.4-rc5. Chris Mason (8): tsacct: don't dereference a stale group_leader exec, cgroup, prlimit: prepare for group_leader resets exit: reset a released task's parent and leader fork: don't leave stale parent pointers in a new task bpf: Don't start a thread walk at a released task drm/amdkfd: fix crashes if a debugged process exits signal: add task_group_leader() signal: move group_leader into signal_struct Documentation/bpf/kfuncs.rst | 2 +- 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 | 6 +- drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 3 +- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 33 ++++--- 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 | 17 ++-- include/linux/cgroup.h | 2 +- include/linux/pid.h | 1 + include/linux/sched.h | 1 - include/linux/sched/signal.h | 28 +++++- include/linux/sched/task.h | 43 +++------ init/init_task.c | 3 +- kernel/acct.c | 2 +- kernel/bpf/task_iter.c | 16 +++- kernel/bpf/verifier.c | 5 + kernel/cgroup/cgroup.c | 26 +++--- kernel/cgroup/cpuset.c | 4 +- kernel/debug/kdb/kdb_main.c | 2 +- kernel/exit.c | 5 +- kernel/fork.c | 93 +++++++++++++------ kernel/signal.c | 6 +- kernel/sys.c | 22 ++--- kernel/tsacct.c | 6 +- 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 +- tools/bpf/bpftool/skeleton/pid_iter.bpf.c | 25 ++++- .../selftests/bpf/progs/rcu_read_lock.c | 4 +- .../selftests/bpf/progs/task_kfunc_success.c | 4 +- .../bpf/progs/test_core_reloc_kernel.c | 47 +++++----- .../test.d/dynevent/btf_typecast_accepted.tc | 4 +- 47 files changed, 301 insertions(+), 200 deletions(-) base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244