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 785D3C4708E for ; Tue, 3 Jan 2023 20:28:39 +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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=loQ4E39TPDqHZBq9zfVeUELeRnm9erla70RJpbNZJBY=; b=pFcNOFobpAkAae fpK+j4O6g8eX8hgshfO8emM1tuoj3lAoLJGDtHds2F75/n7VB0ye3wBT2TAtvBNkEIP1EsNYbqbYP 9WgLLq8nIYaq7gwH+ujl/ixeQAaQOI3WTjUI5VNHB14O2WklhkVRYNMyKAA0B2S8+HoUQl6i1cEkt qMfkoez2hHhpYnaPryS6NYVKCy/HGRXWXQZCHvjG7Hgi7ZlxUUnTyxrn+2xxRs1eZA6D33r16w46R VQyI/1gqZMGgpzwGYYDJt5CykBLj4N9FgmNHGrLZDtJ1DD5j1Hc7UzaTZP1B+vhzPiK7NOkMKWBYg uSuQ80WgrgESxJJvnwnA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pCnsf-004jVx-NZ; Tue, 03 Jan 2023 20:27:30 +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 1pCnqw-004jAc-7f for linux-arm-kernel@lists.infradead.org; Tue, 03 Jan 2023 20:25:44 +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 A5CBB6150C; Tue, 3 Jan 2023 20:25:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 104F0C433F2; Tue, 3 Jan 2023 20:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672777541; bh=tm7z3a7e1dpUp7BcDdm5psXlFys9Y+jlcThdQocuGaE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=GdDp/KIBN0qrkw2lYv5TQueXUnahj+WhE4Ml+XDglEKFX1Gie4jRQ00fKMmz/GRcW aT4Zs88w98JpYOFstEl7tpWsQsxjwGLH8YrElaO4yJ6rumjIX24ooshqfEzR4ZOssA ttiEJmoe+BaRh0VD4nqYdD2VX8zdfpHM2qfWWn4rVriW1SU72Ex1aSnrNXI4cZd2RQ 1Z4hxBNHrcFQRPDbFwF2YFQ2FiQwC6nCiYSyxXeJIPld1pBLJ9EkmatiDJs6A7sYVb 7p88MYUpj7SI9jHzD7Aje90S3jEu/ugp3/PpSMEbu4IHJ8ZThwvTXN9mlLbrtBMqXf kDXIKKtSnI5Cg== From: Mark Brown Date: Tue, 03 Jan 2023 20:25:18 +0000 Subject: [PATCH v2 4/6] arm64/signal: Avoid rereading context frame sizes MIME-Version: 1.0 Message-Id: <20221212-arm64-signal-cleanup-v2-4-14a8f3e088b7@kernel.org> References: <20221212-arm64-signal-cleanup-v2-0-14a8f3e088b7@kernel.org> In-Reply-To: <20221212-arm64-signal-cleanup-v2-0-14a8f3e088b7@kernel.org> To: Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.12-dev-214b3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4225; i=broonie@kernel.org; h=from:subject:message-id; bh=tm7z3a7e1dpUp7BcDdm5psXlFys9Y+jlcThdQocuGaE=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjtI87xKgAdFEn5VkiKiBgPouDLRE9SqfWc8ILuuPT EuE12aCJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCY7SPOwAKCRAk1otyXVSH0FGlB/ 9Sbh85w0Zd93xBgkXHw7aoF2+e44NyDjC17RXGbyfiYDs/tDa+pNhkPcD4R9tJ6SA3/tHRsth+wSKx Apc0G2h+08XKWnPjaUIhIF8sypbJB5kUh1cJ9TVRhlU/7O5NIPFkhpxuRt4CG20onl0sFJZwUqsP3s jVblAE+fXSR/p+3V3CPue6wXlRf/5M0X3EC1yw2EYKouuoD6UP2AbOFI5nivJyb2JlaEA2r5y49SUD NSyD5ViY6e5m7dFn9E7dyJSJcUBOMMLvPxJfZsHVVfp9Et+BqXiIL0OZnqscylVlbKKw1rbWwlIZDK v2FNKL7gCW/fv6dgS3Pxnno5ANwtUX 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-20230103_122542_495589_4D8D4548 X-CRM114-Status: GOOD ( 18.62 ) 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 | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c index e9c6ffc1ebba..82a89b0852ee 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 */ @@ -271,12 +270,12 @@ static int restore_sve_fpsimd_context(struct user_ctxs *user) struct user_fpsimd_state fpsimd; struct sve_context sve; + if (user->sve_size < sizeof(*user->sve)) + return -EINVAL; + if (__copy_from_user(&sve, user->sve, sizeof(sve))) return -EFAULT; - if (sve.head.size < sizeof(*user->sve)) - return -EINVAL; - if (sve.flags & SVE_SIG_FLAG_SM) { if (!system_supports_sme()) return -EINVAL; @@ -292,7 +291,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; current->thread.fp_type = FP_STATE_FPSIMD; @@ -301,7 +300,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; /* @@ -404,23 +403,23 @@ static int restore_za_context(struct user_ctxs *user) unsigned int vq; struct za_context za; + if (user->za_size < sizeof(*user->za)) + return -EINVAL; + if (__copy_from_user(&za, user->za, sizeof(za))) return -EFAULT; - if (za.head.size < sizeof(*user->za)) - return -EINVAL; - 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; /* @@ -517,6 +516,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: @@ -531,6 +531,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: @@ -541,6 +542,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