Skip to contentSkip to conversation

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

PATCH Applied Uros Bizjak 3 participants 3 messages Dec 1, 2023 – Dec 2, 2023 x86

lore
Share & tools
lore
#0 lore raw

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

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")
Cc Ingo Molnar <[email protected]>
---
 arch/x86/kernel/callthunks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/callthunks.c +1 -1
index f5507c95e7be..c561dd481eb9 100644
@@ -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,
Signature · 1 line
2.31.1
Tested-by on v1 1/1
#1 lore raw
Quoted 9 lines · Uros Bizjak

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")
Cc Ingo Molnar <[email protected]>

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

Quoted 20 lines
---
 arch/x86/kernel/callthunks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/callthunks.c +1 -1
index f5507c95e7be..c561dd481eb9 100644
@@ -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,
Signature · 1 line
2.31.1
merge bot Applied
#2 lore raw
In reply to Uros Bizjak
The following commit has been merged into the x86/percpu branch of tip:

The following commit has been merged into the x86/percpu branch of tip:

Commit-ID:     fc50065325f8b88d6986f089ae103b5db858ab96
Gitweb:        https://git.kernel.org/tip/fc50065325f8b88d6986f089ae103b5db858ab96
Author:        Uros Bizjak <[email protected]>
AuthorDate:    Fri, 01 Dec 2023 09:57:27 +01:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Sat, 02 Dec 2023 10:51:28 +01:00

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

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")
---
 arch/x86/kernel/callthunks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/callthunks.c +1 -1
index f56fa30..2324c7f 100644
@@ -312,7 +312,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,