Teach the verifier to recognize that xoring a register with
itself makes it a constant (0).
Signed-off-by: Jakub Kicinski <redacted>
---
kernel/bpf/verifier.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index db68a0e5db1e..0f4494c194f9 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1550,6 +1550,12 @@ static int check_alu_op(struct verifier_env *env, struct bpf_insn *insn)
verbose("invalid BPF_ALU opcode %x\n", opcode);
return -EINVAL;
+ } else if (opcode == BPF_XOR && BPF_SRC(insn->code) == BPF_X &&
+ insn->src_reg == insn->dst_reg) {
+
+ regs[insn->dst_reg].type = CONST_IMM;
+ regs[insn->dst_reg].imm = 0;
+
} else { /* all other ALU ops: and, sub, xor, add, ... */
if (BPF_SRC(insn->code) == BPF_X) {--
1.9.1