aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2018-10-20 20:09:25 -0400
committerAlexei Starovoitov <ast@kernel.org>2018-10-21 02:13:32 -0400
commit4b5defdec398491c5b301a6255cdf468eedfb228 (patch)
tree7dc1384f099dc3740d7af361787254cd5c29acdd /kernel/bpf
parent2a159c6f82381a458bc56e7e202b6bee57a2ccb7 (diff)
bpf, verifier: reject xadd on flow key memory
We should not enable xadd operation for flow key memory if not needed there anyway. There is no such issue as described in the commit f37a8cb84cce ("bpf: reject stores into ctx via st and xadd") since there's no context rewriter for flow keys today, but it also shouldn't become part of the user facing behavior to allow for it. After patch: 0: (79) r7 = *(u64 *)(r1 +144) 1: (b7) r3 = 4096 2: (db) lock *(u64 *)(r7 +0) += r3 BPF_XADD stores into R7 flow_keys is not allowed Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf')
-rw-r--r--kernel/bpf/verifier.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 64e0981a4074..0450ffcc3de4 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1553,6 +1553,14 @@ static bool is_pkt_reg(struct bpf_verifier_env *env, int regno)
1553 return type_is_pkt_pointer(reg->type); 1553 return type_is_pkt_pointer(reg->type);
1554} 1554}
1555 1555
1556static bool is_flow_key_reg(struct bpf_verifier_env *env, int regno)
1557{
1558 const struct bpf_reg_state *reg = reg_state(env, regno);
1559
1560 /* Separate to is_ctx_reg() since we still want to allow BPF_ST here. */
1561 return reg->type == PTR_TO_FLOW_KEYS;
1562}
1563
1556static int check_pkt_ptr_alignment(struct bpf_verifier_env *env, 1564static int check_pkt_ptr_alignment(struct bpf_verifier_env *env,
1557 const struct bpf_reg_state *reg, 1565 const struct bpf_reg_state *reg,
1558 int off, int size, bool strict) 1566 int off, int size, bool strict)
@@ -1961,7 +1969,8 @@ static int check_xadd(struct bpf_verifier_env *env, int insn_idx, struct bpf_ins
1961 } 1969 }
1962 1970
1963 if (is_ctx_reg(env, insn->dst_reg) || 1971 if (is_ctx_reg(env, insn->dst_reg) ||
1964 is_pkt_reg(env, insn->dst_reg)) { 1972 is_pkt_reg(env, insn->dst_reg) ||
1973 is_flow_key_reg(env, insn->dst_reg)) {
1965 verbose(env, "BPF_XADD stores into R%d %s is not allowed\n", 1974 verbose(env, "BPF_XADD stores into R%d %s is not allowed\n",
1966 insn->dst_reg, 1975 insn->dst_reg,
1967 reg_type_str[reg_state(env, insn->dst_reg)->type]); 1976 reg_type_str[reg_state(env, insn->dst_reg)->type]);