Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1704135ybi; Wed, 17 Jul 2019 20:26:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwAkQDNRFYlv188767IMpdAxFR4sReUHB3j1+/w7+P/e5L0gJUqsLX8o4MG1v8bCqyVzPD4 X-Received: by 2002:a17:90a:9301:: with SMTP id p1mr48357359pjo.22.1563420398806; Wed, 17 Jul 2019 20:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563420398; cv=none; d=google.com; s=arc-20160816; b=G6CXmc5PQ9iSz3j55gAnS4PiMzozNW4gDu91ZXn7TA0iE9biIUks8bBAMSOH0aItBm YvO4VVPet3trZ39/zczV6gsZkwY7ThwjJRu29kc4Q0rmwxnorDQPOMQWicsuI/vIgPB/ kZ8HnOtvqSf5Cn9Gp4OaV4uowr5xi8ICh0xygcYIqplTgLpO2521kaIQEybejz+3CHhg 12dzJltwmElmxkkzxY8hRpQweYdvnhCP6zH+lnb3tTKUNQ+d3q0XDnHf4dgljy3wzLEZ /TDbIQ8XmwgguLcAM3Y0zNJ/ETjGRbwLXHxdT8O7KUchkTTVttzaZDc3yVQAxX5uqlmi IUpA== 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=Yy6xT+d0aeO/jsguoTz66RoIJviCWw9rQftWfcz8YY4=; b=GHT5bTe6aXPMJQm2rZ1RgW31B4Yx4Uz3xEpNob7e4+7ctc832GJWH9Ww/Veg/Vpdab WxpXIUH8ujvkahDHxLUJ80W7fvC8YSeQTBoB+33eQaEPxMR131Xl7my7phGCctifqAH3 gFZnuKr7BuuHaelTwbwhR4P+fOjIKrT943VePH2Ifixqk5mFhCCOyeBIP+J9MBSgszQ/ rT+f/clENR1IJSCmRoMVV+IoWBj9CtMINja5XLHCTKQiCDTfSVD9N4Os14lFeMw35W/1 Z9WkaaJVTzjUqngoa6AJ+6sVAWYqAtTaZS9Nwy7dV5j2xk/qCKZa8s6/qBCeaXoS1gkr D5Fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zUKgjymw; 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 r185si1144493pgr.506.2019.07.17.20.26.23; Wed, 17 Jul 2019 20:26:38 -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; dkim=pass header.i=@kernel.org header.s=default header.b=zUKgjymw; 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 S2390416AbfGRDYN (ORCPT + 99 others); Wed, 17 Jul 2019 23:24:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:38898 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390417AbfGRDHV (ORCPT ); Wed, 17 Jul 2019 23:07:21 -0400 Received: from localhost (115.42.148.210.bf.2iij.net [210.148.42.115]) (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 6D08921841; Thu, 18 Jul 2019 03:07:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563419241; bh=HTMTVcyI4ODRSZYSR5Zt8vuz0PIAJWXWe2GIrXjEO7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zUKgjymwDDLUaNkD0XBwUNHBslJioD1XLVbCxx4Sx0fi/Ia7AtgnLUOUIG5QwRxR2 PbSK9VHAJavDkEhNHSp2WjorQwwHwvtJWv0HS34wxzArx60ruIGalOHO2QB/gYrl8O 59p4UDDs4Z/wL5aCK+OlTZZA8FpFba/Ey3cvC2P4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ravi Bangoria , Young Xiao <92siuyang@gmail.com>, "Peter Zijlstra (Intel)" , Will Deacon , Arnaldo Carvalho de Melo , Frederic Weisbecker , Jiri Olsa , Linus Torvalds , Michael Ellerman , "Naveen N. Rao" , Stephane Eranian , Thomas Gleixner , Ingo Molnar , Sasha Levin Subject: [PATCH 4.19 10/47] perf/core: Fix perf_sample_regs_user() mm check Date: Thu, 18 Jul 2019 12:01:24 +0900 Message-Id: <20190718030049.458927533@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190718030045.780672747@linuxfoundation.org> References: <20190718030045.780672747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 085ebfe937d7a7a5df1729f35a12d6d655fea68c ] 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 Signed-off-by: Sasha Levin --- kernel/events/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 171b83ebed4a..3b61ff40bfe2 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5906,7 +5906,7 @@ static void perf_sample_regs_user(struct perf_regs *regs_user, if (user_mode(regs)) { regs_user->abi = perf_reg_abi(current); regs_user->regs = regs; - } else if (current->mm) { + } else if (!(current->flags & PF_KTHREAD)) { perf_get_regs_user(regs_user, regs, regs_user_copy); } else { regs_user->abi = PERF_SAMPLE_REGS_ABI_NONE; -- 2.20.1