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 21E54C43217 for ; Thu, 24 Nov 2022 14:05:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1yCaRr+LqHlQ2Fxj2vfdyuxxolAQ34tOFj99FUpbsS4=; b=YlQdYlSy1NnyG2 ZDm8/AQE9hfgmom4mv6PUeb1IVm9pfGsig2bSHWTivMoli34WlbdtFpNTTVsRkR8WwQRNVI1dIUde wwhgs2BvbOykUiu9Ihme6IxuHqrziGiI/cmlid46UmPgHyrczaN0Igis8vW2oGo1ur1BwC1CIsbW3 J6Fga0/Qf1rfqSEIbRWniCpBbRMb/YWl6s14aqTm8vFmku0j2Vk62Oa81odDG+TV/k7N6AeINoldL hpr8nDdQHeOWrEFNK0mLQTLWUGtLvO06MmZQfdEKrfebNwd+JAFr2rRMFLcAV91vNx/r1BSE6YwWM PZ0qPGIw1pzosMkALdbg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oyCqO-0095g6-Pa; Thu, 24 Nov 2022 14:04:49 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oyCnq-0094iI-AP for linux-arm-kernel@lists.infradead.org; Thu, 24 Nov 2022 14:02:14 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C3C8C6213C; Thu, 24 Nov 2022 14:02:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0C46C433D6; Thu, 24 Nov 2022 14:02:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669298529; bh=xyp+bhxBc8xbahWMRYP1MAnbLE/ZSjeMd6mlUSnl48w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tXu0Rju+VpK4tqzKdNXGozHGPLMafE4AHEP1Tt+A5T44zSrXWgRttyCz5Se3b+kBo ABfGWoZ8bel4B4ZMq/giIsgfkTTvL/fFDPUf2or7MgUalCwf6krhOZ/GSQMLbxRPcq 6mJvY/bO2JSScG3/b+L0wcQRLOmdUMh4v4hWmb/d+aDKYwt5SdvWieLyk7rQyONGKK /l4h6ipjl2U0UdfP64FlAb2xbAhsKxhbF1Q7xNw8cxtdpu0/9WBb+NbgJylvYcP9Rk yrIURyEN1QBo/N7SfRl39TRzBrYa9PIoJbDjcviBxuf+rYPv9ZcA6FPqvL8PGTcFw9 VWkV3It+E1g4Q== From: Mark Brown To: Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, Mark Brown Subject: [PATCH v1 4/6] arm64/signal: Avoid rereading context frame sizes Date: Thu, 24 Nov 2022 13:58:16 +0000 Message-Id: <20221124135818.282955-5-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221124135818.282955-1-broonie@kernel.org> References: <20221124135818.282955-1-broonie@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4081; i=broonie@kernel.org; h=from:subject; bh=xyp+bhxBc8xbahWMRYP1MAnbLE/ZSjeMd6mlUSnl48w=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjf3h4z0ErE8ywX1WmGxRY96e+/0CU+Xo+oxS/0tgL NI8Ys1yJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCY394eAAKCRAk1otyXVSH0ER/B/ 4uIM3hLoVcph+I+ZV6u0F83xDh0HEkbq40eicjmNwGb7H79n5A3HiCNkr4ZFi7FoejIC+F94W5GOdE 2xBWxxchbzCz7Xtw/8FZxnzM+ks7Q+4dTcGUX5l726EzAZzNkcIl41+qRMAfIAfMAEbUjqmGGjc9Vi mSngjI2O76EeaD6QsU29MV3ec/CahN5+2cgsJcPusOv2AVll4k+CDVm2vQ/06TvSI95ztSLN5tch8T GhlzpNhmThRk+X8/0eDJkp3JiD/nMUqy3lvhEFtI8o8SVB4xz0GB0murS1dxv65/7NrtbeqkHHGV04 Ap1UZDRfZOxtcI7bq3q4+0GQwXfCx/ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221124_060210_528978_76719317 X-CRM114-Status: GOOD ( 17.15 ) 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: , 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 We need to read the sizes of the signal context frames as part of parsing the overall signal context in parse_user_sigframe(). In the cases where we defer frame specific parsing to other functions those functions always reread the size and validate the version they read, opening the possibility that the value may change. Avoid this possibility by passing the size read in parse_user_sigframe() through user_ctxs and referring to that. Note that for SVE and ZA contexts we still read the size again but after this change we no longer use the value, further changes will avoid the read. Signed-off-by: Mark Brown --- arch/arm64/kernel/signal.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index 9603a468b104..3a11b87eec4d 100644 --- a/arch/arm64/kernel/signal.c +++ b/arch/arm64/kernel/signal.c @@ -170,8 +170,11 @@ static void __user *apply_user_offset( struct user_ctxs { struct fpsimd_context __user *fpsimd; + u32 fpsimd_size; struct sve_context __user *sve; + u32 sve_size; struct za_context __user *za; + u32 za_size; }; static int preserve_fpsimd_context(struct fpsimd_context __user *ctx) @@ -195,14 +198,10 @@ static int preserve_fpsimd_context(struct fpsimd_context __user *ctx) static int restore_fpsimd_context(struct user_ctxs *user) { struct user_fpsimd_state fpsimd; - __u32 size; int err = 0; /* check the size information */ - __get_user_error(size, &user->fpsimd->head.size, err); - if (err) - return -EFAULT; - if (size != sizeof(struct fpsimd_context)) + if (user->fpsimd_size != sizeof(struct fpsimd_context)) return -EINVAL; /* copy the FP and status/control registers */ @@ -270,7 +269,7 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user) struct user_fpsimd_state fpsimd; struct sve_context sve; - if (sve.head.size < sizeof(*user->sve)) + if (user->sve_size < sizeof(*user->sve)) return -EINVAL; if (__copy_from_user(&sve, user->sve, sizeof(sve))) @@ -291,7 +290,7 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user) if (sve.vl != vl) return -EINVAL; - if (sve.head.size == sizeof(*user->sve)) { + if (user->sve_size == sizeof(*user->sve)) { clear_thread_flag(TIF_SVE); current->thread.svcr &= ~SVCR_SM_MASK; goto fpsimd_only; @@ -299,7 +298,7 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user) vq = sve_vq_from_vl(sve.vl); - if (sve.head.size < SVE_SIG_CONTEXT_SIZE(vq)) + if (user->sve_size < SVE_SIG_CONTEXT_SIZE(vq)) return -EINVAL; /* @@ -401,7 +400,7 @@ static int restore_za_context(struct user_ctxs *user) unsigned int vq; struct za_context za; - if (za.head.size == sizeof(*user->za)) + if (user->za_size < sizeof(*user->za)) return -EINVAL; if (__copy_from_user(&za, user->za, sizeof(za))) @@ -410,14 +409,14 @@ static int restore_za_context(struct user_ctxs *user) if (za.vl != task_get_sme_vl(current)) return -EINVAL; - if (za.head.size == sizeof(*user->za)) { + if (user->za_size == sizeof(*user->za)) { current->thread.svcr &= ~SVCR_ZA_MASK; return 0; } vq = sve_vq_from_vl(za.vl); - if (za.head.size < ZA_SIG_CONTEXT_SIZE(vq)) + if (user->za_size < ZA_SIG_CONTEXT_SIZE(vq)) return -EINVAL; /* @@ -514,6 +513,7 @@ static int parse_user_sigframe(struct user_ctxs *user, goto invalid; user->fpsimd = (struct fpsimd_context __user *)head; + user->fpsimd_size = size; break; case ESR_MAGIC: @@ -528,6 +528,7 @@ static int parse_user_sigframe(struct user_ctxs *user, goto invalid; user->sve = (struct sve_context __user *)head; + user->sve_size = size; break; case ZA_MAGIC: @@ -538,6 +539,7 @@ static int parse_user_sigframe(struct user_ctxs *user, goto invalid; user->za = (struct za_context __user *)head; + user->za_size = size; break; case EXTRA_MAGIC: -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel