Re: [PATCH 0/3] fork, exit: fix BPF use-after-frees on task pointers

From: Chris Mason

Date: Fri Dec 04 2026 - 10:37:05 EST


On Fri, 04 Dec 2026 02:36:25 +0000, Alexei Starovoitov wrote:
> On Thu, Dec 03, 2026 at 12:06 PM Chris Mason <mason@xxxxxxxxxx> wrote:
>> These are AI generated fixes for a few ways that BPF programs can follow
>> task_struct pointers into freed memory.
>
> The bugs look real. fork and exit are the right place to fix them imo.
> The verifier can't tell a released task from a live one.
>
> BUT the title is misleading.
> The kernel has the same bug without bpf. fill_stats_for_pid() holds
> a reference on tsk and nothing else. Then bacct_add_tsk() reads
> tsk->group_leader->start_time.
>
>> Patch 2 makes a released thread hold a reference on its group leader,
>> which I don't love. If there are better ideas, I'm happy to get
>> the bots cranking on them.
>
> I don't see a different option.
>
> Oleg,
> pls review.
>
> Christian,
> if it looks good to folks, could you take patches 1-2 via your tree?
> I'll take patch 3.

Please hold off on patches 1-2, it looks like patch 2 leaks. A BPF program can
keep a thread in its leader's task storage, and then neither of them is freed.
The bots are working on v2, and I'll have them try Oleg's suggestion as well.

You're right about bacct_add_tsk(), claude reproduced that one with KASAN.

-chris