Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3323745pxf; Mon, 15 Mar 2021 07:08:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW6KCUtjZ6Ax6jf7OQm6i+QtiLOekDtyDEdHhkI8+6XcfG4RCcZfqdX3t3swAn3tNcwHSU X-Received: by 2002:aa7:c857:: with SMTP id g23mr30701751edt.86.1615817329649; Mon, 15 Mar 2021 07:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817329; cv=none; d=google.com; s=arc-20160816; b=h+sVTvpnlMNT5xofS1EDnz/IBFi7bvf6r3cBRS2bTH280hqesVPTIPv/BA64tZdsyl a4H9sIz7eOhjqvidwbUabpwL+zCRRep0eP+iOoHgeOj+bBtV6bDtzI3oSnVDfZf5eGNC G73wkbHMFr5ZAhnWxg/NWuc73utNdJe/Bb8Zzj0NZblVJCJS84tLYiBOZcyhjcLuOhGZ DelVP0lq7RYtk45WSuGXdVds2y3BCt8vOH8ILV155PcRE1lGQMPMHck/P/2wtXb7f6Us bHuN6TFOOD06txK0MFq1rQMZaS8OXZN5n4PE/+kUo7U+eCXfh3CSwq+mWaZdV3XDIyAB G6VQ== 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=vqGENIuQyIGwyw2cl/o1zDjXoB1vt1f7RN9fQ4XYPnw=; b=l/lRiroWePa1zxqrtGXlA/HtcEVPqRmETNm31smfrn9rOfkMHttAM1tfisyRfm83jh qz0T/haPOshSdKz0GYMCNMURWGp6+EoouDwtWh5+ECIOs/70WQUOzRoTZULSM4UpWppZ gD3ZxP3yvhO7BXvNxJapGhwvRYDC8CYb72sq/+2adsVKEk64Z9Ap0UO7HOecTKpsQ0Cb J9hS8+5/RT6ltkmVneE5LeVVX6shCZ6+a5NOUfNnCOSJHY/+glgFf6HqkF9PUXfeym1q uMJwsxs/mRZenBqTX1/FaxfuSV7KPUm1rdZfLE9hyVR5gEroqDi3vF4Q+iFcKzznldwL XyWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Uv5tqGPC; 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 c11si11052595edv.591.2021.03.15.07.08.26; Mon, 15 Mar 2021 07:08:49 -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=Uv5tqGPC; 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 S234711AbhCOOEz (ORCPT + 99 others); Mon, 15 Mar 2021 10:04:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:34960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231966AbhCON5Y (ORCPT ); Mon, 15 Mar 2021 09:57:24 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 10D6064F2A; 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=TPhNzBLwzeoCv4BOGk4gCrRfMabbLUbMRpg9/LWeDBs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uv5tqGPC5+SYmXIp0zxUNjVNk1w21mgVj6r2WGr3IC7JjPjBLKV/Th5eUgXJkzM4N iLQ2iauWLl2NWW1rYLptbMT3m4O2EOzj96OTqRMqSZZKbpmWI3aUsqw34wfDMM1Vl/ 6+yMaCLd0odFYr7c0bkoJqvwNWB10B92m4sLw7lc= 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.4 022/168] powerpc/603: Fix protection of user pages mapped with PROT_NONE Date: Mon, 15 Mar 2021 14:54:14 +0100 Message-Id: <20210315135551.085498989@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135550.333963635@linuxfoundation.org> References: <20210315135550.333963635@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_32.S | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) --- a/arch/powerpc/kernel/head_32.S +++ b/arch/powerpc/kernel/head_32.S @@ -418,10 +418,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) bge- 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 */ @@ -480,9 +481,10 @@ DataLoadTLBMiss: lis r1,PAGE_OFFSET@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 bge- 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 */ @@ -556,9 +558,10 @@ DataStoreTLBMiss: lis r1,PAGE_OFFSET@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 bge- 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 */