Message ID | 20230919101336.2223655-2-iii@linux.ibm.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 577c06af8188d1f6919ef7b62fc1b78fb1b86eb7 |
Delegated to: | BPF |
Headers | show |
Series | Implement cpuv4 support for s390x | expand |
Ilya Leoshkevich <iii@linux.ibm.com> writes: > On the architectures that use bpf_jit_needs_zext(), e.g., s390x, the > verifier incorrectly inserts a zero-extension after BPF_MEMSX, leading > to miscompilations like the one below: > > 24: 89 1a ff fe 00 00 00 00 "r1 = *(s16 *)(r10 - 2);" # zext_dst set > 0x3ff7fdb910e: lgh %r2,-2(%r13,%r0) # load halfword > 0x3ff7fdb9114: llgfr %r2,%r2 # wrong! > 25: 65 10 00 03 00 00 7f ff if r1 s> 32767 goto +3 <l0_1> # check_cond_jmp_op() > > Disable such zero-extensions. The JITs need to insert sign-extension > themselves, if necessary. > > Suggested-by: Puranjay Mohan <puranjay12@gmail.com> > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> > --- > kernel/bpf/verifier.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c > index a7178ecf676d..614bf3fa4fd5 100644 > --- a/kernel/bpf/verifier.c > +++ b/kernel/bpf/verifier.c > @@ -3114,7 +3114,7 @@ static bool is_reg64(struct bpf_verifier_env *env, struct bpf_insn *insn, > > if (class == BPF_LDX) { > if (t != SRC_OP) > - return BPF_SIZE(code) == BPF_DW; > + return BPF_SIZE(code) == BPF_DW || BPF_MODE(code) == BPF_MEMSX; > /* LDX source must be ptr. */ > return true; > } > -- > 2.41.0 Reviewed-by: Puranjay Mohan <puranjay12@gmail.com> Thanks for this. Puranjay
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index a7178ecf676d..614bf3fa4fd5 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -3114,7 +3114,7 @@ static bool is_reg64(struct bpf_verifier_env *env, struct bpf_insn *insn, if (class == BPF_LDX) { if (t != SRC_OP) - return BPF_SIZE(code) == BPF_DW; + return BPF_SIZE(code) == BPF_DW || BPF_MODE(code) == BPF_MEMSX; /* LDX source must be ptr. */ return true; }
On the architectures that use bpf_jit_needs_zext(), e.g., s390x, the verifier incorrectly inserts a zero-extension after BPF_MEMSX, leading to miscompilations like the one below: 24: 89 1a ff fe 00 00 00 00 "r1 = *(s16 *)(r10 - 2);" # zext_dst set 0x3ff7fdb910e: lgh %r2,-2(%r13,%r0) # load halfword 0x3ff7fdb9114: llgfr %r2,%r2 # wrong! 25: 65 10 00 03 00 00 7f ff if r1 s> 32767 goto +3 <l0_1> # check_cond_jmp_op() Disable such zero-extensions. The JITs need to insert sign-extension themselves, if necessary. Suggested-by: Puranjay Mohan <puranjay12@gmail.com> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> --- kernel/bpf/verifier.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)