Message ID | 20200305234416.31597-1-luke.r.nels@gmail.com (mailing list archive) |
---|---|
State | Mainlined |
Commit | 80f1f85036355e5581ec0b99913410345ad3491b |
Headers | show |
Series | [bpf,1/2] bpf, x32: fix bug with JMP32 JSET BPF_X checking upper bits | expand |
On 3/6/20 12:44 AM, Luke Nelson wrote: > The current x32 BPF JIT is incorrect for JMP32 JSET BPF_X when the upper > 32 bits of operand registers are non-zero in certain situations. [...] > We found this bug using our automated verification tool, Serval. > > Fixes: 69f827eb6e14 ("x32: bpf: implement jitting of JMP32") > Co-developed-by: Xi Wang <xi.wang@gmail.com> > Signed-off-by: Xi Wang <xi.wang@gmail.com> > Signed-off-by: Luke Nelson <luke.r.nels@gmail.com> Applied both, thanks for the fix!
diff --git a/arch/x86/net/bpf_jit_comp32.c b/arch/x86/net/bpf_jit_comp32.c index 393d251798c0..4d2a7a764602 100644 --- a/arch/x86/net/bpf_jit_comp32.c +++ b/arch/x86/net/bpf_jit_comp32.c @@ -2039,10 +2039,12 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image, } /* and dreg_lo,sreg_lo */ EMIT2(0x23, add_2reg(0xC0, sreg_lo, dreg_lo)); - /* and dreg_hi,sreg_hi */ - EMIT2(0x23, add_2reg(0xC0, sreg_hi, dreg_hi)); - /* or dreg_lo,dreg_hi */ - EMIT2(0x09, add_2reg(0xC0, dreg_lo, dreg_hi)); + if (is_jmp64) { + /* and dreg_hi,sreg_hi */ + EMIT2(0x23, add_2reg(0xC0, sreg_hi, dreg_hi)); + /* or dreg_lo,dreg_hi */ + EMIT2(0x09, add_2reg(0xC0, dreg_lo, dreg_hi)); + } goto emit_cond_jmp; } case BPF_JMP | BPF_JSET | BPF_K: