Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp143621rdb; Mon, 15 Jan 2024 15:45:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHYE/DyS0ph6qKoaZm9YK0gVx7OtfTqhYZqZe3TsryG30WXCBSr4V1/JLGIDdDR4Qo8W6jH X-Received: by 2002:a05:6a00:a85:b0:6d9:bd28:687 with SMTP id b5-20020a056a000a8500b006d9bd280687mr3272144pfl.40.1705362336278; Mon, 15 Jan 2024 15:45:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705362336; cv=none; d=google.com; s=arc-20160816; b=AeWSnmkuThNC2eWRb1WBoDPTcfebpzEMLrr9cxNrJZFysgy9IYT/6qmSyCQtVTb/CU 0h6Z7y95rkG2YpZoYafcj0k/T3BEf6VNx3glC77gh3im7FQw/WhZxkfGBc/u1Ufr9F1d bQ1+XvoDJ52Ro2bPorj1r8n0H+4ZcEtV2zmMhojgwzmZqCyaVrrLLKbUZ9cVZKF51h1x +ZrWOfRdLVKOHI0tesamL3JC0avuZ+EJZPO9EsJfkqWuxKQIEROZtQDT9JDSRPg5Z5Mo 8sbz5iwZPJaw1mciKAYMCtf9ZR0N4Wjg9uO9xKxl04KZly+6egaixoZGJqA/WChtvqOA lqcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=qZZesAjhbJ61cBQEIIZpcUfSGufEFFMUzpJ7YsCHBOw=; fh=30SwNszRFCMR3ECSybIVMAhsM5YWddmpF8QJC5qQWJI=; b=M7BeQe0Q28rNu7X4Ci0N5ct1r+ea1m3/k8nM3Mug4g0OqAVs/djnc1bbdKOLw0nRUq EK9dyIiLLRf9GfzGJSiyRuqN9DHXBNRITRQdrbTwHw3ujr6z/iRbJurps+KCG7ISO49T jihibWN8s5agmQzPP7DTZFogBJoDYwoWaFNNMDbXVgBwoMLBXj8izyyD9dFP9JzUSdDR EC6LnVk1ox6/B9RbJRtQJ6XkQJKTv1KJ7afMynbLGcSpcFeI8CBOiOjKvUrymhRA2SzT O4X9+/lahqBzbkEKWM9SjKz+XkwLyOd5xIceMvj74OvhyrINzZjni/htPVjWgkiFY3q/ u5Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XDHlmOpP; spf=pass (google.com: domain of linux-kernel+bounces-26590-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26590-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id i76-20020a639d4f000000b005cecf2bfa45si9580665pgd.378.2024.01.15.15.45.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 15:45:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26590-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XDHlmOpP; spf=pass (google.com: domain of linux-kernel+bounces-26590-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26590-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id EDE63B231C2 for ; Mon, 15 Jan 2024 23:42:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC3C0249E7; Mon, 15 Jan 2024 23:28:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XDHlmOpP" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1984E24204; Mon, 15 Jan 2024 23:28:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16602C433C7; Mon, 15 Jan 2024 23:28:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705361321; bh=Yn/UoGaSXHAJ2eCWL5SgDLxsIjyrysusKgqDJo7iR+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XDHlmOpPKqQmRd2BNOVCabrcVerNWd0KZSBpsGU+KgU+hXQWXHA778tDuJuXkUHlf Wxz8bcny4G9W3doL4ctTZjlK8c+jsAHjYWaRyD+wdkLLx/iRMD3QoQMG3J611SODRU DhpxgiSv31qImjCnzwNZ3SK7sNIO1z0FbDsn39UMCNpUvQ2EgugSuZo21eq3BT5nZ6 Bk0SeoQ6Gt0bXCryF5cvMXhAv+2K5hpdbX+9WNFh8arm7S9isHmyXF9GhXx0Y4AhOv uF1eIoaNWq/JvcEcP51Yqsn3pz5BtRrNt0gzMZ2UPghG7dewiFiZbT6f+30VgOZAfO kDe9spe1rqLbA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Naveen N Rao , "Gustavo A . R . Silva" , Michael Ellerman , Sasha Levin , christophe.leroy@csgroup.eu, linuxppc-dev@lists.ozlabs.org Subject: [PATCH AUTOSEL 5.10 08/10] powerpc/lib: Validate size for vector operations Date: Mon, 15 Jan 2024 18:27:57 -0500 Message-ID: <20240115232818.210010-8-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115232818.210010-1-sashal@kernel.org> References: <20240115232818.210010-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.208 Content-Transfer-Encoding: 8bit From: Naveen N Rao [ Upstream commit 8f9abaa6d7de0a70fc68acaedce290c1f96e2e59 ] Some of the fp/vmx code in sstep.c assume a certain maximum size for the instructions being emulated. The size of those operations however is determined separately in analyse_instr(). Add a check to validate the assumption on the maximum size of the operations, so as to prevent any unintended kernel stack corruption. Signed-off-by: Naveen N Rao Reviewed-by: Gustavo A. R. Silva Build-tested-by: Gustavo A. R. Silva Signed-off-by: Michael Ellerman Link: https://msgid.link/20231123071705.397625-1-naveen@kernel.org Signed-off-by: Sasha Levin --- arch/powerpc/lib/sstep.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c index 2d19655328f1..ca4733fbd02d 100644 --- a/arch/powerpc/lib/sstep.c +++ b/arch/powerpc/lib/sstep.c @@ -512,6 +512,8 @@ static int do_fp_load(struct instruction_op *op, unsigned long ea, } u; nb = GETSIZE(op->type); + if (nb > sizeof(u)) + return -EINVAL; if (!address_ok(regs, ea, nb)) return -EFAULT; rn = op->reg; @@ -562,6 +564,8 @@ static int do_fp_store(struct instruction_op *op, unsigned long ea, } u; nb = GETSIZE(op->type); + if (nb > sizeof(u)) + return -EINVAL; if (!address_ok(regs, ea, nb)) return -EFAULT; rn = op->reg; @@ -606,6 +610,9 @@ static nokprobe_inline int do_vec_load(int rn, unsigned long ea, u8 b[sizeof(__vector128)]; } u = {}; + if (size > sizeof(u)) + return -EINVAL; + if (!address_ok(regs, ea & ~0xfUL, 16)) return -EFAULT; /* align to multiple of size */ @@ -633,6 +640,9 @@ static nokprobe_inline int do_vec_store(int rn, unsigned long ea, u8 b[sizeof(__vector128)]; } u; + if (size > sizeof(u)) + return -EINVAL; + if (!address_ok(regs, ea & ~0xfUL, 16)) return -EFAULT; /* align to multiple of size */ -- 2.43.0