From patchwork Fri Jul 22 21:24:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 9244353 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4815C60459 for ; Fri, 22 Jul 2016 21:28:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36914280F4 for ; Fri, 22 Jul 2016 21:28:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A72328111; Fri, 22 Jul 2016 21:28:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A53E5280F4 for ; Fri, 22 Jul 2016 21:28:16 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bQhx3-0001VE-LT; Fri, 22 Jul 2016 21:25:45 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bQhx2-0001Sp-Cd for xen-devel@lists.xensource.com; Fri, 22 Jul 2016 21:25:44 +0000 Received: from [193.109.254.147] by server-12.bemta-14.messagelabs.com id 05/F2-28536-75F82975; Fri, 22 Jul 2016 21:25:43 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsVybKJsh25Y/6R wg2dzjS3uTXnP7sDosb1vF3sAYxRrZl5SfkUCa8bLK9fYC5qVK9oubWBvYNwm28XIxSEkMJVR 4vzTK2wQzgwmiUMXzjB1MXJwsAnoSty8LQESFxHYwCSx8MtddhCHWWApp8SHmdtYuxg5OYQF3 CU2z/nMBGKzCKhK3N/+EizOK+AoMWPKHLC4hICcRMuP3awgQzmB4puWKoGEhQQcJJrnNIKFJQ QKJPYfjoao9pJYdOMSK4StJnH13CbmCYx8CxgZVjFqFKcWlaUW6Roa6SUVZaZnlOQmZuboGhq a6OWmFhcnpqfmJCYV6yXn525iBIYJAxDsYDw7zfkQoyQHk5Io7/vgSeFCfEn5KZUZicUZ8UWl OanFhxhlODiUJHhV+oBygkWp6akVaZk5wICFSUtw8CiJ8GqCpHmLCxJzizPTIVKnGBWlxHlv9 AIlBEASGaV5cG2wKLnEKCslzMsIdIgQT0FqUW5mCar8K0ZxDkYlYV59kPE8mXklcNNfAS1mAl o8R6AfZHFJIkJKqoExumOr6RrHBf3adyLPR+pYV0eUcTTvCar0CjrJbbvKtXi/Y+iX8yETO9I sDS5u7eHt+bJc4Lr83rD+GdFF989+f8BcNdNTannoOtENea2XUhYf4TLcs+R1yOeYFf0uyZHJ dTazjfd+EVtWJRzv5rpeZkuPA8Ox9ZzmbM7qn728927IexYopafEUpyRaKjFXFScCAAgDYmmj QIAAA== X-Env-Sender: mcgrof@kernel.org X-Msg-Ref: server-5.tower-27.messagelabs.com!1469222741!55466156!1 X-Originating-IP: [198.145.29.136] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32923 invoked from network); 22 Jul 2016 21:25:42 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.136) by server-5.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Jul 2016 21:25:42 -0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B90A0205E3; Fri, 22 Jul 2016 21:25:39 +0000 (UTC) Received: from garbanzo.do-not-panic.com (c-73-15-241-2.hsd1.ca.comcast.net [73.15.241.2]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BDD02205DF; Fri, 22 Jul 2016 21:25:36 +0000 (UTC) From: "Luis R. Rodriguez" To: hpa@zytor.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, linux@arm.linux.org.uk, mhiramat@kernel.org, masami.hiramatsu.pt@hitachi.com, jbaron@akamai.com, heiko.carstens@de.ibm.com, ananth@linux.vnet.ibm.com, anil.s.keshavamurthy@intel.com, davem@davemloft.net, realmz6@gmail.com Date: Fri, 22 Jul 2016 14:24:47 -0700 Message-Id: <1469222687-1600-14-git-send-email-mcgrof@kernel.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1469222687-1600-1-git-send-email-mcgrof@kernel.org> References: <1469222687-1600-1-git-send-email-mcgrof@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP Cc: gnomes@lxorguk.ukuu.org.uk, linux-ia64@vger.kernel.org, jkosina@suse.cz, benh@kernel.crashing.org, ming.lei@canonical.com, linux@rasmusvillemoes.dk, platform-driver-x86@vger.kernel.org, paul.gortmaker@windriver.com, sparclinux@vger.kernel.org, linux-arch@vger.kernel.org, xen-devel@lists.xensource.com, linux-sh@vger.kernel.org, x86@kernel.org, fontana@sharpeleven.org, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, dvhart@infradead.org, dwmw2@infradead.org, pali.rohar@gmail.com, keescook@chromium.org, arnd@arndb.de, will.deacon@arm.com, rusty@rustcorp.com.au, rostedt@goodmis.org, christopher.denicolo@suse.com, ak@linux.intel.com, ciaran.farrell@suse.com, jpoimboe@redhat.com, andriy.shevchenko@linux.intel.com, mcb30@ipxe.org, linux-kbuild@vger.kernel.org, alan@linux.intel.com, jgross@suse.com, pebolle@tiscali.nl, tony.luck@intel.com, ananth@in.ibm.com, gregkh@linuxfoundation.org, luto@amacapital.net, "Luis R. Rodriguez" , mmarek@suse.com, david.vrabel@citrix.com, andrew.cooper3@citrix.com, akpm@linux-foundation.org, torvalds@linux-foundation.org, korea.drzix@gmail.com Subject: [Xen-devel] [RFC v3 13/13] kprobes: port blacklist kprobes to linker table X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP kprobe makes use of two sections, the one dealing with the actual kprobes was recently ported using the standard section range API. The blacklist functionality of kprobes is still using a custom section and declaring its custom section using the linker script as follows: type Linux-section custom section name begin end table .init.data _kprobe_blacklist __start_kprobe_blacklist __stop_kprobe_blacklist This ports the _kprobe_blacklist custom section to the standard Linux linker table API allowing us remove all the custom blacklist kprobe section declarations from the linker script. This has been tested by trying to register a kprobe on a blacklisted symbol (these are declared with NOKPROBE_SYMBOL()), and confirms that this fails to work as expected. This was tested with: # insmod samples/kprobes/kprobe_example.ko symbol="get_kprobe" This fails to load as expected with: insmod: ERROR: could not insert module samples/kprobes/kprobe_example.ko: Invalid parameters v3: this patch was introduced in this series Signed-off-by: Luis R. Rodriguez Acked-by: Masami Hiramatsu --- include/asm-generic/vmlinux.lds.h | 10 ---------- include/linux/kprobes.h | 5 +++-- kernel/kprobes.c | 11 ++++------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h index 1664050e6560..0e4df8c61c18 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -113,15 +113,6 @@ #define BRANCH_PROFILE() #endif -#ifdef CONFIG_KPROBES -#define KPROBE_BLACKLIST() . = ALIGN(8); \ - VMLINUX_SYMBOL(__start_kprobe_blacklist) = .; \ - *(_kprobe_blacklist) \ - VMLINUX_SYMBOL(__stop_kprobe_blacklist) = .; -#else -#define KPROBE_BLACKLIST() -#endif - #ifdef CONFIG_EVENT_TRACING #define FTRACE_EVENTS() . = ALIGN(8); \ VMLINUX_SYMBOL(__start_ftrace_events) = .; \ @@ -519,7 +510,6 @@ *(SECTION_INIT_RODATA) \ FTRACE_EVENTS() \ TRACE_SYSCALLS() \ - KPROBE_BLACKLIST() \ MEM_DISCARD(init.rodata) \ CLK_OF_TABLES() \ RESERVEDMEM_OF_TABLES() \ diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h index 3f46b282a3f9..c9bb9caef70c 100644 --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -43,9 +43,11 @@ #ifdef CONFIG_KPROBES #include +#include #include DECLARE_SECTION_RANGE(kprobes); +DECLARE_LINKTABLE(unsigned long, _kprobe_blacklist); /* kprobe_status settings */ #define KPROBE_HIT_ACTIVE 0x00000001 @@ -490,8 +492,7 @@ static inline int enable_jprobe(struct jprobe *jp) * by using this macro. */ #define __NOKPROBE_SYMBOL(fname) \ -static unsigned long __used \ - __attribute__((section("_kprobe_blacklist"))) \ +static LINKTABLE_INIT_DATA(_kprobe_blacklist, all) \ _kbl_addr_##fname = (unsigned long)fname; #define NOKPROBE_SYMBOL(fname) __NOKPROBE_SYMBOL(fname) #else diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 387605682622..4801aa3b4adf 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2053,14 +2053,13 @@ NOKPROBE_SYMBOL(dump_kprobe); * since a kprobe need not necessarily be at the beginning * of a function. */ -static int __init populate_kprobe_blacklist(unsigned long *start, - unsigned long *end) +static int __init populate_kprobe_blacklist(void) { unsigned long *iter; struct kprobe_blacklist_entry *ent; unsigned long entry, offset = 0, size = 0; - for (iter = start; iter < end; iter++) { + LINKTABLE_FOR_EACH(iter, _kprobe_blacklist) { entry = arch_deref_entry_point((void *)*iter); if (!kernel_text_address(entry) || @@ -2125,8 +2124,7 @@ static struct notifier_block kprobe_module_nb = { }; /* Markers of _kprobe_blacklist section */ -extern unsigned long __start_kprobe_blacklist[]; -extern unsigned long __stop_kprobe_blacklist[]; +DEFINE_LINKTABLE_INIT_DATA(unsigned long, _kprobe_blacklist); /* Actual kprobes section range */ DEFINE_SECTION_RANGE(kprobes, SECTION_TEXT); @@ -2143,8 +2141,7 @@ static int __init init_kprobes(void) raw_spin_lock_init(&(kretprobe_table_locks[i].lock)); } - err = populate_kprobe_blacklist(__start_kprobe_blacklist, - __stop_kprobe_blacklist); + err = populate_kprobe_blacklist(); if (err) { pr_err("kprobes: failed to populate blacklist: %d\n", err); pr_err("Please take care of using kprobes.\n");