Skip to content

Commit 3af57f7

Browse files
heicarstdavem330
authored andcommitted
s390/bpf,jit: fix 32 bit divisions, use unsigned divide instructions
The s390 bpf jit compiler emits the signed divide instructions "dr" and "d" for unsigned divisions. This can cause problems: the dividend will be zero extended to a 64 bit value and the divisor is the 32 bit signed value as specified A or X accumulator, even though A and X are supposed to be treated as unsigned values. The divide instrunctions will generate an exception if the result cannot be expressed with a 32 bit signed value. This is the case if e.g. the dividend is 0xffffffff and the divisor either 1 or also 0xffffffff (signed: -1). To avoid all these issues simply use unsigned divide instructions. Signed-off-by: Heiko Carstens <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 75b99db commit 3af57f7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

arch/s390/net/bpf_jit_comp.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -368,16 +368,16 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter,
368368
EMIT4_PCREL(0xa7840000, (jit->ret0_ip - jit->prg));
369369
/* lhi %r4,0 */
370370
EMIT4(0xa7480000);
371-
/* dr %r4,%r12 */
372-
EMIT2(0x1d4c);
371+
/* dlr %r4,%r12 */
372+
EMIT4(0xb997004c);
373373
break;
374374
case BPF_S_ALU_DIV_K: /* A /= K */
375375
if (K == 1)
376376
break;
377377
/* lhi %r4,0 */
378378
EMIT4(0xa7480000);
379-
/* d %r4,<d(K)>(%r13) */
380-
EMIT4_DISP(0x5d40d000, EMIT_CONST(K));
379+
/* dl %r4,<d(K)>(%r13) */
380+
EMIT6_DISP(0xe340d000, 0x0097, EMIT_CONST(K));
381381
break;
382382
case BPF_S_ALU_MOD_X: /* A %= X */
383383
jit->seen |= SEEN_XREG | SEEN_RET0;
@@ -387,8 +387,8 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter,
387387
EMIT4_PCREL(0xa7840000, (jit->ret0_ip - jit->prg));
388388
/* lhi %r4,0 */
389389
EMIT4(0xa7480000);
390-
/* dr %r4,%r12 */
391-
EMIT2(0x1d4c);
390+
/* dlr %r4,%r12 */
391+
EMIT4(0xb997004c);
392392
/* lr %r5,%r4 */
393393
EMIT2(0x1854);
394394
break;
@@ -400,8 +400,8 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter,
400400
}
401401
/* lhi %r4,0 */
402402
EMIT4(0xa7480000);
403-
/* d %r4,<d(K)>(%r13) */
404-
EMIT4_DISP(0x5d40d000, EMIT_CONST(K));
403+
/* dl %r4,<d(K)>(%r13) */
404+
EMIT6_DISP(0xe340d000, 0x0097, EMIT_CONST(K));
405405
/* lr %r5,%r4 */
406406
EMIT2(0x1854);
407407
break;

0 commit comments

Comments
 (0)