From: Nicholas Piggin <npiggin@gmail.com> Date: 2021-11-26 03:23:41
Code patching tests patch the stack and (non-module) vmalloc space now,
which falls afoul of the new address check.
The stack patching can easily be fixed, but the vmalloc patching is more
difficult. For now, add an ugly workaround to skip the check while the
test code is running.
Fixes: 8b8a8f0ab3f55 ("powerpc/code-patching: Improve verification of patchability")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/lib/code-patching.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
From: Nicholas Piggin <npiggin@gmail.com> Date: 2021-11-26 03:24:18
Callers are supposed to handle this, but it is possible that they
don't or they do but don't make much noise about it. A failure is
probably an indication of a bigger problem somewhere so it is good
to warn once about it.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/lib/code-patching.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
From: Nicholas Piggin <npiggin@gmail.com> Date: 2021-11-26 03:24:55
Use the existing test function for code patching tests instead of
writing to the stack. This means the address verification does not have
to be bypassed for these tests.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/lib/code-patching.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)
@@ -422,9 +422,11 @@ static void __init test_branch_iform(void){interr;structppc_instinstr;-u32tmp[2];-u32*iptr=tmp;-unsignedlongaddr=(unsignedlong)tmp;+u32*iptr;+unsignedlongaddr;++iptr=(u32*)ppc_function_entry(test_trampoline);+addr=(unsignedlong)iptr;/* The simplest case, branch to self, no flags */check(instr_is_branch_iform(ppc_inst(0x48000000)));
@@ -516,12 +518,12 @@ static void __init test_create_function_call(void)staticvoid__inittest_branch_bform(void){interr;-unsignedlongaddr;structppc_instinstr;-u32tmp[2];-u32*iptr=tmp;+u32*iptr;+unsignedlongaddr;unsignedintflags;+iptr=(u32*)ppc_function_entry(test_trampoline);addr=(unsignedlong)iptr;/* The simplest case, branch to self, no flags */
@@ -603,6 +605,12 @@ static void __init test_translate_branch(void)if(!buf)return;+/*+*Havetodisabletheaddressboundscheckforpatch_instruction+*becausewearepatchingvmallocspacehere.+*/+skip_addr_verif=true;+/* Simple case, branch to self moved a little */p=buf;addr=(unsignedlong)p;
@@ -715,6 +723,8 @@ static void __init test_translate_branch(void)check(instr_is_branch_to_addr(p,addr));check(instr_is_branch_to_addr(q,addr));+skip_addr_verif=false;+/* Free the buffer we were using */vfree(buf);}
Code patching tests patch the stack and (non-module) vmalloc space now,
which falls afoul of the new address check.
The stack patching can easily be fixed, but the vmalloc patching is more
difficult. For now, add an ugly workaround to skip the check while the
test code is running.
This really looks hacky.
To skip the test, you can call do_patch_instruction() instead of calling
patch_instruction().
From: Nicholas Piggin <npiggin@gmail.com> Date: 2021-11-26 10:27:49
Excerpts from Christophe Leroy's message of November 26, 2021 4:34 pm:
Le 26/11/2021 à 04:22, Nicholas Piggin a écrit :
quoted
Code patching tests patch the stack and (non-module) vmalloc space now,
which falls afoul of the new address check.
The stack patching can easily be fixed, but the vmalloc patching is more
difficult. For now, add an ugly workaround to skip the check while the
test code is running.
This really looks hacky.
To skip the test, you can call do_patch_instruction() instead of calling
patch_instruction().
And make a do_patch_branch function. I thought about it, and thought
this is sligtly easier.
Thanks,
Nick
Excerpts from Christophe Leroy's message of November 26, 2021 4:34 pm:
quoted
Le 26/11/2021 à 04:22, Nicholas Piggin a écrit :
quoted
Code patching tests patch the stack and (non-module) vmalloc space now,
which falls afoul of the new address check.
The stack patching can easily be fixed, but the vmalloc patching is more
difficult. For now, add an ugly workaround to skip the check while the
test code is running.
This really looks hacky.
To skip the test, you can call do_patch_instruction() instead of calling
patch_instruction().
And make a do_patch_branch function. I thought about it, and thought
this is sligtly easier.
Anyway, as reported by Sachin the ftrace code also trips in the new
verification. So I have submitted a patch to revert to the previous
level of verification.
Then we can fix all this properly without going through a temporary hack
and activate the verification again once every caller is fixed.
I was not able to reproduce Sachin's problem on PPC32. Could it be
specific to PPC64 ?
Christophe