powerpc/code-patching: Use dedicated memory routines for patching
authorBenjamin Gray <bgray@linux.ibm.com>
Mon, 25 Mar 2024 05:28:15 +0000 (16:28 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 7 May 2024 14:35:42 +0000 (00:35 +1000)
commitc3710ee7cd695dc1b0b4b8cfbf464e313467f970
tree28ec95cd53817160e1a24fa032da55b2bd71fe6b
parentc5ef5e35844ad30503c49802b9d6a6c818fca886
powerpc/code-patching: Use dedicated memory routines for patching

The patching page set up as a writable alias may be in quadrant 0
(userspace) if the temporary mm path is used. This causes sanitiser
failures if so. Sanitiser failures also occur on the non-mm path
because the plain memset family is instrumented, and KASAN treats the
patching window as poisoned.

Introduce locally defined patch_* variants of memset that perform an
uninstrumented lower level set, as well as detecting write errors like
the original single patch variant does.

copy_to_user() is not correct here, as the PTE makes it a proper kernel
page (the EAA is privileged access only, RW). It just happens to be in
quadrant 0 because that's the hardware's mechanism for using the current
PID vs PID 0 in translations. Importantly, it's incorrect to allow user
page accesses.

Now that the patching memsets are used, we also propagate a failure up
to the caller as the single patch variant does.

Signed-off-by: Benjamin Gray <bgray@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/20240325052815.854044-2-bgray@linux.ibm.com
arch/powerpc/lib/code-patching.c