diff options
author | Eric Dumazet <edumazet@google.com> | 2014-01-15 09:50:07 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-01-15 20:02:08 -0500 |
commit | aee636c4809fa54848ff07a899b326eb1f9987a2 (patch) | |
tree | 8f0c327f82dd7d5056dc487064f05f3f804f2fea /arch/s390/net | |
parent | ba42fad0964a41f0830e80c1b6be49c1e6bfcc01 (diff) |
bpf: do not use reciprocal divide
At first Jakub Zawadzki noticed that some divisions by reciprocal_divide
were not correct. (off by one in some cases)
http://www.wireshark.org/~darkjames/reciprocal-buggy.c
He could also show this with BPF:
http://www.wireshark.org/~darkjames/set-and-dump-filter-k-bug.c
The reciprocal divide in linux kernel is not generic enough,
lets remove its use in BPF, as it is not worth the pain with
current cpus.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Jakub Zawadzki <darkjames-ws@darkjames.pl>
Cc: Mircea Gherzan <mgherzan@gmail.com>
Cc: Daniel Borkmann <dxchgb@gmail.com>
Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
Cc: Matt Evans <matt@ozlabs.org>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: David S. Miller <davem@davemloft.net>
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 | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c index 16871da37371..fc0fa77728e1 100644 --- a/arch/s390/net/bpf_jit_comp.c +++ b/arch/s390/net/bpf_jit_comp.c | |||
@@ -371,11 +371,13 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
371 | /* dr %r4,%r12 */ | 371 | /* dr %r4,%r12 */ |
372 | EMIT2(0x1d4c); | 372 | EMIT2(0x1d4c); |
373 | break; | 373 | break; |
374 | case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K) */ | 374 | case BPF_S_ALU_DIV_K: /* A /= K */ |
375 | /* m %r4,<d(K)>(%r13) */ | 375 | if (K == 1) |
376 | EMIT4_DISP(0x5c40d000, EMIT_CONST(K)); | 376 | break; |
377 | /* lr %r5,%r4 */ | 377 | /* lhi %r4,0 */ |
378 | EMIT2(0x1854); | 378 | EMIT4(0xa7480000); |
379 | /* d %r4,<d(K)>(%r13) */ | ||
380 | EMIT4_DISP(0x5d40d000, EMIT_CONST(K)); | ||
379 | break; | 381 | break; |
380 | case BPF_S_ALU_MOD_X: /* A %= X */ | 382 | case BPF_S_ALU_MOD_X: /* A %= X */ |
381 | jit->seen |= SEEN_XREG | SEEN_RET0; | 383 | jit->seen |= SEEN_XREG | SEEN_RET0; |
@@ -391,6 +393,11 @@ static int bpf_jit_insn(struct bpf_jit *jit, struct sock_filter *filter, | |||
391 | EMIT2(0x1854); | 393 | EMIT2(0x1854); |
392 | break; | 394 | break; |
393 | case BPF_S_ALU_MOD_K: /* A %= K */ | 395 | case BPF_S_ALU_MOD_K: /* A %= K */ |
396 | if (K == 1) { | ||
397 | /* lhi %r5,0 */ | ||
398 | EMIT4(0xa7580000); | ||
399 | break; | ||
400 | } | ||
394 | /* lhi %r4,0 */ | 401 | /* lhi %r4,0 */ |
395 | EMIT4(0xa7480000); | 402 | EMIT4(0xa7480000); |
396 | /* d %r4,<d(K)>(%r13) */ | 403 | /* d %r4,<d(K)>(%r13) */ |