@@ -187,6 +187,7 @@ struct bpf_verifier_stack_elem {
};
#define BPF_COMPLEXITY_LIMIT_JMP_SEQ 8192
+#define BPF_COMPLEXITY_LIMIT_SPEC_V1_VERIFICATION (BPF_COMPLEXITY_LIMIT_JMP_SEQ / 2)
#define BPF_COMPLEXITY_LIMIT_STATES 64
#define BPF_MAP_KEY_POISON (1ULL << 63)
@@ -1933,6 +1934,19 @@ static struct bpf_verifier_state *push_stack(struct bpf_verifier_env *env,
struct bpf_verifier_stack_elem *elem;
int err;
+ if (!env->bypass_spec_v1 &&
+ cur->speculative &&
+ env->stack_size > BPF_COMPLEXITY_LIMIT_SPEC_V1_VERIFICATION) {
+ /* Avoiding nested speculative path verification because we are
+ * close to exceeding the jump sequence complexity limit. Will
+ * instead insert a speculation barrier which will impact
+ * performace. To improve performance, authors should reduce the
+ * program's complexity. Barrier will be inserted in
+ * do_check().
+ */
+ return ERR_PTR(-EINVAL);
+ }
+
elem = kzalloc(sizeof(struct bpf_verifier_stack_elem), GFP_KERNEL);
if (!elem) {
err = -ENOMEM;