Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3027766imu; Mon, 17 Dec 2018 11:58:05 -0800 (PST) X-Google-Smtp-Source: AFSGD/W50cNyBImem8WdEW1FMslJoATSVkAvnMY+vvML4Eenrdx6oVZZGKTSVgHqMTV+zgv8lQgx X-Received: by 2002:a63:557:: with SMTP id 84mr12887009pgf.411.1545076685766; Mon, 17 Dec 2018 11:58:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545076685; cv=none; d=google.com; s=arc-20160816; b=uYVOaW5VkPnFoqy2jqrIH2MzyHmWUIdDZNhK/QkQ+yqA0/5TCBV8tl6Gw+5SrQLVut fv35jiiDuuF4btBUK6XoykYlCuz60I+ydbY656QMcZl4P27TnZTEM2RJs1mKHp/O7WQy GCqZWs7xUuO7wnbM6EUOGkO5dZ9ltC9j8G9ypnW3jxd+gFE13yuBSGxTGCncqRedRvY3 BfTixZMwzxgawIHOg1YxVRIwbKs1AhmbXZTDCGGSnmw4Fkq+fg6kanZajCKfbkx6UyVS Wf5CZzlevpYyY+iffF392m104YHLlyseAX4HnZuEHV0Gs6MdmQ8MZlluptCj4j1Gv1zL usJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=bgCcXq+xzPSm+WssqEFj44jrh3mj5vT+PltYhgydU8E=; b=arcwud7w3NLQeHWtT7q1CIMiTuAJnVoMYWpwWvtyOjM5R7wTTBLf2+9h9Y30wjbsoj R1fv2lCg4RVtvv1M/IyBEpC7Q/NaN3NtGVLAhnyJfVyvPSL09Q15SCm9Zzs7PLEMSNm+ pgF1t+jGuQdEXh8yU2SWh0bsnESr876lPHM+HlaS6gw+fiRaAY7s/p09b0K9iW2KSpDx lzi2mhXrvvXXWJdk0Md7VInwz7x6+TDvQkb+XXoSV0OUU9lFN0gjINofd9rImi+OMP05 4WgPdi2Mh/YROniVDZGNP04/u4lV8EW/r/wtAOFwRVpXa8l0nCT2yc6UUiEcWtEsGsv+ nYQw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5si11054009plp.294.2018.12.17.11.57.50; Mon, 17 Dec 2018 11:58:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388703AbeLQSTZ (ORCPT + 99 others); Mon, 17 Dec 2018 13:19:25 -0500 Received: from terminus.zytor.com ([198.137.202.136]:43277 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727597AbeLQSTY (ORCPT ); Mon, 17 Dec 2018 13:19:24 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id wBHIItXw2560769 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 17 Dec 2018 10:18:55 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id wBHIItvv2560766; Mon, 17 Dec 2018 10:18:55 -0800 Date: Mon, 17 Dec 2018 10:18:55 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Masami Hiramatsu Message-ID: Cc: anil.s.keshavamurthy@intel.com, torvalds@linux-foundation.org, peterz@infradead.org, tglx@linutronix.de, yhs@fb.com, davem@davemloft.net, hpa@zytor.com, bp@alien8.de, righi.andrea@gmail.com, mhiramat@kernel.org, naveen.n.rao@linux.vnet.ibm.com, mingo@kernel.org, linux-kernel@vger.kernel.org, luto@kernel.org Reply-To: davem@davemloft.net, tglx@linutronix.de, yhs@fb.com, peterz@infradead.org, torvalds@linux-foundation.org, anil.s.keshavamurthy@intel.com, luto@kernel.org, naveen.n.rao@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, mingo@kernel.org, righi.andrea@gmail.com, mhiramat@kernel.org, hpa@zytor.com, bp@alien8.de In-Reply-To: <154503485491.26176.15823229545155174796.stgit@devbox> References: <154503485491.26176.15823229545155174796.stgit@devbox> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] kprobes: Blacklist symbols in arch-defined prohibited area Git-Commit-ID: fb1a59fae8baa3f3c69b72a87ff94fc4fa5683ec X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=1.4 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_96_Q,FREEMAIL_FORGED_REPLYTO autolearn=no autolearn_force=no version=3.4.2 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: fb1a59fae8baa3f3c69b72a87ff94fc4fa5683ec Gitweb: https://git.kernel.org/tip/fb1a59fae8baa3f3c69b72a87ff94fc4fa5683ec Author: Masami Hiramatsu AuthorDate: Mon, 17 Dec 2018 17:20:55 +0900 Committer: Ingo Molnar CommitDate: Mon, 17 Dec 2018 17:48:38 +0100 kprobes: Blacklist symbols in arch-defined prohibited area Blacklist symbols in arch-defined probe-prohibited areas. With this change, user can see all symbols which are prohibited to probe in debugfs. All archtectures which have custom prohibit areas should define its own arch_populate_kprobe_blacklist() function, but unless that, all symbols marked __kprobes are blacklisted. Reported-by: Andrea Righi Tested-by: Andrea Righi Signed-off-by: Masami Hiramatsu Cc: Andy Lutomirski Cc: Anil S Keshavamurthy Cc: Borislav Petkov Cc: David S. Miller Cc: Linus Torvalds Cc: Naveen N. Rao Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Yonghong Song Link: http://lkml.kernel.org/r/154503485491.26176.15823229545155174796.stgit@devbox Signed-off-by: Ingo Molnar --- include/linux/kprobes.h | 3 +++ kernel/kprobes.c | 67 ++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 56 insertions(+), 14 deletions(-) diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h index e909413e4e38..5da8a1de2187 100644 --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -242,10 +242,13 @@ extern int arch_init_kprobes(void); extern void show_registers(struct pt_regs *regs); extern void kprobes_inc_nmissed_count(struct kprobe *p); extern bool arch_within_kprobe_blacklist(unsigned long addr); +extern int arch_populate_kprobe_blacklist(void); extern bool arch_kprobe_on_func_entry(unsigned long offset); extern bool kprobe_on_func_entry(kprobe_opcode_t *addr, const char *sym, unsigned long offset); extern bool within_kprobe_blacklist(unsigned long addr); +extern int kprobe_add_ksym_blacklist(unsigned long entry); +extern int kprobe_add_area_blacklist(unsigned long start, unsigned long end); struct kprobe_insn_cache { struct mutex mutex; diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 90e98e233647..90569aec0f24 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2093,6 +2093,47 @@ void dump_kprobe(struct kprobe *kp) } NOKPROBE_SYMBOL(dump_kprobe); +int kprobe_add_ksym_blacklist(unsigned long entry) +{ + struct kprobe_blacklist_entry *ent; + unsigned long offset = 0, size = 0; + + if (!kernel_text_address(entry) || + !kallsyms_lookup_size_offset(entry, &size, &offset)) + return -EINVAL; + + ent = kmalloc(sizeof(*ent), GFP_KERNEL); + if (!ent) + return -ENOMEM; + ent->start_addr = entry; + ent->end_addr = entry + size; + INIT_LIST_HEAD(&ent->list); + list_add_tail(&ent->list, &kprobe_blacklist); + + return (int)size; +} + +/* Add all symbols in given area into kprobe blacklist */ +int kprobe_add_area_blacklist(unsigned long start, unsigned long end) +{ + unsigned long entry; + int ret = 0; + + for (entry = start; entry < end; entry += ret) { + ret = kprobe_add_ksym_blacklist(entry); + if (ret < 0) + return ret; + if (ret == 0) /* In case of alias symbol */ + ret = 1; + } + return 0; +} + +int __init __weak arch_populate_kprobe_blacklist(void) +{ + return 0; +} + /* * Lookup and populate the kprobe_blacklist. * @@ -2104,26 +2145,24 @@ NOKPROBE_SYMBOL(dump_kprobe); static int __init populate_kprobe_blacklist(unsigned long *start, unsigned long *end) { + unsigned long entry; unsigned long *iter; - struct kprobe_blacklist_entry *ent; - unsigned long entry, offset = 0, size = 0; + int ret; for (iter = start; iter < end; iter++) { entry = arch_deref_entry_point((void *)*iter); - - if (!kernel_text_address(entry) || - !kallsyms_lookup_size_offset(entry, &size, &offset)) + ret = kprobe_add_ksym_blacklist(entry); + if (ret == -EINVAL) continue; - - ent = kmalloc(sizeof(*ent), GFP_KERNEL); - if (!ent) - return -ENOMEM; - ent->start_addr = entry; - ent->end_addr = entry + size; - INIT_LIST_HEAD(&ent->list); - list_add_tail(&ent->list, &kprobe_blacklist); + if (ret < 0) + return ret; } - return 0; + + /* Symbols in __kprobes_text are blacklisted */ + ret = kprobe_add_area_blacklist((unsigned long)__kprobes_text_start, + (unsigned long)__kprobes_text_end); + + return ret ? : arch_populate_kprobe_blacklist(); } /* Module notifier call back, checking kprobes on the module */