* [PATCH] ftrace: shut up -Wcast-function-type warning for ftrace_ops_no_ops
@ 2021-03-22 21:49 Arnd Bergmann
2021-03-22 22:00 ` Steven Rostedt
2021-03-23 7:39 ` Peter Zijlstra
0 siblings, 2 replies; 6+ messages in thread
From: Arnd Bergmann @ 2021-03-22 21:49 UTC (permalink / raw)
To: Steven Rostedt, Ingo Molnar
Cc: Arnd Bergmann, Peter Zijlstra (Intel),
Adrian Hunter, Tobias Klauser, Wei Yang, Chengming Zhou,
Naveen N. Rao, Paul E. McKenney, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
With 'make W=1', gcc warns about casts between incompatible function
types:
kernel/trace/ftrace.c:128:31: error: cast between incompatible function types from 'void (*)(long unsigned int, long unsigned int)' to 'void (*)(long unsigned int, long unsigned int, struct ftrace_ops *, struct ftrace_regs *)' [-Werror=cast-function-type]
128 | #define ftrace_ops_list_func ((ftrace_func_t)ftrace_ops_no_ops)
| ^
As the commet here explains, this one was intentional, so shut up the
warning harder by using a double cast.
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
kernel/trace/ftrace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 4d8e35575549..d8fc87a17421 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -125,7 +125,7 @@ static void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
#else
/* See comment below, where ftrace_ops_list_func is defined */
static void ftrace_ops_no_ops(unsigned long ip, unsigned long parent_ip);
-#define ftrace_ops_list_func ((ftrace_func_t)ftrace_ops_no_ops)
+#define ftrace_ops_list_func ((ftrace_func_t)(void *)ftrace_ops_no_ops)
#endif
static inline void ftrace_ops_init(struct ftrace_ops *ops)
--
2.29.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] ftrace: shut up -Wcast-function-type warning for ftrace_ops_no_ops
2021-03-22 21:49 [PATCH] ftrace: shut up -Wcast-function-type warning for ftrace_ops_no_ops Arnd Bergmann
@ 2021-03-22 22:00 ` Steven Rostedt
2021-03-23 7:39 ` Peter Zijlstra
1 sibling, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2021-03-22 22:00 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Ingo Molnar, Arnd Bergmann, Peter Zijlstra (Intel),
Adrian Hunter, Tobias Klauser, Wei Yang, Chengming Zhou,
Naveen N. Rao, Paul E. McKenney, linux-kernel
On Mon, 22 Mar 2021 22:49:58 +0100
Arnd Bergmann <arnd@kernel.org> wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> With 'make W=1', gcc warns about casts between incompatible function
> types:
>
> kernel/trace/ftrace.c:128:31: error: cast between incompatible function types from 'void (*)(long unsigned int, long unsigned int)' to 'void (*)(long unsigned int, long unsigned int, struct ftrace_ops *, struct ftrace_regs *)' [-Werror=cast-function-type]
> 128 | #define ftrace_ops_list_func ((ftrace_func_t)ftrace_ops_no_ops)
> | ^
>
> As the commet here explains, this one was intentional, so shut up the
> warning harder by using a double cast.
Bonus points for reading the comment ;-)
I'll take this patch for the next merge window, thanks!
-- Steve
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ftrace: shut up -Wcast-function-type warning for ftrace_ops_no_ops
2021-03-22 21:49 [PATCH] ftrace: shut up -Wcast-function-type warning for ftrace_ops_no_ops Arnd Bergmann
2021-03-22 22:00 ` Steven Rostedt
@ 2021-03-23 7:39 ` Peter Zijlstra
2021-03-23 12:57 ` Steven Rostedt
1 sibling, 1 reply; 6+ messages in thread
From: Peter Zijlstra @ 2021-03-23 7:39 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Steven Rostedt, Ingo Molnar, Arnd Bergmann, Adrian Hunter,
Tobias Klauser, Wei Yang, Chengming Zhou, Naveen N. Rao,
Paul E. McKenney, linux-kernel
On Mon, Mar 22, 2021 at 10:49:58PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> With 'make W=1', gcc warns about casts between incompatible function
> types:
>
> kernel/trace/ftrace.c:128:31: error: cast between incompatible function types from 'void (*)(long unsigned int, long unsigned int)' to 'void (*)(long unsigned int, long unsigned int, struct ftrace_ops *, struct ftrace_regs *)' [-Werror=cast-function-type]
> 128 | #define ftrace_ops_list_func ((ftrace_func_t)ftrace_ops_no_ops)
> | ^
>
> As the commet here explains, this one was intentional, so shut up the
> warning harder by using a double cast.
>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> kernel/trace/ftrace.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 4d8e35575549..d8fc87a17421 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -125,7 +125,7 @@ static void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
> #else
> /* See comment below, where ftrace_ops_list_func is defined */
> static void ftrace_ops_no_ops(unsigned long ip, unsigned long parent_ip);
> -#define ftrace_ops_list_func ((ftrace_func_t)ftrace_ops_no_ops)
> +#define ftrace_ops_list_func ((ftrace_func_t)(void *)ftrace_ops_no_ops)
So now we're making perfectly fine code worse, because GCC is stupid?
Please just kill the warning, like we do with so many other warnings.
It's broken!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ftrace: shut up -Wcast-function-type warning for ftrace_ops_no_ops
2021-03-23 7:39 ` Peter Zijlstra
@ 2021-03-23 12:57 ` Steven Rostedt
2021-03-23 15:25 ` Peter Zijlstra
0 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2021-03-23 12:57 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Arnd Bergmann, Ingo Molnar, Arnd Bergmann, Adrian Hunter,
Tobias Klauser, Wei Yang, Chengming Zhou, Naveen N. Rao,
Paul E. McKenney, linux-kernel, Kees Cook
On Tue, 23 Mar 2021 08:39:08 +0100
Peter Zijlstra <peterz@infradead.org> wrote:
> > index 4d8e35575549..d8fc87a17421 100644
> > --- a/kernel/trace/ftrace.c
> > +++ b/kernel/trace/ftrace.c
> > @@ -125,7 +125,7 @@ static void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
> > #else
> > /* See comment below, where ftrace_ops_list_func is defined */
> > static void ftrace_ops_no_ops(unsigned long ip, unsigned long parent_ip);
> > -#define ftrace_ops_list_func ((ftrace_func_t)ftrace_ops_no_ops)
> > +#define ftrace_ops_list_func ((ftrace_func_t)(void *)ftrace_ops_no_ops)
>
> So now we're making perfectly fine code worse, because GCC is stupid?
>
> Please just kill the warning, like we do with so many other warnings.
> It's broken!
[ Adding Kees ]
Well, from what I understand is that typecasting functions to other types
of functions is one of the mistakes that cause security bugs to happen. And
there's been a few of them in the kernel. Which is why the compilers have
now been flagging them.
This particular instance of the typecasting is unique and there's a bit of
magic involved. Adding this little work around here is fine. Probably needs
a better comment though.
-- Steve
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ftrace: shut up -Wcast-function-type warning for ftrace_ops_no_ops
2021-03-23 12:57 ` Steven Rostedt
@ 2021-03-23 15:25 ` Peter Zijlstra
2021-03-23 16:05 ` Peter Zijlstra
0 siblings, 1 reply; 6+ messages in thread
From: Peter Zijlstra @ 2021-03-23 15:25 UTC (permalink / raw)
To: Steven Rostedt
Cc: Arnd Bergmann, Ingo Molnar, Arnd Bergmann, Adrian Hunter,
Tobias Klauser, Wei Yang, Chengming Zhou, Naveen N. Rao,
Paul E. McKenney, linux-kernel, Kees Cook
On Tue, Mar 23, 2021 at 08:57:42AM -0400, Steven Rostedt wrote:
> Well, from what I understand is that typecasting functions to other types
> of functions is one of the mistakes that cause security bugs to happen. And
> there's been a few of them in the kernel. Which is why the compilers have
> now been flagging them.
Doing the cast in the first pace is an indication something weird is
happening anyway. C will already warn you if you assign non-matching
pointer types.
So if there's bugs, audit all (function) pointer casts. Don't wreck
casts.
This warning will only make people add more (void *) intermediate casts
and then we have uglier code and an equal amount of hidden bugs. IE. we
really didn't win anything at all.
> This particular instance of the typecasting is unique and there's a bit of
> magic involved. Adding this little work around here is fine. Probably needs
> a better comment though.
Nah, it's not unique, static_call() has a whole bunch of them, including
the exact same you have. Yes, we're doing something C thinks is UB, but
we do that all day every day.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ftrace: shut up -Wcast-function-type warning for ftrace_ops_no_ops
2021-03-23 15:25 ` Peter Zijlstra
@ 2021-03-23 16:05 ` Peter Zijlstra
0 siblings, 0 replies; 6+ messages in thread
From: Peter Zijlstra @ 2021-03-23 16:05 UTC (permalink / raw)
To: Steven Rostedt
Cc: Arnd Bergmann, Ingo Molnar, Arnd Bergmann, Adrian Hunter,
Tobias Klauser, Wei Yang, Chengming Zhou, Naveen N. Rao,
Paul E. McKenney, linux-kernel, Kees Cook
On Tue, Mar 23, 2021 at 04:25:07PM +0100, Peter Zijlstra wrote:
> On Tue, Mar 23, 2021 at 08:57:42AM -0400, Steven Rostedt wrote:
>
> > Well, from what I understand is that typecasting functions to other types
> > of functions is one of the mistakes that cause security bugs to happen. And
> > there's been a few of them in the kernel. Which is why the compilers have
> > now been flagging them.
>
> Doing the cast in the first pace is an indication something weird is
> happening anyway. C will already warn you if you assign non-matching
> pointer types.
>
> So if there's bugs, audit all (function) pointer casts. Don't wreck
> casts.
>
> This warning will only make people add more (void *) intermediate casts
> and then we have uglier code and an equal amount of hidden bugs. IE. we
> really didn't win anything at all.
>
> > This particular instance of the typecasting is unique and there's a bit of
> > magic involved. Adding this little work around here is fine. Probably needs
> > a better comment though.
>
> Nah, it's not unique, static_call() has a whole bunch of them, including
> the exact same you have. Yes, we're doing something C thinks is UB, but
> we do that all day every day.
Here's weakening static_call_update() to get around this new
fail^Wfeature:
https://lkml.kernel.org/r/YFoN7nCl8OfGtpeh@hirez.programming.kicks-ass.net
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-03-23 16:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22 21:49 [PATCH] ftrace: shut up -Wcast-function-type warning for ftrace_ops_no_ops Arnd Bergmann
2021-03-22 22:00 ` Steven Rostedt
2021-03-23 7:39 ` Peter Zijlstra
2021-03-23 12:57 ` Steven Rostedt
2021-03-23 15:25 ` Peter Zijlstra
2021-03-23 16:05 ` Peter Zijlstra
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.