0258-bpf-prevent-speculative-execution-in-eBPF-interprete.patch 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
  2. From: Elena Reshetova <[email protected]>
  3. Date: Mon, 4 Sep 2017 13:11:44 +0300
  4. Subject: [PATCH] bpf: prevent speculative execution in eBPF interpreter
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5753
  9. CVE-2017-5715
  10. This adds a generic memory barrier before LD_IMM_DW and
  11. LDX_MEM_B/H/W/DW eBPF instructions during eBPF program
  12. execution in order to prevent speculative execution on out
  13. of bound BFP_MAP array indexes. This way an arbitary kernel
  14. memory is not exposed through side channel attacks.
  15. For more details, please see this Google Project Zero report: tbd
  16. Signed-off-by: Elena Reshetova <[email protected]>
  17. Signed-off-by: Tim Chen <[email protected]>
  18. Signed-off-by: Andy Whitcroft <[email protected]>
  19. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  20. (cherry picked from commit dd13f73106c260dea7a689d33d1457639af820aa)
  21. Signed-off-by: Fabian Grünbichler <[email protected]>
  22. ---
  23. kernel/bpf/core.c | 3 +++
  24. 1 file changed, 3 insertions(+)
  25. diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
  26. index 9a1bed1f3029..3f83c60e3e86 100644
  27. --- a/kernel/bpf/core.c
  28. +++ b/kernel/bpf/core.c
  29. @@ -33,6 +33,7 @@
  30. #include <linux/rcupdate.h>
  31. #include <asm/unaligned.h>
  32. +#include <asm/barrier.h>
  33. /* Registers */
  34. #define BPF_R0 regs[BPF_REG_0]
  35. @@ -920,6 +921,7 @@ static unsigned int ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn,
  36. DST = IMM;
  37. CONT;
  38. LD_IMM_DW:
  39. + gmb();
  40. DST = (u64) (u32) insn[0].imm | ((u64) (u32) insn[1].imm) << 32;
  41. insn++;
  42. CONT;
  43. @@ -1133,6 +1135,7 @@ static unsigned int ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn,
  44. *(SIZE *)(unsigned long) (DST + insn->off) = IMM; \
  45. CONT; \
  46. LDX_MEM_##SIZEOP: \
  47. + gmb(); \
  48. DST = *(SIZE *)(unsigned long) (SRC + insn->off); \
  49. CONT;
  50. --
  51. 2.14.2