BPF List
 help / color / mirror / Atom feed
From: Ihor Solodrai <ihor.solodrai@linux.dev>
To: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Kumar Kartikeya Dwivedi <memxor@gmail.com>,
	Quentin Monnet <qmo@kernel.org>
Cc: bpf@vger.kernel.org, Alan Maguire <alan.maguire@oracle.com>,
	Yonghong Song <yonghong.song@linux.dev>
Subject: [PATCH bpf-next v1 1/3] Revert "libbpf: Fix use-after-free in btf__add_type"
Date: Fri,  6 Nov 2026 12:57:28 -0700	[thread overview]
Message-ID: <20261106195730.2623973-1-ihor.solodrai@linux.dev> (raw)

This reverts commit 9abe2c42ecab6c86b54838d2d645ca2e10204606.

The commit made btf_rewrite_str() make every base of the destination
modifiable before taking a pointer to the source string, because
looking the string up in a base made it modifiable and freed its raw
data. Since commit efeb5ab5753d ("libbpf: Look up BTF strings without
making BTF modifiable"), the lookup leaves the raw data in place, so
the pointer stays valid.

Making a base modifiable fails for BTF with unknown header-extension
bytes. With the loop in place, btf__add_type() and btf__add_btf() into
a split over such a base fail with -EOPNOTSUPP, and so does bpftool
when it merges module BTFs over it:

  $ bpftool -B base.btf btf dump file mod1.btf file mod2.btf format raw
  Error: failed to merge BTF from mod1.btf: Operation not supported

Suggested-by: BPF CI bot <bot+bpf-ci@kernel.org>
Link: https://lore.kernel.org/bpf/e0df4fa9e17514c79de41ee9fd2eb610d43a95741fb994db160b35fd488f054a@mail.kernel.org/
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
 tools/lib/bpf/btf.c | 14 --------------
 1 file changed, 14 deletions(-)

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 0984a8ccb526..448ee6acf519 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -2232,7 +2232,6 @@ struct btf_pipe {
 
 static int btf_rewrite_str(struct btf_pipe *p, __u32 *str_off)
 {
-	struct btf *base;
 	long mapped_off;
 	int off, err;
 
@@ -2245,19 +2244,6 @@ static int btf_rewrite_str(struct btf_pipe *p, __u32 *str_off)
 		return 0;
 	}
 
-	/*
-	 * btf__add_str() first looks the string up in the base BTFs of dst,
-	 * which makes each of them modifiable and frees its raw data. If src
-	 * shares a base with dst and the string lives in that base, the
-	 * pointer taken below would be left dangling. So make the bases
-	 * modifiable before the pointer is taken.
-	 */
-	for (base = p->dst->base_btf; base; base = base->base_btf) {
-		err = btf_ensure_modifiable(base);
-		if (err)
-			return err;
-	}
-
 	off = btf__add_str(p->dst, btf__str_by_offset(p->src, *str_off));
 	if (off < 0)
 		return off;

base-commit: 3e18218484126afb9da722080659c038cb2256ab
-- 
2.56.0


             reply	other threads:[~2026-11-06 19:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 19:57 Ihor Solodrai [this message]
2026-11-06 19:57 ` [PATCH bpf-next v1 2/3] libbpf: Drop btf_dump details from the BTF docs Ihor Solodrai
2026-11-06 19:57 ` [PATCH bpf-next v1 3/3] bpftool: Replace the type tag override table with two checks Ihor Solodrai
2026-11-07  0:50 ` [PATCH bpf-next v1 1/3] Revert "libbpf: Fix use-after-free in btf__add_type" patchwork-bot+netdevbpf

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=20261106195730.2623973-1-ihor.solodrai@linux.dev \
    --to=ihor.solodrai@linux.dev \
    --cc=alan.maguire@oracle.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=memxor@gmail.com \
    --cc=qmo@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