Re: [PATCH] ftrace: shut up -Wcast-function-type warning for ftrace_ops_no_ops

From: Peter Zijlstra
Date: Tue Mar 23 2021 - 11:27:22 EST


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.