Received: by 10.223.185.116 with SMTP id b49csp1119911wrg; Sat, 3 Mar 2018 16:09:35 -0800 (PST) X-Google-Smtp-Source: AG47ELssBxmeP0Skpp8+qSXEUirGQVowDvpBgWt0CCa7nDuVU1T7OveIKuQQOHENIjsGrPQgZZh5 X-Received: by 10.99.120.193 with SMTP id t184mr8577055pgc.348.1520122175625; Sat, 03 Mar 2018 16:09:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520122175; cv=none; d=google.com; s=arc-20160816; b=sUkGpyRbUs4Y4StGkgH69BPiALRRjHW8okBdjwn0PuXCN9z6GyxvnKj371OAELkVEE pcRl7vm0iTkgJiVeXwdsGlrNHwl/scFl6pGHaK0fgxcd3j8/6SFqHw5+4uUo3yackaPW gXBHy6zYDGn4FtPoXeaXQRxRdn1JCxpVjY0w/o6jTq8/CbZ9DKmGBBPBiVD+UN1zR0ex Sa6Hqwjk53rPpXEc2yHQl92wWgAbxNNakhiC9mRw5w9STResL140J607fgMK9Ut3ZF+I aUm8wcW7DAMAIZYSZlx0ZP+KAioOUjBeOXY5ivXSwWofdyE8Cw3aD4qfCP/1VMoEHbDO FScg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=3hF8iXf+9fhTM8z7xX4RSjFfWgsYFI2cDMM6fPeiszI=; b=OE7h8K54cyDnvWxtimtJvJbOWaMNsYFWfiOPF+thy0AUK0XdOeJQz7qh1WHwOGws6t SiddpY2NR/cPC6yRxTTVhfN4+9ulr2FAiisCkM6Y2JBnpjFKLRcyPQs5rUL6KTdEMVJ2 VpAAb+z7nhl6wOW4tDbgmQEN51rCbcQLP9CrDOspTTmsT00Y0bO7Tw8wys0nmA9Bn6sW i0DcNSlnzznzRneWKVAFtlo1Dc6AYIlFYETkilKW0hgyaHcCZryDoEfYlOgmQmTAgcwI nWRV44YyRZFWDs7K1IbLv1qaqg02AmzuU46VDDz1oJXyVlttWeksnlgR6hiqOGUWeP+M QIpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=YHXgHaA1; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 89si1431615pfo.111.2018.03.03.16.09.21; Sat, 03 Mar 2018 16:09:35 -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=@microsoft.com header.s=selector1 header.b=YHXgHaA1; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933591AbeCCWbG (ORCPT + 99 others); Sat, 3 Mar 2018 17:31:06 -0500 Received: from mail-sn1nam01on0137.outbound.protection.outlook.com ([104.47.32.137]:51749 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933566AbeCCWbD (ORCPT ); Sat, 3 Mar 2018 17:31:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=3hF8iXf+9fhTM8z7xX4RSjFfWgsYFI2cDMM6fPeiszI=; b=YHXgHaA1P9/4a6DlnX6L1YA/g8vd2s+ADusbTYTo9Wia7izHIw33lroicW/R5V/ot0A2p6heSPE9yiqQbLoGlFI13cpY9Q9ky9Qs6UZgGO1Affym4vujhx2OQhla2C/sizEu2S6/p3MGyZxwK3a0y7cPAPzn8AIVZL+oQepMR9o= Received: from MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) by MW2PR2101MB0970.namprd21.prod.outlook.com (52.132.146.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.3; Sat, 3 Mar 2018 22:30:59 +0000 Received: from MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0]) by MW2PR2101MB1034.namprd21.prod.outlook.com ([fe80::1d56:338f:e2b:cec0%3]) with mapi id 15.20.0567.006; Sat, 3 Mar 2018 22:30:58 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: "Naveen N. Rao" , Ananth N Mavinakayanahalli , Michael Ellerman , Steven Rostedt , "linuxppc-dev@lists.ozlabs.org" , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 005/219] kretprobes: Ensure probe location is at function entry Thread-Topic: [PATCH AUTOSEL for 4.9 005/219] kretprobes: Ensure probe location is at function entry Thread-Index: AQHTsz7h+vIeWDcysk6ztI3Ut2DD/A== Date: Sat, 3 Mar 2018 22:27:58 +0000 Message-ID: <20180303222716.26640-5-alexander.levin@microsoft.com> References: <20180303222716.26640-1-alexander.levin@microsoft.com> In-Reply-To: <20180303222716.26640-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;MW2PR2101MB0970;7:Ug3nGh/gN9Wc/mqKhuoCkOcFkD0X+vUvIz/1KwEIcvzxqcMTdp4lnCm6DnN3AGot399JweEwnXUSUDaqmZWvmf2j3zVkz8gqGXOKftwydawUD0i8JmKqegJEDf4OfhjAG+gdbB/L9By8i4h/QhP6OcKFCUnylrZ0tDq+2aOBi3mUBk9ygzqtkgnE9gtJPO1w961ksgog55Ie8xprjL/UPkhMvhtzZpYVllAzWimETR2qq/rvUYVz+sx6ctVmUUSB x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 07b1cfd7-806b-4d9f-42d2-08d58156700e x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:MW2PR2101MB0970; x-ms-traffictypediagnostic: MW2PR2101MB0970: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(65623756079841)(42068640409301)(104084551191319); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(10201501046)(3002001)(3231220)(944501244)(52105095)(6055026)(61426038)(61427038)(6041288)(20161123562045)(20161123558120)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:MW2PR2101MB0970;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB0970; x-forefront-prvs: 0600F93FE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(39380400002)(366004)(396003)(39860400002)(346002)(199004)(189003)(86362001)(110136005)(4326008)(6506007)(14454004)(99286004)(8936002)(1076002)(36756003)(2906002)(102836004)(76176011)(25786009)(6486002)(316002)(478600001)(3280700002)(107886003)(186003)(54906003)(26005)(81166006)(966005)(7736002)(8676002)(6512007)(6306002)(81156014)(305945005)(72206003)(59450400001)(6436002)(53936002)(6116002)(86612001)(68736007)(3846002)(2950100002)(3660700001)(10290500003)(22452003)(10090500001)(2900100001)(106356001)(2501003)(66066001)(97736004)(5660300001)(5250100002)(105586002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB0970;H:MW2PR2101MB1034.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: v17vIabGKgxEPI9qKASaWOsjkR9mD5gUELgHayeGRb/7Rjn3oFFbxdWxacK0NefsVW8honfZnJ7Ywo0+4pllsbNZpWulQGDvlDztIOuTdIXBRPmN0IRIy9SJcWNgPv3Bu58HEbK/v2nFitNkofpVq3GZFk/NCZbzN98oT+76sKU= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 07b1cfd7-806b-4d9f-42d2-08d58156700e X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2018 22:27:58.2443 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB0970 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Naveen N. Rao" [ Upstream commit 90ec5e89e393c76e19afc845d8f88a5dc8315919 ] kretprobes can be registered by specifying an absolute address or by specifying offset to a symbol. However, we need to ensure this falls at function entry so as to be able to determine the return address. Validate the same during kretprobe registration. By default, there should not be any offset from a function entry, as determined through a kallsyms_lookup(). Introduce arch_function_offset_within_entry() as a way for architectures to override this. Signed-off-by: Naveen N. Rao Acked-by: Masami Hiramatsu Cc: Ananth N Mavinakayanahalli Cc: Michael Ellerman Cc: Steven Rostedt Cc: linuxppc-dev@lists.ozlabs.org Link: http://lkml.kernel.org/r/f1583bc4839a3862cfc2acefcc56f9c8837fa2ba.148= 7770934.git.naveen.n.rao@linux.vnet.ibm.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- include/linux/kprobes.h | 1 + kernel/kprobes.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h index e23392517db9..56a998f34bdd 100644 --- a/include/linux/kprobes.h +++ b/include/linux/kprobes.h @@ -266,6 +266,7 @@ 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 bool arch_function_offset_within_entry(unsigned long offset); =20 extern bool within_kprobe_blacklist(unsigned long addr); =20 diff --git a/kernel/kprobes.c b/kernel/kprobes.c index a1a07cf1101f..2ede39e4227f 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1834,12 +1834,25 @@ static int pre_handler_kretprobe(struct kprobe *p, = struct pt_regs *regs) } NOKPROBE_SYMBOL(pre_handler_kretprobe); =20 +bool __weak arch_function_offset_within_entry(unsigned long offset) +{ + return !offset; +} + int register_kretprobe(struct kretprobe *rp) { int ret =3D 0; struct kretprobe_instance *inst; int i; void *addr; + unsigned long offset; + + addr =3D kprobe_addr(&rp->kp); + if (!kallsyms_lookup_size_offset((unsigned long)addr, NULL, &offset)) + return -EINVAL; + + if (!arch_function_offset_within_entry(offset)) + return -EINVAL; =20 if (kretprobe_blacklist_size) { addr =3D kprobe_addr(&rp->kp); --=20 2.14.1