Skip to contentSkip to conversation

bpf: Enforce 'return 0' in BTF-enabled raw_tp programs

PATCH Applied Alexei Starovoitov 3 participants 3 messages Oct 29, 2019 – Oct 30, 2019

Subsystems (4)
lore
Share & tools
lore

Alexei Starovoitov

author maintainer
#0 lore raw

PATCH 1/1 bpf: Enforce 'return 0' in BTF-enabled raw_tp programs

The return value of raw_tp programs is ignored by __bpf_trace_run() that calls them. The verifier also allows any value to be returned. For BTF-enabled raw_tp lets enforce 'return 0', so that return value can be used for something in the future.

---
 kernel/bpf/verifier.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/bpf/verifier.c +5 -0
index c59778c0fc4d..6b0de04f8b91 100644
@@ -6279,6 +6279,11 @@ static int check_return_code(struct bpf_verifier_env *env)
 	case BPF_PROG_TYPE_CGROUP_SYSCTL:
 	case BPF_PROG_TYPE_CGROUP_SOCKOPT:
 		break;
+	case BPF_PROG_TYPE_RAW_TRACEPOINT:
+		if (!env->prog->aux->attach_btf_id)
+			return 0;
+		range = tnum_const(0);
+		break;
 	default:
 		return 0;
 	}
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Alexei Starovoitov

The return value of raw_tp programs is ignored by __bpf_trace_run() that calls them. The verifier also allows any value to be returned. For BTF-enabled raw_tp lets enforce 'return 0', so that return value can be used for something in the future.

---

Looks good, if the return value is ignored, no need to specify anything but 0 for now.

Quoted 20 lines
  kernel/bpf/verifier.c | 5 +++++
  1 file changed, 5 insertions(+)
kernel/bpf/verifier.c +5 -0
index c59778c0fc4d..6b0de04f8b91 100644
@@ -6279,6 +6279,11 @@ static int check_return_code(struct bpf_verifier_env *env)
  	case BPF_PROG_TYPE_CGROUP_SYSCTL:
  	case BPF_PROG_TYPE_CGROUP_SOCKOPT:
  		break;
+	case BPF_PROG_TYPE_RAW_TRACEPOINT:
+		if (!env->prog->aux->attach_btf_id)
+			return 0;
+		range = tnum_const(0);
+		break;
  	default:
  		return 0;
  	}