From patchwork Mon Mar 2 14:24:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 5913461 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 24102BF440 for ; Mon, 2 Mar 2015 14:29:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4EB65201FA for ; Mon, 2 Mar 2015 14:29:53 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 767FE2013A for ; Mon, 2 Mar 2015 14:29:52 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YSRJB-00041p-TX; Mon, 02 Mar 2015 14:26:57 +0000 Received: from szxga01-in.huawei.com ([119.145.14.64]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YSRJ2-0003iO-8H for linux-arm-kernel@lists.infradead.org; Mon, 02 Mar 2015 14:26:52 +0000 Received: from 172.24.2.119 (EHLO lggeml422-hub.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CKE50576; Mon, 02 Mar 2015 22:25:46 +0800 (CST) Received: from kernel-host.huawei (10.107.197.247) by lggeml422-hub.china.huawei.com (10.72.61.32) with Microsoft SMTP Server id 14.3.158.1; Mon, 2 Mar 2015 22:25:35 +0800 From: Wang Nan To: , , , , Subject: [RFC PATCH v4 04/34] early kprobes: within_kprobe_blacklist_early() early. Date: Mon, 2 Mar 2015 22:24:42 +0800 Message-ID: <1425306312-3437-5-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1425306312-3437-1-git-send-email-wangnan0@huawei.com> References: <1425306312-3437-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.197.247] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150302_062648_676568_44F0E21E X-CRM114-Status: GOOD ( 11.92 ) X-Spam-Score: -2.3 (--) Cc: x86@kernel.org, lizefan@huawei.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces within_kprobe_blacklist_early(), which will be used when registering early kprobes. In init_kprobes(), populate_kprobe_blacklist() is the only function which rely on memory system so unable to be executed at very early stage. Following patches will move other parts of init_kprobes() to early stage and leave populate_kprobe_blacklist() at its original position. Before populate_kprobe_blacklist(), within_kprobe_blacklist_early() can be used for checking blacklist. Signed-off-by: Wang Nan --- kernel/kprobes.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index c90e417..427d761 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -68,6 +68,7 @@ #endif static int kprobes_initialized; +static int kprobes_blacklist_initialized; static struct hlist_head kprobe_table[KPROBE_TABLE_SIZE]; static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE]; @@ -1332,12 +1333,41 @@ bool __weak arch_within_kprobe_blacklist(unsigned long addr) addr < (unsigned long)__kprobes_text_end; } + +static bool within_kprobe_blacklist_early(unsigned long addr) +{ + /* Markers of _kprobe_blacklist section */ + extern unsigned long __start_kprobe_blacklist[]; + extern unsigned long __stop_kprobe_blacklist[]; + + unsigned long *start = __start_kprobe_blacklist; + unsigned long *end = __stop_kprobe_blacklist; + unsigned long *iter; + unsigned long entry, offset = 0, size = 0; + + 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)) + continue; + if (addr >= entry && addr < entry + size) + return true; + } + + return false; +} + static bool within_kprobe_blacklist(unsigned long addr) { struct kprobe_blacklist_entry *ent; if (arch_within_kprobe_blacklist(addr)) return true; + + if (!kprobes_blacklist_initialized) + return within_kprobe_blacklist_early(addr); + /* * If there exists a kprobe_blacklist, verify and * fail any probe registration in the prohibited area @@ -2147,6 +2177,7 @@ static int __init init_kprobes(void) pr_err("kprobes: failed to populate blacklist: %d\n", err); pr_err("Please take care of using kprobes.\n"); } + kprobes_blacklist_initialized = (err == 0); if (kretprobe_blacklist_size) { /* lookup the function address from its name */