Skip to content

Commit e8583af

Browse files
borkmannSomasundaram Krishnasamy
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]> (cherry picked from commit 6a87d309fefaabc18f694bd6d52bb3160557e4a9)
1 parent b906dd4 commit e8583af

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
@@ -2177,8 +2177,12 @@ static int sanitize_ptr_alu(struct bpf_verifier_env *env,
21772177
/* If we're in commit phase, we're done here given we already
21782178
* pushed the truncated dst_reg into the speculative verification
21792179
* stack.
2180+
*
2181+
* Also, when register is a known constant, we rewrite register-based
2182+
* operation to immediate-based, and thus do not need masking (and as
2183+
* a consequence, do not need to simulate the zero-truncation either).
21802184
*/
2181-
if (commit_window)
2185+
if (commit_window || off_is_imm)
21822186
return 0;
21832187

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

0 commit comments

Comments
 (0)