Commit 19539ce7 authored by Tycho Andersen's avatar Tycho Andersen Committed by David S. Miller

ebpf: emit correct src_reg for conditional jumps

Instead of always emitting BPF_REG_X, let's emit BPF_REG_X only when the
source actually is BPF_X. This causes programs generated by the classic
converter to not be importable via bpf(), as the eBPF verifier checks that
the src_reg is correct or 0. While not a problem yet, this will be a
problem when BPF_PROG_DUMP lands, and we can potentially dump and re-import
programs generated by the converter.
Signed-off-by: default avatarTycho Andersen <tycho.andersen@canonical.com>
CC: Alexei Starovoitov <ast@kernel.org>
CC: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1853c949
...@@ -478,9 +478,9 @@ static int bpf_convert_filter(struct sock_filter *prog, int len, ...@@ -478,9 +478,9 @@ static int bpf_convert_filter(struct sock_filter *prog, int len,
bpf_src = BPF_X; bpf_src = BPF_X;
} else { } else {
insn->dst_reg = BPF_REG_A; insn->dst_reg = BPF_REG_A;
insn->src_reg = BPF_REG_X;
insn->imm = fp->k; insn->imm = fp->k;
bpf_src = BPF_SRC(fp->code); bpf_src = BPF_SRC(fp->code);
insn->src_reg = bpf_src == BPF_X ? BPF_REG_X : 0;
} }
/* Common case where 'jump_false' is next insn. */ /* Common case where 'jump_false' is next insn. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment