From patchwork Fri Jan 19 01:50:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 863273 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 3zN4f03LSqz9t3p for ; Fri, 19 Jan 2018 13:34:16 +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="iLc/l9Wd"; 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 3zN4f01X9pzDqmV for ; Fri, 19 Jan 2018 13:34:16 +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="iLc/l9Wd"; 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:c0d::241; helo=mail-qt0-x241.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="iLc/l9Wd"; dkim-atps=neutral Received: from mail-qt0-x241.google.com (mail-qt0-x241.google.com [IPv6:2607:f8b0:400d:c0d::241]) (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 3zN3jt5mmczF0mY for ; Fri, 19 Jan 2018 12:52:34 +1100 (AEDT) Received: by mail-qt0-x241.google.com with SMTP id 33so466777qtv.1 for ; Thu, 18 Jan 2018 17:52:34 -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=tYTbG/QleqLYROSi6e2GygGvmnN9no2w/HfPLTHwAXM=; b=iLc/l9WdzWqeH1dfZeFFjycqKTcwEfz6L/Y7BKuBnhnMrw/90M31KF2rKzj/KGOJLK 0cxUzw+UCLxAedjydKr/ESh0FhgFqkbb2MdvK9cg6QnG5wkGL2kf3Tf46/CLoR/37sXK wbV8nwy3aG28AwdCTgEwG28HV+DuYxBNmuAwXorGThWlnDIwEU0I8VWQ++oRjWGhcRC5 fNkNC4F0denEuX+HXNkdfEFXfug/YLw1hYeTgKxo9+CfKLhMshtm3jpV9SP4jQ9oATWX PrwWoDvhSEi+FWXIX4gLkkUwNj6TdKvsLjMqGG65WeMCW2ZRiuLRmCz8larYAuzDBTTT sQBQ== 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=tYTbG/QleqLYROSi6e2GygGvmnN9no2w/HfPLTHwAXM=; b=mmwo/NSkv3XcLeL9BFAYpPo5pN9c6f1kwPwapEoKMQWM0j6T5Txib5ftbnVHL3G1vp nFnVB1nnIfMN1tm64MYXQLy7vb3/nUETFNEt2mPq6VV46p06Hf26sJw2ZhW+xVqYpda5 NWIxOMOkDMAoan1PnO0C+ZshygPOALRed5t8qu+ePquifeotW/LJTtkB8gJuuzaqsPTc OaWdZ/XGW0rdmT5N998kaHxzJ6bCDU6CJbAV1bDo3t/82ggiZ0WV5X61Fl3h6yEEkuqK 7mTtdrSfjAMRMPGhbxid5bgaoiR3HjtshfpsY5AlV5iQPSbEgbBX4OnuixkKzC2l6rVA bpiw== X-Gm-Message-State: AKwxytdRCKA1KDa/tHOI+SVjPSSpzcKfZZCQ54gOq+hbMb1QD8S43wMR fkffj4XMSg/GNXkltHOBwL0= X-Google-Smtp-Source: AH8x224yP6kCi6G+b58F8RLdtp44XaIxuDQeWeUqwyEC0u3nfRpJJgU9Wcz5fRiHuCPwkdJ5a0swcg== X-Received: by 10.237.34.10 with SMTP id n10mr71545qtc.105.1516326752344; Thu, 18 Jan 2018 17:52:32 -0800 (PST) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id c127sm5483161qke.78.2018.01.18.17.52.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Jan 2018 17:52:31 -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 v10 17/27] powerpc: check key protection for user page access Date: Thu, 18 Jan 2018 17:50:38 -0800 Message-Id: <1516326648-22775-18-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1516326648-22775-1-git-send-email-linuxram@us.ibm.com> References: <1516326648-22775-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 | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/include/asm/book3s/64/pgtable.h index e785c68..3d8186e 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -464,6 +464,25 @@ 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/pud for huge pages. 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))) + +#define pud_access_permitted(pud, write) \ + (pud_present(pud) && \ + ((!(write) || pud_write(pud)) && \ + arch_pte_access_permitted(pud_val(pud), !!write, 0))) + #endif /* CONFIG_PPC_MEM_KEYS */ #define __HAVE_ARCH_PTEP_GET_AND_CLEAR