From: Alexei Starovoitov Date: Mon, 7 Jul 2025 15:32:34 +0000 (-0700) Subject: Merge branch 'bpf-fix-and-test-aux-usage-after-do_check_insn' X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df4b1eebd8d1985d2016bc02fe3ea27c2e628e56;p=thirdparty%2Flinux.git Merge branch 'bpf-fix-and-test-aux-usage-after-do_check_insn' Luis Gerhorst says: ==================== bpf: Fix and test aux usage after do_check_insn() Fix cur_aux()->nospec_result test after do_check_insn() referring to the to-be-analyzed (potentially unsafe) instruction, not the already-analyzed (safe) instruction. This might allow a unsafe insn to slip through on a speculative path. Create some tests from the reproducer [1]. Commit d6f1c85f2253 ("bpf: Fall back to nospec for Spectre v1") should not be in any stable kernel yet, therefore bpf-next should suffice. [1] https://lore.kernel.org/bpf/685b3c1b.050a0220.2303ee.0010.GAE@google.com/ Changes since v2: - Use insn_aux variable instead of introducing prev_aux() as suggested by Eduard (and therefore also drop patch 1) - v2: https://lore.kernel.org/bpf/20250628145016.784256-1-luis.gerhorst@fau.de/ Changes since v1: - Fix compiler error due to missed rename of prev_insn_idx in first patch - v1: https://lore.kernel.org/bpf/20250628125927.763088-1-luis.gerhorst@fau.de/ Changes since RFC: - Introduce prev_aux() as suggested by Alexei. For this, we must move the env->prev_insn_idx assignment to happen directly after do_check_insn(), for which I have created a separate commit. This patch could be simplified by using a local prev_aux variable as sugested by Eduard, but I figured one might find the new assignment-strategy easier to understand (before, prev_insn_idx and env->prev_insn_idx were out-of-sync for the latter part of the loop). Also, like this we do not have an additional prev_* variable that must be kept in-sync and the local variable's usage (old prev_insn_idx, new tmp) is much more local. If you think it would be better to not take the risk and keep the fix simple by just introducing the prev_aux variable, let me know. - Change WARN_ON_ONCE() to verifier_bug_if() as suggested by Alexei - Change assertion to check instruction is BPF_JMP[32] as suggested by Eduard - RFC: https://lore.kernel.org/bpf/8734bmoemx.fsf@fau.de/ ==================== Link: https://patch.msgid.link/20250705190908.1756862-1-luis.gerhorst@fau.de Signed-off-by: Alexei Starovoitov --- df4b1eebd8d1985d2016bc02fe3ea27c2e628e56