kernel-hardening.lists.openwall.com archive mirror
 help / color / mirror / Atom feed
From: Oscar Carter <oscar.carter@gmx.com>
To: Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>, Kees Cook <keescook@chromium.org>
Cc: Oscar Carter <oscar.carter@gmx.com>,
	linux-kernel@vger.kernel.org,
	kernel-hardening@lists.openwall.com, Jann Horn <jannh@google.com>
Subject: [PATCH v2 1/2] kernel/trace: Prepare to remove function callback casts
Date: Sun, 19 Jul 2020 17:50:32 +0200	[thread overview]
Message-ID: <20200719155033.24201-2-oscar.carter@gmx.com> (raw)
In-Reply-To: <20200719155033.24201-1-oscar.carter@gmx.com>

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

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 the function
ftrace_ops_list_func() has four parameters.

This patch prepares all the infrastructure to remove the casts.

Define a new function pointer to use when the archs don't support ftrace
ops. Also define a union to combine this new function pointer (two
parameters) with the ftrace_func_t function pointer (four parameters).
This way, using this union it's possible to use two different function
prototypes with the same variable.

Also create two static inline helpers to set and compare against the
fields of the new union type. These helpers are duplicated for the archs
that support ftrace ops and for the archs that don't support ftrace ops
as both cases use different function prototypes.

Signed-off-by: Oscar Carter <oscar.carter@gmx.com>
---
 kernel/trace/ftrace.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 1903b80db6eb..fd8fbb422860 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -119,13 +119,45 @@ struct ftrace_ops __rcu *ftrace_ops_list __read_mostly = &ftrace_list_end;
 ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub;
 struct ftrace_ops global_ops;

+typedef void (*ftrace_func_no_ops_t)(unsigned long ip,
+				     unsigned long parent_ip);
+
+union ftrace_func {
+	ftrace_func_t ops;
+	ftrace_func_no_ops_t no_ops;
+};
+
 #if ARCH_SUPPORTS_FTRACE_OPS
 static void ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
 				 struct ftrace_ops *op, struct pt_regs *regs);
+
+static inline void ftrace_set_ufunc(union ftrace_func *ufunc,
+				    ftrace_func_t func)
+{
+	ufunc->ops = func;
+}
+
+static inline bool ftrace_same_address_ufunc(union ftrace_func *ufunc,
+					     ftrace_func_t func)
+{
+	return (ufunc->ops == func);
+}
 #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)
+
+static inline void ftrace_set_ufunc(union ftrace_func *ufunc,
+				    ftrace_func_no_ops_t func)
+{
+	ufunc->no_ops = func;
+}
+
+static inline bool ftrace_same_address_ufunc(union ftrace_func *ufunc,
+					     ftrace_func_no_ops_t func)
+{
+	return (ufunc->no_ops == func);
+}
 #endif

 static inline void ftrace_ops_init(struct ftrace_ops *ops)
--
2.20.1


  reply	other threads:[~2020-07-19 15:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-19 15:50 [PATCH v2 0/2] kernel/trace: Remove function callback casts Oscar Carter
2020-07-19 15:50 ` Oscar Carter [this message]
2020-07-19 15:50 ` [PATCH v2 2/2] " Oscar Carter
2020-07-21 18:05   ` Steven Rostedt
2020-07-24 16:19     ` Oscar Carter
2020-07-24 16:35       ` Steven Rostedt
2020-07-24 17:14         ` Oscar Carter
2020-07-24 17:24           ` Oscar Carter
2020-07-24 17:36           ` Steven Rostedt
2020-07-24 17:40             ` Steven Rostedt
2020-07-24 17:48               ` Steven Rostedt
2020-07-24 17:55               ` Oscar Carter
2020-07-24 18:34                 ` Steven Rostedt
2020-07-25 15:09                   ` Oscar Carter
2020-07-25 15:19                     ` Oscar Carter
2020-07-26 15:52                     ` Oscar Carter
2020-07-27 13:53                       ` Steven Rostedt
2020-07-31 14:41                         ` Oscar Carter

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=20200719155033.24201-2-oscar.carter@gmx.com \
    --to=oscar.carter@gmx.com \
    --cc=jannh@google.com \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=rostedt@goodmis.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).