BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: restore memory layout of bpf_object_open_opts
@ 2022-09-23 23:05 Andrii Nakryiko
  2022-09-23 23:30 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Andrii Nakryiko @ 2022-09-23 23:05 UTC (permalink / raw)
  To: bpf, ast, daniel; +Cc: andrii, kernel-team, Grant Seltzer Richman

When attach_prog_fd field was removed in libbpf 1.0 and replaced with
`long: 0` placeholder, it actually shifted all the subsequent fields by
8 byte. This is due to `long: 0` promising to adjust next field's offset
to long-aligned offset. But in this case we were already long-aligned
as pin_root_path is a pointer. So `long: 0` had no effect, and thus
didn't feel the gap created by removed attach_prog_fd.

Non-zero bitfield should have been used instead. I validated using
pahole. Originally kconfig field was at offset 40. With `long: 0` it's
at offset 32, which is wrong. With this change it's back at offset 40.

While technically libbpf 1.0 is allowed to break backwards
compatibility and applications should have been recompiled against
libbpf 1.0 headers, but given how trivial it is to preserve memory
layout, let's fix this.

Reported-by: Grant Seltzer Richman <grantseltzer@gmail.com>
Fixes: 146bf811f5ac ("libbpf: remove most other deprecated high-level APIs")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 tools/lib/bpf/libbpf.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index e2d8c17f2e85..eee883f007f9 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -118,7 +118,9 @@ struct bpf_object_open_opts {
 	 * auto-pinned to that path on load; defaults to "/sys/fs/bpf".
 	 */
 	const char *pin_root_path;
-	long :0;
+
+	__u32 :32; /* stub out now removed attach_prog_fd */
+
 	/* Additional kernel config content that augments and overrides
 	 * system Kconfig for CONFIG_xxx externs.
 	 */
-- 
2.30.2


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

* Re: [PATCH bpf-next] libbpf: restore memory layout of bpf_object_open_opts
  2022-09-23 23:05 [PATCH bpf-next] libbpf: restore memory layout of bpf_object_open_opts Andrii Nakryiko
@ 2022-09-23 23:30 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-09-23 23:30 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: bpf, ast, daniel, kernel-team, grantseltzer

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Martin KaFai Lau <martin.lau@kernel.org>:

On Fri, 23 Sep 2022 16:05:59 -0700 you wrote:
> When attach_prog_fd field was removed in libbpf 1.0 and replaced with
> `long: 0` placeholder, it actually shifted all the subsequent fields by
> 8 byte. This is due to `long: 0` promising to adjust next field's offset
> to long-aligned offset. But in this case we were already long-aligned
> as pin_root_path is a pointer. So `long: 0` had no effect, and thus
> didn't feel the gap created by removed attach_prog_fd.
> 
> [...]

Here is the summary with links:
  - [bpf-next] libbpf: restore memory layout of bpf_object_open_opts
    https://git.kernel.org/bpf/bpf-next/c/dbdea9b36fb6

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:[~2022-09-23 23:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-23 23:05 [PATCH bpf-next] libbpf: restore memory layout of bpf_object_open_opts Andrii Nakryiko
2022-09-23 23:30 ` 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