Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1242245imu; Fri, 11 Jan 2019 18:30:08 -0800 (PST) X-Google-Smtp-Source: ALg8bN604FgaYz7KsTOsPiiaOxcfSfPdnoR06HtG/MzztKjyX9nro7hRL9Iq6OG6vCVj4Kb6ig2f X-Received: by 2002:a65:4142:: with SMTP id x2mr15050876pgp.356.1547260208147; Fri, 11 Jan 2019 18:30:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547260208; cv=none; d=google.com; s=arc-20160816; b=0+/lLpQdTp5kYUEOSal+LMdlAj6iXtbiP6IUXN8IgaQU8Vq3oha7FQ/niy9LrSMBU4 NkyUDYwExfgQ5zY3P0OgMx9P4e+CrGt5rCI5LQkdUa14Xow5mFoa9wDfsH2oHvNEqWxQ 1lNnncbnbhxbS6+IQwHE00Vp28lxtsGyEYdZ4qKpETJpeSldtDf9fQ/N6S18EsHryE8b gY8E0ducLF6IGswcAhpcdpemTmfC1IW44ehqwSD+wG+GetrngD5YZG0/AQUH4Q6X7NRk dPmBDZZ9yPN5IVxQPWoSTGW4zYOQ5naujpEJwNsm8Avy8wAY8lzJfhLzEYLMe25VXv+S wCPQ== 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=nHvwtK4khsxFdxCQl0RUiOHc/EDyvJ4HTPzXnlGjksM=; b=mt14waeLqwxXFW4j95SYNorJOqvg4Z2zOlkcqr8Yrth8pWfrhgi3qqYtduqzybjViw 46NeB9J0lTmOOlZMJX8W+PoLoTSqkJ+TwPsQIabbQwful1n/VpdcOqTc76tKNuRHoyPD Q3PD4wd1MQ985QVyzfkQVpR5DKoBI2YAfwYjve9LX0WTGwfI2wVkn2OffwMC4pemG2hz PX+u3tdat880qwZG35OA28iBzN1xMY0iXerF5y8Hd9oKE5G+VMTZRS4LozoO7n+6XZ+w c/GHTixo3A/TxEWyzO3jzpoogXKXEy09Hwb1zTD3zDeRtfq7sFEmUdCDR8eiQhfvNt3j kSmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ebP93Dwf; 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 q19si19952558pfh.138.2019.01.11.18.29.53; Fri, 11 Jan 2019 18:30:08 -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=ebP93Dwf; 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 S1726610AbfALC20 (ORCPT + 99 others); Fri, 11 Jan 2019 21:28:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:48460 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726227AbfALC20 (ORCPT ); Fri, 11 Jan 2019 21:28:26 -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 4319B204FD; Sat, 12 Jan 2019 02:28:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547260105; bh=YtrS9Eu6vSLzd1eZiv2zYRFV5MTPlYIgS5GA9OxPs3M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ebP93Dwf1++xq/hlbZMv2byQukpK6HwhrDLMdVFEBj1R66fMYzs2eJyc4SKLqtjSV 4xWYWX0cj9QF64SyOw5jY+bh2hoaM2bmD4R0yfy5BB2s9Dh5KHb38y7wnb6O6Uw339 ktTFYEGSQSJ3RpPSO6WxYKznaIshZTpV5IqtVEGA= From: Masami Hiramatsu To: Ingo Molnar Cc: Masami Hiramatsu , peterz@infradead.org, Mathieu Desnoyers , linux-kernel , Andrea Righi , Steven Rostedt Subject: [PATCH v2 5/9] kprobes: Search non-suffixed symbol in blacklist Date: Sat, 12 Jan 2019 11:28:02 +0900 Message-Id: <154726008226.18060.9082091974811290044.stgit@devbox> X-Mailer: git-send-email 2.13.6 In-Reply-To: <154725993986.18060.2759150647140353514.stgit@devbox> References: <154725993986.18060.2759150647140353514.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 e8c76164f541..faa519f07aad 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; }