mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Will Drewry <wad@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: kees.cook@canonical.com, eparis@redhat.com, agl@chromium.org,
	mingo@elte.hu, jmorris@namei.org, rostedt@goodmis.org,
	Will Drewry <wad@chromium.org>,
	Steven Rostedt <srostedt@redhat.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Masami Hiramatsu <mhiramat@redhat.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Subject: [PATCH 6/7] include/linux/syscalls.h: add __ layer of macros with return types.
Date: Wed, 27 Apr 2011 22:08:50 -0500	[thread overview]
Message-ID: <1303960136-14298-5-git-send-email-wad@chromium.org> (raw)
In-Reply-To: <1303960136-14298-1-git-send-email-wad@chromium.org>

This change addresses two issues directly:
1. The inability for ftrace to hook system calls that don't return
   a long.
2. The fact that SYSCALL_DEFINE() does not touch ftrace at all

1 is fixed by adding __SYSCALL_DEFINEx/0 and __SYSCALL_TRACEx/0
macros which lay underneath the normal call,
SYSCALL_DEFINE0, and SYSCALL_DEFINE[1-6].  All existing calls will
continue to work normally and SYSCALL_DEFINE calls will become
ftrace-able but without argument inspection  support.

2 is addressed by separating out SYSCALL_TRACE0 and pulling it under
SYSCALL_DEFINE.  It means that calls that may lack argument
introspection will still be traceable in a binary way without any
additional code changes.

There are still some challenges for wrapping calls that have a
trampoline directly in the assembly, like the ptregs calls in
arch/x86/kernel (e.g., sys_clone).  Given that the arguments to the
function do not directly map to those of the system call, the main
macros are not friendly for use.  However, the SYSCALL_TRACE0 macro in
this change could be used as a placeholder (declared above the function
definition) to allow limited tracing functionality until a better
solution is presented.

Signed-off-by: Will Drewry <wad@chromium.org>
---
 include/linux/syscalls.h |   52 +++++++++++++++++++++++++++++++---------------
 1 files changed, 35 insertions(+), 17 deletions(-)

diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 83ecc17..1c4a3fb 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -171,7 +171,7 @@ extern struct trace_event_functions exit_syscall_print_funcs;
 	  __attribute__((section("__syscalls_metadata")))	\
 	 *__p_syscall_meta_##sname = &__syscall_meta_##sname;
 
-#define SYSCALL_DEFINE0(sname)					\
+#define __SYSCALL_TRACE0(linkage, ret, sname)			\
 	SYSCALL_TRACE_ENTER_EVENT(_##sname);			\
 	SYSCALL_TRACE_EXIT_EVENT(_##sname);			\
 	static struct syscall_metadata __used			\
@@ -185,12 +185,16 @@ extern struct trace_event_functions exit_syscall_print_funcs;
 	};							\
 	static struct syscall_metadata __used			\
 	  __attribute__((section("__syscalls_metadata")))	\
-	 *__p_syscall_meta_##sname = &__syscall_meta__##sname;	\
-	asmlinkage long sys_##sname(void)
+	 *__p_syscall_meta_##sname = &__syscall_meta__##sname;
 #else
-#define SYSCALL_DEFINE0(name)	   asmlinkage long sys_##name(void)
+#define __SYSCALL_TRACE0(linkage, ret, sname)
 #endif
 
+#define __SYSCALL_DEFINE0(linkage, ret, sname)			\
+	__SYSCALL_TRACE0(linkage, ret, sname)			\
+	linkage ret sys_##sname(void)
+
+#define SYSCALL_DEFINE0(name) __SYSCALL_DEFINE0(asmlinkage, long, name)
 #define SYSCALL_DEFINE1(name, ...) SYSCALL_DEFINEx(1, _##name, __VA_ARGS__)
 #define SYSCALL_DEFINE2(name, ...) SYSCALL_DEFINEx(2, _##name, __VA_ARGS__)
 #define SYSCALL_DEFINE3(name, ...) SYSCALL_DEFINEx(3, _##name, __VA_ARGS__)
@@ -214,39 +218,53 @@ extern struct trace_event_functions exit_syscall_print_funcs;
 
 #ifdef CONFIG_FTRACE_SYSCALLS
 #define SYSCALL_DEFINEx(x, sname, ...)				\
+	__SYSCALL_DEFINEx(asmlinkage, long, x, sname, __VA_ARGS__)
+
+#define __SYSCALL_TRACEx(linkage, ret, x, sname, ...)	\
 	static const char *types_##sname[] = {			\
 		__SC_STR_TDECL##x(__VA_ARGS__)			\
 	};							\
 	static const char *args_##sname[] = {			\
 		__SC_STR_ADECL##x(__VA_ARGS__)			\
 	};							\
