From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 088B4C3E8C5 for ; Fri, 27 Nov 2020 18:32:48 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9858C21534 for ; Fri, 27 Nov 2020 18:32:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tx6Ac/dJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9858C21534 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HmPvzpo9PUfQ4fqO0YwZyX0zRqXnTfdtvb58p4BsBM0=; b=tx6Ac/dJOYXTN45UFwFIQHVbb vPZWnpIT2pOX8gr4rd9/Jy2M/OxN9F6yTVqlXpLgWxwidbMDRKL8Gc8CHXLOCKPDBN100dQMUpT8M sPPXidysLmJQoNEfgQz5SU2Cb1WnXKGZJkHFmzsBJBKtgdopGaDFYo0ABJINm5KamD6avadh8npN1 5Zr4yH1MO0m9rNtgNZ1KmF8GyxcGkvSy2FQDinMrSw4TuMEsXBLt8wMqXufZUkCLB4GS0Hj6ytJSZ uYLG1T6AtzaTSnH+dY6ioetNfm5M1XLcKXM4ppWG7gBb1sAemt7dqD51ZqjfTMXYLksfzheTOwRUg CI6/hNaJQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kiiWt-0008Ip-Bb; Fri, 27 Nov 2020 18:31:35 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kiiWp-0008Hx-Lk for linux-arm-kernel@lists.infradead.org; Fri, 27 Nov 2020 18:31:32 +0000 Received: from gaia (unknown [95.146.230.165]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 77073208B3; Fri, 27 Nov 2020 18:31:29 +0000 (UTC) Date: Fri, 27 Nov 2020 18:31:27 +0000 From: Catalin Marinas To: Dave Martin Subject: Re: [PATCH 1/2] arm64: Support execute-only permissions with Enhanced PAN Message-ID: <20201127183125.GA16839@gaia> References: <20201119133953.15585-1-vladimir.murzin@arm.com> <20201119133953.15585-2-vladimir.murzin@arm.com> <20201119185205.GO6882@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201119185205.GO6882@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201127_133131_821204_81EABD70 X-CRM114-Status: GOOD ( 27.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vladimir Murzin , keescook@chromium.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Nov 19, 2020 at 06:52:05PM +0000, Dave P Martin wrote: > On Thu, Nov 19, 2020 at 01:39:52PM +0000, Vladimir Murzin wrote: > > Enhanced Privileged Access Never (EPAN) allows Privileged Access Never > > to be used with Execute-only mappings. > > > > Absence of such support was a reason for 24cecc377463 ("arm64: Revert > > support for execute-only user mappings"). Thus now it can be revisited > > and re-enabled. > > > > Cc: Kees Cook > > Cc: Catalin Marinas > > Signed-off-by: Vladimir Murzin > > --- > > arch/arm64/Kconfig | 17 +++++++++++++++++ > > arch/arm64/include/asm/cpucaps.h | 5 +++-- > > arch/arm64/include/asm/pgtable-prot.h | 5 +++-- > > arch/arm64/include/asm/pgtable.h | 14 +++++++++++++- > > arch/arm64/include/asm/sysreg.h | 1 + > > arch/arm64/kernel/cpufeature.c | 21 +++++++++++++++++++++ > > arch/arm64/mm/fault.c | 3 +++ > > 7 files changed, 61 insertions(+), 5 deletions(-) > > > > [...] > > > diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c > > index 1ee9400..b93222e 100644 > > --- a/arch/arm64/mm/fault.c > > +++ b/arch/arm64/mm/fault.c > > @@ -467,6 +467,9 @@ static int __kprobes do_page_fault(unsigned long addr, unsigned int esr, > > if (faulthandler_disabled() || !mm) > > goto no_context; > > > > + if (cpus_have_const_cap(ARM64_HAS_EPAN)) > > + vm_flags &= ~VM_EXEC; > > + > > IIUC, this would be telling __do_page_fault() that the access would have > succeeded with any kind of permissions except for write access, which > doesn't seem right. I always have trouble remembering what the vm_flags does. So __do_page_fault() checks vma->vm_flags & vm_flags and returns an error if the intersection is empty. We start with all rwx permission but modify it further down in the in do_page_fault(): if it was an exec fault, we set vm_flags to VM_EXEC only as that's what we want to check against vma->vm_flags; similarly, if it was a write fault, we want to check VM_WRITE only. If it's neither exec nor a write fault (i.e. a read), we leave it as rwx since both write and exec (prior to EPAN) imply read. With the EPAN patches, exec no longer implies read, so if it's neither an exec nor a write fault, we want vm_flags to be VM_READ|VM_WRITE since only write now implies read. > Also, isn't vm_flags just overwritten by the code after the hunk? > > The logic in __do_page_fault() looks like might not have been written > with the assumption that there might be more than a single set bit in > vm_flags. I think it was, it's checking the intersection. We could do with some comments in this code, otherwise next time someone asks I'll spend another 30 min reading the code ;). -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel