Skip to content

Commit d21e07b

Browse files
borkmanngregkh
authored andcommitted
bpf: Restrict bpf_probe_read{, str}() only to archs where they work
commit 0ebeea8 upstream. Given the legacy bpf_probe_read{,str}() BPF helpers are broken on archs with overlapping address ranges, we should really take the next step to disable them from BPF use there. To generally fix the situation, we've recently added new helper variants bpf_probe_read_{user,kernel}() and bpf_probe_read_{user,kernel}_str(). For details on them, see 6ae08ae ("bpf: Add probe_read_{user, kernel} and probe_read_{user,kernel}_str helpers"). Given bpf_probe_read{,str}() have been around for ~5 years by now, there are plenty of users at least on x86 still relying on them today, so we cannot remove them entirely w/o breaking the BPF tracing ecosystem. However, their use should be restricted to archs with non-overlapping address ranges where they are working in their current form. Therefore, move this behind a CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE and have x86, arm64, arm select it (other archs supporting it can follow-up on it as well). For the remaining archs, they can workaround easily by relying on the feature probe from bpftool which spills out defines that can be used out of BPF C code to implement the drop-in replacement for old/new kernels via: bpftool feature probe macro Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org> Acked-by: Linus Torvalds <torvalds@linux-foundation.org> Cc: Brendan Gregg <brendan.d.gregg@gmail.com> Cc: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/bpf/20200515101118.6508-2-daniel@iogearbox.net Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent bd348da commit d21e07b

5 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎arch/arm/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ config ARM
1313
select ARCH_HAS_KEEPINITRD
1414
select ARCH_HAS_KCOV
1515
select ARCH_HAS_MEMBARRIER_SYNC_CORE
16+
select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
1617
select ARCH_HAS_PTE_SPECIAL if ARM_LPAE
1718
select ARCH_HAS_PHYS_TO_DMA
1819
select ARCH_HAS_SETUP_DMA_OPS

‎arch/arm64/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ config ARM64
2121
select ARCH_HAS_KCOV
2222
select ARCH_HAS_KEEPINITRD
2323
select ARCH_HAS_MEMBARRIER_SYNC_CORE
24+
select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
2425
select ARCH_HAS_PTE_DEVMAP
2526
select ARCH_HAS_PTE_SPECIAL
2627
select ARCH_HAS_SETUP_DMA_OPS

‎arch/x86/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ config X86
7070
select ARCH_HAS_KCOV if X86_64
7171
select ARCH_HAS_MEM_ENCRYPT
7272
select ARCH_HAS_MEMBARRIER_SYNC_CORE
73+
select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
7374
select ARCH_HAS_PMEM_API if X86_64
7475
select ARCH_HAS_PTE_DEVMAP if X86_64
7576
select ARCH_HAS_PTE_SPECIAL

‎init/Kconfig‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,6 +2223,9 @@ config ASN1
22232223

22242224
source "kernel/Kconfig.locks"
22252225

2226+
config ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
2227+
bool
2228+
22262229
config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE
22272230
bool
22282231

‎kernel/trace/bpf_trace.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,14 +857,16 @@ tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
857857
return &bpf_probe_read_user_proto;
858858
case BPF_FUNC_probe_read_kernel:
859859
return &bpf_probe_read_kernel_proto;
860-
case BPF_FUNC_probe_read:
861-
return &bpf_probe_read_compat_proto;
862860
case BPF_FUNC_probe_read_user_str:
863861
return &bpf_probe_read_user_str_proto;
864862
case BPF_FUNC_probe_read_kernel_str:
865863
return &bpf_probe_read_kernel_str_proto;
864+
#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
865+
case BPF_FUNC_probe_read:
866+
return &bpf_probe_read_compat_proto;
866867
case BPF_FUNC_probe_read_str:
867868
return &bpf_probe_read_compat_str_proto;
869+
#endif
868870
#ifdef CONFIG_CGROUPS
869871
case BPF_FUNC_get_current_cgroup_id:
870872
return &bpf_get_current_cgroup_id_proto;

0 commit comments

Comments
 (0)