Commit 415f1f4
bpf: Allow nospec-protected var-offset stack access
Insert a nospec before the access to prevent it from ever using an index
that is subject to speculative scalar-confusion.
The access itself can either happen directly in the BPF program (reads
only, check_stack_read_var_off()) or in a helper (read/write,
check_helper_mem_access()).
This relies on the fact that the speculative scalar confusion that leads
to the variable-stack access going OOBs must stem from a prior
speculative store or branch bypass. Adding a nospec before the
variable-stack access will force all previously bypassed stores/branches
to complete and cause the stack access to only ever go to the stack slot
that is accessed architecturally.
Alternatively, the variable-offset stack access might be a write that
can itself be subject to speculative store bypass (this can happen in
theory even if this code adds a nospec /before/ the variable-offset
write). Only indirect writes by helpers might be affected here (e.g.,
those taking ARG_PTR_TO_MAP_VALUE). (Because check_stack_write_var_off()
does not use check_stack_range_initialized(), in-program variable-offset
writes are not affected.) If the in-helper write can be subject to
Spectre v4 and the helper writes/overwrites pointers on the BPF stack,
they are already a problem for fixed-offset stack accesses and should be
subject to Spectre v4 sanitization.
Signed-off-by: Luis Gerhorst <[email protected]>
Acked-by: Henriette Herzog <[email protected]>
Cc: Maximilian Ott <[email protected]>
Cc: Milan Stephan <[email protected]>1 parent add0fbb commit 415f1f4
1 file changed
+12
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7894 | 7894 | | |
7895 | 7895 | | |
7896 | 7896 | | |
| 7897 | + | |
| 7898 | + | |
| 7899 | + | |
| 7900 | + | |
| 7901 | + | |
7897 | 7902 | | |
7898 | 7903 | | |
7899 | 7904 | | |
| |||
7933 | 7938 | | |
7934 | 7939 | | |
7935 | 7940 | | |
7936 | | - | |
| 7941 | + | |
7937 | 7942 | | |
7938 | 7943 | | |
7939 | 7944 | | |
7940 | 7945 | | |
7941 | 7946 | | |
7942 | | - | |
7943 | | - | |
7944 | | - | |
7945 | | - | |
7946 | | - | |
7947 | | - | |
| 7947 | + | |
| 7948 | + | |
| 7949 | + | |
| 7950 | + | |
| 7951 | + | |
| 7952 | + | |
7948 | 7953 | | |
7949 | 7954 | | |
7950 | 7955 | | |
| |||
11172 | 11177 | | |
11173 | 11178 | | |
11174 | 11179 | | |
11175 | | - | |
11176 | | - | |
11177 | | - | |
11178 | | - | |
11179 | | - | |
11180 | 11180 | | |
11181 | 11181 | | |
11182 | 11182 | | |
| |||
0 commit comments