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/sparc | |
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/sparc')
-rw-r--r-- | arch/sparc/net/bpf_jit_comp.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c index 218b6b23c378..01fe9946d388 100644 --- a/arch/sparc/net/bpf_jit_comp.c +++ b/arch/sparc/net/bpf_jit_comp.c | |||
@@ -497,9 +497,20 @@ void bpf_jit_compile(struct sk_filter *fp) | |||
497 | case BPF_S_ALU_MUL_K: /* A *= K */ | 497 | case BPF_S_ALU_MUL_K: /* A *= K */ |
498 | emit_alu_K(MUL, K); | 498 | emit_alu_K(MUL, K); |
499 | break; | 499 | break; |
500 | case BPF_S_ALU_DIV_K: /* A /= K */ | 500 | case BPF_S_ALU_DIV_K: /* A /= K with K != 0*/ |
501 | emit_alu_K(MUL, K); | 501 | if (K == 1) |
502 | emit_read_y(r_A); | 502 | break; |
503 | emit_write_y(G0); | ||
504 | #ifdef CONFIG_SPARC32 | ||
505 | /* The Sparc v8 architecture requires | ||
506 | * three instructions between a %y | ||
507 | * register write and the first use. | ||
508 | */ | ||
509 | emit_nop(); | ||
510 | emit_nop(); | ||
511 | emit_nop(); | ||
512 | #endif | ||
513 | emit_alu_K(DIV, K); | ||
503 | break; | 514 | break; |
504 | case BPF_S_ALU_DIV_X: /* A /= X; */ | 515 | case BPF_S_ALU_DIV_X: /* A /= X; */ |
505 | emit_cmpi(r_X, 0); | 516 | emit_cmpi(r_X, 0); |