Skip to content

Commit a703619

Browse files
committed
bpf: No need to simulate speculative domain for immediates
In 801c605 ("bpf: Fix leakage of uninitialized bpf stack under speculation") we replaced masking logic with direct loads of immediates if the register is a known constant. Given in this case we do not apply any masking, there is also no reason for the operation to be truncated under the speculative domain. Therefore, there is also zero reason for the verifier to branch-off and simulate this case, it only needs to do it for unknown but bounded scalars. As a side-effect, this also enables few test cases that were previously rejected due to simulation under zero truncation. Signed-off-by: Daniel Borkmann <[email protected]> Reviewed-by: Piotr Krysiuk <[email protected]> Acked-by: Alexei Starovoitov <[email protected]>
1 parent bb01a1b commit a703619

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

kernel/bpf/verifier.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6545,8 +6545,12 @@ static int sanitize_ptr_alu(struct bpf_verifier_env *env,
65456545
/* If we're in commit phase, we're done here given we already
65466546
* pushed the truncated dst_reg into the speculative verification
65476547
* stack.
6548+
*
6549+
* Also, when register is a known constant, we rewrite register-based
6550+
* operation to immediate-based, and thus do not need masking (and as
6551+
* a consequence, do not need to simulate the zero-truncation either).
65486552
*/
6549-
if (commit_window)
6553+
if (commit_window || off_is_imm)
65506554
return 0;
65516555

65526556
/* Simulate and find potential out-of-bounds access under

0 commit comments

Comments
 (0)