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 F1AA37BB10; Wed, 21 Feb 2024 14:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708525121; cv=none; b=Y3Ljze2YfARagh/mfFdXBPftSl9ylzRG3ulymnmMcgToazulQ4NjQYC+Gq//oRqu22QuISeik0382oueyV4/H95K76t6AHsDABgX2KFpt5/EachVs9+VNSatwEyq5neIxEbkH+9/NPduasWYr9jwaC4WEybimZ+UcSuf1G6RAtI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708525121; c=relaxed/simple; bh=QoduzM6PmvniTukcZp/ozawlQUCDDc6jbMH6u1VPdz8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ljy8szZET17r49CZ+HMpOIzz+cQcPcBPtU1VGCaYTx9kCL+DX8U++veLi9ftzf9/KW9UPUocAs/srhdoajegy/MMZWHVW2d4llgDMOvT94O06QoeccXwmTvso38/iP2rdpWTHd3LseuRIcDa5p4MMgtfjttuuy7j27l4wnh024I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=fZYAhyGb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="fZYAhyGb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 580D4C433F1; Wed, 21 Feb 2024 14:18:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708525120; bh=QoduzM6PmvniTukcZp/ozawlQUCDDc6jbMH6u1VPdz8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fZYAhyGbvIB0xH5+hg7ntQkERVBe1VdXtcsyaKfzo3L8cZFdhmsmQ7PB3lvXlXxVv aqfG53T1wJqacDQclNtnNWcKBsLbSYZAFSXptMeiN7ZLw8lNjaFx0E778qLnhIT2yc YJYVNPKKU+Kvd38PUEOpYCGusj9UGwWQKSSekMA4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Naveen N Rao , "Gustavo A. R. Silva" , Michael Ellerman , Sasha Levin Subject: [PATCH 5.4 065/267] powerpc/lib: Validate size for vector operations Date: Wed, 21 Feb 2024 14:06:46 +0100 Message-ID: <20240221125942.037544940@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125940.058369148@linuxfoundation.org> References: <20240221125940.058369148@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ 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 27650cd5857f..490162fb0893 100644 --- a/arch/powerpc/lib/sstep.c +++ b/arch/powerpc/lib/sstep.c @@ -469,6 +469,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; @@ -519,6 +521,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; @@ -563,6 +567,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 */ @@ -590,6 +597,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