Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3321867pxf; Mon, 15 Mar 2021 07:06:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpqn+qRebrFzMIzRaH+uVwOKyI09BykgoJSl9eY9O7NAkZAYfRN/DiThj+I5aa9DvGBcYs X-Received: by 2002:a05:6402:51d0:: with SMTP id r16mr29919794edd.48.1615817217694; Mon, 15 Mar 2021 07:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817217; cv=none; d=google.com; s=arc-20160816; b=IF0nosSXjPqGM2jWBuzuffAqu41zO3+isA8+vYZfIwuGm8xpxQ3bPyhT0D0HNZt+9c ITywesp8WyKp9F3OlZPVdvJMRWU1s7cpwYLl4X0DcpfyOZP4mBuWjw0KZtxUwGA6vYyl RbqHnFEhNY1nUChE2GP9ixs6WKUW6sDOU+3T09/atudFl9O402ia4eVWJZoijZ9hNtnC pp4c0VzBMFJWiweOUxdtr+uV3H+mKOwzKK+7WVkndmK1PN0GUu+nGVy8/t18R75CQmAy q3F0kgCTcUxN2WDNh0CO9MMOjhVwLiDN9EOsGTPI/QP4wsa4CAaLyXw1O6r/UjixuXEQ mM/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hyb0CKutplY20DYLds7TabSLb8aH4EAz3ujnvZdV5Mk=; b=VgetVZaDM26k5M4SGqPtzah2Rcgd8uBSlxvDPJ0Lug4aN0kJGtOxAEDtR8+ikM1GuR uUHwUZbBd/e6sCClppzsUEzkKw+J1CqQB9aSMJLdA4gCjtDpFvWizb73aOeCOemh8TyG VhJUjmPWl3EHvU0euFN17jftOc4nNuZZQW08/HVunxlgqhamycEZxe8SNso4t8mchkNp eiHhTWo0HvQr4l4HablQPgBUPbP8hsjA+tfpXdkw8iBXzxDkYzzC0FBmxc3n9K6GPBh8 E5Rk/AUihGriHfrA1z5b1tt8Czpo4GPZOBsIo9iD/6+iL17hgYTXb5CU2CjxNawp2sca OPNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="V/VBLTZw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u9si11067468ejx.635.2021.03.15.07.06.33; Mon, 15 Mar 2021 07:06:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="V/VBLTZw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234698AbhCOOEw (ORCPT + 99 others); Mon, 15 Mar 2021 10:04:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:34948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231965AbhCON5Y (ORCPT ); Mon, 15 Mar 2021 09:57:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D864564F2D; Mon, 15 Mar 2021 13:57:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816644; bh=KUgnUfIhMV6ghQ263E7VfkbB5r4OQ8SSZIpzaryCweQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V/VBLTZwuW1PfHDYW6mSJo9qIztITKt5A2cwR+8G7dzd8pcuFjBFA9a/n6FtxxG/I rSPiMWeur5CWZ1eUXZu5BBee7KiP1ppymQiIq3vQbIHgYFj/jSWYUU28yMqwUpqzAy gjfMR5RjCVP0vx63NgXDWdMbBFiWbAnuNkB1vxoY= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Plattner , Christophe Leroy , Michael Ellerman Subject: [PATCH 5.10 030/290] powerpc/603: Fix protection of user pages mapped with PROT_NONE Date: Mon, 15 Mar 2021 14:52:03 +0100 Message-Id: <20210315135542.940267543@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Christophe Leroy commit c119565a15a628efdfa51352f9f6c5186e506a1c upstream. On book3s/32, page protection is defined by the PP bits in the PTE which provide the following protection depending on the access keys defined in the matching segment register: - PP 00 means RW with key 0 and N/A with key 1. - PP 01 means RW with key 0 and RO with key 1. - PP 10 means RW with both key 0 and key 1. - PP 11 means RO with both key 0 and key 1. Since the implementation of kernel userspace access protection, PP bits have been set as follows: - PP00 for pages without _PAGE_USER - PP01 for pages with _PAGE_USER and _PAGE_RW - PP11 for pages with _PAGE_USER and without _PAGE_RW For kernelspace segments, kernel accesses are performed with key 0 and user accesses are performed with key 1. As PP00 is used for non _PAGE_USER pages, user can't access kernel pages not flagged _PAGE_USER while kernel can. For userspace segments, both kernel and user accesses are performed with key 0, therefore pages not flagged _PAGE_USER are still accessible to the user. This shouldn't be an issue, because userspace is expected to be accessible to the user. But unlike most other architectures, powerpc implements PROT_NONE protection by removing _PAGE_USER flag instead of flagging the page as not valid. This means that pages in userspace that are not flagged _PAGE_USER shall remain inaccessible. To get the expected behaviour, just mimic other architectures in the TLB miss handler by checking _PAGE_USER permission on userspace accesses as if it was the _PAGE_PRESENT bit. Note that this problem only is only for 603 cores. The 604+ have an hash table, and hash_page() function already implement the verification of _PAGE_USER permission on userspace pages. Fixes: f342adca3afc ("powerpc/32s: Prepare Kernel Userspace Access Protection") Cc: stable@vger.kernel.org # v5.2+ Reported-by: Christoph Plattner Signed-off-by: Christophe Leroy Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/4a0c6e3bb8f0c162457bf54d9bc6fd8d7b55129f.1612160907.git.christophe.leroy@csgroup.eu Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/kernel/head_book3s_32.S | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/arch/powerpc/kernel/head_book3s_32.S +++ b/arch/powerpc/kernel/head_book3s_32.S @@ -461,10 +461,11 @@ InstructionTLBMiss: cmplw 0,r1,r3 #endif mfspr r2, SPRN_SPRG_PGDIR - li r1,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC + li r1,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC | _PAGE_USER #if defined(CONFIG_MODULES) || defined(CONFIG_DEBUG_PAGEALLOC) bgt- 112f lis r2, (swapper_pg_dir - PAGE_OFFSET)@ha /* if kernel address, use */ + li r1,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC addi r2, r2, (swapper_pg_dir - PAGE_OFFSET)@l /* kernel page table */ #endif 112: rlwimi r2,r3,12,20,29 /* insert top 10 bits of address */ @@ -523,9 +524,10 @@ DataLoadTLBMiss: lis r1, TASK_SIZE@h /* check if kernel address */ cmplw 0,r1,r3 mfspr r2, SPRN_SPRG_PGDIR - li r1, _PAGE_PRESENT | _PAGE_ACCESSED + li r1, _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_USER bgt- 112f lis r2, (swapper_pg_dir - PAGE_OFFSET)@ha /* if kernel address, use */ + li r1, _PAGE_PRESENT | _PAGE_ACCESSED addi r2, r2, (swapper_pg_dir - PAGE_OFFSET)@l /* kernel page table */ 112: rlwimi r2,r3,12,20,29 /* insert top 10 bits of address */ lwz r2,0(r2) /* get pmd entry */ @@ -599,9 +601,10 @@ DataStoreTLBMiss: lis r1, TASK_SIZE@h /* check if kernel address */ cmplw 0,r1,r3 mfspr r2, SPRN_SPRG_PGDIR - li r1, _PAGE_RW | _PAGE_DIRTY | _PAGE_PRESENT | _PAGE_ACCESSED + li r1, _PAGE_RW | _PAGE_DIRTY | _PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_USER bgt- 112f lis r2, (swapper_pg_dir - PAGE_OFFSET)@ha /* if kernel address, use */ + li r1, _PAGE_RW | _PAGE_DIRTY | _PAGE_PRESENT | _PAGE_ACCESSED addi r2, r2, (swapper_pg_dir - PAGE_OFFSET)@l /* kernel page table */ 112: rlwimi r2,r3,12,20,29 /* insert top 10 bits of address */ lwz r2,0(r2) /* get pmd entry */