From: Alexei Starovoitov Only offloaded programs are affected. A valid program loads, but nfp can refuse to attach it. No unsafe program is accepted, because the pass that the driver sees is a full pass with all checks. The driver must see only a pass without errors. So the verifier runs the good pass once more with the hooks of the driver. This is the replay. Before it, bpf_partition_for_pessimized() tries more precision. If that fails, bpf_restore_precision() takes the precision masks back from prec->undo. partition_next() makes that copy. If find_calls_to_unproven() is over the cost limit, partition_next() does not run, and prec->undo has the masks of an older pass. The limit is low after the first good pass, so this happens if a later good pass ends just below it. Then the replay can join more states than that pass did. In a test with a stub driver max_pkt_offset was 448 in place of 56. If that value and the MTU are above the packet split boundary, nfp refuses to attach the program. Make the copy in bpf_partition_for_pessimized() too. Fixes: cd97aa1387d9 ("bpf: Do not let a join raise what a program requires") Signed-off-by: Alexei Starovoitov --- kernel/bpf/precision.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/bpf/precision.c b/kernel/bpf/precision.c index e6dfb9f4bd..33b180b35c 100644 --- a/kernel/bpf/precision.c +++ b/kernel/bpf/precision.c @@ -1645,6 +1645,9 @@ int bpf_partition_for_pessimized(struct bpf_verifier_env *env) prec->good_budget = prec->budget; for (i = 0; i < prec->loop_cnt; i++) prec->loops[i]->good = prec->loops[i]->precision; + /* bpf_partition_more() can fail before partition_next() makes this copy */ + if (prec->data_deps) + memcpy(prec->undo, prec->data_deps, 5 * prec->words * sizeof(long)); for (i = 0; i < env->prog->len; i++) if (env->insn_aux_data[i].pessimized) note_unproven_after_pass(env, i); -- 2.55.0