Commit 430e68d1 authored by Quentin Monnet's avatar Quentin Monnet Committed by Daniel Borkmann

bpf: export function to write into verifier log buffer

Rename the BPF verifier `verbose()` to `bpf_verifier_log_write()` and
export it, so that other components (in particular, drivers for BPF
offload) can reuse the user buffer log to dump error messages at
verification time.

Renaming `verbose()` was necessary in order to avoid a name so generic
to be exported to the global namespace. However to prevent too much pain
for backports, the calls to `verbose()` in the kernel BPF verifier were
not changed. Instead, use function aliasing to make `verbose` point to
`bpf_verifier_log_write`. Another solution could consist in making a
wrapper around `verbose()`, but since it is a variadic function, I don't
see a clean way without creating two identical wrappers, one for the
verifier and one to export.
Signed-off-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent c087aa8b
...@@ -192,6 +192,9 @@ struct bpf_verifier_env { ...@@ -192,6 +192,9 @@ struct bpf_verifier_env {
u32 subprog_cnt; u32 subprog_cnt;
}; };
__printf(2, 3) void bpf_verifier_log_write(struct bpf_verifier_env *env,
const char *fmt, ...);
static inline struct bpf_reg_state *cur_regs(struct bpf_verifier_env *env) static inline struct bpf_reg_state *cur_regs(struct bpf_verifier_env *env)
{ {
struct bpf_verifier_state *cur = env->cur_state; struct bpf_verifier_state *cur = env->cur_state;
......
...@@ -169,11 +169,11 @@ struct bpf_call_arg_meta { ...@@ -169,11 +169,11 @@ struct bpf_call_arg_meta {
static DEFINE_MUTEX(bpf_verifier_lock); static DEFINE_MUTEX(bpf_verifier_lock);
/* log_level controls verbosity level of eBPF verifier. /* log_level controls verbosity level of eBPF verifier.
* verbose() is used to dump the verification trace to the log, so the user * bpf_verifier_log_write() is used to dump the verification trace to the log,
* can figure out what's wrong with the program * so the user can figure out what's wrong with the program
*/ */
static __printf(2, 3) void verbose(struct bpf_verifier_env *env, __printf(2, 3) void bpf_verifier_log_write(struct bpf_verifier_env *env,
const char *fmt, ...) const char *fmt, ...)
{ {
struct bpf_verifer_log *log = &env->log; struct bpf_verifer_log *log = &env->log;
unsigned int n; unsigned int n;
...@@ -197,6 +197,14 @@ static __printf(2, 3) void verbose(struct bpf_verifier_env *env, ...@@ -197,6 +197,14 @@ static __printf(2, 3) void verbose(struct bpf_verifier_env *env,
else else
log->ubuf = NULL; log->ubuf = NULL;
} }
EXPORT_SYMBOL_GPL(bpf_verifier_log_write);
/* Historically bpf_verifier_log_write was called verbose, but the name was too
* generic for symbol export. The function was renamed, but not the calls in
* the verifier to avoid complicating backports. Hence the alias below.
*/
static __printf(2, 3) void verbose(struct bpf_verifier_env *env,
const char *fmt, ...)
__attribute__((alias("bpf_verifier_log_write")));
static bool type_is_pkt_pointer(enum bpf_reg_type type) static bool type_is_pkt_pointer(enum bpf_reg_type type)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment