Skip to content

Commit 27acfd1

Browse files
borkmanngregkh
authored andcommitted
bpf: No need to simulate speculative domain for immediates
commit a703619 upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c87ef24 commit 27acfd1

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
@@ -5802,8 +5802,12 @@ static int sanitize_ptr_alu(struct bpf_verifier_env *env,
58025802
/* If we're in commit phase, we're done here given we already
58035803
* pushed the truncated dst_reg into the speculative verification
58045804
* stack.
5805+
*
5806+
* Also, when register is a known constant, we rewrite register-based
5807+
* operation to immediate-based, and thus do not need masking (and as
5808+
* a consequence, do not need to simulate the zero-truncation either).
58055809
*/
5806-
if (commit_window)
5810+
if (commit_window || off_is_imm)
58075811
return 0;
58085812

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

0 commit comments

Comments
 (0)