aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2017-02-21 13:30:15 -0500
committerDavid S. Miller <davem@davemloft.net>2017-02-21 13:30:15 -0500
commitd54fef315399e0b16f8ae2b41167f34f8df12e88 (patch)
tree954aa0e71dbb2fc5fad9d6a77ca6477a873ffbe6
parent559c59b238ebb7d39b732b6b08a59693b972e75c (diff)
parent9d876e79df6a2f364b9f2737eacd72ceb27da53a (diff)
Merge branch 'bpf-unlocking-fix'
Daniel Borkmann says: ==================== BPF fix with regards to unlocking This set fixes the issue Eric was reporting recently [1]. First patch is a prerequisite discussed with Laura that is needed for the later fix in the second one. I've tested this extensively and it does not reproduce anymore on my side after the fix. Thanks & sorry about that! [1] https://www.spinics.net/lists/netdev/msg421877.html ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--arch/Kconfig4
-rw-r--r--arch/arm/Kconfig1
-rw-r--r--arch/arm64/Kconfig1
-rw-r--r--arch/arm64/net/bpf_jit_comp.c2
-rw-r--r--arch/s390/Kconfig1
-rw-r--r--arch/s390/net/bpf_jit_comp.c2
-rw-r--r--arch/x86/Kconfig1
-rw-r--r--arch/x86/net/bpf_jit_comp.c2
-rw-r--r--include/linux/filter.h13
9 files changed, 22 insertions, 5 deletions
diff --git a/arch/Kconfig b/arch/Kconfig
index bd04eace455c..e8ada79ec71f 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -222,6 +222,10 @@ config GENERIC_SMP_IDLE_THREAD
222config GENERIC_IDLE_POLL_SETUP 222config GENERIC_IDLE_POLL_SETUP
223 bool 223 bool
224 224
225# Select if arch has all set_memory_ro/rw/x/nx() functions in asm/cacheflush.h
226config ARCH_HAS_SET_MEMORY
227 bool
228
225# Select if arch init_task initializer is different to init/init_task.c 229# Select if arch init_task initializer is different to init/init_task.c
226config ARCH_INIT_TASK 230config ARCH_INIT_TASK
227 bool 231 bool
diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 186c4c214e0a..edae056b2af0 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -4,6 +4,7 @@ config ARM
4 select ARCH_CLOCKSOURCE_DATA 4 select ARCH_CLOCKSOURCE_DATA
5 select ARCH_HAS_DEVMEM_IS_ALLOWED 5 select ARCH_HAS_DEVMEM_IS_ALLOWED
6 select ARCH_HAS_ELF_RANDOMIZE 6 select ARCH_HAS_ELF_RANDOMIZE
7 select ARCH_HAS_SET_MEMORY
7 select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST 8 select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
8 select ARCH_HAVE_CUSTOM_GPIO_H 9 select ARCH_HAVE_CUSTOM_GPIO_H
9 select ARCH_HAS_GCOV_PROFILE_ALL 10 select ARCH_HAS_GCOV_PROFILE_ALL
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig
index 111742126897..1853405a897e 100644
--- a/arch/arm64/Kconfig
+++ b/arch/arm64/Kconfig
@@ -12,6 +12,7 @@ config ARM64
12 select ARCH_HAS_GCOV_PROFILE_ALL 12 select ARCH_HAS_GCOV_PROFILE_ALL
13 select ARCH_HAS_GIGANTIC_PAGE 13 select ARCH_HAS_GIGANTIC_PAGE
14 select ARCH_HAS_KCOV 14 select ARCH_HAS_KCOV
15 select ARCH_HAS_SET_MEMORY
15 select ARCH_HAS_SG_CHAIN 16 select ARCH_HAS_SG_CHAIN
16 select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST 17 select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
17 select ARCH_USE_CMPXCHG_LOCKREF 18 select ARCH_USE_CMPXCHG_LOCKREF
diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c
index 05d12104d270..a785554916c0 100644
--- a/arch/arm64/net/bpf_jit_comp.c
+++ b/arch/arm64/net/bpf_jit_comp.c
@@ -898,7 +898,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
898 898
899 bpf_flush_icache(header, ctx.image + ctx.idx); 899 bpf_flush_icache(header, ctx.image + ctx.idx);
900 900
901 set_memory_ro((unsigned long)header, header->pages); 901 bpf_jit_binary_lock_ro(header);
902 prog->bpf_func = (void *)ctx.image; 902 prog->bpf_func = (void *)ctx.image;
903 prog->jited = 1; 903 prog->jited = 1;
904 904
diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index c6722112527d..094deb1abbe7 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -72,6 +72,7 @@ config S390
72 select ARCH_HAS_GCOV_PROFILE_ALL 72 select ARCH_HAS_GCOV_PROFILE_ALL
73 select ARCH_HAS_GIGANTIC_PAGE 73 select ARCH_HAS_GIGANTIC_PAGE
74 select ARCH_HAS_KCOV 74 select ARCH_HAS_KCOV
75 select ARCH_HAS_SET_MEMORY
75 select ARCH_HAS_SG_CHAIN 76 select ARCH_HAS_SG_CHAIN
76 select ARCH_HAS_UBSAN_SANITIZE_ALL 77 select ARCH_HAS_UBSAN_SANITIZE_ALL
77 select ARCH_HAVE_NMI_SAFE_CMPXCHG 78 select ARCH_HAVE_NMI_SAFE_CMPXCHG
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index f1d0e62ec1dd..b49c52a02087 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -1327,7 +1327,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *fp)
1327 print_fn_code(jit.prg_buf, jit.size_prg); 1327 print_fn_code(jit.prg_buf, jit.size_prg);
1328 } 1328 }
1329 if (jit.prg_buf) { 1329 if (jit.prg_buf) {
1330 set_memory_ro((unsigned long)header, header->pages); 1330 bpf_jit_binary_lock_ro(header);
1331 fp->bpf_func = (void *) jit.prg_buf; 1331 fp->bpf_func = (void *) jit.prg_buf;
1332 fp->jited = 1; 1332 fp->jited = 1;
1333 } 1333 }
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index e487493bbd47..434dd2a1c5f2 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -53,6 +53,7 @@ config X86
53 select ARCH_HAS_KCOV if X86_64 53 select ARCH_HAS_KCOV if X86_64
54 select ARCH_HAS_MMIO_FLUSH 54 select ARCH_HAS_MMIO_FLUSH
55 select ARCH_HAS_PMEM_API if X86_64 55 select ARCH_HAS_PMEM_API if X86_64
56 select ARCH_HAS_SET_MEMORY
56 select ARCH_HAS_SG_CHAIN 57 select ARCH_HAS_SG_CHAIN
57 select ARCH_HAS_UBSAN_SANITIZE_ALL 58 select ARCH_HAS_UBSAN_SANITIZE_ALL
58 select ARCH_HAVE_NMI_SAFE_CMPXCHG 59 select ARCH_HAVE_NMI_SAFE_CMPXCHG
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 18a62e208826..32322ce9b405 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -1165,7 +1165,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog *prog)
1165 1165
1166 if (image) { 1166 if (image) {
1167 bpf_flush_icache(header, image + proglen); 1167 bpf_flush_icache(header, image + proglen);
1168 set_memory_ro((unsigned long)header, header->pages); 1168 bpf_jit_binary_lock_ro(header);
1169 prog->bpf_func = (void *)image; 1169 prog->bpf_func = (void *)image;
1170 prog->jited = 1; 1170 prog->jited = 1;
1171 } else { 1171 } else {
diff --git a/include/linux/filter.h b/include/linux/filter.h
index 0c1cc9143cb2..0c167fdee5f7 100644
--- a/include/linux/filter.h
+++ b/include/linux/filter.h
@@ -551,7 +551,7 @@ static inline bool bpf_prog_was_classic(const struct bpf_prog *prog)
551 551
552#define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0])) 552#define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0]))
553 553
554#ifdef CONFIG_DEBUG_SET_MODULE_RONX 554#ifdef CONFIG_ARCH_HAS_SET_MEMORY
555static inline void bpf_prog_lock_ro(struct bpf_prog *fp) 555static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
556{ 556{
557 set_memory_ro((unsigned long)fp, fp->pages); 557 set_memory_ro((unsigned long)fp, fp->pages);
@@ -562,6 +562,11 @@ static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
562 set_memory_rw((unsigned long)fp, fp->pages); 562 set_memory_rw((unsigned long)fp, fp->pages);
563} 563}
564 564
565static inline void bpf_jit_binary_lock_ro(struct bpf_binary_header *hdr)
566{
567 set_memory_ro((unsigned long)hdr, hdr->pages);
568}
569
565static inline void bpf_jit_binary_unlock_ro(struct bpf_binary_header *hdr) 570static inline void bpf_jit_binary_unlock_ro(struct bpf_binary_header *hdr)
566{ 571{
567 set_memory_rw((unsigned long)hdr, hdr->pages); 572 set_memory_rw((unsigned long)hdr, hdr->pages);
@@ -575,10 +580,14 @@ static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
575{ 580{
576} 581}
577 582
583static inline void bpf_jit_binary_lock_ro(struct bpf_binary_header *hdr)
584{
585}
586
578static inline void bpf_jit_binary_unlock_ro(struct bpf_binary_header *hdr) 587static inline void bpf_jit_binary_unlock_ro(struct bpf_binary_header *hdr)
579{ 588{
580} 589}
581#endif /* CONFIG_DEBUG_SET_MODULE_RONX */ 590#endif /* CONFIG_ARCH_HAS_SET_MEMORY */
582 591
583static inline struct bpf_binary_header * 592static inline struct bpf_binary_header *
584bpf_jit_binary_hdr(const struct bpf_prog *fp) 593bpf_jit_binary_hdr(const struct bpf_prog *fp)