Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2507331imm; Mon, 28 May 2018 09:22:46 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqTfJQdtEtkiBXshwbXs9Xhh1+diux6hazcsIxMCnhJ2KOqqzokFjx0102sUoe4jleZlEGo X-Received: by 2002:a17:902:a717:: with SMTP id w23-v6mr14142401plq.130.1527524566441; Mon, 28 May 2018 09:22:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527524566; cv=none; d=google.com; s=arc-20160816; b=bqpH0UKIgb3xeG/5I8gfFVEa/rYzRpUMVVy0rDtb01FQzpn6hpHF2Xxr+uyKAoQHZo /KoQuOshX8HNxSAO81OLF5uYi2/f0HN4EqaBLvEQ+778lxqe8sprw3XgO7hkie+4CRiC A/GTctqOysdp+71dFifm3DKhF3zTHIkyuxFNkSWcCD5UM/UdtEwjbQgoH7r00vvuhasV luwvNjbFciGiTSBxd48sCSfZp2vHMtbuD0UUNbek22rBe+6wEsSetfclcoWsscCKBtAT khEVq+KiHcQQ+eEeFDCi3ZmMLTBvsje9SdBMbSd4cthjV4yGofUqX2W2MrXwt6LPtdso X4cA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=su56wbxjuTc3hOEP35EK6P0SOWiy8Poa3npIf9Rhq4c=; b=ukjnrIqt/qHV4w1ni5V2xDHVK1h6scdFnuivREaG/QbjpHS70up7NdpYl3edG141mC 3knAkZCo1BwijZxq/kerO6cd15sdT5sbjunq7j9lmTH2QbGPSEIerX9Yxf+5/ArX7iVN bZky5yvMNOYmLG1WH0j4618hhxWd7MHUbWkU3W5ElQ8eV/Q8Yq1uil4o8/HJnZ7p36wN 32HxxbtHDd/dVIehcfn3paiClF79wF7wn9wyaqJWCC1oRdJxZJfR7Ygj9BFEIHDdvSok Bfm2/d/rXtH85X8iD9PwBdfmottuKqNwcs1OHiBoQ6mNqmK4LsEQWevOO/4lSJfVvEvP 40yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NIh8Pegu; 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 t13-v6si32074449pfc.333.2018.05.28.09.22.31; Mon, 28 May 2018 09:22:46 -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=NIh8Pegu; 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 S936635AbeE1KLl (ORCPT + 99 others); Mon, 28 May 2018 06:11:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:59806 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936610AbeE1KLg (ORCPT ); Mon, 28 May 2018 06:11:36 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 E57212086D; Mon, 28 May 2018 10:11:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502296; bh=MhVikgMcOzKIFfwNiGjlhcNOOAm+ehhs4MBu9Z2v/z8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NIh8Peguigeqjngtb/z7X4wwiUw5jK9ievEHoW1iaAGQYdpmngSBdRdGIDIB7cbVc p1ktOQia6cWfljpXuQ5ptomZp2dXpKsUe1AqIlIXeVjrV8kPIhNK0ghjfnMrMc8pot mc/FvXW87Iu64b4ynmPLR5WnZY4DUkf0qEl9HsgI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Balbir Singh , Madhavan Srinivasan , Michael Ellerman , Sasha Levin Subject: [PATCH 3.18 133/185] powerpc/perf: Prevent kernel address leak to userspace via BHRB buffer Date: Mon, 28 May 2018 12:02:54 +0200 Message-Id: <20180528100105.057226816@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100050.700971285@linuxfoundation.org> References: <20180528100050.700971285@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Madhavan Srinivasan [ Upstream commit bb19af816025d495376bd76bf6fbcf4244f9a06d ] The current Branch History Rolling Buffer (BHRB) code does not check for any privilege levels before updating the data from BHRB. This could leak kernel addresses to userspace even when profiling only with userspace privileges. Add proper checks to prevent it. Acked-by: Balbir Singh Signed-off-by: Madhavan Srinivasan Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/perf/core-book3s.c | 10 ++++++++++ 1 file changed, 10 insertions(+) --- a/arch/powerpc/perf/core-book3s.c +++ b/arch/powerpc/perf/core-book3s.c @@ -443,6 +443,16 @@ static void power_pmu_bhrb_read(struct c /* invalid entry */ continue; + /* + * BHRB rolling buffer could very much contain the kernel + * addresses at this point. Check the privileges before + * exporting it to userspace (avoid exposure of regions + * where we could have speculative execution) + */ + if (perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN) && + is_kernel_addr(addr)) + continue; + /* Branches are read most recent first (ie. mfbhrb 0 is * the most recent branch). * There are two types of valid entries: