* [PATCH] powerpc/code-patching: Relax verification of patchability
@ 2021-11-26 7:39 ` Christophe Leroy
0 siblings, 0 replies; 6+ messages in thread
From: Christophe Leroy @ 2021-11-26 7:39 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
Cc: Sachin Sant, Stephen Rothwell, linux-kernel, Nicholas Piggin,
linuxppc-dev
Commit 8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of
patchability") introduced a stricter verification of the patched
area by checking it is proper kernel text.
But as least two usages of patch_instruction() fall outside:
- Code patching selftests, which use stack and vmalloc space.
- Ftrace
So for the time being, partially revert commit 8b8a8f0ab3f5 and add
a onetime warning:
Running code patching self-tests ...
patch_instruction() called on invalid text address 0xe1011e58 from test_code_patching+0x34/0xd6c
Reported-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Fixes: 8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of patchability")
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
arch/powerpc/lib/code-patching.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 1dd636a85cc1..c87eea773930 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -190,9 +190,13 @@ static int do_patch_instruction(u32 *addr, struct ppc_inst instr)
int patch_instruction(u32 *addr, struct ppc_inst instr)
{
/* Make sure we aren't patching a freed init section */
- if (!kernel_text_address((unsigned long)addr))
+ if (system_state >= SYSTEM_FREEING_INITMEM && init_section_contains(addr, 4))
return 0;
+ if (!kernel_text_address((unsigned long)addr))
+ pr_warn_once("%s() called on invalid text address 0x%p from %pS\n",
+ __func__, addr, __builtin_return_address(0));
+
return do_patch_instruction(addr, instr);
}
NOKPROBE_SYMBOL(patch_instruction);
--
2.33.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] powerpc/code-patching: Relax verification of patchability
@ 2021-11-26 7:39 ` Christophe Leroy
0 siblings, 0 replies; 6+ messages in thread
From: Christophe Leroy @ 2021-11-26 7:39 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
Cc: Christophe Leroy, linux-kernel, linuxppc-dev, Sachin Sant,
Stephen Rothwell, Nicholas Piggin
Commit 8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of
patchability") introduced a stricter verification of the patched
area by checking it is proper kernel text.
But as least two usages of patch_instruction() fall outside:
- Code patching selftests, which use stack and vmalloc space.
- Ftrace
So for the time being, partially revert commit 8b8a8f0ab3f5 and add
a onetime warning:
Running code patching self-tests ...
patch_instruction() called on invalid text address 0xe1011e58 from test_code_patching+0x34/0xd6c
Reported-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Nicholas Piggin <npiggin@gmail.com>
Fixes: 8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of patchability")
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
arch/powerpc/lib/code-patching.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
index 1dd636a85cc1..c87eea773930 100644
--- a/arch/powerpc/lib/code-patching.c
+++ b/arch/powerpc/lib/code-patching.c
@@ -190,9 +190,13 @@ static int do_patch_instruction(u32 *addr, struct ppc_inst instr)
int patch_instruction(u32 *addr, struct ppc_inst instr)
{
/* Make sure we aren't patching a freed init section */
- if (!kernel_text_address((unsigned long)addr))
+ if (system_state >= SYSTEM_FREEING_INITMEM && init_section_contains(addr, 4))
return 0;
+ if (!kernel_text_address((unsigned long)addr))
+ pr_warn_once("%s() called on invalid text address 0x%p from %pS\n",
+ __func__, addr, __builtin_return_address(0));
+
return do_patch_instruction(addr, instr);
}
NOKPROBE_SYMBOL(patch_instruction);
--
2.33.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] powerpc/code-patching: Relax verification of patchability
2021-11-26 7:39 ` Christophe Leroy
@ 2021-11-26 8:49 ` Christophe Leroy
-1 siblings, 0 replies; 6+ messages in thread
From: Christophe Leroy @ 2021-11-26 8:49 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
Cc: Sachin Sant, Stephen Rothwell, linuxppc-dev, linux-kernel,
Nicholas Piggin
Le 26/11/2021 à 08:39, Christophe Leroy a écrit :
> Commit 8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of
> patchability") introduced a stricter verification of the patched
> area by checking it is proper kernel text.
>
> But as least two usages of patch_instruction() fall outside:
> - Code patching selftests, which use stack and vmalloc space.
> - Ftrace
>
> So for the time being, partially revert commit 8b8a8f0ab3f5 and add
> a onetime warning:
>
> Running code patching self-tests ...
> patch_instruction() called on invalid text address 0xe1011e58 from test_code_patching+0x34/0xd6c
>
> Reported-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Fixes: 8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of patchability")
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> arch/powerpc/lib/code-patching.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
> index 1dd636a85cc1..c87eea773930 100644
> --- a/arch/powerpc/lib/code-patching.c
> +++ b/arch/powerpc/lib/code-patching.c
> @@ -190,9 +190,13 @@ static int do_patch_instruction(u32 *addr, struct ppc_inst instr)
> int patch_instruction(u32 *addr, struct ppc_inst instr)
> {
> /* Make sure we aren't patching a freed init section */
> - if (!kernel_text_address((unsigned long)addr))
> + if (system_state >= SYSTEM_FREEING_INITMEM && init_section_contains(addr, 4))
> return 0;
>
> + if (!kernel_text_address((unsigned long)addr))
> + pr_warn_once("%s() called on invalid text address 0x%p from %pS\n",
> + __func__, addr, __builtin_return_address(0));
> +
May it be better to use pr_warn_ratelimited() instead in order to catch
more than the first occurence ?
> return do_patch_instruction(addr, instr);
> }
> NOKPROBE_SYMBOL(patch_instruction);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] powerpc/code-patching: Relax verification of patchability
@ 2021-11-26 8:49 ` Christophe Leroy
0 siblings, 0 replies; 6+ messages in thread
From: Christophe Leroy @ 2021-11-26 8:49 UTC (permalink / raw)
To: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman
Cc: linux-kernel, linuxppc-dev, Sachin Sant, Stephen Rothwell,
Nicholas Piggin
Le 26/11/2021 à 08:39, Christophe Leroy a écrit :
> Commit 8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of
> patchability") introduced a stricter verification of the patched
> area by checking it is proper kernel text.
>
> But as least two usages of patch_instruction() fall outside:
> - Code patching selftests, which use stack and vmalloc space.
> - Ftrace
>
> So for the time being, partially revert commit 8b8a8f0ab3f5 and add
> a onetime warning:
>
> Running code patching self-tests ...
> patch_instruction() called on invalid text address 0xe1011e58 from test_code_patching+0x34/0xd6c
>
> Reported-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Fixes: 8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of patchability")
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> arch/powerpc/lib/code-patching.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c
> index 1dd636a85cc1..c87eea773930 100644
> --- a/arch/powerpc/lib/code-patching.c
> +++ b/arch/powerpc/lib/code-patching.c
> @@ -190,9 +190,13 @@ static int do_patch_instruction(u32 *addr, struct ppc_inst instr)
> int patch_instruction(u32 *addr, struct ppc_inst instr)
> {
> /* Make sure we aren't patching a freed init section */
> - if (!kernel_text_address((unsigned long)addr))
> + if (system_state >= SYSTEM_FREEING_INITMEM && init_section_contains(addr, 4))
> return 0;
>
> + if (!kernel_text_address((unsigned long)addr))
> + pr_warn_once("%s() called on invalid text address 0x%p from %pS\n",
> + __func__, addr, __builtin_return_address(0));
> +
May it be better to use pr_warn_ratelimited() instead in order to catch
more than the first occurence ?
> return do_patch_instruction(addr, instr);
> }
> NOKPROBE_SYMBOL(patch_instruction);
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] powerpc/code-patching: Relax verification of patchability
2021-11-26 7:39 ` Christophe Leroy
@ 2021-11-26 18:00 ` Sachin Sant
-1 siblings, 0 replies; 6+ messages in thread
From: Sachin Sant @ 2021-11-26 18:00 UTC (permalink / raw)
To: Christophe Leroy
Cc: Stephen Rothwell, linux-kernel, Nicholas Piggin, Paul Mackerras,
linuxppc-dev
> Running code patching self-tests ...
> patch_instruction() called on invalid text address 0xe1011e58 from test_code_patching+0x34/0xd6c
>
> Reported-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Fixes: 8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of patchability")
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> arch/powerpc/lib/code-patching.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
This fixes the problem for me.
Tested-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
Thanks
-Sachin
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] powerpc/code-patching: Relax verification of patchability
@ 2021-11-26 18:00 ` Sachin Sant
0 siblings, 0 replies; 6+ messages in thread
From: Sachin Sant @ 2021-11-26 18:00 UTC (permalink / raw)
To: Christophe Leroy
Cc: Benjamin Herrenschmidt, Paul Mackerras, Michael Ellerman,
Stephen Rothwell, linux-kernel, Nicholas Piggin, linuxppc-dev
> Running code patching self-tests ...
> patch_instruction() called on invalid text address 0xe1011e58 from test_code_patching+0x34/0xd6c
>
> Reported-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
> Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Cc: Nicholas Piggin <npiggin@gmail.com>
> Fixes: 8b8a8f0ab3f5 ("powerpc/code-patching: Improve verification of patchability")
> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
> ---
> arch/powerpc/lib/code-patching.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
This fixes the problem for me.
Tested-by: Sachin Sant <sachinp@linux.vnet.ibm.com>
Thanks
-Sachin
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-11-26 18:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-26 7:39 [PATCH] powerpc/code-patching: Relax verification of patchability Christophe Leroy
2021-11-26 7:39 ` Christophe Leroy
2021-11-26 8:49 ` Christophe Leroy
2021-11-26 8:49 ` Christophe Leroy
2021-11-26 18:00 ` Sachin Sant
2021-11-26 18:00 ` Sachin Sant
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.