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 1702B69D28; Wed, 21 Feb 2024 13:15:15 +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=1708521316; cv=none; b=GYe1m5AhoJUg2hnBLMcyp3gIbQRZ80K+kBcMK5T9o9RoNE0AJeIJUnmamEQD7a85R20slAiCuEXCmiaSBun+36qWKMy0wNCx9GXurTafChQYwtRMnWcg3T3MgSQnM+7OgAM+0284K2JC3vEZeN+ecBAZAZILjv0JkkwtUKAWHQ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708521316; c=relaxed/simple; bh=r3xY8sWuuQjtvS89qcMxH+vjgj+nM3/WNCK0c5hf3T0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tYq7E+UkiMBMGEHjLoPN6QbRlMZ5dwsEHnZb6zeDjXNnO2KtgIviqF8GE3/OqA5r1v2/oTTUFg9lN75qlj/SAClY38bwopxKjtImtAsnrnkmAHkaDiAEtWkUkJko3KSge+7L3541ji7ll8X2ksyOIV/jqJcHjIDfEK2gBxHRxrw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=jkCFKOpK; 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="jkCFKOpK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21495C433F1; Wed, 21 Feb 2024 13:15:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708521315; bh=r3xY8sWuuQjtvS89qcMxH+vjgj+nM3/WNCK0c5hf3T0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jkCFKOpKkOAsv6erqjbtpLLSQeBuMff0lHwKDOXBr4v5QfL24hUhy4mxR9XhHKcRy lbz0Zka78gVpTHIuFnNmjR+L43aTDhblwFqxoQSMV2kt6v5w8m/nPIlOW9CJKS1wvq J5aH3PJzM1QyI9YFpXD9FNb4oElvpTA7Ao8Q/P3c= 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 4.19 053/202] powerpc/lib: Validate size for vector operations Date: Wed, 21 Feb 2024 14:05:54 +0100 Message-ID: <20240221125933.553791935@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125931.742034354@linuxfoundation.org> References: <20240221125931.742034354@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 4.19-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 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