Commit ef4e68f
bpf: Tighten speculative pointer arithmetic mask
commit 7fedb63 upstream.
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>
[fllinden@amazon.com: backported to 5.4]
Signed-off-by: Frank van der Linden <fllinden@amazon.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>1 parent 4dc6e55 commit ef4e68f
1 file changed
Lines changed: 44 additions & 29 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4278 | 4278 | | |
4279 | 4279 | | |
4280 | 4280 | | |
4281 | | - | |
| 4281 | + | |
4282 | 4282 | | |
4283 | 4283 | | |
4284 | 4284 | | |
| |||
4287 | 4287 | | |
4288 | 4288 | | |
4289 | 4289 | | |
4290 | | - | |
| 4290 | + | |
| 4291 | + | |
| 4292 | + | |
4291 | 4293 | | |
4292 | 4294 | | |
4293 | | - | |
4294 | | - | |
4295 | | - | |
4296 | | - | |
4297 | | - | |
4298 | | - | |
4299 | | - | |
4300 | | - | |
| 4295 | + | |
4301 | 4296 | | |
4302 | 4297 | | |
4303 | 4298 | | |
4304 | | - | |
4305 | | - | |
4306 | | - | |
4307 | | - | |
4308 | | - | |
4309 | | - | |
| 4299 | + | |
| 4300 | + | |
| 4301 | + | |
4310 | 4302 | | |
4311 | 4303 | | |
4312 | 4304 | | |
| |||
4361 | 4353 | | |
4362 | 4354 | | |
4363 | 4355 | | |
4364 | | - | |
| 4356 | + | |
| 4357 | + | |
| 4358 | + | |
4365 | 4359 | | |
| 4360 | + | |
4366 | 4361 | | |
4367 | | - | |
4368 | 4362 | | |
4369 | 4363 | | |
4370 | 4364 | | |
| |||
4383 | 4377 | | |
4384 | 4378 | | |
4385 | 4379 | | |
4386 | | - | |
4387 | | - | |
4388 | | - | |
4389 | | - | |
4390 | 4380 | | |
4391 | 4381 | | |
4392 | 4382 | | |
4393 | 4383 | | |
| 4384 | + | |
| 4385 | + | |
| 4386 | + | |
| 4387 | + | |
| 4388 | + | |
| 4389 | + | |
| 4390 | + | |
| 4391 | + | |
| 4392 | + | |
| 4393 | + | |
| 4394 | + | |
| 4395 | + | |
4394 | 4396 | | |
4395 | 4397 | | |
4396 | 4398 | | |
4397 | 4399 | | |
| 4400 | + | |
| 4401 | + | |
| 4402 | + | |
| 4403 | + | |
| 4404 | + | |
| 4405 | + | |
| 4406 | + | |
4398 | 4407 | | |
4399 | 4408 | | |
4400 | 4409 | | |
| |||
4506 | 4515 | | |
4507 | 4516 | | |
4508 | 4517 | | |
| 4518 | + | |
4509 | 4519 | | |
4510 | 4520 | | |
4511 | 4521 | | |
| |||
4564 | 4574 | | |
4565 | 4575 | | |
4566 | 4576 | | |
4567 | | - | |
4568 | | - | |
4569 | | - | |
| 4577 | + | |
| 4578 | + | |
| 4579 | + | |
4570 | 4580 | | |
4571 | 4581 | | |
| 4582 | + | |
4572 | 4583 | | |
| 4584 | + | |
| 4585 | + | |
4573 | 4586 | | |
4574 | 4587 | | |
4575 | 4588 | | |
| |||
4620 | 4633 | | |
4621 | 4634 | | |
4622 | 4635 | | |
4623 | | - | |
4624 | | - | |
4625 | | - | |
4626 | | - | |
4627 | 4636 | | |
4628 | 4637 | | |
4629 | 4638 | | |
| |||
4706 | 4715 | | |
4707 | 4716 | | |
4708 | 4717 | | |
| 4718 | + | |
| 4719 | + | |
| 4720 | + | |
| 4721 | + | |
| 4722 | + | |
| 4723 | + | |
4709 | 4724 | | |
4710 | 4725 | | |
4711 | 4726 | | |
| |||
0 commit comments