All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v1 1/3] Revert "libbpf: Fix use-after-free in btf__add_type"
@ 2026-11-06 19:57 Ihor Solodrai
  2026-11-06 19:57 ` [PATCH bpf-next v1 2/3] libbpf: Drop btf_dump details from the BTF docs Ihor Solodrai
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ihor Solodrai @ 2026-11-06 19:57 UTC (permalink / raw)
  To: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Quentin Monnet
  Cc: bpf, Alan Maguire, Yonghong Song

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-07  0:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-06 19:57 [PATCH bpf-next v1 1/3] Revert "libbpf: Fix use-after-free in btf__add_type" Ihor Solodrai
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.