* [PATCH bpf-next] libbpf: don't adjust USDT semaphore address if .stapsdt.base addr is missing
@ 2024-11-21 22:45 Andrii Nakryiko
2024-11-22 16:20 ` Jiri Olsa
2024-11-25 22:20 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Andrii Nakryiko @ 2024-11-21 22:45 UTC (permalink / raw)
To: bpf, ast, daniel, martin.lau; +Cc: andrii, kernel-team
USDT ELF note optionally can record an offset of .stapsdt.base, which is
used to make adjustments to USDT target attach address. Currently,
libbpf will do this address adjustment unconditionally if it finds
.stapsdt.base ELF section in target binary. But there is a corner case
where .stapsdt.base ELF section is present, but specific USDT note
doesn't reference it. In such case, libbpf will basically just add base
address and end up with absolutely incorrect USDT target address.
This adjustment has to be done only if both .stapsdt.sema section is
present and USDT note is recording a reference to it.
Fixes: 74cc6311cec9 ("libbpf: Add USDT notes parsing and resolution logic")
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
tools/lib/bpf/usdt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
index 5f085736c6c4..4e4a52742b01 100644
--- a/tools/lib/bpf/usdt.c
+++ b/tools/lib/bpf/usdt.c
@@ -661,7 +661,7 @@ static int collect_usdt_targets(struct usdt_manager *man, Elf *elf, const char *
* [0] https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation
*/
usdt_abs_ip = note.loc_addr;
- if (base_addr)
+ if (base_addr && note.base_addr)
usdt_abs_ip += base_addr - note.base_addr;
/* When attaching uprobes (which is what USDTs basically are)
--
2.43.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] libbpf: don't adjust USDT semaphore address if .stapsdt.base addr is missing
2024-11-21 22:45 [PATCH bpf-next] libbpf: don't adjust USDT semaphore address if .stapsdt.base addr is missing Andrii Nakryiko
@ 2024-11-22 16:20 ` Jiri Olsa
2024-11-25 22:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Jiri Olsa @ 2024-11-22 16:20 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: bpf, ast, daniel, martin.lau, kernel-team
On Thu, Nov 21, 2024 at 02:45:58PM -0800, Andrii Nakryiko wrote:
> USDT ELF note optionally can record an offset of .stapsdt.base, which is
> used to make adjustments to USDT target attach address. Currently,
> libbpf will do this address adjustment unconditionally if it finds
> .stapsdt.base ELF section in target binary. But there is a corner case
> where .stapsdt.base ELF section is present, but specific USDT note
> doesn't reference it. In such case, libbpf will basically just add base
> address and end up with absolutely incorrect USDT target address.
>
> This adjustment has to be done only if both .stapsdt.sema section is
> present and USDT note is recording a reference to it.
>
> Fixes: 74cc6311cec9 ("libbpf: Add USDT notes parsing and resolution logic")
> Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
nice, lgtm
Acked-by: Jiri Olsa <jolsa@kernel.org>
jirka
> ---
> tools/lib/bpf/usdt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/usdt.c b/tools/lib/bpf/usdt.c
> index 5f085736c6c4..4e4a52742b01 100644
> --- a/tools/lib/bpf/usdt.c
> +++ b/tools/lib/bpf/usdt.c
> @@ -661,7 +661,7 @@ static int collect_usdt_targets(struct usdt_manager *man, Elf *elf, const char *
> * [0] https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation
> */
> usdt_abs_ip = note.loc_addr;
> - if (base_addr)
> + if (base_addr && note.base_addr)
> usdt_abs_ip += base_addr - note.base_addr;
>
> /* When attaching uprobes (which is what USDTs basically are)
> --
> 2.43.5
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf-next] libbpf: don't adjust USDT semaphore address if .stapsdt.base addr is missing
2024-11-21 22:45 [PATCH bpf-next] libbpf: don't adjust USDT semaphore address if .stapsdt.base addr is missing Andrii Nakryiko
2024-11-22 16:20 ` Jiri Olsa
@ 2024-11-25 22:20 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-11-25 22:20 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: bpf, ast, daniel, martin.lau, kernel-team
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Alexei Starovoitov <ast@kernel.org>:
On Thu, 21 Nov 2024 14:45:58 -0800 you wrote:
> USDT ELF note optionally can record an offset of .stapsdt.base, which is
> used to make adjustments to USDT target attach address. Currently,
> libbpf will do this address adjustment unconditionally if it finds
> .stapsdt.base ELF section in target binary. But there is a corner case
> where .stapsdt.base ELF section is present, but specific USDT note
> doesn't reference it. In such case, libbpf will basically just add base
> address and end up with absolutely incorrect USDT target address.
>
> [...]
Here is the summary with links:
- [bpf-next] libbpf: don't adjust USDT semaphore address if .stapsdt.base addr is missing
https://git.kernel.org/bpf/bpf-next/c/d00058e676a9
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] 3+ messages in thread
end of thread, other threads:[~2024-11-25 22:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-21 22:45 [PATCH bpf-next] libbpf: don't adjust USDT semaphore address if .stapsdt.base addr is missing Andrii Nakryiko
2024-11-22 16:20 ` Jiri Olsa
2024-11-25 22:20 ` 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