Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1189399ybn; Wed, 2 Oct 2019 12:10:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpPlWIAVVgaVUcq/EgN0UFnqoRIVe6P6DlKQfZB7zF7wsWUSO/9xtYCOdF4IvRLl+DbDaQ X-Received: by 2002:a50:d949:: with SMTP id u9mr5543505edj.142.1570043437603; Wed, 02 Oct 2019 12:10:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570043437; cv=none; d=google.com; s=arc-20160816; b=pC27jAOa9dABX0quWgb0IJSzsgm5eT8ULPWpBIszVneRjk+gqy8igzQCThBAl2shUB KNdR8SDOrWOjfjSvnbGKkMDkhRIGizoSecbojwJXZCU/S7BFRKt9WbkeA3LtZXN3GiSQ 3f0JY5iu0cHUTmQ/ILkr9wBMRRitVrRRCNHltqcWh1m474vt3aq1p/HkO+BroA1dOpDt 0rsyqmgoX26zKXl/qHWkAuvCs/wLihVVkzAWXdHu/xIiPkiLmvhav+yTU7fYlsLQr5ME suuAps05RXbBu9yib5aC10RzFG3Bd0gJ28MTNyhmSN/G2au2htDNj22GfMDeX8kvUBs9 NaJg== 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:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=8GvdrCxwz9svUJVTnnTNljfZYEYtyxgUgvDrfLn7nZw=; b=ROxGm9vWywRcfIXjA3Eu/yLFTEJy8rc/NfDZwyUfI3sY/ur3hcIIY3QGaQJnIcIkLB /gaMkbNqem8ux3INvmXw1Si9L1OQuyNn0y4A7vVTxT1Tbkio8wMYSLcZbUhTqSxs80pN EMJBbkqEoAn7cXmVVyoilpnV0al67mjtW67wAeGznj1eh85ZkTYThLTbIN5f+dHdUTP7 r49SF/2y7m9Z2VCun9RWuX7mCeT0rJkIaLqzU2f/JDhRSyoG/22pfNVsrI94EFzHlcZc QVN3wQs62oT3i2sbdqtwdRuQP+Dxzd6XTl4gpqYZm6kSh9Ij8UBL0ZXG0zqlk3tO/0HY Cz6Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i18si13481ejb.145.2019.10.02.12.10.13; Wed, 02 Oct 2019 12:10:37 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729599AbfJBTJU (ORCPT + 99 others); Wed, 2 Oct 2019 15:09:20 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:36110 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729381AbfJBTIW (ORCPT ); Wed, 2 Oct 2019 15:08:22 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iFjyx-00035x-Q7; Wed, 02 Oct 2019 20:08:15 +0100 Received: from ben by deadeye with local (Exim 4.92.1) (envelope-from ) id 1iFjyp-0003fB-Ep; Wed, 02 Oct 2019 20:08:07 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Michael Ellerman" , "Arnaldo Carvalho de Melo" , "Thomas Gleixner" , "Ingo Molnar" , "Ravi Bangoria" , "Stephane Eranian" , "Peter Zijlstra" , "Young Xiao" <92siuyang@gmail.com>, "Naveen N. Rao" , "Jiri Olsa" , "Linus Torvalds" , "Will Deacon" , "Frederic Weisbecker" Date: Wed, 02 Oct 2019 20:06:51 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 66/87] perf/core: Fix perf_sample_regs_user() mm check In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.75-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Peter Zijlstra commit 085ebfe937d7a7a5df1729f35a12d6d655fea68c upstream. perf_sample_regs_user() uses 'current->mm' to test for the presence of userspace, but this is insufficient, consider use_mm(). A better test is: '!(current->flags & PF_KTHREAD)', exec() clears PF_KTHREAD after it sets the new ->mm but before it drops to userspace for the first time. Possibly obsoletes: bf05fc25f268 ("powerpc/perf: Fix oops when kthread execs user process") Reported-by: Ravi Bangoria Reported-by: Young Xiao <92siuyang@gmail.com> Signed-off-by: Peter Zijlstra (Intel) Acked-by: Will Deacon Cc: Arnaldo Carvalho de Melo Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Linus Torvalds Cc: Michael Ellerman Cc: Naveen N. Rao Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Fixes: 4018994f3d87 ("perf: Add ability to attach user level registers dump to sample") Signed-off-by: Ingo Molnar [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -4581,7 +4581,7 @@ static void perf_sample_regs_user(struct struct pt_regs *regs) { if (!user_mode(regs)) { - if (current->mm) + if (!(current->flags & PF_KTHREAD)) regs = task_pt_regs(current); else regs = NULL;