All of
 help / color / mirror / Atom feed
From: Jann Horn <>
To: Steven Rostedt <>
Cc: LKML <>,
	Ingo Molnar <>, Kees Cook <>,
	Kernel Hardening <>,
	Oscar Carter <>,
	Andrew Morton <>
Subject: Re: [PATCH] tracing: Use linker magic instead of recasting ftrace_ops_list_func()
Date: Wed, 17 Jun 2020 23:30:07 +0200	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <20200617165616.52241bde@oasis.local.home>

On Wed, Jun 17, 2020 at 10:56 PM Steven Rostedt <> wrote:
> In an effort to enable -Wcast-function-type in the top-level Makefile to
> support Control Flow Integrity builds, all function casts need to be
> removed.
> This means that ftrace_ops_list_func() can no longer be defined as
> ftrace_ops_no_ops(). The reason for ftrace_ops_no_ops() is to use that when
> an architecture calls ftrace_ops_list_func() with only two parameters
> (called from assembly). And to make sure there's no C side-effects, those
> archs call ftrace_ops_no_ops() which only has two parameters, as
> ftrace_ops_list_func() has four parameters.
> Instead of a typecast, use to define ftrace_ops_list_func() to
> arch_ftrace_ops_list_func() that will define the proper set of parameters.
> Link:
> diff --git a/include/asm-generic/ b/include/asm-generic/
> +                       ftrace_ops_list_func = arch_ftrace_ops_list_func;
>  #else
>  #  define MCOUNT_REC() ftrace_stub_graph = ftrace_stub;
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> +/* Defined by see the commment above arch_ftrace_ops_list_func for details */
> +void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
> +                         struct ftrace_ops *op, struct pt_regs *regs);
> +void arch_ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip)
>  {

Well, it's not like the function cast itself is the part that's
problematic for CFI; the problematic part is when you actually make a
C function call (in particular an indirect one) where the destination
is compiled with a prototype that is different from the prototype used
at the call site. Doing this linker hackery isn't really any better
than shutting up the compiler warning by piling on enough casts or
whatever. (There should be some combination of casts that'll shut up
this warning, right?)

IIUC the real issue here is that ftrace_func_t is defined as a fixed
type, but actually has different types depending on the architecture?
If so, it might be cleaner to define ftrace_func_t differently
depending on architecture, or something like that?

And if that's not feasible, I think it would be better to at least
replace this linker trickery with straightforward
shut-up-the-compiler-casts - it'd be much easier to understand what's
actually going on that way.

  reply	other threads:[~2020-06-17 21:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-17 20:56 Steven Rostedt
2020-06-17 21:30 ` Jann Horn [this message]
2020-06-17 21:30   ` Jann Horn
2020-06-17 22:36   ` Steven Rostedt
2020-06-17 23:12     ` Jann Horn
2020-06-17 23:12       ` Jann Horn
2020-06-18 16:41       ` Steven Rostedt
2020-06-18 17:58         ` Jann Horn
2020-06-18 17:58           ` Jann Horn
2020-06-18  9:13 ` kernel test robot
2020-06-18 10:06 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \ \ \
    --subject='Re: [PATCH] tracing: Use linker magic instead of recasting ftrace_ops_list_func()' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.