From mboxrd@z Thu Jan 1 00:00:00 1970 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 5639D286AC; Mon, 15 Jan 2024 23:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="uZ4dkR3T" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECE4CC433F1; Mon, 15 Jan 2024 23:29:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705361385; bh=4sz/D6BUjVTtSNq5aU5z2RxJVXyWrK9kgwUbcjvX90I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uZ4dkR3TJr4dlj79rA9Br15XrZi+Mtd8nduH4UyO3C83RMqH/+Jyo+UqG6tOmW+/9 BBnmpFLIqYkJZ7bX3FabT9rYSYujiqjXpM+YKW1hOPYvycshbkmM3NilLf1++XGjWq bBY1dVpbZwkwGE5e7lk08BgbBthXAP9vT7sCwXq9dhjoy/N1Pk7z0KcjRAzuyzM1vQ HSfgGe5rbBuBBDuszmv92kSOgTQNyrOAU+v9Byf+CiN63Dbhj61/h8X8WlwxHLubRP 2xlLpaccXW5jx+R0rLCkC5atXUTPDoRt15TTqr1ph+U3t7OuADvxRhlsYqtXiEH+lV p5xAB4oiMEXcQ== 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 4.19 4/4] powerpc/lib: Validate size for vector operations Date: Mon, 15 Jan 2024 18:29:29 -0500 Message-ID: <20240115232935.210529-4-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115232935.210529-1-sashal@kernel.org> References: <20240115232935.210529-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 4.19.305 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 30c434abe861..3da6290e3ccc 100644 --- a/arch/powerpc/lib/sstep.c +++ b/arch/powerpc/lib/sstep.c @@ -473,6 +473,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; @@ -523,6 +525,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; @@ -567,6 +571,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 */ @@ -594,6 +601,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