]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
bpf: disallow direct packet access for unpriv in cg_skb
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 24 Oct 2018 20:05:44 +0000 (22:05 +0200)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 26 Oct 2018 00:02:06 +0000 (17:02 -0700)
Commit b39b5f411dcf ("bpf: add cg_skb_is_valid_access for
BPF_PROG_TYPE_CGROUP_SKB") added support for returning pkt pointers
for direct packet access. Given this program type is allowed for both
unprivileged and privileged users, we shouldn't allow unprivileged
ones to use it, e.g. besides others one reason would be to avoid any
potential speculation on the packet test itself, thus guard this for
root only.

Fixes: b39b5f411dcf ("bpf: add cg_skb_is_valid_access for BPF_PROG_TYPE_CGROUP_SKB")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Cc: Song Liu <songliubraving@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
net/core/filter.c
tools/testing/selftests/bpf/test_verifier.c

index 35c6933c262298d0951725ea255d70bbdd294353..3fdddfa9a0fd983cf400b3cf5ebca6426b1e377c 100644 (file)
@@ -5496,7 +5496,13 @@ static bool cg_skb_is_valid_access(int off, int size,
        case bpf_ctx_range(struct __sk_buff, data_meta):
        case bpf_ctx_range(struct __sk_buff, flow_keys):
                return false;
+       case bpf_ctx_range(struct __sk_buff, data):
+       case bpf_ctx_range(struct __sk_buff, data_end):
+               if (!capable(CAP_SYS_ADMIN))
+                       return false;
+               break;
        }
+
        if (type == BPF_WRITE) {
                switch (off) {
                case bpf_ctx_range(struct __sk_buff, mark):
index 8e1a79d2792c471fbb23845ca557b51881d5d901..36f3d3009d1a079e57032b47b57bc306d045a3a8 100644 (file)
@@ -4892,7 +4892,7 @@ static struct bpf_test tests[] = {
                },
                .result = ACCEPT,
                .result_unpriv = REJECT,
-               .errstr_unpriv = "R3 pointer comparison prohibited",
+               .errstr_unpriv = "invalid bpf_context access off=76 size=4",
                .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
        },
        {