aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@plumgrid.com>2015-04-27 17:40:37 -0400
committerDavid S. Miller <davem@davemloft.net>2015-04-27 23:11:49 -0400
commit876a7ae65b86d8cec8efe7d15d050ac61116874e (patch)
tree6458c36e3f2c0cd2f2ca7c1dfcee6fc5b9c7dd19 /kernel/bpf
parent8e046d68ba719a5bb95912c154c6314472edccfa (diff)
bpf: fix 64-bit divide
ALU64_DIV instruction should be dividing 64-bit by 64-bit, whereas do_div() does 64-bit by 32-bit divide. x64 and arm64 JITs correctly implement 64 by 64 unsigned divide. llvm BPF backend emits code assuming that ALU64_DIV does 64 by 64. Fixes: 89aa075832b0 ("net: sock: allow eBPF programs to be attached to sockets") Reported-by: Michael Holzheu <holzheu@linux.vnet.ibm.com> Acked-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Alexei Starovoitov <ast@plumgrid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf')
-rw-r--r--kernel/bpf/core.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 4139a0f8b558..54f0e7fcd0e2 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -357,8 +357,8 @@ select_insn:
357 ALU64_MOD_X: 357 ALU64_MOD_X:
358 if (unlikely(SRC == 0)) 358 if (unlikely(SRC == 0))
359 return 0; 359 return 0;
360 tmp = DST; 360 div64_u64_rem(DST, SRC, &tmp);
361 DST = do_div(tmp, SRC); 361 DST = tmp;
362 CONT; 362 CONT;
363 ALU_MOD_X: 363 ALU_MOD_X:
364 if (unlikely(SRC == 0)) 364 if (unlikely(SRC == 0))
@@ -367,8 +367,8 @@ select_insn:
367 DST = do_div(tmp, (u32) SRC); 367 DST = do_div(tmp, (u32) SRC);
368 CONT; 368 CONT;
369 ALU64_MOD_K: 369 ALU64_MOD_K:
370 tmp = DST; 370 div64_u64_rem(DST, IMM, &tmp);
371 DST = do_div(tmp, IMM); 371 DST = tmp;
372 CONT; 372 CONT;
373 ALU_MOD_K: 373 ALU_MOD_K:
374 tmp = (u32) DST; 374 tmp = (u32) DST;
@@ -377,7 +377,7 @@ select_insn:
377 ALU64_DIV_X: 377 ALU64_DIV_X:
378 if (unlikely(SRC == 0)) 378 if (unlikely(SRC == 0))
379 return 0; 379 return 0;
380 do_div(DST, SRC); 380 DST = div64_u64(DST, SRC);
381 CONT; 381 CONT;
382 ALU_DIV_X: 382 ALU_DIV_X:
383 if (unlikely(SRC == 0)) 383 if (unlikely(SRC == 0))
@@ -387,7 +387,7 @@ select_insn:
387 DST = (u32) tmp; 387 DST = (u32) tmp;
388 CONT; 388 CONT;
389 ALU64_DIV_K: 389 ALU64_DIV_K:
390 do_div(DST, IMM); 390 DST = div64_u64(DST, IMM);
391 CONT; 391 CONT;
392 ALU_DIV_K: 392 ALU_DIV_K:
393 tmp = (u32) DST; 393 tmp = (u32) DST;