Kernel-hardening archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] parisc/kernel/ftrace: Remove function callback casts
@ 2020-06-27 13:43 Oscar Carter
  2020-06-27 20:09 ` Helge Deller
  0 siblings, 1 reply; 3+ messages in thread
From: Oscar Carter @ 2020-06-27 13:43 UTC (permalink / raw)
  To: Kees Cook, Steven Rostedt, Ingo Molnar, James E . J . Bottomley,
	Helge Deller
  Cc: kernel-hardening, linux-parisc, linux-kernel, 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).

Signed-off-by: Oscar Carter <oscar.carter@gmx.com>
---
 arch/parisc/kernel/ftrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/parisc/kernel/ftrace.c b/arch/parisc/kernel/ftrace.c
index 1df0f67ed667..86b49a5fc049 100644
--- a/arch/parisc/kernel/ftrace.c
+++ b/arch/parisc/kernel/ftrace.c
@@ -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


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

* Re: [PATCH] parisc/kernel/ftrace: Remove function callback casts
  2020-06-27 13:43 [PATCH] parisc/kernel/ftrace: Remove function callback casts Oscar Carter
@ 2020-06-27 20:09 ` Helge Deller
  2020-07-04 12:12   ` Oscar Carter
  0 siblings, 1 reply; 3+ messages in thread
From: Helge Deller @ 2020-06-27 20:09 UTC (permalink / raw)
  To: Oscar Carter, Kees Cook, Steven Rostedt, Ingo Molnar,
	James E . J . Bottomley
  Cc: kernel-hardening, linux-parisc, linux-kernel

On 27.06.20 15:43, Oscar Carter wrote:
> 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...

> Signed-off-by: Oscar Carter <oscar.carter@gmx.com>
> ---
>  arch/parisc/kernel/ftrace.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/parisc/kernel/ftrace.c b/arch/parisc/kernel/ftrace.c
> index 1df0f67ed667..86b49a5fc049 100644
> --- a/arch/parisc/kernel/ftrace.c
> +++ b/arch/parisc/kernel/ftrace.c
> @@ -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

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

* Re: [PATCH] parisc/kernel/ftrace: Remove function callback casts
  2020-06-27 20:09 ` Helge Deller
@ 2020-07-04 12:12   ` Oscar Carter
  0 siblings, 0 replies; 3+ messages in thread
From: Oscar Carter @ 2020-07-04 12:12 UTC (permalink / raw)
  To: Helge Deller
  Cc: Oscar Carter, Kees Cook, Steven Rostedt, Ingo Molnar,
	James E . J . Bottomley, kernel-hardening, linux-parisc,
	linux-kernel

On Sat, Jun 27, 2020 at 10:09:40PM +0200, Helge Deller wrote:
> On 27.06.20 15:43, Oscar Carter wrote:
> > 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...

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

> > Signed-off-by: Oscar Carter <oscar.carter@gmx.com>
> > ---
> >  arch/parisc/kernel/ftrace.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/parisc/kernel/ftrace.c b/arch/parisc/kernel/ftrace.c
> > index 1df0f67ed667..86b49a5fc049 100644
> > --- a/arch/parisc/kernel/ftrace.c
> > +++ b/arch/parisc/kernel/ftrace.c
> > @@ -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)

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

> ?
> Helge

Regards,
Oscar Carter

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-27 13:43 [PATCH] parisc/kernel/ftrace: Remove function callback casts Oscar Carter
2020-06-27 20:09 ` Helge Deller
2020-07-04 12:12   ` Oscar Carter

Kernel-hardening archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/kernel-hardening/0 kernel-hardening/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 kernel-hardening kernel-hardening/ https://lore.kernel.org/kernel-hardening \
		kernel-hardening@lists.openwall.com
	public-inbox-index kernel-hardening

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/com.openwall.lists.kernel-hardening


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git