Received: by 10.223.185.116 with SMTP id b49csp1094433wrg; Sat, 3 Mar 2018 15:23:18 -0800 (PST) X-Google-Smtp-Source: AG47ELteXMzaFagC+Gb0qej64mC6WnIWzQLfEFxAesnmAiS2nWrHAFNk7QXZMGLqeRrpH1g4kdNN X-Received: by 10.167.128.143 with SMTP id v15mr10483159pff.36.1520119398819; Sat, 03 Mar 2018 15:23:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520119398; cv=none; d=google.com; s=arc-20160816; b=vmNX9JD19j7fq1zE5jzTlFULmKgySgapKyFNzoF4xXiXbrTOXhMsHNGd8li73tW7CD GuiF53g0fpzn5ouMq8OJTxZJbAIWA/UY5Z3vO6/dfBk/gt9K16kU+om2zaYI/RzXebNq IfC9K+JnSA6U24zoH++NIgP9iZcjHZrhG22oHzL8Co5Potkvu7pKiZpvnE84+ecn9uLo idGDOiRYKCK0ARaPcN4JhuKWuxzySlqFD295NMWF3J8UnM4fZfQV2Od2LSJtoqYr4Ba3 pui13ETggrOMa/faH/iIOjjziYPomnKNVAlTd/Wfcshy18SagoIfV+oJ/PbmcS2C7Mta Iuzw== 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=Dlfr63CP3UPJGS+IoAbfg/S1ForJv366ds59pgel/Sw=; b=yIJtS8h9lSnjSQ5+ucmRmHDzeOB4hhGsP0NU0DnMQKgATD+DlWtA+ql6gBp4a1hoVb NEsAjBwVEgmYk1tpcso3Fxv8CpKHbFfO2kFKkp5o44zsCjaD8yIL4W3wvM1go9b7ZOG1 qqdglcOqs4YfvTB2IfwqU0koAuVZKqedJPhe3v5T7kWBcqXHbfdENJZOTT5Tr91Fm+cR 1QyQ6R9QApqmCU89qmahWCd4NQ8j8Xn6KO4NmS3xOsIODmyZ6dZyOTm2tQa8OBb+M48r 4fkliYaE8PybCJJ3Vf1Xt6uFITfMxO3/n+KTzYL80kiWArS1WV6Hr9PHK6nHFcW4T9M7 NwGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=FkuDfZZf; 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 j191si6081355pge.369.2018.03.03.15.23.04; Sat, 03 Mar 2018 15:23:18 -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=FkuDfZZf; 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 S933933AbeCCXVO (ORCPT + 99 others); Sat, 3 Mar 2018 18:21:14 -0500 Received: from mail-co1nam03on0134.outbound.protection.outlook.com ([104.47.40.134]:45128 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932373AbeCCWh4 (ORCPT ); Sat, 3 Mar 2018 17:37:56 -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=Dlfr63CP3UPJGS+IoAbfg/S1ForJv366ds59pgel/Sw=; b=FkuDfZZfMalKx8+7SWVVDiGjNy9v2m7CAu3rlBW0U1ly/O/8c5186OD4Ni6N7vbUzVWbrwtRW4bV7pcadL+83pxxPnW1zY2u5BY6/sqUTvDnmFTndd7UaUXtqm7OWPD9ohGLHId2LEcDKdacHNSNSiPl/8ChezXCirPPsqkRTvQ= Received: from MW2PR2101MB1034.namprd21.prod.outlook.com (52.132.149.10) by MW2PR2101MB1100.namprd21.prod.outlook.com (52.132.149.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.567.2; Sat, 3 Mar 2018 22:37:52 +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:37:52 +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.4 002/115] kretprobes: Ensure probe location is at function entry Thread-Topic: [PATCH AUTOSEL for 4.4 002/115] kretprobes: Ensure probe location is at function entry Thread-Index: AQHTsz9HDS4qD1Aj3EKTA+b72Tcx+Q== Date: Sat, 3 Mar 2018 22:30:48 +0000 Message-ID: <20180303223010.27106-2-alexander.levin@microsoft.com> References: <20180303223010.27106-1-alexander.levin@microsoft.com> In-Reply-To: <20180303223010.27106-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;MW2PR2101MB1100;7:OsTI/kdd818yZl/u2TuK2zNq2Db4UMiBWcIJmZsgPfyiIGwCv6g/ZxJNrK31JXm204SecST5+Ki9hEgylTqBylh/OmjIEw1diwGVTVMffm86CDdd8C9WMshwqdYBrIgQ5vGBxqUFNIQdZlRPSd/Dvx4JHjW3HHdK8hffssvUaIY6LfMVaoVVdSBn5aM15QsaWMbfWiFSRFvAB3i3+ZsW4fhvEjwHu15TPTX1SOmzlykmy9bNcRauSJjSlNn0EJIg x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: b851328a-dee5-4a77-ccea-08d58157667a x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:MW2PR2101MB1100; x-ms-traffictypediagnostic: MW2PR2101MB1100: 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)(10201501046)(3002001)(3231220)(944501244)(52105095)(93006095)(93001095)(6055026)(61426038)(61427038)(6041288)(20161123560045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011);SRVR:MW2PR2101MB1100;BCL:0;PCL:0;RULEID:;SRVR:MW2PR2101MB1100; x-forefront-prvs: 0600F93FE1 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(376002)(39860400002)(396003)(366004)(346002)(199004)(189003)(22452003)(97736004)(7736002)(5250100002)(105586002)(2906002)(6506007)(72206003)(966005)(66066001)(59450400001)(4326008)(305945005)(10290500003)(186003)(3280700002)(102836004)(2950100002)(6666003)(2501003)(478600001)(26005)(2900100001)(10090500001)(53936002)(8676002)(25786009)(81166006)(81156014)(575784001)(54906003)(86362001)(6436002)(106356001)(110136005)(68736007)(36756003)(316002)(6512007)(5660300001)(107886003)(8936002)(1076002)(6486002)(3660700001)(99286004)(6306002)(76176011)(3846002)(86612001)(14454004)(6116002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:MW2PR2101MB1100;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: Ejhb0sJWalGRvlNi+f6tyf7QSWkW1ZrtiKdjqDZJHwhZ65GAuvFAySJ3RsaRsFde1hWiWc5UmMTcv38Xdr1Ke6A/lcEEJaqFjN8oexSJVZiVVCzlTtZvysJL5Gv/qi0UG68CtlgTCyoeowzhpDicdZSSW+b/qbkfuHNKyvknjFg= 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: b851328a-dee5-4a77-ccea-08d58157667a X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2018 22:30:48.2915 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR2101MB1100 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 695763516908..f6232bbbc0e3 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