]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
[ia64] sanitize elf_access_gpreg()
authorAl Viro <viro@zeniv.linux.org.uk>
Sat, 6 Jun 2020 21:55:02 +0000 (17:55 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 26 Jun 2020 05:01:53 +0000 (01:01 -0400)
commit4c35bf3ae948d6232f3d2c6fbf2008c341490683
treee1ef8e207e0f24d0729b2b5daf8f221d1e6e3b39
parentb3a9e3b9622ae10064826dccb4f7a52bd88c7407
[ia64] sanitize elf_access_gpreg()

The function takes the register number, finds the corresponding field
of pt_regs for registers that are saved there or does the unwind for the
registers that end up spilled on the kernel stack.  Then it reads from
or writes to the resulting location.

Unfortunately, finding the required pt_regs field is done by rather
horrible switch.  It's microoptimized in all the wrong places - it
even uses the knowledge that fields for r8..r11 follow each other
in pt_regs layout, while r12..r13 are not adjacent to those, etc.

All of that is to encode the mapping from register numbers to offsets +
the information that r4..r7 are not to be found in pt_regs.

It's deeply in nasal demon territory, at that - the games it plays
with pointer arithmetics on addresses of structure members are
undefined behaviour.

Valid C ends up with better code in this case: just initialize a constant
array with offsets of relevant pt_regs fields and we don't need that
switch anymore.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
arch/ia64/kernel/ptrace.c