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

Showing the changes to kernel (1 of 5 files). Show all

Unified · Split

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