History

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 6ae08ae3dea2 ("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

Daniel Borkmann committed 6 years ago

Commit 0ebeea81 parent 6d74f645 files · +10 −2Browse files

Unified · Split

5 files
  1. arch/arm/Kconfig +1 −0
  2. arch/arm64/Kconfig +1 −0
  3. arch/x86/Kconfig +1 −0
  4. init/Kconfig +3 −0
  5. kernel/trace/bpf_trace.c +4 −2
arch/arm/Kconfig+1−0
@@ -12,6 +12,7 @@ config ARM · 11 unmodified lines
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+1−0
@@ -20,6 +20,7 @@ config ARM64 · 19 unmodified lines
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+1−0
@@ -68,6 +68,7 @@ config X86 · 67 unmodified lines
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+3−0
@@ -2279,6 +2279,9 @@ config ASN1 · 2278 unmodified lines
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+4−2
@@ -825,14 +825,16 @@ bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) · 824 unmodified lines
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;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t