Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp663351pxa; Wed, 5 Aug 2020 09:50:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypGRbm8ocqhzrQGRJ3y3hn2WWsX6uZfACZQnGMfd2ZuDU2CfrP9lhKLuEDi8SapM0AlI+L X-Received: by 2002:a50:c449:: with SMTP id w9mr158351edf.65.1596646252527; Wed, 05 Aug 2020 09:50:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596646252; cv=none; d=google.com; s=arc-20160816; b=EvioxYNS737IUBuSyNis9b2Y9PI9H0lr4ode8n9XIQJi82J/KMkEiWAcazsv9+YpVD XBXwUc4TKM/QoLmbUIM8zxgdZjzNJ7d6wz2MTzxa8AH3eW0D6NHuR/7/RX0VjvyyrfIQ cSr7WnahR0U8bdqcovzhiyanq/W7PDLCoUNCSczJf+7kcguLAesVZ4MNBH/im2XniU1Y 6IC/p17SUj8sY0mHqKl2U6XSIVl5gc4V9eoywxXArGUkANQPt256rOdKmvRf02bMWJz8 GktH9MvhBia1WP9JgM+bhE+wx/FUZvl1YcUyovEfFQzrwEp2uNy3U4D0wfP5XZ5c/4wI GgPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=Gt9NJuA9NqxmEUokFcw04m2QCDlb3+WQJaB6tPto9FA=; b=XPjCuHPfacDV3Dm6elfMRUjwJl0Hx1JyIEw2MitL7FDhycuXSVl8p1WE+OtphPwnQw epxi/Qn70HyOz1oGzrJoFraisri/aGN5AvDM4qq3LRp3MQ7F84YJGdVMDtyFsQpShVpc 4M563EaN9dWIAwVlSOoNNyz/dKdyYjnRNDRgKcYhR5MTm9bELbtI3Hk1JpUJQUpO84J4 DjDwNLsvnNICll5SxYtpAG5v/5Z9yvhYgoyuAgYLyJ14pPXw1olyj/7jKQVNl0EVLq+O cT0EpjFT2Z7F/ssx8hpGLE/DKneKMfpD6tiunLOSlfqFv9xqDddRWES7d1tUh6dM17VQ lDOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=eftEKmga; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h21si1564402edw.233.2020.08.05.09.50.08; Wed, 05 Aug 2020 09:50:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=casper.20170209 header.b=eftEKmga; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728133AbgHEQtj (ORCPT + 99 others); Wed, 5 Aug 2020 12:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728076AbgHEQsi (ORCPT ); Wed, 5 Aug 2020 12:48:38 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66197C03461D for ; Wed, 5 Aug 2020 05:57:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Gt9NJuA9NqxmEUokFcw04m2QCDlb3+WQJaB6tPto9FA=; b=eftEKmgaThAuFa0orFvtGPAOiu s8pj8/SncERZwwqVyJQhJ7T2c+Z61TwMviUEWCveyF4i1kyZyfA8uy1LiTvm6llCjAjC6PoIO9Aqx U4j7p+wBzYOO/G+gNMiKJOAADsh2Xbb2XvdbOAODuX/3ovwz0OsGhu7kl+93TvAADgGq/6ZtZQ6jo FQ2Dqvu2Ys1XYrpC2A1gBL+XBkHvPb33oK2xvW7VF+olR5C6Q44hsdi24a4iQWr6dDFZq03+ysi0D s9sPHaTP6sEPY2nVSo4qoNdf08vAMqGe69DUF7K5976e8/Ex2hnMrZyLwETLlHY2PVe8k62sybSKB BJulv18Q==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1k3Iyj-0003Pb-27; Wed, 05 Aug 2020 12:57:09 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 0685F300F7A; Wed, 5 Aug 2020 14:57:08 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id DA00821493853; Wed, 5 Aug 2020 14:57:07 +0200 (CEST) Date: Wed, 5 Aug 2020 14:57:07 +0200 From: peterz@infradead.org To: "Jin, Yao" Cc: mingo@redhat.com, oleg@redhat.com, acme@kernel.org, jolsa@kernel.org, Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com, alexander.shishkin@linux.intel.com, mark.rutland@arm.com Subject: Re: [PATCH v1 2/2] perf/core: Fake regs for leaked kernel samples Message-ID: <20200805125707.GC35926@hirez.programming.kicks-ass.net> References: <20200731025617.16243-1-yao.jin@linux.intel.com> <20200731025617.16243-2-yao.jin@linux.intel.com> <20200804114900.GI2657@hirez.programming.kicks-ass.net> <4c958d61-11a7-9f3e-9e7d-d733270144a1@linux.intel.com> <20200805124454.GP2657@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200805124454.GP2657@hirez.programming.kicks-ass.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 05, 2020 at 02:44:54PM +0200, peterz@infradead.org wrote: > How's this? Clearly I didn't even hold it near a compiler... > --- > kernel/events/core.c | 38 +++++++++++++++++++++++++++++++++----- > 1 file changed, 33 insertions(+), 5 deletions(-) > > diff --git a/kernel/events/core.c b/kernel/events/core.c > index 7c436d705fbd..3e4e328b521a 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -6988,23 +6988,49 @@ perf_callchain(struct perf_event *event, struct pt_regs *regs) > return callchain ?: &__empty_callchain; > } > > +/* > + * Due to interrupt latency (skid), we may enter the kernel before taking the > + * PMI, even if the PMU is configured to only count user events. To avoid > + * leaking kernel addresses, use task_pt_regs(), when available. > + */ > +static struct pt_regs *sanitize_sample_regs(struct perf_event *event, struct pt_regs *regs) > +{ > + struct pt_regs *sample_regs = regs; > + > + /* user only */ > + if (!event->attr.exclude_kernel || !event->attr.exclude_hv || > + !event->attr.exclude_host || !event->attr.exclude_guest) > + return sample_regs; > + > + if (sample_regs(regs)) > + return sample_regs; That wants to he: if (user_regs(regs)) return sample_regs; > + > + if (!(current->flags & PF_KTHREAD)) { s/{// > + sample_regs = task_pt_regs(current); > + else > + instruction_pointer_set(regs, -1L); > + > + return sample_regs; > +}