Skip to content

Commit 0ebeea8

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf: Restrict bpf_probe_read{, str}() only to archs where they work
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 <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Reviewed-by: Masami Hiramatsu <[email protected]> Acked-by: Linus Torvalds <[email protected]> Cc: Brendan Gregg <[email protected]> Cc: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 6d74f64 commit 0ebeea8

File tree

5 files changed

+10
-2
lines changed

5 files changed

+10
-2
lines changed

arch/arm/Kconfig

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

arch/arm64/Kconfig

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

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ config X86
6868
select ARCH_HAS_KCOV if X86_64
6969
select ARCH_HAS_MEM_ENCRYPT
7070
select ARCH_HAS_MEMBARRIER_SYNC_CORE
71+
select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
7172
select ARCH_HAS_PMEM_API if X86_64
7273
select ARCH_HAS_PTE_DEVMAP if X86_64
7374
select ARCH_HAS_PTE_SPECIAL

init/Kconfig

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

22802280
source "kernel/Kconfig.locks"
22812281

2282+
config ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
2283+
bool
2284+
22822285
config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE
22832286
bool
22842287

kernel/trace/bpf_trace.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -825,14 +825,16 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
825825
return &bpf_probe_read_user_proto;
826826
case BPF_FUNC_probe_read_kernel:
827827
return &bpf_probe_read_kernel_proto;
828-
case BPF_FUNC_probe_read:
829-
return &bpf_probe_read_compat_proto;
830828
case BPF_FUNC_probe_read_user_str:
831829
return &bpf_probe_read_user_str_proto;
832830
case BPF_FUNC_probe_read_kernel_str:
833831
return &bpf_probe_read_kernel_str_proto;
832+
#ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
833+
case BPF_FUNC_probe_read:
834+
return &bpf_probe_read_compat_proto;
834835
case BPF_FUNC_probe_read_str:
835836
return &bpf_probe_read_compat_str_proto;
837+
#endif
836838
#ifdef CONFIG_CGROUPS
837839
case BPF_FUNC_get_current_cgroup_id:
838840
return &bpf_get_current_cgroup_id_proto;

0 commit comments

Comments
 (0)