Skip to contentSkip to conversation

bpf: return -EOPNOTSUPP when attaching to non-kernel BTF

PATCH Superseded Andrii Nakryiko 3 participants 4 messages Dec 5, 2020 – Dec 7, 2020

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Andrii Nakryiko

author maintainer
#0 lore raw

PATCH 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.

---
 kernel/bpf/syscall.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
kernel/bpf/syscall.c +4 -1
index 0cd3cc2af9c1..7e2bf671c6db 100644
@@ -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
#1 lore raw
Quoted 1 line · Andrii Nakryiko

+ return -EOPNOTSUPP;

$ cd kernel/bpf
$ git grep ENOTSUPP|wc -l
46
$ git grep EOPNOTSUPP|wc -l
11
#2 lore raw
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

#3 lore raw
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
11

But 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