Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp5117012imm; Tue, 21 Aug 2018 06:36:02 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb6G79T1T5TOl2AYNTtHuHHbdfEg/rqrXiL4hyrzITWgiefJ+1Zosg2Z/3oT4v/ooglHRhp X-Received: by 2002:a17:902:981:: with SMTP id 1-v6mr294680pln.229.1534858562093; Tue, 21 Aug 2018 06:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534858562; cv=none; d=google.com; s=arc-20160816; b=K/eZ+Mf+6bji8BM549XaW45NfmqdSUHtXTzXO+tmw5EXWOsd6gdch5mp1RhBcnKLZf MXQTWoJsnLcY2a9hESM4/pV+w3DD5+xwOGqzxHnFs7sHTDuw7GXdaTC5iHHjvb0z4HB/ CBMdVJIkvFBU+vFYEizz22Ry8T/NrSNNmFJYWpk905VCpWcIqWPnPIH9E2IAT4c8M+HS fSpkCgd4Gd6ACXJSNrnR8Waena4Arpje1A9xpGx6/xjcuyO6GP5+P1iRPvcQq05xBti3 USfmCjA96q6brDvjxeeoqeSAaSNPyt37TOpA04IaqUJqm3Zh3bYuNhGoJSAgOJHm7fBS ewog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:message-id :arc-authentication-results; bh=nAkw5G5FfAe0P1vhpa7JcWzAHDvk1KTXLIaZSK8E/Ao=; b=qW1+/weYZ6MpImlaKy6lmdQT5bYA/Ns9HksnhGrAsEuionkHTCHVd3shRbf951r8PO IjWWegAZ9WK1zwh5MrFtnXcTmeRLRcxfoFVKpPRisxHDcdIAdwQ9Lu5eV3R/QdWQ3rrG 7s0+/E+NHrUQiuXlF0IIU6BXYORzVbCvShirG28zxWUEoib2PFR9k8UJP5F7s/KJcnkq 29z9yBaUyTBof1N5RwK7gHbrP0YdFOv33sCNQG5Gc5ht7u856q2kjUYRLFkgN1ptZzMQ r6N6wRkCi/FDxR/kv0MhKJ5YV6oPbPHoDsw54eiwIVppQ7N4y4tWZN3Rz7hrU5pVbG/m m4XQ== 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 o3-v6si12948533pld.281.2018.08.21.06.35.47; Tue, 21 Aug 2018 06:36:02 -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 S1727573AbeHUQX2 (ORCPT + 99 others); Tue, 21 Aug 2018 12:23:28 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:63874 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727043AbeHUQX2 (ORCPT ); Tue, 21 Aug 2018 12:23:28 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 41vrSv5S1mz9tvSH; Tue, 21 Aug 2018 15:03:11 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id IdBwutQ7B8UH; Tue, 21 Aug 2018 15:03:11 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 41vrSv4zv4z9tvS6; Tue, 21 Aug 2018 15:03:11 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id BEC398B7EE; Tue, 21 Aug 2018 15:03:23 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id TSHdD2BLHpQ2; Tue, 21 Aug 2018 15:03:23 +0200 (CEST) Received: from pc16082vm.idsi0.si.c-s.fr (unknown [192.168.232.3]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 90B3D8B7DD; Tue, 21 Aug 2018 15:03:23 +0200 (CEST) Received: by pc16082vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 44C9A71322; Tue, 21 Aug 2018 13:03:23 +0000 (UTC) Message-Id: <8097a1d32403ea47d076803e9070869badfe24bc.1534856426.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH] powerpc/nohash: fix pte_access_permitted() To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , aneesh.kumar@linux.vnet.ibm.com Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, stable@vger.kernel.org Date: Tue, 21 Aug 2018 13:03:23 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 5769beaf180a8 ("powerpc/mm: Add proper pte access check helper for other platforms") replaced generic pte_access_permitted() by an arch specific one. The generic one is defined as (pte_present(pte) && (!(write) || pte_write(pte))) The arch specific one is open coded checking that _PAGE_USER and _PAGE_WRITE (_PAGE_RW) flags are set, but lacking to check that _PAGE_RO and _PAGE_PRIVILEGED are unset, leading to a useless test on targets like the 8xx which defines _PAGE_RW and _PAGE_USER as 0. Commit 5fa5b16be5b31 ("powerpc/mm/hugetlb: Use pte_access_permitted for hugetlb access check") replaced some tests performed with pte helpers by a call to pte_access_permitted(), leading to the same issue. This patch rewrites powerpc/nohash pte_access_permitted() using pte helpers. Fixes: 5769beaf180a8 ("powerpc/mm: Add proper pte access check helper for other platforms") Fixes: 5fa5b16be5b31 ("powerpc/mm/hugetlb: Use pte_access_permitted for hugetlb access check") Cc: stable@vger.kernel.org # v4.15+ Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/nohash/pgtable.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/asm/nohash/pgtable.h b/arch/powerpc/include/asm/nohash/pgtable.h index 2160be2e4339..b321c82b3624 100644 --- a/arch/powerpc/include/asm/nohash/pgtable.h +++ b/arch/powerpc/include/asm/nohash/pgtable.h @@ -51,17 +51,14 @@ static inline int pte_present(pte_t pte) #define pte_access_permitted pte_access_permitted static inline bool pte_access_permitted(pte_t pte, bool write) { - unsigned long pteval = pte_val(pte); /* * A read-only access is controlled by _PAGE_USER bit. * We have _PAGE_READ set for WRITE and EXECUTE */ - unsigned long need_pte_bits = _PAGE_PRESENT | _PAGE_USER; - - if (write) - need_pte_bits |= _PAGE_WRITE; + if (!pte_present(pte) || !pte_user(pte) || !pte_read(pte)) + return false; - if ((pteval & need_pte_bits) != need_pte_bits) + if (write && !pte_write(pte)) return false; return true; -- 2.13.3