Commit 1c66f4a
bpf: Fix state use-after-free on push_stack() err
Without this, `state->speculative` is used after the cleanup cycles in
push_stack() or push_async_cb() freed `env->cur_state` (i.e., `state`).
Avoid this by relying on the short-circuit logic to only access `state`
if the error is recoverable (and make sure it never is after push_*()
failed).
push_*() callers must always return an error for which
error_recoverable_with_nospec(err) is false if push_*() returns NULL,
otherwise we try to recover and access the stale `state`. This is only
violated by sanitize_ptr_alu(), thus also fix this case to return
-ENOMEM.
state->speculative does not make sense if the error path of push_*()
ran. In that case, `state->speculative &&
error_recoverable_with_nospec(err)` as a whole should already never
evaluate to true (because all cases where push_stack() fails must return
-ENOMEM/-EFAULT). As mentioned, this is only violated by the
push_stack() call in sanitize_speculative_path() which returns -EACCES
without [1] (through REASON_STACK in sanitize_err() after
sanitize_ptr_alu()). To fix this, return -ENOMEM for REASON_STACK (which
is also the behavior we will have after [1]).
Checked that it fixes the syzbot reproducer as expected.
[1] https://lore.kernel.org/all/[email protected]/
Fixes: d6f1c85 ("bpf: Fall back to nospec for Spectre v1")
Reported-by: [email protected]
Reported-by: Eduard Zingerman <[email protected]>
Link: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Luis Gerhorst <[email protected]>
Acked-by: Eduard Zingerman <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexei Starovoitov <[email protected]>1 parent 05e2249 commit 1c66f4a
1 file changed
+2
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14293 | 14293 | | |
14294 | 14294 | | |
14295 | 14295 | | |
14296 | | - | |
| 14296 | + | |
14297 | 14297 | | |
14298 | 14298 | | |
14299 | 14299 | | |
| |||
19926 | 19926 | | |
19927 | 19927 | | |
19928 | 19928 | | |
19929 | | - | |
| 19929 | + | |
19930 | 19930 | | |
19931 | 19931 | | |
19932 | 19932 | | |
| |||
0 commit comments