linux-trace-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86: alternative: Fix int3 handling failure from broken text_poke array
@ 2025-06-18  0:05 Masami Hiramatsu (Google)
  2025-06-18 11:57 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Masami Hiramatsu (Google) @ 2025-06-18  0:05 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Thomas Gleixner, Borislav Petkov,
	Dave Hansen
  Cc: Steven Rostedt, x86, Naresh Kamboju, open list,
	Linux trace kernel, lkft-triage, Stephen Rothwell, Arnd Bergmann,
	Dan Carpenter, Anders Roxell

From: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Since smp_text_poke_single() does not expect there is another
text_poke request is queued, it can make text_poke_array not
sorted or cause a buffer overflow on the text_poke_array.vec[].
This will cause an Oops in int3 because of bsearch failing;


   CPU 0                        CPU 1                      CPU 2
   -----                        -----                      -----

 smp_text_poke_batch_add()

			    smp_text_poke_single() <<-- Adds out of order

							<int3>
                                                	[Fails o find address
                                                        in text_poke_array ]
                                                        OOPS!

Or unhandled page fault because of a buffer overflow;


   CPU 0                        CPU 1
   -----                        -----

 smp_text_poke_batch_add() <<+
 ...                         |
 smp_text_poke_batch_add() <<-- Adds TEXT_POKE_ARRAY_MAX times.

			     smp_text_poke_single() {
			     	__smp_text_poke_batch_add() <<-- Adds entry at
								TEXT_POKE_ARRAY_MAX + 1

                		smp_text_poke_batch_finish()
                        	  [Unhandled page fault because
				   text_poke_array.nr_entries is
				   overwritten]
				   BUG!
			     }


Use smp_text_poke_batch_add() instead of __smp_text_poke_batch_add()
so that it correctly flush the queue if needed.

Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
Closes: https://lore.kernel.org/all/CA+G9fYsLu0roY3DV=tKyqP7FEKbOEETRvTDhnpPxJGbA=Cg+4w@mail.gmail.com/
Fixes: c8976ade0c1b ("x86/alternatives: Simplify smp_text_poke_single() by using tp_vec and existing APIs")
Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
---
 arch/x86/kernel/alternative.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index ecfe7b497cad..8038951650c6 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -3107,6 +3107,6 @@ void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t len, c
  */
 void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len, const void *emulate)
 {
-	__smp_text_poke_batch_add(addr, opcode, len, emulate);
+	smp_text_poke_batch_add(addr, opcode, len, emulate);
 	smp_text_poke_batch_finish();
 }


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86: alternative: Fix int3 handling failure from broken text_poke array
  2025-06-18  0:05 [PATCH] x86: alternative: Fix int3 handling failure from broken text_poke array Masami Hiramatsu (Google)
@ 2025-06-18 11:57 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2025-06-18 11:57 UTC (permalink / raw)
  To: Masami Hiramatsu (Google)
  Cc: Ingo Molnar, Thomas Gleixner, Borislav Petkov, Dave Hansen,
	Steven Rostedt, x86, Naresh Kamboju, open list,
	Linux trace kernel, lkft-triage, Stephen Rothwell, Arnd Bergmann,
	Dan Carpenter, Anders Roxell

On Wed, Jun 18, 2025 at 09:05:23AM +0900, Masami Hiramatsu (Google) wrote:
> From: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> 
> Since smp_text_poke_single() does not expect there is another
> text_poke request is queued, it can make text_poke_array not
> sorted or cause a buffer overflow on the text_poke_array.vec[].
> This will cause an Oops in int3 because of bsearch failing;
> 
> 
>    CPU 0                        CPU 1                      CPU 2
>    -----                        -----                      -----
> 
>  smp_text_poke_batch_add()
> 
> 			    smp_text_poke_single() <<-- Adds out of order
> 
> 							<int3>
>                                                 	[Fails o find address
>                                                         in text_poke_array ]
>                                                         OOPS!
> 
> Or unhandled page fault because of a buffer overflow;
> 
> 
>    CPU 0                        CPU 1
>    -----                        -----
> 
>  smp_text_poke_batch_add() <<+
>  ...                         |
>  smp_text_poke_batch_add() <<-- Adds TEXT_POKE_ARRAY_MAX times.
> 
> 			     smp_text_poke_single() {
> 			     	__smp_text_poke_batch_add() <<-- Adds entry at
> 								TEXT_POKE_ARRAY_MAX + 1
> 
>                 		smp_text_poke_batch_finish()
>                         	  [Unhandled page fault because
> 				   text_poke_array.nr_entries is
> 				   overwritten]
> 				   BUG!
> 			     }
> 
> 
> Use smp_text_poke_batch_add() instead of __smp_text_poke_batch_add()
> so that it correctly flush the queue if needed.
> 
> Reported-by: Linux Kernel Functional Testing <lkft@linaro.org>
> Closes: https://lore.kernel.org/all/CA+G9fYsLu0roY3DV=tKyqP7FEKbOEETRvTDhnpPxJGbA=Cg+4w@mail.gmail.com/
> Fixes: c8976ade0c1b ("x86/alternatives: Simplify smp_text_poke_single() by using tp_vec and existing APIs")
> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>

Thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-18 11:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-18  0:05 [PATCH] x86: alternative: Fix int3 handling failure from broken text_poke array Masami Hiramatsu (Google)
2025-06-18 11:57 ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).