diff options
| author | Daniel Borkmann <daniel@iogearbox.net> | 2019-04-23 18:45:57 -0400 |
|---|---|---|
| committer | Alexei Starovoitov <ast@kernel.org> | 2019-04-25 16:47:29 -0400 |
| commit | 4f8827d2b61ed32133e51f6a782bb69d80c7c3d4 (patch) | |
| tree | 2f161816188f7f305cc44ceea74afcf32ecc7b42 | |
| parent | 8837fe5dd09bd0331b3e2d1b6e400b7fcda8963a (diff) | |
bpf, libbpf: fix segfault in bpf_object__init_maps' pr_debug statement
Ran into it while testing; in bpf_object__init_maps() data can be NULL
in the case where no map section is present. Therefore we simply cannot
access data->d_size before NULL test. Move the pr_debug() where it's
safe to access.
Fixes: d859900c4c56 ("bpf, libbpf: support global data/bss/rodata sections")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
| -rw-r--r-- | tools/lib/bpf/libbpf.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 85315dedbde4..9052061ba7fc 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c | |||
| @@ -875,14 +875,14 @@ bpf_object__init_maps(struct bpf_object *obj, int flags) | |||
| 875 | nr_maps++; | 875 | nr_maps++; |
| 876 | } | 876 | } |
| 877 | 877 | ||
| 878 | /* Alloc obj->maps and fill nr_maps. */ | ||
| 879 | pr_debug("maps in %s: %d maps in %zd bytes\n", obj->path, | ||
| 880 | nr_maps, data->d_size); | ||
| 881 | if (!nr_maps && !nr_maps_glob) | 878 | if (!nr_maps && !nr_maps_glob) |
| 882 | return 0; | 879 | return 0; |
| 883 | 880 | ||
| 884 | /* Assume equally sized map definitions */ | 881 | /* Assume equally sized map definitions */ |
| 885 | if (data) { | 882 | if (data) { |
| 883 | pr_debug("maps in %s: %d maps in %zd bytes\n", obj->path, | ||
| 884 | nr_maps, data->d_size); | ||
| 885 | |||
| 886 | map_def_sz = data->d_size / nr_maps; | 886 | map_def_sz = data->d_size / nr_maps; |
| 887 | if (!data->d_size || (data->d_size % nr_maps) != 0) { | 887 | if (!data->d_size || (data->d_size % nr_maps) != 0) { |
| 888 | pr_warning("unable to determine map definition size " | 888 | pr_warning("unable to determine map definition size " |
