Commit 7fedb63
committed
bpf: Tighten speculative pointer arithmetic mask
This work tightens the offset mask we use for unprivileged pointer arithmetic
in order to mitigate a corner case reported by Piotr and Benedict where in
the speculative domain it is possible to advance, for example, the map value
pointer by up to value_size-1 out-of-bounds in order to leak kernel memory
via side-channel to user space.
Before this change, the computed ptr_limit for retrieve_ptr_limit() helper
represents largest valid distance when moving pointer to the right or left
which is then fed as aux->alu_limit to generate masking instructions against
the offset register. After the change, the derived aux->alu_limit represents
the largest potential value of the offset register which we mask against which
is just a narrower subset of the former limit.
For minimal complexity, we call sanitize_ptr_alu() from 2 observation points
in adjust_ptr_min_max_vals(), that is, before and after the simulated alu
operation. In the first step, we retieve the alu_state and alu_limit before
the operation as well as we branch-off a verifier path and push it to the
verification stack as we did before which checks the dst_reg under truncation,
in other words, when the speculative domain would attempt to move the pointer
out-of-bounds.
In the second step, we retrieve the new alu_limit and calculate the absolute
distance between both. Moreover, we commit the alu_state and final alu_limit
via update_alu_sanitation_state() to the env's instruction aux data, and bail
out from there if there is a mismatch due to coming from different verification
paths with different states.
Reported-by: Piotr Krysiuk <piotras@gmail.com>
Reported-by: Benedict Schlueter <benedict.schlueter@rub.de>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: John Fastabend <john.fastabend@gmail.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Tested-by: Benedict Schlueter <benedict.schlueter@rub.de>1 parent f528819 commit 7fedb63
1 file changed
Lines changed: 44 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5871 | 5871 | | |
5872 | 5872 | | |
5873 | 5873 | | |
5874 | | - | |
| 5874 | + | |
5875 | 5875 | | |
5876 | 5876 | | |
5877 | 5877 | | |
| |||
5880 | 5880 | | |
5881 | 5881 | | |
5882 | 5882 | | |
5883 | | - | |
| 5883 | + | |
| 5884 | + | |
| 5885 | + | |
5884 | 5886 | | |
5885 | 5887 | | |
5886 | | - | |
5887 | | - | |
5888 | | - | |
5889 | | - | |
5890 | | - | |
5891 | | - | |
5892 | | - | |
5893 | | - | |
| 5888 | + | |
5894 | 5889 | | |
5895 | 5890 | | |
5896 | 5891 | | |
5897 | | - | |
5898 | | - | |
5899 | | - | |
5900 | | - | |
5901 | | - | |
5902 | | - | |
| 5892 | + | |
| 5893 | + | |
| 5894 | + | |
5903 | 5895 | | |
5904 | 5896 | | |
5905 | 5897 | | |
| |||
5954 | 5946 | | |
5955 | 5947 | | |
5956 | 5948 | | |
5957 | | - | |
| 5949 | + | |
| 5950 | + | |
| 5951 | + | |
5958 | 5952 | | |
| 5953 | + | |
5959 | 5954 | | |
5960 | | - | |
5961 | 5955 | | |
5962 | 5956 | | |
5963 | 5957 | | |
| |||
5976 | 5970 | | |
5977 | 5971 | | |
5978 | 5972 | | |
5979 | | - | |
5980 | | - | |
5981 | | - | |
5982 | | - | |
5983 | 5973 | | |
5984 | 5974 | | |
5985 | 5975 | | |
5986 | 5976 | | |
| 5977 | + | |
| 5978 | + | |
| 5979 | + | |
| 5980 | + | |
| 5981 | + | |
| 5982 | + | |
| 5983 | + | |
| 5984 | + | |
| 5985 | + | |
| 5986 | + | |
| 5987 | + | |
| 5988 | + | |
5987 | 5989 | | |
5988 | 5990 | | |
5989 | 5991 | | |
5990 | 5992 | | |
| 5993 | + | |
| 5994 | + | |
| 5995 | + | |
| 5996 | + | |
| 5997 | + | |
| 5998 | + | |
| 5999 | + | |
5991 | 6000 | | |
5992 | 6001 | | |
5993 | 6002 | | |
| |||
6130 | 6139 | | |
6131 | 6140 | | |
6132 | 6141 | | |
| 6142 | + | |
6133 | 6143 | | |
6134 | 6144 | | |
6135 | 6145 | | |
| |||
6196 | 6206 | | |
6197 | 6207 | | |
6198 | 6208 | | |
6199 | | - | |
6200 | | - | |
6201 | | - | |
| 6209 | + | |
| 6210 | + | |
| 6211 | + | |
6202 | 6212 | | |
6203 | 6213 | | |
| 6214 | + | |
6204 | 6215 | | |
| 6216 | + | |
| 6217 | + | |
6205 | 6218 | | |
6206 | 6219 | | |
6207 | 6220 | | |
| |||
6252 | 6265 | | |
6253 | 6266 | | |
6254 | 6267 | | |
6255 | | - | |
6256 | | - | |
6257 | | - | |
6258 | | - | |
6259 | 6268 | | |
6260 | 6269 | | |
6261 | 6270 | | |
| |||
6338 | 6347 | | |
6339 | 6348 | | |
6340 | 6349 | | |
| 6350 | + | |
| 6351 | + | |
| 6352 | + | |
| 6353 | + | |
| 6354 | + | |
| 6355 | + | |
6341 | 6356 | | |
6342 | 6357 | | |
6343 | 6358 | | |
| |||
0 commit comments