Skip to contentSkip to conversation

parisc/kernel/ftrace: Remove function callback casts

PATCH Superseded Oscar Carter 2 participants 3 messages Jun 27, 2020 – Jul 4, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 parisc/kernel/ftrace: Remove function callback casts

In an effort to enable -Wcast-function-type in the top-level Makefile to support Control Flow Integrity builds, remove all the function callback casts.

To do this remove the cast to a function pointer type in the comparison statement and add to the right and left operand a cast to unsigned long type. This can be done since the comparison is against function address (these operands are not function calls).

---
 arch/parisc/kernel/ftrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/kernel/ftrace.c +1 -1
index 1df0f67ed667..86b49a5fc049 100644
@@ -64,7 +64,7 @@ void notrace __hot ftrace_function_trampoline(unsigned long parent,
 				function_trace_op, regs);
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
-	if (ftrace_graph_return != (trace_func_graph_ret_t) ftrace_stub ||
+	if ((unsigned long)ftrace_graph_return != (unsigned long)ftrace_stub ||
 	    ftrace_graph_entry != ftrace_graph_entry_stub) {
 		unsigned long *parent_rp;
 

--
2.20.1

maintainer
#1 lore raw
Quoted 8 lines · Oscar Carter

In an effort to enable -Wcast-function-type in the top-level Makefile to support Control Flow Integrity builds, remove all the function callback casts.

To do this remove the cast to a function pointer type in the comparison statement and add to the right and left operand a cast to unsigned long type. This can be done since the comparison is against function address (these operands are not function calls).

On some architectures (namely ia64, ppc64 and parisc64) function pointers actually refer to function descriptors, which in turn point to the real function address. The compiler usually takes care of such comparism. That said, casting to "unsigned long" might break this...

Quoted 10 lines
---
 arch/parisc/kernel/ftrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/kernel/ftrace.c +0 -0
index 1df0f67ed667..86b49a5fc049 100644

arch/parisc/kernel/ftrace.c void notrace __hot ftrace_function_trampoline(unsigned long parent, · line 67

Quoted 5 lines
arch/parisc/kernel/ftrace.c +1 -1
@@ -64,7 +64,7 @@ void notrace __hot ftrace_function_trampoline(unsigned long parent,
 				function_trace_op, regs);
 
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
-	if (ftrace_graph_return != (trace_func_graph_ret_t) ftrace_stub ||
+	if ((unsigned long)ftrace_graph_return != (unsigned long)ftrace_stub ||

Untested, but maybe better use:

	dereference_function_descriptor(ftrace_graph_return) !=
		dereference_function_descriptor(ftrace_stub)

?
Helge

#2 lore raw
Quoted 10 lines · Helge Deller
Quoted 8 lines · Oscar Carter

In an effort to enable -Wcast-function-type in the top-level Makefile to support Control Flow Integrity builds, remove all the function callback casts.

To do this remove the cast to a function pointer type in the comparison statement and add to the right and left operand a cast to unsigned long type. This can be done since the comparison is against function address (these operands are not function calls).

Quoted 4 lines

On some architectures (namely ia64, ppc64 and parisc64) function pointers actually refer to function descriptors, which in turn point to the real function address. The compiler usually takes care of such comparism. That said, casting to "unsigned long" might break this...

Ok, thanks for the clarification. Today I have learned about function descriptors.

Quoted 12 lines
Quoted 12 lines
---
 arch/parisc/kernel/ftrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/kernel/ftrace.c +0 -0
index 1df0f67ed667..86b49a5fc049 100644
@@ -64,7 +64,7 @@ void notrace __hot ftrace_function_trampoline(unsigned long parent,
 				function_trace_op, regs);
 
Quoted 7 lines

arch/parisc/kernel/ftrace.c void notrace __hot ftrace_function_trampoline(unsigned long parent, · line 67

Quoted 3 lines
arch/parisc/kernel/ftrace.c +1 -1
 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
-	if (ftrace_graph_return != (trace_func_graph_ret_t) ftrace_stub ||
+	if ((unsigned long)ftrace_graph_return != (unsigned long)ftrace_stub ||

Untested, but maybe better use:

	dereference_function_descriptor(ftrace_graph_return) !=
		dereference_function_descriptor(ftrace_stub)

Thanks for point me to the right direction about this theme. I will do a new version and I will resend.

Quoted 2 lines

?
Helge

Regards,
Oscar Carter