linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf v2] bpf: fix libelf endian handling in resolv_btfids
       [not found] <20210616092521.800788-1-Tony.Ambardar@gmail.com>
@ 2021-06-18  6:14 ` Tony Ambardar
  2021-06-18 15:10   ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Tony Ambardar @ 2021-06-18  6:14 UTC (permalink / raw)
  To: Daniel Borkmann, Alexei Starovoitov, Andrii Nakryiko
  Cc: Tony Ambardar, bpf, netdev, linux-mips, stable, Frank Eigler,
	Mark Wielaard, Jiri Olsa, Yonghong Song, Jiri Olsa

The vmlinux ".BTF_ids" ELF section is declared in btf_ids.h to hold a list
of zero-filled BTF IDs, which is then patched at link-time with correct
values by resolv_btfids. The section is flagged as "allocable" to preclude
compression, but notably the section contents (BTF IDs) are untyped.

When patching the BTF IDs, resolve_btfids writes in host-native endianness
and relies on libelf for any required translation on reading and updating
vmlinux. However, since the type of the .BTF_ids section content defaults
to ELF_T_BYTE (i.e. unsigned char), no translation occurs. This results in
incorrect patched values when cross-compiling to non-native endianness,
and can manifest as kernel Oops and test failures which are difficult to
troubleshoot [1].

Explicitly set the type of patched data to ELF_T_WORD, the architecture-
neutral ELF type corresponding to the u32 BTF IDs. This enables libelf to
transparently perform any needed endian conversions.

Fixes: fbbb68de80a4 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
Cc: stable@vger.kernel.org # v5.10+
Cc: Frank Eigler <fche@redhat.com>
Cc: Mark Wielaard <mark@klomp.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Yonghong Song <yhs@fb.com>
Link: [1] https://lore.kernel.org/bpf/CAPGftE_eY-Zdi3wBcgDfkz_iOr1KF10n=9mJHm1_a_PykcsoeA@mail.gmail.com/
Signed-off-by: Tony Ambardar <Tony.Ambardar@gmail.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
---
v1 -> v2:
 * add context and elaborate on commit message per request
 * include ACK from Jiri Olsa
---
 tools/bpf/resolve_btfids/main.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
index d636643ddd35..f32c059fbfb4 100644
--- a/tools/bpf/resolve_btfids/main.c
+++ b/tools/bpf/resolve_btfids/main.c
@@ -649,6 +649,9 @@ static int symbols_patch(struct object *obj)
 	if (sets_patch(obj))
 		return -1;
 
+	/* Set type to ensure endian translation occurs. */
+	obj->efile.idlist->d_type = ELF_T_WORD;
+
 	elf_flagdata(obj->efile.idlist, ELF_C_SET, ELF_F_DIRTY);
 
 	err = elf_update(obj->efile.elf, ELF_C_WRITE);
-- 
2.25.1


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

* Re: [PATCH bpf v2] bpf: fix libelf endian handling in resolv_btfids
  2021-06-18  6:14 ` [PATCH bpf v2] bpf: fix libelf endian handling in resolv_btfids Tony Ambardar
@ 2021-06-18 15:10   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-06-18 15:10 UTC (permalink / raw)
  To: Tony Ambardar
  Cc: daniel, ast, andrii, Tony.Ambardar, bpf, netdev, linux-mips,
	stable, fche, mark, jolsa, yhs, jolsa

Hello:

This patch was applied to bpf/bpf.git (refs/heads/master):

On Thu, 17 Jun 2021 23:14:04 -0700 you wrote:
> The vmlinux ".BTF_ids" ELF section is declared in btf_ids.h to hold a list
> of zero-filled BTF IDs, which is then patched at link-time with correct
> values by resolv_btfids. The section is flagged as "allocable" to preclude
> compression, but notably the section contents (BTF IDs) are untyped.
> 
> When patching the BTF IDs, resolve_btfids writes in host-native endianness
> and relies on libelf for any required translation on reading and updating
> vmlinux. However, since the type of the .BTF_ids section content defaults
> to ELF_T_BYTE (i.e. unsigned char), no translation occurs. This results in
> incorrect patched values when cross-compiling to non-native endianness,
> and can manifest as kernel Oops and test failures which are difficult to
> troubleshoot [1].
> 
> [...]

Here is the summary with links:
  - [bpf,v2] bpf: fix libelf endian handling in resolv_btfids
    https://git.kernel.org/bpf/bpf/c/61e8aeda9398

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-06-18 15:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20210616092521.800788-1-Tony.Ambardar@gmail.com>
2021-06-18  6:14 ` [PATCH bpf v2] bpf: fix libelf endian handling in resolv_btfids Tony Ambardar
2021-06-18 15:10   ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).