Skip to content

Commit

Permalink
bpf: disallow attaching modify_return tracing functions to other BPF …
Browse files Browse the repository at this point in the history
…programs

From the checks and commit messages for modify_return, it seems it was
never the intention that it should be possible to attach a tracing program
with expected_attach_type == BPF_MODIFY_RETURN to another BPF program.
However, check_attach_modify_return() will only look at the function name,
so if the target function starts with "security_", the attach will be
allowed even for bpf2bpf attachment.

Fix this oversight by also blocking the modification if a target program is
supplied.

Fixes: 18644ce ("bpf: Fix use-after-free in fmod_ret check")
Fixes: 6ba43b7 ("bpf: Attachment verification for BPF_MODIFY_RETURN")
Acked-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
Toke Høiland-Jørgensen authored and Alexei Starovoitov committed Sep 29, 2020
1 parent 84a20d8 commit 1af9270
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions kernel/bpf/verifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -11500,6 +11500,11 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
verbose(env, "%s is not sleepable\n",
prog->aux->attach_func_name);
} else if (prog->expected_attach_type == BPF_MODIFY_RETURN) {
if (tgt_prog) {
verbose(env, "can't modify return codes of BPF programs\n");
ret = -EINVAL;
goto out;
}
ret = check_attach_modify_return(prog, addr);
if (ret)
verbose(env, "%s() is not modifiable\n",
Expand Down

0 comments on commit 1af9270

Please sign in to comment.