Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp4005291imj; Tue, 12 Feb 2019 08:14:40 -0800 (PST) X-Google-Smtp-Source: AHgI3IaMLOpo+i8mRz5BdzasYpiowLvxPCyNvxoDjIS/ryCyvspahDqqa4UcH8XW9SQn4CORApP1 X-Received: by 2002:a63:1105:: with SMTP id g5mr4325446pgl.322.1549988080227; Tue, 12 Feb 2019 08:14:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549988080; cv=none; d=google.com; s=arc-20160816; b=k6Fisbcwo11vtg+RONn4TNNx//Bl9OCH0FBRRekeINA81K6rrHg4BaipZ7eHE79hSt 4Bsc8eEiZFGmIC4yJLUx8Q5jUQRkwh0VScCtdt+8AEZtkK4lWPT2/sMe1YjTUI/+40A+ a8RsXJPrWLMLxLuPX11svS/oFiDtvCHR2jGL2VISKHf3/l6N43kuQTi5vK2LhUQCeQSR mDSNtwmtTH40KpzvDWXucaPtXfStoZJkpOWecsntpAYVQChpl9D7T/ITtY410uKgxuC2 uoijafdMZFosfVN5nVYyQ/tsPdFcb+lkO1hhYpr5G8ioh04l78l6w60Pv/zhZj9Omvw+ TgdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/A7guJrxYfresd7AQSj/I2Mk9ZXtf4q3nUPMcs99LzA=; b=FnqNeEaN6LfE3AVhRxMLSyaBhdqBRaTjafdOG+qucdzHtQOMsq60fa9NW5tyUVjxq8 23V/b+4rZPqOalTBIB/bwHPrZpSWbgA+09dOjKSLKykxwQd2/b+4mhTPbqm6ZBAP4Duf iUaSr+UlFnu2voFmVTCBvBM8Q8TZWuxId/J9ZzUJnpskbPDmvrEO/HhW4NwD+V2DS8Rr Fu78Lv7udwjMSNlbv5ihj2n8jrWadl5fryGvw5WH8rY9J2UO4PhCtjMcmAFYgdgC5lxH cBXznxoepp0lhfo5fvKlY7auG/0WjapYVL3eZhGuZ3zKKgQq8sPAJO9QJNHX3bcqibUX 9x9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eHyQBYvW; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m21si8795727pls.324.2019.02.12.08.14.24; Tue, 12 Feb 2019 08:14:40 -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; dkim=pass header.i=@kernel.org header.s=default header.b=eHyQBYvW; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730808AbfBLQNg (ORCPT + 99 others); Tue, 12 Feb 2019 11:13:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:42318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728035AbfBLQNg (ORCPT ); Tue, 12 Feb 2019 11:13:36 -0500 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 56B3621773; Tue, 12 Feb 2019 16:13:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549988015; bh=6jnmvEU0+6T1UAxD7pf7iAk01qe90EQAG6XlZSBrsnk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eHyQBYvW0/UsVua55sSqU/qjmkdYNDSTRR4fT17DEYVPlzHDfMQR0ZIR0cLuTxQss 5vI860jeahTuYX5UMvKJo3V28oPVtsB/cLimVGY/k4RXcR8VhtljqHgx3XZhx4OedX YPzsNC3qKHrQMQoDkRyuofYsYjAfSQBBYc1Fr1Q8= From: Masami Hiramatsu To: Ingo Molnar Cc: Masami Hiramatsu , peterz@infradead.org, Mathieu Desnoyers , linux-kernel , Andrea Righi , Steven Rostedt Subject: [PATCH -tip v3 05/10] kprobes: Search non-suffixed symbol in blacklist Date: Wed, 13 Feb 2019 01:13:12 +0900 Message-Id: <154998799234.31052.6136378903570418008.stgit@devbox> X-Mailer: git-send-email 2.13.6 In-Reply-To: <154998785011.31052.1475728497912659748.stgit@devbox> References: <154998785011.31052.1475728497912659748.stgit@devbox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Newer gcc can generate some different instances of a function with suffixed symbols if the function is optimized and only has a part of that. (e.g. .constprop, .part etc.) In this case, it is not enough to check the entry of kprobe blacklist because it only records non-suffixed symbol address. To fix this issue, search non-suffixed symbol in blacklist if given address is within a symbol which has a suffix. Note that this can cause false positive cases if a kprobe-safe function is optimized to suffixed instance and has same name symbol which is blacklisted. But I would like to chose a fail-safe design for this issue. Signed-off-by: Masami Hiramatsu --- kernel/kprobes.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index f4ddfdd2d07e..c83e54727131 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1396,7 +1396,7 @@ bool __weak arch_within_kprobe_blacklist(unsigned long addr) addr < (unsigned long)__kprobes_text_end; } -bool within_kprobe_blacklist(unsigned long addr) +static bool __within_kprobe_blacklist(unsigned long addr) { struct kprobe_blacklist_entry *ent; @@ -1410,7 +1410,26 @@ bool within_kprobe_blacklist(unsigned long addr) if (addr >= ent->start_addr && addr < ent->end_addr) return true; } + return false; +} +bool within_kprobe_blacklist(unsigned long addr) +{ + char symname[KSYM_NAME_LEN], *p; + + if (__within_kprobe_blacklist(addr)) + return true; + + /* Check if the address is on a suffixed-symbol */ + if (!lookup_symbol_name(addr, symname)) { + p = strchr(symname, '.'); + if (!p) + return false; + *p = '\0'; + addr = (unsigned long)kprobe_lookup_name(symname, 0); + if (addr) + return __within_kprobe_blacklist(addr); + } return false; }