]> git.baikalelectronics.ru Git - kernel.git/commitdiff
bpf: program: Refuse non-O_RDWR flags in BPF_OBJ_GET
authorLorenz Bauer <lmb@cloudflare.com>
Fri, 26 Mar 2021 16:05:01 +0000 (16:05 +0000)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 1 Apr 2021 21:33:48 +0000 (14:33 -0700)
As for bpf_link, refuse creating a non-O_RDWR fd. Since program fds
currently don't allow modifications this is a precaution, not a
straight up bug fix.

Signed-off-by: Lorenz Bauer <lmb@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20210326160501.46234-2-lmb@cloudflare.com
kernel/bpf/inode.c

index dc56237d69600603143e6d3274127149b610b2d9..d2de2abec35b6ea5d41caceebc640612f09c8a47 100644 (file)
@@ -543,7 +543,7 @@ int bpf_obj_get_user(const char __user *pathname, int flags)
                return PTR_ERR(raw);
 
        if (type == BPF_TYPE_PROG)
-               ret = bpf_prog_new_fd(raw);
+               ret = (f_flags != O_RDWR) ? -EINVAL : bpf_prog_new_fd(raw);
        else if (type == BPF_TYPE_MAP)
                ret = bpf_map_new_fd(raw, f_flags);
        else if (type == BPF_TYPE_LINK)