From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933410AbcKPRh7 (ORCPT ); Wed, 16 Nov 2016 12:37:59 -0500 Received: from omzsmtpe03.verizonbusiness.com ([199.249.25.208]:1660 "EHLO omzsmtpe03.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932247AbcKPRhy (ORCPT ); Wed, 16 Nov 2016 12:37:54 -0500 X-IronPort-Anti-Spam-Filtered: false X-IronPort-AV: E=Sophos;i="5.31,500,1473120000"; d="scan'208";a="235608494" From: alexander.levin@verizon.com Cc: "tglx@linutronix.de" , "scientist@fb.com" , "glider@google.com" , "andreyknvl@google.com" , "rostedt@goodmis.org" , "arnd@arndb.de" , "mathieu.desnoyers@efficios.com" , "daniel.vetter@ffwll.ch" , "linux-kernel@vger.kernel.org" , alexander.levin@verizon.com X-Host: ranger.odc.vzwcorp.com To: "dvyukov@google.com" Subject: [RFC 2/3] abi_spec: hooks into syscall to allow pre and post checking Thread-Topic: [RFC 2/3] abi_spec: hooks into syscall to allow pre and post checking Thread-Index: AQHSQDAJlqw7kecckUi4ie7nFK05EQ== Date: Wed, 16 Nov 2016 17:37:01 +0000 Message-ID: <1479317803-17220-3-git-send-email-alexander.levin@verizon.com> References: <1479317803-17220-1-git-send-email-alexander.levin@verizon.com> In-Reply-To: <1479317803-17220-1-git-send-email-alexander.levin@verizon.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.144.60.250] Content-Type: text/plain; charset="iso-8859-1" MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id uAGHc72v004604 This is a simple way to be able to verify syscall parameters before the call to the actual syscall, and also verify the return value after the call. Signed-off-by: Sasha Levin --- include/linux/syscalls.h | 7 ++++++- kernel/Makefile | 2 ++ kernel/abi_spec.c | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 kernel/abi_spec.c diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 91a740f..6aa3228 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -79,6 +79,7 @@ union bpf_attr; #include #include #include +#include /* * __MAP - apply a macro to syscall arguments @@ -192,13 +193,17 @@ extern struct trace_event_functions exit_syscall_print_funcs; #define __PROTECT(...) asmlinkage_protect(__VA_ARGS__) #define __SYSCALL_DEFINEx(x, name, ...) \ + extern const struct syscall_spec syscall_spec##name; \ asmlinkage long sys##name(__MAP(x,__SC_DECL,__VA_ARGS__)) \ __attribute__((alias(__stringify(SyS##name)))); \ static inline long SYSC##name(__MAP(x,__SC_DECL,__VA_ARGS__)); \ asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)); \ asmlinkage long SyS##name(__MAP(x,__SC_LONG,__VA_ARGS__)) \ { \ - long ret = SYSC##name(__MAP(x,__SC_CAST,__VA_ARGS__)); \ + long ret; \ + abispec_check_pre(&syscall_spec##name, __MAP(x,__SC_CAST,__VA_ARGS__)); \ + ret = SYSC##name(__MAP(x,__SC_CAST,__VA_ARGS__)); \ + abispec_check_post(&syscall_spec##name, ret, __MAP(x,__SC_CAST,__VA_ARGS__)); \ __MAP(x,__SC_TEST,__VA_ARGS__); \ __PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__)); \ return ret; \ diff --git a/kernel/Makefile b/kernel/Makefile index eb26e12c..d94a1f9 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -113,6 +113,8 @@ obj-$(CONFIG_MEMBARRIER) += membarrier.o obj-$(CONFIG_HAS_IOMEM) += memremap.o +obj-y += abi_spec.o + $(obj)/configs.o: $(obj)/config_data.h # config_data.h contains the same information as ikconfig.h but gzipped. diff --git a/kernel/abi_spec.c b/kernel/abi_spec.c new file mode 100644 index 0000000..7933c45 --- /dev/null +++ b/kernel/abi_spec.c @@ -0,0 +1,15 @@ +#include +#include +#include +#include + +void abispec_check_pre(const struct syscall_spec *s, ...) +{ +} +EXPORT_SYMBOL_GPL(abispec_check_pre); + +void abispec_check_post(const struct syscall_spec *s, long retval, ...) +{ +} +EXPORT_SYMBOL_GPL(abispec_check_post); + -- 2.7.4