diff options
author | Heiko Carstens <heiko.carstens@de.ibm.com> | 2014-01-17 03:37:15 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-02-06 14:08:16 -0500 |
commit | f93f502e2d6a6acb36fbac0236e6088318c6d757 (patch) | |
tree | b9b6f434eb55236788f7041d22e2a18d34ad4b7a /arch/s390 | |
parent | cd7361dc9fa60c35d011d674d48eababcc3eb767 (diff) |
s390/bpf,jit: fix 32 bit divisions, use unsigned divide instructions
[ Upstream commit 3af57f78c38131b7a66e2b01e06fdacae01992a3 ]
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'arch/s390')
-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 b7792d499da6..1919db6c0607 100644 --- a/arch/s390/net/bpf_jit_comp.c +++ b/arch/s390/net/bpf_jit_comp.c | |||
@@ -335,16 +335,16 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
335 | EMIT4_PCREL(0xa7840000, (jit->ret0_ip - jit->prg)); | 335 | EMIT4_PCREL(0xa7840000, (jit->ret0_ip - jit->prg)); |
336 | /* lhi %r4,0 */ | 336 | /* lhi %r4,0 */ |
337 | EMIT4(0xa7480000); | 337 | EMIT4(0xa7480000); |
338 | /* dr %r4,%r12 */ | 338 | /* dlr %r4,%r12 */ |
339 | EMIT2(0x1d4c); | 339 | EMIT4(0xb997004c); |
340 | break; | 340 | break; |
341 | case BPF_S_ALU_DIV_K: /* A /= K */ | 341 | case BPF_S_ALU_DIV_K: /* A /= K */ |
342 | if (K == 1) | 342 | if (K == 1) |
343 | break; | 343 | break; |
344 | /* lhi %r4,0 */ | 344 | /* lhi %r4,0 */ |
345 | EMIT4(0xa7480000); | 345 | EMIT4(0xa7480000); |
346 | /* d %r4,<d(K)>(%r13) */ | 346 | /* dl %r4,<d(K)>(%r13) */ |
347 | EMIT4_DISP(0x5d40d000, EMIT_CONST(K)); | 347 | EMIT6_DISP(0xe340d000, 0x0097, EMIT_CONST(K)); |
348 | break; | 348 | break; |
349 | case BPF_S_ALU_MOD_X: /* A %= X */ | 349 | case BPF_S_ALU_MOD_X: /* A %= X */ |
350 | jit->seen |= SEEN_XREG | SEEN_RET0; | 350 | jit->seen |= SEEN_XREG | SEEN_RET0; |
@@ -354,8 +354,8 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
354 | EMIT4_PCREL(0xa7840000, (jit->ret0_ip - jit->prg)); | 354 | EMIT4_PCREL(0xa7840000, (jit->ret0_ip - jit->prg)); |
355 | /* lhi %r4,0 */ | 355 | /* lhi %r4,0 */ |
356 | EMIT4(0xa7480000); | 356 | EMIT4(0xa7480000); |
357 | /* dr %r4,%r12 */ | 357 | /* dlr %r4,%r12 */ |
358 | EMIT2(0x1d4c); | 358 | EMIT4(0xb997004c); |
359 | /* lr %r5,%r4 */ | 359 | /* lr %r5,%r4 */ |
360 | EMIT2(0x1854); | 360 | EMIT2(0x1854); |
361 | break; | 361 | break; |
@@ -367,8 +367,8 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
367 | } | 367 | } |
368 | /* lhi %r4,0 */ | 368 | /* lhi %r4,0 */ |
369 | EMIT4(0xa7480000); | 369 | EMIT4(0xa7480000); |
370 | /* d %r4,<d(K)>(%r13) */ | 370 | /* dl %r4,<d(K)>(%r13) */ |
371 | EMIT4_DISP(0x5d40d000, EMIT_CONST(K)); | 371 | EMIT6_DISP(0xe340d000, 0x0097, EMIT_CONST(K)); |
372 | /* lr %r5,%r4 */ | 372 | /* lr %r5,%r4 */ |
373 | EMIT2(0x1854); | 373 | EMIT2(0x1854); |
374 | break; | 374 | break; |