-	SYSCALL_METADATA(sname, x);				\
-	__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
+	SYSCALL_METADATA(sname, x);				
 #else
 #define SYSCALL_DEFINEx(x, sname, ...)				\
-	__SYSCALL_DEFINEx(x, sname, __VA_ARGS__)
+	__SYSCALL_DEFINEx(asmlinkage, long, x, sname, __VA_ARGS__)
+#define __SYSCALL_TRACEx(linkage, ret, x, sname, ...)
 #endif
 
 #ifdef CONFIG_HAVE_SYSCALL_WRAPPERS
 
-#define SYSCALL_DEFINE(name) static inline long SYSC_##name
-
-#define __SYSCALL_DEFINEx(x, name, ...)					\
-	asmlinkage long sys##name(__SC_DECL##x(__VA_ARGS__));		\
-	static inline long SYSC##name(__SC_DECL##x(__VA_ARGS__));	\
-	asmlinkage long SyS##name(__SC_LONG##x(__VA_ARGS__))		\
+#define SYSCALL_DEFINE(name)						\
+	__SYSCALL_DEFINE(long, name)
+#define __SYSCALL_DEFINE(ret, name)				\
+	__SYSCALL_TRACE0(, ret, name)
+	static inline ret SYSC_##name
+
+#define __SYSCALL_DEFINEx(linkage, ret, x, name, ...)			\
+	__SYSCALL_TRACEx(linkage, ret, x, name, __VA_ARGS__)		\
+	linkage ret sys##name(__SC_DECL##x(__VA_ARGS__));		\
+	static inline ret SYSC##name(__SC_DECL##x(__VA_ARGS__));	\
+	linkage ret SyS##name(__SC_LONG##x(__VA_ARGS__))		\
 	{								\
 		__SC_TEST##x(__VA_ARGS__);				\
-		return (long) SYSC##name(__SC_CAST##x(__VA_ARGS__));	\
+		return (ret) SYSC##name(__SC_CAST##x(__VA_ARGS__));	\
 	}								\
 	SYSCALL_ALIAS(sys##name, SyS##name);				\
-	static inline long SYSC##name(__SC_DECL##x(__VA_ARGS__))
+	static inline ret SYSC##name(__SC_DECL##x(__VA_ARGS__))
 
 #else /* CONFIG_HAVE_SYSCALL_WRAPPERS */
 
-#define SYSCALL_DEFINE(name) asmlinkage long sys_##name
-#define __SYSCALL_DEFINEx(x, name, ...)					\
-	asmlinkage long sys##name(__SC_DECL##x(__VA_ARGS__))
+#define SYSCALL_DEFINE(name)						\
+	__SYSCALL_DEFINE(asmlinkage, long, name)
+#define __SYSCALL_DEFINE(linkage, ret, name)				\
+	__SYSCALL_TRACE0(linkage, ret, name)				\
+	linkage ret sys_##name
+
+#define __SYSCALL_DEFINEx(linkage, ret, x, name, ...)			\
+	__SYSCALL_TRACEx(linkage, ret, x, name, __VA_ARGS__)		\
+	linkage ret sys##name(__SC_DECL##x(__VA_ARGS__))
 
 #endif /* CONFIG_HAVE_SYSCALL_WRAPPERS */
 
-- 
1.7.0.4


  parent reply	other threads:[~2011-04-28  3:19 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-28  3:08 [PATCH 2/7] tracing: split out syscall_trace_enter construction Will Drewry
2011-04-28  3:08 ` [PATCH 3/7] seccomp_filter: Enable ftrace-based system call filtering Will Drewry
2011-04-28 13:50   ` Steven Rostedt
2011-04-28 15:30     ` Will Drewry
2011-04-28 16:20       ` Serge E. Hallyn
2011-04-28 16:56       ` Steven Rostedt
2011-04-28 18:02         ` Will Drewry
2011-04-28 14:29   ` Frederic Weisbecker
2011-04-28 15:15     ` Will Drewry
2011-04-28 15:57       ` Frederic Weisbecker
2011-04-28 16:05         ` Will Drewry
2011-04-28 15:12   ` Frederic Weisbecker
2011-04-28 15:20     ` Frederic Weisbecker
2011-04-28 15:29     ` Will Drewry
2011-04-28 16:13       ` Frederic Weisbecker
2011-04-28 16:48         ` Will Drewry
2011-04-28 17:36           ` Frederic Weisbecker
2011-04-28 18:21             ` Will Drewry
2011-04-28 16:28   ` Steven Rostedt
2011-04-28 16:53     ` Will Drewry
2011-04-28 16:55   ` Serge E. Hallyn
2011-04-28 17:16     ` Steven Rostedt
2011-04-28 17:39       ` Serge E. Hallyn
2011-04-28 18:01         ` Will Drewry
2011-04-28 18:21           ` Steven Rostedt
2011-04-28 18:34             ` Will Drewry
2011-04-28 18:54               ` Serge E. Hallyn
2011-04-28 19:07                 ` Steven Rostedt
2011-04-28 19:06               ` Steven Rostedt
2011-04-28 18:51           ` Serge E. Hallyn
2011-05-03  8:39   ` Avi Kivity
2011-04-28  3:08 ` [PATCH 4/7] seccomp_filter: add process state reporting Will Drewry
2011-04-28  3:21   ` KOSAKI Motohiro
2011-04-28  3:24     ` Will Drewry
2011-04-28  3:40       ` Al Viro
2011-04-28  3:43         ` Will Drewry
2011-04-28 22:54       ` James Morris
2011-05-02 10:08         ` Will Drewry
2011-05-12  3:04   ` [PATCH 4/5] v2 " Will Drewry
2011-04-28  3:08 ` [PATCH 5/7] seccomp_filter: Document what seccomp_filter is and how it works Will Drewry
2011-04-28  7:06   ` Ingo Molnar
2011-04-28 14:56     ` Eric Paris
2011-04-28 18:37       ` Will Drewry
2011-04-29 13:18         ` Frederic Weisbecker
2011-04-29 16:13           ` Will Drewry
2011-05-03  1:29             ` Frederic Weisbecker
2011-05-03  1:47               ` Frederic Weisbecker
2011-05-04  9:15                 ` Will Drewry
2011-05-04  9:29                   ` Will Drewry
2011-05-04 17:52                   ` Frederic Weisbecker
2011-05-04 18:23                     ` Steven Rostedt
2011-05-04 18:30                       ` Frederic Weisbecker
2011-05-04 18:46                         ` Steven Rostedt
2011-05-05  9:21                           ` Will Drewry
2011-05-05 13:14                             ` Serge E. Hallyn
2011-05-12  3:20                               ` Will Drewry
2011-05-06 11:53                             ` Steven Rostedt
2011-05-06 13:35                               ` Eric Paris
2011-05-07  1:58                               ` Will Drewry
2011-05-12  3:04                                 ` [PATCH 5/5] v2 " Will Drewry
2011-05-06 16:30                             ` [PATCH 5/7] " Eric Paris
2011-05-07  2:11                               ` Will Drewry
2011-05-04 12:16                 ` Steven Rostedt
2011-05-04 15:54                   ` Eric Paris
2011-05-04 16:06                     ` Steven Rostedt
2011-05-04 16:22                       ` Eric Paris
2011-05-04 16:39                         ` Steven Rostedt
2011-05-04 18:02                           ` Eric Paris
2011-05-04 17:03                         ` Frederic Weisbecker
2011-05-04 17:55                           ` Eric Paris
2011-04-28 17:43     ` Serge E. Hallyn
2011-04-28 15:46   ` Randy Dunlap
2011-04-28 18:23     ` Will Drewry
2011-04-28  3:08 ` Will Drewry [this message]
2011-04-28  3:08 ` [PATCH 7/7] arch/x86: hook int returning system calls Will Drewry

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=1303960136-14298-5-git-send-email-wad@chromium.org \
    --to=wad@chromium.org \
    --cc=agl@chromium.org \
    --cc=eparis@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=jmorris@namei.org \
    --cc=kees.cook@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@redhat.com \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=srostedt@redhat.com \
    /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

all inboxes | Powered by JetHome®