]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
Merge branch 'bpf-fix-torn-writes-in-non-prealloc-htab-with-bpf_f_lock'
authorAlexei Starovoitov <ast@kernel.org>
Mon, 6 Apr 2026 01:37:32 +0000 (18:37 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 6 Apr 2026 01:37:41 +0000 (18:37 -0700)
commit24dbbf8a2343d4063c370a1f25645eabc50d68c9
tree151644c9a12e571bd9257619b9cbd4fb1774506c
parent6a14beefab457f267b8cedc6ac697a9562ec1244
parentf64eb44ce9067d37e6334a940518dcf1254e83fe
Merge branch 'bpf-fix-torn-writes-in-non-prealloc-htab-with-bpf_f_lock'

Mykyta Yatsenko says:

====================
bpf: Fix torn writes in non-prealloc htab with BPF_F_LOCK

A torn write issue was reported in htab_map_update_elem() with
BPF_F_LOCK on hash maps. The BPF_F_LOCK fast path performs
a lockless lookup and copies the value under the element's embedded
spin_lock. A concurrent delete can free the element via
bpf_mem_cache_free(), which allows immediate reuse. When
alloc_htab_elem() recycles the same memory, it writes the value with
plain copy_map_value() without taking the spin_lock, racing with the
stale lock holder and producing torn writes.

Patch 1 fixes alloc_htab_elem() to use copy_map_value_locked() when
BPF_F_LOCK is set.

Patch 2 adds a selftest that reliably detects the torn writes on an
unpatched kernel.

Reported-by: Aaron Esau <aaron1esau@gmail.com>
Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
====================

Link: https://patch.msgid.link/20260401-bpf_map_torn_writes-v1-0-782d071c55e7@meta.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>