diff options
author | Eric Dumazet <edumazet@google.com> | 2014-01-15 09:50:07 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-02-06 14:08:16 -0500 |
commit | cd7361dc9fa60c35d011d674d48eababcc3eb767 (patch) | |
tree | 51c5b5cdfabf829671688e9df26623fa64feb5ea /arch/powerpc | |
parent | 8c035b62e21a2d26c1a5181ee0d27a76c8996be8 (diff) |
bpf: do not use reciprocal divide
[ Upstream commit aee636c4809fa54848ff07a899b326eb1f9987a2 ]
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'arch/powerpc')
-rw-r--r-- | arch/powerpc/net/bpf_jit_comp.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c index c427ae36374a..a012a9747cdd 100644 --- a/arch/powerpc/net/bpf_jit_comp.c +++ b/arch/powerpc/net/bpf_jit_comp.c | |||
@@ -209,10 +209,11 @@ static int bpf_jit_build_body(struct sk_filter *fp, u32 *image, | |||
209 | } | 209 | } |
210 | PPC_DIVWU(r_A, r_A, r_X); | 210 | PPC_DIVWU(r_A, r_A, r_X); |
211 | break; | 211 | break; |
212 | case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */ | 212 | case BPF_S_ALU_DIV_K: /* A /= K */ |
213 | if (K == 1) | ||
214 | break; | ||
213 | PPC_LI32(r_scratch1, K); | 215 | PPC_LI32(r_scratch1, K); |
214 | /* Top 32 bits of 64bit result -> A */ | 216 | PPC_DIVWU(r_A, r_A, r_scratch1); |
215 | PPC_MULHWU(r_A, r_A, r_scratch1); | ||
216 | break; | 217 | break; |
217 | case BPF_S_ALU_AND_X: | 218 | case BPF_S_ALU_AND_X: |
218 | ctx->seen |= SEEN_XREG; | 219 | ctx->seen |= SEEN_XREG; |