Skip to content

Commit b0fd185

Browse files
sinkapMartin KaFai Lau
authored andcommitted
bpf: Fix UAF in task local storage
When task local storage was generalized for tracing programs, the bpf_task_local_storage callback was moved from a BPF LSM hook callback for security_task_free LSM hook to it's own callback. But a failure case in bad_fork_cleanup_security was missed which, when triggered, led to a dangling task owner pointer and a subsequent use-after-free. Move the bpf_task_storage_free to the very end of free_task to handle all failure cases. This issue was noticed when a BPF LSM program was attached to the task_alloc hook on a kernel with KASAN enabled. The program used bpf_task_storage_get to copy the task local storage from the current task to the new task being created. Fixes: a10787e ("bpf: Enable task local storage for tracing programs") Reported-by: Kuba Piecuch <[email protected]> Signed-off-by: KP Singh <[email protected]> Acked-by: Song Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin KaFai Lau <[email protected]>
1 parent b320a45 commit b0fd185

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

kernel/fork.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ void free_task(struct task_struct *tsk)
627627
arch_release_task_struct(tsk);
628628
if (tsk->flags & PF_KTHREAD)
629629
free_kthread_struct(tsk);
630+
bpf_task_storage_free(tsk);
630631
free_task_struct(tsk);
631632
}
632633
EXPORT_SYMBOL(free_task);
@@ -979,7 +980,6 @@ void __put_task_struct(struct task_struct *tsk)
979980
cgroup_free(tsk);
980981
task_numa_free(tsk, true);
981982
security_task_free(tsk);
982-
bpf_task_storage_free(tsk);
983983
exit_creds(tsk);
984984
delayacct_tsk_free(tsk);
985985
put_signal_struct(tsk->signal);

0 commit comments

Comments
 (0)