x86/callthunks: Correct calculation of dest address in is_callthunk()

Message ID 20231201085727.3647051-1-ubizjak@gmail.com
State New
Headers
Series x86/callthunks: Correct calculation of dest address in is_callthunk() |

Commit Message

Uros Bizjak Dec. 1, 2023, 8:57 a.m. UTC
  GCC didn't warn on the invalid use of relocation destination
pointer, so the calculated destination value was applied to
the uninitialized pointer location in error.

Fixes: 17bce3b2ae2d ("x86/callthunks: Handle %rip-relative relocations in call thunk template")
Reported-by: Nathan Chancellor <nathan@kernel.org>
Closes: https://lore.kernel.org/lkml/20231201035457.GA321497@dev-arch.thelio-3990X/
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
 arch/x86/kernel/callthunks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Nathan Chancellor Dec. 1, 2023, 9:44 p.m. UTC | #1
On Fri, Dec 01, 2023 at 09:57:27AM +0100, Uros Bizjak wrote:
> GCC didn't warn on the invalid use of relocation destination
> pointer, so the calculated destination value was applied to
> the uninitialized pointer location in error.
> 
> Fixes: 17bce3b2ae2d ("x86/callthunks: Handle %rip-relative relocations in call thunk template")
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Closes: https://lore.kernel.org/lkml/20231201035457.GA321497@dev-arch.thelio-3990X/
> Cc: Ingo Molnar <mingo@kernel.org>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>

This obviously clears up the warning and all my machines booted
(although I don't think any of them actually exercise this code path?):

Tested-by: Nathan Chancellor <nathan@kernel.org>

> ---
>  arch/x86/kernel/callthunks.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/callthunks.c b/arch/x86/kernel/callthunks.c
> index f5507c95e7be..c561dd481eb9 100644
> --- a/arch/x86/kernel/callthunks.c
> +++ b/arch/x86/kernel/callthunks.c
> @@ -306,7 +306,7 @@ static bool is_callthunk(void *addr)
>  	if (!thunks_initialized || skip_addr((void *)dest))
>  		return false;
>  
> -	*pad = dest - tmpl_size;
> +	pad = (void *)(dest - tmpl_size);
>  
>  	memcpy(insn_buff, skl_call_thunk_template, tmpl_size);
>  	apply_relocation(insn_buff, tmpl_size, pad,
> -- 
> 2.31.1
>
  

Patch

diff --git a/arch/x86/kernel/callthunks.c b/arch/x86/kernel/callthunks.c
index f5507c95e7be..c561dd481eb9 100644
--- a/arch/x86/kernel/callthunks.c
+++ b/arch/x86/kernel/callthunks.c
@@ -306,7 +306,7 @@  static bool is_callthunk(void *addr)
 	if (!thunks_initialized || skip_addr((void *)dest))
 		return false;
 
-	*pad = dest - tmpl_size;
+	pad = (void *)(dest - tmpl_size);
 
 	memcpy(insn_buff, skl_call_thunk_template, tmpl_size);
 	apply_relocation(insn_buff, tmpl_size, pad,