Skip to contentSkip to conversation

bpftool: Fix printing incorrect pointer in btf_dump_ptr

PATCH Applied Martin KaFai Lau 3 participants 3 messages Jan 10, 2020 – Jan 12, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpftool: Fix printing incorrect pointer in btf_dump_ptr

For plain text output, it incorrectly prints the pointer value "void *data". The "void *data" is actually pointing to memory that contains a bpf-map's value. The intention is to print the content of the bpf-map's value instead of printing the pointer pointing to the bpf-map's value.

In this case, a member of the bpf-map's value is a pointer type. Thus, it should print the "*(void **)data".

Fixes 22c349e8db89 ("tools: bpftool: fix format strings and arguments for jsonw_printf()")
Cc Quentin Monnet <[email protected]>
---
 tools/bpf/bpftool/btf_dumper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/btf_dumper.c +1 -1
index d66131f69689..397e5716ab6d 100644
@@ -26,7 +26,7 @@ static void btf_dumper_ptr(const void *data, json_writer_t *jw,
 			   bool is_plain_text)
 {
 	if (is_plain_text)
-		jsonw_printf(jw, "%p", data);
+		jsonw_printf(jw, "%p", *(void **)data);
 	else
 		jsonw_printf(jw, "%lu", *(unsigned long *)data);
 }
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw

2020-01-10 15:16 UTC-0800 ~ Martin KaFai Lau <[email protected]>

Quoted 6 lines

For plain text output, it incorrectly prints the pointer value "void *data". The "void *data" is actually pointing to memory that contains a bpf-map's value. The intention is to print the content of the bpf-map's value instead of printing the pointer pointing to the bpf-map's value.

Quoted 6 lines

In this case, a member of the bpf-map's value is a pointer type. Thus, it should print the "*(void **)data".

Fixes 22c349e8db89 ("tools: bpftool: fix format strings and arguments for jsonw_printf()")
Cc Quentin Monnet <[email protected]>

My bad, thank you for the fix!

#2 lore raw
Quoted 11 lines · Quentin Monnet

2020-01-10 15:16 UTC-0800 ~ Martin KaFai Lau <[email protected]>

Quoted 9 lines

For plain text output, it incorrectly prints the pointer value "void *data". The "void *data" is actually pointing to memory that contains a bpf-map's value. The intention is to print the content of the bpf-map's value instead of printing the pointer pointing to the bpf-map's value.

In this case, a member of the bpf-map's value is a pointer type. Thus, it should print the "*(void **)data".

Quoted 7 lines
Quoted 3 lines
Fixes 22c349e8db89 ("tools: bpftool: fix format strings and arguments for jsonw_printf()")
Cc Quentin Monnet <[email protected]>

My bad, thank you for the fix!

Applied to bpf tree. Thanks