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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3077AD0E6E0 for ; Mon, 21 Oct 2024 10:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CAGuCtcY7ub7dFYDc3lyc+pbj1h3VUz/L/XeKwJpt6Q=; b=W02EJB1AEMIBBu1RIOwr05jPil Ub38opjl1vUFC74Dv2SmybRE6CyIc8PPFhbwH49E7EWNEnqe6QW21APStZkXkkftEJ1faERjdR6DY N+h9KeG8rhPJ74rLDEVpUEXqOdm5CssPtR7Ka0DzR8gfVDGDTqIRbvpLU1zhUu9jF1mx18TCu118f mcK5dT/4maHF+/yL2+CjB7m4YnUYtvWUp+x4v9JlGr8ReSyoGwxSgoHwC0ibIJmPhFckYkBuqz8/y 3kSPqWnVyCeHHYRyf9+kahQ+1/CGrtB3T984IhrauDHoHsl9Fe91QsaFikr6pysqiX+uVXZhoKmEo imeMcm2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t2pVS-00000006raz-1bfQ; Mon, 21 Oct 2024 10:19:22 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t2pJ3-00000006pMF-0jet for linux-arm-kernel@lists.infradead.org; Mon, 21 Oct 2024 10:06:34 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 72015DA7; Mon, 21 Oct 2024 03:07:02 -0700 (PDT) Received: from [10.57.65.82] (unknown [10.57.65.82]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 72E003F73B; Mon, 21 Oct 2024 03:06:28 -0700 (PDT) Message-ID: <627c1297-8151-43d1-b46b-a962301b18fa@arm.com> Date: Mon, 21 Oct 2024 12:06:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 0/5] Improve arm64 pkeys handling in signal delivery To: Dave Martin Cc: linux-arm-kernel@lists.infradead.org, akpm@linux-foundation.org, anshuman.khandual@arm.com, aruna.ramakrishna@oracle.com, broonie@kernel.org, catalin.marinas@arm.com, dave.hansen@linux.intel.com, jeffxu@chromium.org, joey.gouly@arm.com, shuah@kernel.org, will@kernel.org, linux-kselftest@vger.kernel.org, x86@kernel.org, pierre.langlois@arm.com References: <20241017133909.3837547-1-kevin.brodsky@arm.com> Content-Language: en-GB From: Kevin Brodsky In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_030633_283660_563D243C X-CRM114-Status: GOOD ( 19.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 17/10/2024 17:48, Dave Martin wrote: > On Thu, Oct 17, 2024 at 02:39:04PM +0100, Kevin Brodsky wrote: >> This series is a follow-up to Joey's Permission Overlay Extension (POE) >> series [1] that recently landed on mainline. The goal is to improve the >> way we handle the register that governs which pkeys/POIndex are >> accessible (POR_EL0) during signal delivery. As things stand, we may >> unexpectedly fail to write the signal frame on the stack because POR_EL0 >> is not reset before the uaccess operations. See patch 3 for more details >> and the main changes this series brings. >> >> A similar series landed recently for x86/MPK [2]; the present series >> aims at aligning arm64 with x86. Worth noting: once the signal frame is >> written, POR_EL0 is still set to POR_EL0_INIT, granting access to pkey 0 >> only. This means that a program that sets up an alternate signal stack >> with a non-zero pkey will need some assembly trampoline to set POR_EL0 >> before invoking the real signal handler, as discussed here [3]. > This feels a bit bogus (though it's anyway orthogonal to this series). I'm not very fond of this either. However I believe this is the correct first step: bring arm64 in line with x86. Removing all restrictions before uaccess and then setting POR_EL0 to POR_EL0_INIT enables userspace to use any pkey for the alternate signal stack without an ABI change, albeit not in a very comfortable way (if the pkey is not 0). > Really, we want some way for userspace to tell the kernel what > permissions to use for the alternate signal stack and signal handlers > using it, and then honour that request consistently (just as we try to > do for the main stack today). > > ss_flags is mostly unused... I wonder whether we could add something in > there? Or add a sigaltstack2()? Yes, this would be sensible as a second step (backwards-compatible extension). Exactly how that API would look like is not trivial though: is the pkey implicitly derived from the pointer provided to sigaltstack()? Is there a need to specify another pkey for code, or do we just assume that the signal handler is only using code with pkey 0? (Not a concern on x86 as MPK doesn't restrict execution.) Would be very interested to hear opinions on this. Kevin