]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: prevent overwriting of log_level in bpf_object__load_progs()
authorQuentin Monnet <quentin.monnet@netronome.com>
Wed, 29 May 2019 14:26:41 +0000 (15:26 +0100)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 29 May 2019 17:36:55 +0000 (19:36 +0200)
commit9714b9e4dcb927437377ca7adf12784180de2a67
tree7c3dc464704650e58498a96cd1f8c005ea44ef2d
parent943bd4ce0b0a93b1669a94d8531f821247b31a4e
libbpf: prevent overwriting of log_level in bpf_object__load_progs()

There are two functions in libbpf that support passing a log_level
parameter for the verifier for loading programs:
bpf_object__load_xattr() and bpf_prog_load_xattr(). Both accept an
attribute object containing the log_level, and apply it to the programs
to load.

It turns out that to effectively load the programs, the latter function
eventually relies on the former. This was not taken into account when
adding support for log_level in bpf_object__load_xattr(), and the
log_level passed to bpf_prog_load_xattr() later gets overwritten with a
zero value, thus disabling verifier logs for the program in all cases:

bpf_prog_load_xattr()             // prog->log_level = attr1->log_level;
-> bpf_object__load()             // attr2->log_level = 0;
   -> bpf_object__load_xattr()    // <pass prog and attr2>
      -> bpf_object__load_progs() // prog->log_level = attr2->log_level;

Fix this by OR-ing the log_level in bpf_object__load_progs(), instead of
overwriting it.

v2: Fix commit log description (confusion on function names in v1).

Fixes: 8da7d273f510 ("libbpf: add bpf_object__load_xattr() API function to pass log_level")
Reported-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/lib/bpf/libbpf.c