Files
chipsec-chipsec/drivers
Nicolas Iooss 9547b609b9 Simplify parsing /proc/kallsyms in Linux kernel module
While debugging issues on Linux systems using clang CFI (Control Flow
Integrity, `CONFIG_CFI_CLANG`), it appeared to me that
`chipsec_lookup_name` could be simplified.

- Instead of using `set_fs(KERNEL_DS);` to invoke read operations,
  `kernel_read` can directly be used. This function existed since at
  least Linux 2.4.0
  (https://elixir.bootlin.com/linux/2.4.0/source/fs/exec.c#L368) so
  there should not be compatibility issues.

- Instead of allocating a 128-byte buffer with `kmalloc`, use a stack
  buffer. While at it, fix a buffer overflow issue on systems with large
  symbol names such as ones using clang's CFI: some lines were 142
  characters long.

- Instead of matching anything on the line of `/proc/kallsyms` with
  `strstr`, only do prefix-matching on the start of the symbol name.
  This involves counting spaces in the line, in order to extract the
  name as the 3rd item.

- Last but not least, show a clear error message if the symbol is not
  found in /proc/kallsyms. This helps debugging issues.

While at it, add a comment which explains why reading `/proc/kallsyms`
does not work with Linux 5.10.
2021-05-27 10:26:38 -07:00
..
2020-01-16 08:59:09 -08:00