diff options
author | Heiko Carstens <heiko.carstens@de.ibm.com> | 2014-01-17 03:37:15 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-01-17 21:54:49 -0500 |
commit | 3af57f78c38131b7a66e2b01e06fdacae01992a3 (patch) | |
tree | e19b729126d28efa4f4325b21f834100d981e5bf /arch/s390/net | |
parent | 75b99dbd634f9caf7b4e48ec5c2dcec8c1837372 (diff) |
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 <heiko.carstens@de.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/s390/net')
-rw-r--r-- | arch/s390/net/bpf_jit_comp.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c index fc0fa77728e1..708d60e40066 100644 --- a/arch/s390/net/bpf_jit_comp.c +++ b/arch/s390/net/bpf_jit_comp.c | |||
@@ -368,16 +368,16 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
368 | EMIT4_PCREL(0xa7840000, (jit->ret0_ip - jit->prg)); | 368 | EMIT4_PCREL(0xa7840000, (jit->ret0_ip - jit->prg)); |
369 | /* lhi %r4,0 */ | 369 | /* lhi %r4,0 */ |
370 | EMIT4(0xa7480000); | 370 | EMIT4(0xa7480000); |
371 | /* dr %r4,%r12 */ | 371 | /* dlr %r4,%r12 */ |
372 | EMIT2(0x1d4c); | 372 | EMIT4(0xb997004c); |
373 | break; | 373 | break; |
374 | case BPF_S_ALU_DIV_K: /* A /= K */ | 374 | case BPF_S_ALU_DIV_K: /* A /= K */ |
375 | if (K == 1) | 375 | if (K == 1) |
376 | break; | 376 | break; |
377 | /* lhi %r4,0 */ | 377 | /* lhi %r4,0 */ |
378 | EMIT4(0xa7480000); | 378 | EMIT4(0xa7480000); |
379 | /* d %r4,<d(K)>(%r13) */ | 379 | /* dl %r4,<d(K)>(%r13) */ |
380 | EMIT4_DISP(0x5d40d000, EMIT_CONST(K)); | 380 | EMIT6_DISP(0xe340d000, 0x0097, EMIT_CONST(K)); |
381 | break; | 381 | break; |
382 | case BPF_S_ALU_MOD_X: /* A %= X */ | 382 | case BPF_S_ALU_MOD_X: /* A %= X */ |
383 | jit->seen |= SEEN_XREG | SEEN_RET0; | 383 | jit->seen |= SEEN_XREG | SEEN_RET0; |
@@ -387,8 +387,8 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
387 | EMIT4_PCREL(0xa7840000, (jit->ret0_ip - jit->prg)); | 387 | EMIT4_PCREL(0xa7840000, (jit->ret0_ip - jit->prg)); |
388 | /* lhi %r4,0 */ | 388 | /* lhi %r4,0 */ |
389 | EMIT4(0xa7480000); | 389 | EMIT4(0xa7480000); |
390 | /* dr %r4,%r12 */ | 390 | /* dlr %r4,%r12 */ |
391 | EMIT2(0x1d4c); | 391 | EMIT4(0xb997004c); |
392 | /* lr %r5,%r4 */ | 392 | /* lr %r5,%r4 */ |
393 | EMIT2(0x1854); | 393 | EMIT2(0x1854); |
394 | break; | 394 | break; |
@@ -400,8 +400,8 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
400 | } | 400 | } |
401 | /* lhi %r4,0 */ | 401 | /* lhi %r4,0 */ |
402 | EMIT4(0xa7480000); | 402 | EMIT4(0xa7480000); |
403 | /* d %r4,<d(K)>(%r13) */ | 403 | /* dl %r4,<d(K)>(%r13) */ |
404 | EMIT4_DISP(0x5d40d000, EMIT_CONST(K)); | 404 | EMIT6_DISP(0xe340d000, 0x0097, EMIT_CONST(K)); |
405 | /* lr %r5,%r4 */ | 405 | /* lr %r5,%r4 */ |
406 | EMIT2(0x1854); | 406 | EMIT2(0x1854); |
407 | break; | 407 | break; |