Skip to content

Commit e92888c

Browse files
yonghong-songAlexei Starovoitov
authored andcommitted
bpf: Enforce returning 0 for fentry/fexit progs
Currently, tracing/fentry and tracing/fexit prog return values are not enforced. In trampoline codes, the fentry/fexit prog return values are ignored. Let us enforce it to be 0 to avoid confusion and allows potential future extension. This patch also explicitly added return value checking for tracing/raw_tp, tracing/fmod_ret, and freplace programs such that these program return values can be anything. The purpose are two folds: 1. to make it explicit about return value expectations for these programs in verifier. 2. for tracing prog_type, if a future attach type is added, the default is -ENOTSUPP which will enforce to specify return value ranges explicitly. Fixes: fec56f5 ("bpf: Introduce BPF trampoline") Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 625236b commit e92888c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

kernel/bpf/verifier.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7059,6 +7059,23 @@ static int check_return_code(struct bpf_verifier_env *env)
70597059
return 0;
70607060
range = tnum_const(0);
70617061
break;
7062+
case BPF_PROG_TYPE_TRACING:
7063+
switch (env->prog->expected_attach_type) {
7064+
case BPF_TRACE_FENTRY:
7065+
case BPF_TRACE_FEXIT:
7066+
range = tnum_const(0);
7067+
break;
7068+
case BPF_TRACE_RAW_TP:
7069+
case BPF_MODIFY_RETURN:
7070+
return 0;
7071+
default:
7072+
return -ENOTSUPP;
7073+
}
7074+
break;
7075+
case BPF_PROG_TYPE_EXT:
7076+
/* freplace program can return anything as its return value
7077+
* depends on the to-be-replaced kernel func or bpf program.
7078+
*/
70627079
default:
70637080
return 0;
70647081
}

0 commit comments

Comments
 (0)