From: Qiliang Yuan <odys.yuan@gmail.com>
To: Amery Hung <ameryhung@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Ihor Solodrai <ihor.solodrai@linux.dev>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>,
Yonghong Song <yonghong.song@linux.dev>,
Jiri Olsa <jolsa@kernel.org>,
Emil Tsalapatis <emil@etsalapatis.com>,
Shuah Khan <shuah@kernel.org>,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next v3 0/3] bpf: Fix a struct_ops use-after-free behind a flaky assoc_in_timer test
Date: Fri, 16 Oct 2026 11:02:33 +0800 [thread overview]
Message-ID: <20261016030233.3429038-1-odys.yuan@gmail.com> (raw)
In-Reply-To: <CAMB2axPRjfe=ROzA0rMR1_FPyv1mA-jaH3bHQHZje=Q1PjoEVA@mail.gmail.com>
On Thu, Oct 15, 2026 at 10:41 AM Amery Hung <ameryhung@gmail.com> wrote:
> I think this fix is heading in the wrong direction. The struct_ops map
> association was designed as an RCU-protected pointer: asynchronous
> users may outlive the map and observe a NULL association. The existing
> selftest explicitly verifies this behavior.
>
> The problem is that the disassociation now happens after the grace
> period initiated by bpf_map_put(). Could we instead make
> disassociation safe in map_free_pre_rcu(), before that existing grace
> period, rather than adding another deferred-free path?
Agreed, that is simpler. v4 [1] does it in two steps:
1. Replace st_ops_assoc_mutex with a spinlock taken with irqs disabled,
and put the map of a non-struct_ops prog after dropping it.
map_free_pre_rcu() runs wherever the last reference is dropped,
which can be softirq, e.g. bpf_struct_ops_put() from
tcp_cleanup_congestion_control().
2. Call bpf_struct_ops_map_dissoc_progs() from
bpf_struct_ops_map_free_pre_rcu() instead of
bpf_struct_ops_map_free().
One thing to confirm: bpf_map_put() waits only for a regular RCU grace
period unless free_after_mult_rcu_gp is set, and no struct_ops sets it
today. bpf_wq_work() runs the callback of a struct_ops prog under
rcu_read_lock_trace(), and that callback can read the association too,
so v4 sets free_after_mult_rcu_gp for every struct_ops map. Would you
rather leave that to each struct_ops?
On a KASAN kernel with v4, st_ops_assoc_in_timer_free passes 100 of 100
runs, where it hits the int3 Oops on run 1 without the fix, and lockdep
reports nothing over the struct_ops and tcp_ca selftests.
[1] https://lore.kernel.org/r/20261016-selftests-bpf-struct-ops-assoc-timer-v4-0-9ad31c21220c@gmail.com
prev parent reply other threads:[~2026-10-16 3:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 1:35 Qiliang Yuan
2026-10-15 1:35 ` [PATCH bpf-next v3 1/3] bpf: Defer freeing a struct_ops map until its progs are done Qiliang Yuan
2026-10-15 1:35 ` [PATCH bpf-next v3 2/3] selftests/bpf: Test freeing a struct_ops map under a running prog Qiliang Yuan
2026-10-15 1:35 ` [PATCH bpf-next v3 3/3] selftests/bpf: Wait for the struct_ops map to be freed in assoc_in_timer Qiliang Yuan
2026-10-15 17:41 ` [PATCH bpf-next v3 0/3] bpf: Fix a struct_ops use-after-free behind a flaky assoc_in_timer test Amery Hung
2026-10-16 3:02 ` Qiliang Yuan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261016030233.3429038-1-odys.yuan@gmail.com \
--to=odys.yuan@gmail.com \
--cc=ameryhung@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=shuah@kernel.org \
--cc=song@kernel.org \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®