bpf: Only reply field should be writeable
authorLawrence Brakmo <brakmo@fb.com>
Fri, 26 Jan 2018 00:14:05 +0000 (16:14 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 26 Jan 2018 00:41:13 +0000 (16:41 -0800)
Currently, a sock_ops BPF program can write the op field and all the
reply fields (reply and replylong). This is a bug. The op field should
not have been writeable and there is currently no way to use replylong
field for indices >= 1. This patch enforces that only the reply field
(which equals replylong[0]) is writeable.

Fixes: 40304b2a1567 ("bpf: BPF support for sock_ops")
Signed-off-by: Lawrence Brakmo <brakmo@fb.com>
Acked-by: Yuchung Cheng <ycheng@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
net/core/filter.c

index 18da42a..bf9bb75 100644 (file)
@@ -3845,8 +3845,7 @@ static bool sock_ops_is_valid_access(int off, int size,
 {
        if (type == BPF_WRITE) {
                switch (off) {
-               case offsetof(struct bpf_sock_ops, op) ...
-                    offsetof(struct bpf_sock_ops, replylong[3]):
+               case offsetof(struct bpf_sock_ops, reply):
                        break;
                default:
                        return false;