summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAlexei Starovoitov <ast@kernel.org>2026-04-02 18:23:25 -0700
committerAlexei Starovoitov <ast@kernel.org>2026-04-02 18:23:26 -0700
commit6f6c794d0ff05dab1fa4677f39043de8a6a80da3 (patch)
treec3d3a2e0538b64a9ea27fcc87caac932aee713a7 /include
parent7e85ca02ef3aa2f37ce6dbba820f55b385330ce9 (diff)
parent7cbded6ed98f363cc7fa84304da1f03eefa03f67 (diff)
Merge branch 'fix-invariant-violations-and-improve-branch-detection'
Paul Chaignon says: ==================== Fix invariant violations and improve branch detection This patchset fixes invariant violations on register bounds. These invariant violations cause a warning and happen when reg_bounds_sync is trying to refine register bounds while walking an impossible branch. This patchset takes this situation as an opportunity to improve verification performance. That is, the verifier will use the invariant violations as a signal that a branch cannot be taken and process it as dead code. This patchset implements this approach and covers it in selftests with a new invariant violation case. Some of the logic in reg_bounds_sync likely acts as a duplicate with logic from is_scalar_branch_taken. This patchset does not attempt to remove superfluous logic from is_scalar_branch_taken and leaves it to a future patchset (ex. once syzbot has confirmed that all invariant violations are fixed). In the future, there is also a potential opportunity to simplify existing logic by merging reg_bounds_sync and range_bounds_violation (have reg_bounds_sync error out on invariant violation). That is however not needed to fix invariant violation, which we focus on in this patchset. Changes in v3: - Rename and refactor the helper functions checking for tnum-related invariant violations (Mykyta). - Small changes to comment style in verifier changes and new selftest (Mykyta). - Rebased. Changes in v2: - Moved tmp registers to env in preparatory commit (Eduard). - Updated reg_bounds_sync to bail out in case of ill-formed registers, thus avoiding one set of invariant violation checks in simulate_both_branches_taken (Eduard). - Drop the Fixes tag to avoid misleading backporters (Shung-Hsi). - Improve wording of commit descriptions (Shung-Hsi, Hari). - Fix error in code comments (AI bot). - Rebased. ==================== Link: https://patch.msgid.link/cover.1775142354.git.paul.chaignon@gmail.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'include')
-rw-r--r--include/linux/bpf_verifier.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 090aa26d1c98..b129e0aaee20 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -837,7 +837,9 @@ struct bpf_verifier_env {
u64 scratched_stack_slots;
u64 prev_log_pos, prev_insn_print_pos;
/* buffer used to temporary hold constants as scalar registers */
- struct bpf_reg_state fake_reg[2];
+ struct bpf_reg_state fake_reg[1];
+ /* buffers used to save updated reg states while simulating branches */
+ struct bpf_reg_state true_reg1, true_reg2, false_reg1, false_reg2;
/* buffer used to generate temporary string representations,
* e.g., in reg_type_str() to generate reg_type string
*/