bpf: return -EOPNOTSUPP when attaching to non-kernel BTF
Subsystems (4)
Andrii Nakryiko
maintainerPATCH 1/1 bpf: return -EOPNOTSUPP when attaching to non-kernel BTF
Return -EOPNOTSUPP if tracing BPF program is attempted to be attached with specified attach_btf_obj_fd pointing to non-kernel (neither vmlinux nor module) BTF object. This scenario might be supported in the future and isn't outright invalid, so -EINVAL isn't the most appropriate error code.
Suggested-by Alexei Starovoitov <[email protected]>
Signed-off-by Andrii Nakryiko <[email protected]>
--- kernel/bpf/syscall.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/bpf/syscall.c +4 -1
@@ -2121,8 +2121,11 @@ static int bpf_prog_load(union bpf_attr *attr, union bpf_attr __user *uattr)if (IS_ERR (attach_btf))return -EINVAL ;if (!btf_is_kernel (attach_btf)) { +/* attaching through specifying bpf_prog's BTF +* objects directly might be supported eventually +*/ btf_put (attach_btf); -return -EINVAL ; +return -EOPNOTSUPP ; } } }else if (attr->attach_btf_id) {
Signature · 1 line
2.24.1
Quoted 1 line · Andrii Nakryiko
+ return
-EOPNOTSUPP;
$ cd kernel/bpf $ git grep ENOTSUPP|wc -l 46 $ git grep EOPNOTSUPP|wc -l 11
Quoted 8 lines · Alexei Starovoitov
Quoted 1 line · Andrii Nakryiko
+ return
-EOPNOTSUPP;$ cd kernel/bpf $ git grep ENOTSUPP|wc -l 46 $ git grep EOPNOTSUPP|wc -l 11
But also
$ cd kernel/include/uapi $ git grep ENOTSUPP | wc -l 0 $ git grep EOPNOTSUPP | wc -l 8
(i.e., ENOTSUPP is not defined in userspace headers at all)
-Toke
Quoted 14 lines · Toke Høiland-Jørgensen
Quoted 8 lines · Alexei Starovoitov
Quoted 1 line · Andrii Nakryiko
+ return
-EOPNOTSUPP;$ cd kernel/bpf $ git grep ENOTSUPP|wc -l 46 $ git grep EOPNOTSUPP|wc -l 11But also
Quoted 7 lines
$ cd kernel/include/uapi $ git grep ENOTSUPP | wc -l 0 $ git grep EOPNOTSUPP | wc -l 8(i.e., ENOTSUPP is not defined in userspace headers at all)
that's irrelevant. The kernel returns it already. It's a known constant regardless of .h