Files
Nicolas Iooss 4599981389 Use copy_from_kernel_nofault when reading physical memory
Currently Linux driver uses `memcpy` when reading physical memory. This
causes a kernel panic on some systems when trying to access "forbidden"
physical memory. The Linux kernel provides function
`copy_from_kernel_nofault` (previously named `probe_kernel_read`) to read
memory without crashing (and this function is used by the implementation
of `/dev/mem`).

Replace `memcpy` with `copy_from_kernel_nofault`, providing a simple
wrapper for older kernels.

While at it:
- Move the allocation of a bounce buffer outside of the while loop. As
  memory is always read one page at a time, a `PAGE_SIZE` buffer is
  enough.
- Use `size_t` as the type of `sz` instead of the signed type `ssize_t`.
- Replace calls to `min_t` with `if` statements which are easier to read.
- Name the number of written bytes `written` instead of `read`, in
  `write_mem`.
- Remove stray spaces in various places.

By the way, the `write_mem` function was not updated to use
`copy_to_kernel_nofault`, as this function has no longer been exported
since Linux 5.8.

Fixes: https://github.com/chipsec/chipsec/issues/1094
Signed-off-by: Nicolas Iooss <nicolas.iooss_git@polytechnique.org>
2022-01-10 15:04:33 -08:00
..
2020-01-16 08:59:09 -08:00