Skip to content

Commit 2df6bb5

Browse files
liu-song-6Alexei Starovoitov
authored andcommitted
bpf: Allow %pB in bpf_seq_printf() and bpf_trace_printk()
This makes it easy to dump stack trace in text. Signed-off-by: Song Liu <songliubraving@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Yonghong Song <yhs@fb.com> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/20200630062846.664389-4-songliubraving@fb.com
1 parent fa28dcb commit 2df6bb5

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎kernel/trace/bpf_trace.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ static void bpf_trace_copy_string(char *buf, void *unsafe_ptr, char fmt_ptype,
376376

377377
/*
378378
* Only limited trace_printk() conversion specifiers allowed:
379-
* %d %i %u %x %ld %li %lu %lx %lld %lli %llu %llx %p %pks %pus %s
379+
* %d %i %u %x %ld %li %lu %lx %lld %lli %llu %llx %p %pB %pks %pus %s
380380
*/
381381
BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, fmt_size, u64, arg1,
382382
u64, arg2, u64, arg3)
@@ -420,6 +420,11 @@ BPF_CALL_5(bpf_trace_printk, char *, fmt, u32, fmt_size, u64, arg1,
420420
goto fmt_str;
421421
}
422422

423+
if (fmt[i + 1] == 'B') {
424+
i++;
425+
goto fmt_next;
426+
}
427+
423428
/* disallow any further format extensions */
424429
if (fmt[i + 1] != 0 &&
425430
!isspace(fmt[i + 1]) &&
@@ -636,7 +641,8 @@ BPF_CALL_5(bpf_seq_printf, struct seq_file *, m, char *, fmt, u32, fmt_size,
636641
if (fmt[i] == 'p') {
637642
if (fmt[i + 1] == 0 ||
638643
fmt[i + 1] == 'K' ||
639-
fmt[i + 1] == 'x') {
644+
fmt[i + 1] == 'x' ||
645+
fmt[i + 1] == 'B') {
640646
/* just kernel pointers */
641647
params[fmt_cnt] = args[fmt_cnt];
642648
fmt_cnt++;

0 commit comments

Comments
 (0)