Message ID | 20230628115329.248450-3-laoar.shao@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Delegated to: | BPF |
Headers | show |
Series | bpf: Support ->fill_link_info for kprobe_multi and perf_event links | expand |
2023-06-28 11:53 UTC+0000 ~ Yafang Shao <laoar.shao@gmail.com> > If the kernel symbol is in a module, we will dump the module name as > well. The square brackets around the module name are trimmed. > > Signed-off-by: Yafang Shao <laoar.shao@gmail.com> > Reviewed-by: Quentin Monnet <quentin@isovalent.com> > --- > tools/bpf/bpftool/xlated_dumper.c | 6 +++++- > tools/bpf/bpftool/xlated_dumper.h | 2 ++ > 2 files changed, 7 insertions(+), 1 deletion(-) > > diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c > index da608e10c843..567f56dfd9f1 100644 > --- a/tools/bpf/bpftool/xlated_dumper.c > +++ b/tools/bpf/bpftool/xlated_dumper.c > @@ -46,7 +46,11 @@ void kernel_syms_load(struct dump_data *dd) > } > dd->sym_mapping = tmp; > sym = &dd->sym_mapping[dd->sym_count]; > - if (sscanf(buff, "%p %*c %s", &address, sym->name) != 2) > + > + /* module is optional */ > + sym->module[0] = '\0'; > + /* trim the square brackets around the module name */ > + if (sscanf(buff, "%p %*c %s [%[^]]s", &address, sym->name, sym->module) < 2) Looking again at this patch, we should be good for parsing the module name with the sscanf() because I don't expect a module name longer than MODULE_MAX_NAME to show up, but I wonder what guarantee we have about symbols names staying under SYM_MAX_NAME? Maybe we should specify the max length to read, to remain on the safe side (or in case these limits change in the future). But it doesn't have to be part of your set, I can send a follow-up after that. > continue; > sym->address = (unsigned long)address; > if (!strcmp(sym->name, "__bpf_call_base")) { > diff --git a/tools/bpf/bpftool/xlated_dumper.h b/tools/bpf/bpftool/xlated_dumper.h > index 9a946377b0e6..db3ba0671501 100644 > --- a/tools/bpf/bpftool/xlated_dumper.h > +++ b/tools/bpf/bpftool/xlated_dumper.h > @@ -5,12 +5,14 @@ > #define __BPF_TOOL_XLATED_DUMPER_H > > #define SYM_MAX_NAME 256 > +#define MODULE_MAX_NAME 64 > > struct bpf_prog_linfo; > > struct kernel_sym { > unsigned long address; > char name[SYM_MAX_NAME]; > + char module[MODULE_MAX_NAME]; > }; > > struct dump_data {
On Thu, Jun 29, 2023 at 9:46 PM Quentin Monnet <quentin@isovalent.com> wrote: > > 2023-06-28 11:53 UTC+0000 ~ Yafang Shao <laoar.shao@gmail.com> > > If the kernel symbol is in a module, we will dump the module name as > > well. The square brackets around the module name are trimmed. > > > > Signed-off-by: Yafang Shao <laoar.shao@gmail.com> > > Reviewed-by: Quentin Monnet <quentin@isovalent.com> > > --- > > tools/bpf/bpftool/xlated_dumper.c | 6 +++++- > > tools/bpf/bpftool/xlated_dumper.h | 2 ++ > > 2 files changed, 7 insertions(+), 1 deletion(-) > > > > diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c > > index da608e10c843..567f56dfd9f1 100644 > > --- a/tools/bpf/bpftool/xlated_dumper.c > > +++ b/tools/bpf/bpftool/xlated_dumper.c > > @@ -46,7 +46,11 @@ void kernel_syms_load(struct dump_data *dd) > > } > > dd->sym_mapping = tmp; > > sym = &dd->sym_mapping[dd->sym_count]; > > - if (sscanf(buff, "%p %*c %s", &address, sym->name) != 2) > > + > > + /* module is optional */ > > + sym->module[0] = '\0'; > > + /* trim the square brackets around the module name */ > > + if (sscanf(buff, "%p %*c %s [%[^]]s", &address, sym->name, sym->module) < 2) > > Looking again at this patch, we should be good for parsing the module > name with the sscanf() because I don't expect a module name longer than > MODULE_MAX_NAME to show up, but I wonder what guarantee we have about > symbols names staying under SYM_MAX_NAME? Maybe we should specify the > max length to read, to remain on the safe side (or in case these limits > change in the future). But it doesn't have to be part of your set, I can > send a follow-up after that. Great, thanks for your work!
diff --git a/tools/bpf/bpftool/xlated_dumper.c b/tools/bpf/bpftool/xlated_dumper.c index da608e10c843..567f56dfd9f1 100644 --- a/tools/bpf/bpftool/xlated_dumper.c +++ b/tools/bpf/bpftool/xlated_dumper.c @@ -46,7 +46,11 @@ void kernel_syms_load(struct dump_data *dd) } dd->sym_mapping = tmp; sym = &dd->sym_mapping[dd->sym_count]; - if (sscanf(buff, "%p %*c %s", &address, sym->name) != 2) + + /* module is optional */ + sym->module[0] = '\0'; + /* trim the square brackets around the module name */ + if (sscanf(buff, "%p %*c %s [%[^]]s", &address, sym->name, sym->module) < 2) continue; sym->address = (unsigned long)address; if (!strcmp(sym->name, "__bpf_call_base")) { diff --git a/tools/bpf/bpftool/xlated_dumper.h b/tools/bpf/bpftool/xlated_dumper.h index 9a946377b0e6..db3ba0671501 100644 --- a/tools/bpf/bpftool/xlated_dumper.h +++ b/tools/bpf/bpftool/xlated_dumper.h @@ -5,12 +5,14 @@ #define __BPF_TOOL_XLATED_DUMPER_H #define SYM_MAX_NAME 256 +#define MODULE_MAX_NAME 64 struct bpf_prog_linfo; struct kernel_sym { unsigned long address; char name[SYM_MAX_NAME]; + char module[MODULE_MAX_NAME]; }; struct dump_data {