Skip to content

Commit 6c4fc20

Browse files
borkmannAlexei Starovoitov
authored andcommitted
bpf: remove useless version check for prog load
Existing libraries and tracing frameworks work around this kernel version check by automatically deriving the kernel version from uname(3) or similar such that the user does not need to do it manually; these workarounds also make the version check useless at the same time. Moreover, most other BPF tracing types enabling bpf_probe_read()-like functionality have /not/ adapted this check, and in general these days it is well understood anyway that all the tracing programs are not stable with regards to future kernels as kernel internal data structures are subject to change from release to release. Back at last netconf we discussed [0] and agreed to remove this check from bpf_prog_load() and instead document it here in the uapi header that there is no such guarantee for stable API for these programs. [0] http://vger.kernel.org/netconf2018_files/DanielBorkmann_netconf2018.pdf Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent 034565d commit 6c4fc20

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

include/uapi/linux/bpf.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ enum bpf_map_type {
133133
BPF_MAP_TYPE_STACK,
134134
};
135135

136+
/* Note that tracing related programs such as
137+
* BPF_PROG_TYPE_{KPROBE,TRACEPOINT,PERF_EVENT,RAW_TRACEPOINT}
138+
* are not subject to a stable API since kernel internal data
139+
* structures can change from release to release and may
140+
* therefore break existing tracing BPF programs. Tracing BPF
141+
* programs correspond to /a/ specific kernel which is to be
142+
* analyzed, and not /a/ specific kernel /and/ all future ones.
143+
*/
136144
enum bpf_prog_type {
137145
BPF_PROG_TYPE_UNSPEC,
138146
BPF_PROG_TYPE_SOCKET_FILTER,
@@ -343,7 +351,7 @@ union bpf_attr {
343351
__u32 log_level; /* verbosity level of verifier */
344352
__u32 log_size; /* size of user buffer */
345353
__aligned_u64 log_buf; /* user supplied buffer */
346-
__u32 kern_version; /* checked when prog_type=kprobe */
354+
__u32 kern_version; /* not used */
347355
__u32 prog_flags;
348356
char prog_name[BPF_OBJ_NAME_LEN];
349357
__u32 prog_ifindex; /* ifindex of netdev to prep for */

kernel/bpf/syscall.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,11 +1473,6 @@ static int bpf_prog_load(union bpf_attr *attr, union bpf_attr __user *uattr)
14731473

14741474
if (attr->insn_cnt == 0 || attr->insn_cnt > BPF_MAXINSNS)
14751475
return -E2BIG;
1476-
1477-
if (type == BPF_PROG_TYPE_KPROBE &&
1478-
attr->kern_version != LINUX_VERSION_CODE)
1479-
return -EINVAL;
1480-
14811476
if (type != BPF_PROG_TYPE_SOCKET_FILTER &&
14821477
type != BPF_PROG_TYPE_CGROUP_SKB &&
14831478
!capable(CAP_SYS_ADMIN))

tools/include/uapi/linux/bpf.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ enum bpf_map_type {
133133
BPF_MAP_TYPE_STACK,
134134
};
135135

136+
/* Note that tracing related programs such as
137+
* BPF_PROG_TYPE_{KPROBE,TRACEPOINT,PERF_EVENT,RAW_TRACEPOINT}
138+
* are not subject to a stable API since kernel internal data
139+
* structures can change from release to release and may
140+
* therefore break existing tracing BPF programs. Tracing BPF
141+
* programs correspond to /a/ specific kernel which is to be
142+
* analyzed, and not /a/ specific kernel /and/ all future ones.
143+
*/
136144
enum bpf_prog_type {
137145
BPF_PROG_TYPE_UNSPEC,
138146
BPF_PROG_TYPE_SOCKET_FILTER,
@@ -343,7 +351,7 @@ union bpf_attr {
343351
__u32 log_level; /* verbosity level of verifier */
344352
__u32 log_size; /* size of user buffer */
345353
__aligned_u64 log_buf; /* user supplied buffer */
346-
__u32 kern_version; /* checked when prog_type=kprobe */
354+
__u32 kern_version; /* not used */
347355
__u32 prog_flags;
348356
char prog_name[BPF_OBJ_NAME_LEN];
349357
__u32 prog_ifindex; /* ifindex of netdev to prep for */

0 commit comments

Comments
 (0)