From: "Alexei Starovoitov" <alexei.starovoitov@gmail.com>
To: "Matthew Wood" <thepacketgeek@gmail.com>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eduard Zingerman" <eddyz87@gmail.com>,
"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>,
"Ihor Solodrai" <ihor.solodrai@linux.dev>,
"Puranjay Mohan" <puranjay@kernel.org>,
"Xu Kuohai" <xukuohai@huaweicloud.com>,
"Catalin Marinas" <catalin.marinas@arm.com>,
"Will Deacon" <will@kernel.org>
Cc: "Breno Leitao" <leitao@debian.org>, <bpf@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] bpf, arm64: Fix text_mutex critical section in bpf_arch_text_poke()
Date: Fri, 02 Oct 2026 11:21:52 +0000 [thread overview]
Message-ID: <DLUBA9JR5QHY.31UKYQQ9EYMDL@gmail.com> (raw)
In-Reply-To: <20261002044050.1277356-1-thepacketgeek@gmail.com>
On Thu, Oct 01, 2026 at 09:40 PM Matthew Wood <thepacketgeek@gmail.com> wrote:
> + /* pages of the bpf prog pack are shared between progs, so the
> + * set_memory_rw()/set_memory_ro() window below must be serialized
> + * against other pokers too.
> + */
> + mutex_lock(&text_mutex);
> +
> if (plt_target) {
> /* non-zero plt_target indicates we're patching a bpf prog,
> * which is read only.
> */
> - if (set_memory_rw(PAGE_MASK & ((uintptr_t)&plt->target), 1))
> - return -EFAULT;
> + if (set_memory_rw(PAGE_MASK & ((uintptr_t)&plt->target), 1)) {
> + ret = -EFAULT;
> + goto out;
> + }
> WRITE_ONCE(plt->target, plt_target);
> set_memory_ro(PAGE_MASK & ((uintptr_t)&plt->target), 1);
The lock hides the crash, but set_memory_rw() is the actual problem.
The page is shared, so it makes 64K of other progs writable and
executable at the same time.
Use aarch64_insn_write_literal_u64(&plt->target, plt_target) instead.
That's how ftrace_rec_set_ops() and arch_static_call_transform()
update 64-bit literals in the text.
It's atomic and writes via fixmap under patch_lock, just like
aarch64_insn_patch_text_nosync() below.
No need to change page permissions and no need to move text_mutex.
pw-bot: cr
next prev parent reply other threads:[~2026-10-02 11:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-02 4:40 Matthew Wood
2026-10-02 5:16 ` bot+bpf-ci
2026-10-02 10:40 ` Puranjay Mohan
2026-10-02 11:21 ` Alexei Starovoitov [this message]
2026-10-02 11:37 ` Matthew Wood
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=DLUBA9JR5QHY.31UKYQQ9EYMDL@gmail.com \
--to=alexei.starovoitov@gmail.com \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=emil@etsalapatis.com \
--cc=ihor.solodrai@linux.dev \
--cc=jolsa@kernel.org \
--cc=leitao@debian.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=puranjay@kernel.org \
--cc=song@kernel.org \
--cc=thepacketgeek@gmail.com \
--cc=will@kernel.org \
--cc=xukuohai@huaweicloud.com \
--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®