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
12 select ARCH_HAS_KEEPINITRD12 select ARCH_HAS_KEEPINITRD
13 select ARCH_HAS_KCOV13 select ARCH_HAS_KCOV
14 select ARCH_HAS_MEMBARRIER_SYNC_CORE14 select ARCH_HAS_MEMBARRIER_SYNC_CORE
15 select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
15 select ARCH_HAS_PTE_SPECIAL if ARM_LPAE16 select ARCH_HAS_PTE_SPECIAL if ARM_LPAE
16 select ARCH_HAS_PHYS_TO_DMA17 select ARCH_HAS_PHYS_TO_DMA
17 select ARCH_HAS_SETUP_DMA_OPS18 select ARCH_HAS_SETUP_DMA_OPS
arch/arm64/Kconfig+1−0
@@ -20,6 +20,7 @@ config ARM64 · 19 unmodified lines
20 select ARCH_HAS_KCOV20 select ARCH_HAS_KCOV
21 select ARCH_HAS_KEEPINITRD21 select ARCH_HAS_KEEPINITRD
22 select ARCH_HAS_MEMBARRIER_SYNC_CORE22 select ARCH_HAS_MEMBARRIER_SYNC_CORE
23 select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
23 select ARCH_HAS_PTE_DEVMAP24 select ARCH_HAS_PTE_DEVMAP
24 select ARCH_HAS_PTE_SPECIAL25 select ARCH_HAS_PTE_SPECIAL
25 select ARCH_HAS_SETUP_DMA_OPS26 select ARCH_HAS_SETUP_DMA_OPS
arch/x86/Kconfig+1−0
@@ -68,6 +68,7 @@ config X86 · 67 unmodified lines
68 select ARCH_HAS_KCOV if X86_6468 select ARCH_HAS_KCOV if X86_64
69 select ARCH_HAS_MEM_ENCRYPT69 select ARCH_HAS_MEM_ENCRYPT
70 select ARCH_HAS_MEMBARRIER_SYNC_CORE70 select ARCH_HAS_MEMBARRIER_SYNC_CORE
71 select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
71 select ARCH_HAS_PMEM_API if X86_6472 select ARCH_HAS_PMEM_API if X86_64
72 select ARCH_HAS_PTE_DEVMAP if X86_6473 select ARCH_HAS_PTE_DEVMAP if X86_64
73 select ARCH_HAS_PTE_SPECIAL74 select ARCH_HAS_PTE_SPECIAL
init/Kconfig+3−0
@@ -2279,6 +2279,9 @@ config ASN1 · 2278 unmodified lines
2279 2279
2280source "kernel/Kconfig.locks"2280source "kernel/Kconfig.locks"
2281 2281
2282config ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
2283 bool
2284
2282config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE2285config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE
2283 bool2286 bool
2284 2287
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
825 return &bpf_probe_read_user_proto;825 return &bpf_probe_read_user_proto;
826 case BPF_FUNC_probe_read_kernel:826 case BPF_FUNC_probe_read_kernel:
827 return &bpf_probe_read_kernel_proto;827 return &bpf_probe_read_kernel_proto;
828 case BPF_FUNC_probe_read:
829 return &bpf_probe_read_compat_proto;
830 case BPF_FUNC_probe_read_user_str:828 case BPF_FUNC_probe_read_user_str:
831 return &bpf_probe_read_user_str_proto;829 return &bpf_probe_read_user_str_proto;
832 case BPF_FUNC_probe_read_kernel_str:830 case BPF_FUNC_probe_read_kernel_str:
833 return &bpf_probe_read_kernel_str_proto;831 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;
834 case BPF_FUNC_probe_read_str:835 case BPF_FUNC_probe_read_str:
835 return &bpf_probe_read_compat_str_proto;836 return &bpf_probe_read_compat_str_proto;
837#endif
836#ifdef CONFIG_CGROUPS838#ifdef CONFIG_CGROUPS
837 case BPF_FUNC_get_current_cgroup_id:839 case BPF_FUNC_get_current_cgroup_id:
838 return &bpf_get_current_cgroup_id_proto;840 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