summaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorToke Høiland-Jørgensen <toke@redhat.com>2020-09-25 23:25:00 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-10-29 10:11:30 +0100
commit9d6b33d27c250eb381d97297e40eb15f5586913d (patch)
tree5acab6ed523cbc32a99fd5f884990343b53cf1d9 /kernel
parent05ad722863103b860fcfea25827cbb9b68868ae2 (diff)
downloadlinux-stable-9d6b33d27c250eb381d97297e40eb15f5586913d.tar.gz
linux-stable-9d6b33d27c250eb381d97297e40eb15f5586913d.tar.bz2
linux-stable-9d6b33d27c250eb381d97297e40eb15f5586913d.zip
bpf: disallow attaching modify_return tracing functions to other BPF programs
[ Upstream commit 1af9270e908cd50a4f5d815c9b6f794c7d57ed07 ] 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: 18644cec714a ("bpf: Fix use-after-free in fmod_ret check") Fixes: 6ba43b761c41 ("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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/bpf/verifier.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index fba52d9ec8fc..5b9d2cf06fc6 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -11046,6 +11046,11 @@ static int check_attach_btf_id(struct bpf_verifier_env *env)
}
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",