From: Alexei Starovoitov If a check fails on a speculative path, do_check() adds a nospec before the insn and ends the path. The check can have written nospec_result and ctx_field_size of the insn already. The other paths can use the insn with another type of pointer, so these values do not apply to them. Save both fields before the check and restore them. Fixes: d6f1c85f2253 ("bpf: Fall back to nospec for Spectre v1") Signed-off-by: Alexei Starovoitov --- kernel/bpf/verifier.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index d4b31990fcb9..c553e1533ace 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -20649,7 +20649,8 @@ static int do_check(struct bpf_verifier_env *env) for (;;) { struct bpf_insn *insn; struct bpf_insn_aux_data *insn_aux; - int err; + int err, ctx_field_size; + bool nospec_result; if (signal_pending(current)) return -EAGAIN; @@ -20802,6 +20803,8 @@ static int do_check(struct bpf_verifier_env *env) if (state->speculative && insn_aux->nospec) goto process_bpf_exit; + nospec_result = insn_aux->nospec_result; + ctx_field_size = insn_aux->ctx_field_size; err = do_check_insn(env, &do_print_state); if (error_recoverable_with_nospec(err) && state->speculative) { /* Prevent this speculative path from ever reaching the @@ -20812,6 +20815,8 @@ static int do_check(struct bpf_verifier_env *env) * markings for alu sanitization. */ insn_aux->alu_state = 0; + insn_aux->nospec_result = nospec_result; + insn_aux->ctx_field_size = ctx_field_size; goto process_bpf_exit; } else if (err < 0) { return err; -- 2.55.0