From patchwork Mon Nov 6 08:57:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 834567 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yVp615Mgcz9s7c for ; Mon, 6 Nov 2017 21:03:05 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UXyNo4WT"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yVp6144zzzDr5S for ; Mon, 6 Nov 2017 21:03:05 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UXyNo4WT"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c09::243; helo=mail-qk0-x243.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="UXyNo4WT"; dkim-atps=neutral Received: from mail-qk0-x243.google.com (mail-qk0-x243.google.com [IPv6:2607:f8b0:400d:c09::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yVmhD1sbtzDrJv for ; Mon, 6 Nov 2017 19:59:08 +1100 (AEDT) Received: by mail-qk0-x243.google.com with SMTP id q83so10020967qke.6 for ; Mon, 06 Nov 2017 00:59:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=nxk5VMPpg3HXaVzjsrCv8GKh2UzEGwd1dacz4RORheI=; b=UXyNo4WTCt5ZHgZxUuLMqFZytTXutxM1H4r71mpUj/OEOqoSgUe4VPhHj9f+/0t0qu Ccfc/AzmJclLs/hddILslZHdLkfnfomqH3jfwoWSTFSHklZgE5yLVGu6gManm6sheRl3 tQB9yX9CaVbH5gvM1Wc7kANgv0g2N6OEYzm8AiKu2ZQeynlZVGOPak9D16PHCms/TwBF SDn+aPM0ilTtCjQQ/AqGFaqN7iKZ5/puXAt4KTU9QmlM0IQE0PbOU++nrzyApkChpu1w Ed8NfCiLGg2stqCN3zE5XRpDm9sA0+roP/kMuCZLZk7zNu+GNXddCur9rsXxfk4DiQTZ K2xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=nxk5VMPpg3HXaVzjsrCv8GKh2UzEGwd1dacz4RORheI=; b=C+VbTr/MXsrfxIpE8QWcpyQOfC9fFUM7i/UsGxy42M9KoeBDy1qHe9xk277Q6/5FAP 6+/NHXowc/1qUOrwXagH7rPcrd/UcrXwJ//m9adx3gjWV0jVXhnlYtzk8Aue6aoUQuD4 6sb3QNkZXzwlAgM38dC2u0NiBMtSEeeG7vhxfLnVC1Gu+NEBcb/lqC39FcCF3Wl+JO4c q2HIawkjQWh2071+9ucwzEwujS8KlV5aU0rv1Z0YA7UgSo5JKp0AzFT6OmlQsVBTWYS4 QbNqFivgkOGqi9iEzPO5tY3FPMjaukTPUZVKZG7cGJv/fzSGn+Bu9RoPdmZnKBnGrYlq LxBQ== X-Gm-Message-State: AMCzsaV2bXQi7Pd+OCtqMAOREaEbtHbQMV3RbZkU/3EtPr5DYk02PJ6f RQPbFjsBaLxaWidSjKd7Ccw= X-Google-Smtp-Source: ABhQp+TKuOhTdOU1lt++Qk9aQMcxKcqYNTOAJcyIxdILb/wUHGSGAdVTwDg3sWNndvO/YJDhnIRcyA== X-Received: by 10.55.82.7 with SMTP id g7mr21372901qkb.276.1509958746408; Mon, 06 Nov 2017 00:59:06 -0800 (PST) Received: from localhost.localdomain (50-39-103-96.bvtn.or.frontiernet.net. [50.39.103.96]) by smtp.gmail.com with ESMTPSA id r26sm8001094qki.42.2017.11.06.00.59.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Nov 2017 00:59:06 -0800 (PST) From: Ram Pai To: mpe@ellerman.id.au, mingo@redhat.com, akpm@linux-foundation.org, corbet@lwn.net, arnd@arndb.de Subject: [PATCH v9 17/51] powerpc: check key protection for user page access Date: Mon, 6 Nov 2017 00:57:09 -0800 Message-Id: <1509958663-18737-18-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1509958663-18737-1-git-send-email-linuxram@us.ibm.com> References: <1509958663-18737-1-git-send-email-linuxram@us.ibm.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, ebiederm@xmission.com, linux-doc@vger.kernel.org, x86@kernel.org, dave.hansen@intel.com, linux-kernel@vger.kernel.org, linuxram@us.ibm.com, mhocko@kernel.org, linux-mm@kvack.org, paulus@samba.org, aneesh.kumar@linux.vnet.ibm.com, linux-kselftest@vger.kernel.org, bauerman@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org, khandual@linux.vnet.ibm.com Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Make sure that the kernel does not access user pages without checking their key-protection. Signed-off-by: Ram Pai --- arch/powerpc/include/asm/book3s/64/pgtable.h | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h index c277a63..5ecb846 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -464,6 +464,19 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, #ifdef CONFIG_PPC_MEM_KEYS extern bool arch_pte_access_permitted(u64 pte, bool write, bool execute); + +#define pte_access_permitted(pte, write) \ + (pte_present(pte) && \ + ((!(write) || pte_write(pte)) && \ + arch_pte_access_permitted(pte_val(pte), !!write, 0))) + +/* + * We store key in pmd for huge tlb pages. So need to check for key protection. + */ +#define pmd_access_permitted(pmd, write) \ + (pmd_present(pmd) && \ + ((!(write) || pmd_write(pmd)) && \ + arch_pte_access_permitted(pmd_val(pmd), !!write, 0))) #endif /* CONFIG_PPC_MEM_KEYS */ #define __HAVE_ARCH_PTEP_GET_AND_CLEAR