Commit caedc19
bpf: Fall back to nospec for sanitization-failures
ALU sanitization was introduced to ensure that a subsequent ptr access
can never go OOB, even under speculation. This is required because we
currently allow speculative scalar confusion. Spec. scalar confusion is
possible because Spectre v4 sanitization only adds a nospec after
critical stores (e.g., scalar overwritten with a pointer).
If we add a nospec before the ALU op, none of the operands can be
subject to scalar confusion. As an ADD/SUB can not introduce scalar
confusion itself, the result will also not be subject to scalar
confusion. Therefore, the subsequent ptr access is always safe.
We directly fall back to nospec for the sanitization errors
REASON_BOUNDS, _TYPE, _PATHS, and _LIMIT, even if we are not on a
speculative path. For REASON_STACK, we return the error directly now.
Decided to directly set cur_aux(env)->nospec to implement the fallback
instead of (conceptually) making the nospec part of the ALU sanitization
state and therefore potentially dragging it through info.aux before
copying it over into cur_aux(env). This has the drawback that the usage
of cur_aux(env) and aux in these functions might be confusing, but it
has the upside that it does not needlessly complicate the dataflow for
nospec. Also the presence of cur_aux() might make it more obvious that
aux might not equal cur_aux() here. In the commit window,
sanitize_ptr_alu() will bail out early because can_skip_alu_sanitation()
checks cur_aux(env)->nospec.
Regarding commit 97744b4 ("bpf: Clarify sanitize_check_bounds()"),
having the assertion trigger if alu_state is set on a non-speculative
path makes the most sense, because the masking would truncate the bounds
on that path when executed and sanitize_check_bounds() exists to ensure
this trucation does not happen. Two cases are relevant:
- First, if a case in sanitize_check_bounds() is omitted, it fails with
EOPNOTSUPP but retrieve_ptr_limit() returns 0 (thereby potentially not
setting cur_aux(env)->nospec instead of setting alu_state). With the
old/new assertion, this is cought.
- Second, if a case is omitted from retrieve_ptr_limit() but not from
sanitize_check_bounds(), bounds_ret equals 0 or -EACCES. If it is 0
and the default case in retrieve_ptr_limit() runs errorously, we mark
the insn for nospec-sanitization. This is not really a security
problem and it could also only be detected by adding a
verifier_bug_if(bounds_ret != -EOPNOTSUPP) into the default case in
retrieve_ptr_limit(). It is not cought by the old/new assertion.
Because it remove the possibility for these errors altogether, this
change also fixes some unwarranted test failures on architectures that
have bpf_jit_bypass_spec_v1 set (e.g., LoongArch).
Signed-off-by: Luis Gerhorst <[email protected]>
Acked-by: Kumar Kartikeya Dwivedi <[email protected]>
Acked-by: Henriette Herzog <[email protected]>
Cc: Hengqi Chen <[email protected]>1 parent ce3f403 commit caedc19
File tree
5 files changed
+180
-115
lines changed- kernel/bpf
- tools/testing/selftests/bpf/progs
5 files changed
+180
-115
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14195 | 14195 | | |
14196 | 14196 | | |
14197 | 14197 | | |
14198 | | - | |
14199 | | - | |
14200 | | - | |
14201 | | - | |
14202 | | - | |
14203 | | - | |
14204 | | - | |
14205 | | - | |
14206 | 14198 | | |
14207 | 14199 | | |
14208 | 14200 | | |
| |||
14225 | 14217 | | |
14226 | 14218 | | |
14227 | 14219 | | |
14228 | | - | |
| 14220 | + | |
| 14221 | + | |
14229 | 14222 | | |
14230 | 14223 | | |
| 14224 | + | |
14231 | 14225 | | |
14232 | | - | |
| 14226 | + | |
14233 | 14227 | | |
14234 | 14228 | | |
14235 | 14229 | | |
| |||
14242 | 14236 | | |
14243 | 14237 | | |
14244 | 14238 | | |
14245 | | - | |
14246 | | - | |
| 14239 | + | |
| 14240 | + | |
| 14241 | + | |
14247 | 14242 | | |
14248 | 14243 | | |
14249 | 14244 | | |
14250 | 14245 | | |
14251 | 14246 | | |
14252 | 14247 | | |
14253 | | - | |
14254 | | - | |
| 14248 | + | |
| 14249 | + | |
| 14250 | + | |
| 14251 | + | |
| 14252 | + | |
| 14253 | + | |
| 14254 | + | |
| 14255 | + | |
14255 | 14256 | | |
14256 | 14257 | | |
14257 | 14258 | | |
14258 | 14259 | | |
14259 | | - | |
14260 | 14260 | | |
14261 | 14261 | | |
14262 | | - | |
14263 | | - | |
| 14262 | + | |
| 14263 | + | |
14264 | 14264 | | |
14265 | 14265 | | |
14266 | 14266 | | |
14267 | 14267 | | |
14268 | | - | |
| 14268 | + | |
14269 | 14269 | | |
14270 | | - | |
| 14270 | + | |
14271 | 14271 | | |
14272 | 14272 | | |
14273 | 14273 | | |
| |||
14332 | 14332 | | |
14333 | 14333 | | |
14334 | 14334 | | |
14335 | | - | |
14336 | | - | |
| 14335 | + | |
| 14336 | + | |
| 14337 | + | |
| 14338 | + | |
| 14339 | + | |
| 14340 | + | |
| 14341 | + | |
| 14342 | + | |
14337 | 14343 | | |
14338 | 14344 | | |
14339 | 14345 | | |
14340 | 14346 | | |
14341 | 14347 | | |
14342 | 14348 | | |
14343 | | - | |
14344 | | - | |
| 14349 | + | |
| 14350 | + | |
| 14351 | + | |
| 14352 | + | |
| 14353 | + | |
| 14354 | + | |
| 14355 | + | |
| 14356 | + | |
| 14357 | + | |
14345 | 14358 | | |
14346 | 14359 | | |
14347 | 14360 | | |
| |||
14362 | 14375 | | |
14363 | 14376 | | |
14364 | 14377 | | |
14365 | | - | |
14366 | | - | |
14367 | | - | |
| 14378 | + | |
14368 | 14379 | | |
14369 | 14380 | | |
14370 | 14381 | | |
| |||
14373 | 14384 | | |
14374 | 14385 | | |
14375 | 14386 | | |
| 14387 | + | |
14376 | 14388 | | |
14377 | | - | |
| 14389 | + | |
14378 | 14390 | | |
14379 | 14391 | | |
14380 | 14392 | | |
| |||
14394 | 14406 | | |
14395 | 14407 | | |
14396 | 14408 | | |
14397 | | - | |
| 14409 | + | |
14398 | 14410 | | |
14399 | 14411 | | |
14400 | 14412 | | |
| |||
14410 | 14422 | | |
14411 | 14423 | | |
14412 | 14424 | | |
14413 | | - | |
14414 | | - | |
14415 | | - | |
14416 | | - | |
14417 | | - | |
14418 | | - | |
14419 | | - | |
14420 | | - | |
14421 | | - | |
14422 | | - | |
14423 | | - | |
14424 | | - | |
14425 | | - | |
14426 | | - | |
14427 | | - | |
14428 | | - | |
14429 | | - | |
14430 | | - | |
14431 | | - | |
14432 | | - | |
14433 | | - | |
14434 | | - | |
14435 | | - | |
14436 | | - | |
14437 | | - | |
14438 | | - | |
14439 | | - | |
14440 | | - | |
14441 | | - | |
14442 | | - | |
14443 | | - | |
14444 | | - | |
14445 | | - | |
14446 | | - | |
14447 | | - | |
14448 | | - | |
14449 | | - | |
14450 | | - | |
14451 | 14425 | | |
14452 | 14426 | | |
14453 | 14427 | | |
| |||
14620 | 14594 | | |
14621 | 14595 | | |
14622 | 14596 | | |
14623 | | - | |
| 14597 | + | |
14624 | 14598 | | |
14625 | 14599 | | |
14626 | 14600 | | |
| |||
14748 | 14722 | | |
14749 | 14723 | | |
14750 | 14724 | | |
14751 | | - | |
14752 | | - | |
14753 | | - | |
14754 | | - | |
14755 | | - | |
14756 | | - | |
14757 | | - | |
14758 | 14725 | | |
14759 | | - | |
| 14726 | + | |
| 14727 | + | |
| 14728 | + | |
| 14729 | + | |
| 14730 | + | |
| 14731 | + | |
| 14732 | + | |
| 14733 | + | |
14760 | 14734 | | |
14761 | 14735 | | |
14762 | 14736 | | |
| |||
15385 | 15359 | | |
15386 | 15360 | | |
15387 | 15361 | | |
15388 | | - | |
15389 | | - | |
15390 | | - | |
| 15362 | + | |
15391 | 15363 | | |
15392 | 15364 | | |
15393 | 15365 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
| |||
Lines changed: 29 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
25 | | - | |
| 25 | + | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| |||
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
43 | | - | |
| 47 | + | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
49 | | - | |
| 53 | + | |
| 54 | + | |
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
53 | 58 | | |
54 | 59 | | |
55 | 60 | | |
56 | | - | |
57 | | - | |
| 61 | + | |
58 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
59 | 67 | | |
60 | 68 | | |
61 | 69 | | |
| |||
73 | 81 | | |
74 | 82 | | |
75 | 83 | | |
76 | | - | |
| 84 | + | |
77 | 85 | | |
78 | 86 | | |
79 | 87 | | |
80 | 88 | | |
81 | 89 | | |
| 90 | + | |
82 | 91 | | |
83 | 92 | | |
84 | 93 | | |
| |||
87 | 96 | | |
88 | 97 | | |
89 | 98 | | |
90 | | - | |
| 99 | + | |
91 | 100 | | |
92 | 101 | | |
93 | 102 | | |
94 | 103 | | |
95 | 104 | | |
96 | 105 | | |
97 | | - | |
| 106 | + | |
| 107 | + | |
98 | 108 | | |
99 | 109 | | |
100 | 110 | | |
101 | 111 | | |
102 | 112 | | |
103 | 113 | | |
104 | 114 | | |
105 | | - | |
| 115 | + | |
106 | 116 | | |
107 | 117 | | |
108 | 118 | | |
109 | 119 | | |
110 | 120 | | |
111 | 121 | | |
112 | | - | |
| 122 | + | |
| 123 | + | |
113 | 124 | | |
114 | 125 | | |
115 | 126 | | |
| |||
121 | 132 | | |
122 | 133 | | |
123 | 134 | | |
124 | | - | |
| 135 | + | |
125 | 136 | | |
126 | 137 | | |
127 | 138 | | |
128 | 139 | | |
129 | 140 | | |
130 | 141 | | |
| 142 | + | |
131 | 143 | | |
132 | 144 | | |
133 | 145 | | |
| |||
140 | 152 | | |
141 | 153 | | |
142 | 154 | | |
143 | | - | |
| 155 | + | |
144 | 156 | | |
145 | 157 | | |
146 | 158 | | |
147 | 159 | | |
148 | 160 | | |
149 | | - | |
| 161 | + | |
| 162 | + | |
150 | 163 | | |
151 | 164 | | |
152 | 165 | | |
| |||
0 commit comments