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 1CA2FC77B75 for ; Mon, 22 May 2023 19:39:56 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LqqS7MQfWwI4jW36irGYzsOUl2YJcz4jUSvLXV+V+3M=; b=Yw/UdgvrIN3hzs HKExI3nWUSwLutf22Fe5FEkToVp6wG15YdSqDt9FVZVLiQ5ZSxlcRE8/Fwbcogx5RWtgM4TsXHCDv fSoW44q7fXM168tk5r7zz6yQM9HE+JtfnwXdxVRl3eAC9w6Dk1EzZ2lgONnfguI8qzLKJBRlpwu/S ajFBxgACuQ2m/w4an3D6tei9M0k5qgd8KXOBeQzJYLqK0HQD5vE9/4zZZ2oyHJSW6IGfxCa8LTkF2 W9t1p1vXdh/wZzV/GZAkFV4Q475RGF8W+62lhw/dsHdG+h/ClEKcyulXUH6TdoPtwLzrBkITwUYvq UPyR+xKzvh1+V+xIpuEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q1BNV-007mNW-18; Mon, 22 May 2023 19:39:33 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q1BNT-007mLD-1d for linux-arm-kernel@bombadil.infradead.org; Mon, 22 May 2023 19:39:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=uTHqU3FI0vLyKxo8vynMZFtuuIjizmG7rsRAiBuEo08=; b=j4k8XRBi0fCcn/hSAvaOEyuWAm 8HuwhLagx0+PyFnbAFy01NA44Z+vVsGCFLCL7hWkIwcbLJrxsryZmjcsHP9Ag+JuyzG8VOcLQuRN/ 2IfutZEVywp03ulQTcH+Nj1tZ8v0yS+xJMaDwESAORfnC1vJsqf0TsFQC9mn+qqYd4eL1l9GFb5dc d6wz08JhQQ9g/Yj2Q8kb+mxr+2lB3ph/SwVz692nqY39TrIygmgoI2gGk4UdYz0TIYuhqNkpQBx00 hUtdzieri2MAy5AMsoS32XE1TFRhwW2MZmCmVhzD7hZ4+uFmBoUq7Or82HlyFhaNbOwIWKZs3LOjB uXMdJYFA==; Received: from dfw.source.kernel.org ([139.178.84.217]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q1BNQ-0027g3-0g for linux-arm-kernel@lists.infradead.org; Mon, 22 May 2023 19:39:30 +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 E5E42629DD; Mon, 22 May 2023 19:39:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C588CC433D2; Mon, 22 May 2023 19:39:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1684784364; bh=3RQ3NpkUvKvMX1Q9TThOfZqbeNUdpgUUkq+Yf3PtgjM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gEKofzya2y0//CGS7y1tSd0rpcnyLpzADU8AUsg4zii3xxAP01FnmM2Z26FnyGPMI sHqsuvVe6ccZ3MNrXgh/nvhgy91ZTYxg7wiOD3I54bhTZw/OL+FJRwYjyzPS20IpA2 6hsOc1Yysi5kwHQVbM71o+UqUdg/npksBMca9Ez4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Mirela Rabulea , NXP Linux Team , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , linux-arm-kernel@lists.infradead.org, Kees Cook , Hans Verkuil , Mauro Carvalho Chehab , Sasha Levin Subject: [PATCH 6.3 057/364] media: imx-jpeg: Bounds check sizeimage access Date: Mon, 22 May 2023 20:06:02 +0100 Message-Id: <20230522190414.222626164@linuxfoundation.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230522190412.801391872@linuxfoundation.org> References: <20230522190412.801391872@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230522_203928_664286_5D963912 X-CRM114-Status: GOOD ( 16.07 ) 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 From: Kees Cook [ Upstream commit 474acc639fc8671fa4c1919d9e03253c82b6d321 ] The call of mxc_jpeg_get_plane_size() from mxc_jpeg_dec_irq() sets plane_no argument to 1. The compiler sees that it's possible to end up with an access beyond the bounds of sizeimage, if mem_planes was too large: if (plane_no >= fmt->mem_planes) // mem_planes = 2+ return 0; if (fmt->mem_planes == fmt->comp_planes) // comp_planes != mem_planes return q_data->sizeimage[plane_no]; if (plane_no < fmt->mem_planes - 1) // mem_planes = 2 return q_data->sizeimage[plane_no]; comp_planes == 0 or 1 is safe. comp_planes > 2 would be out of bounds. (This isn't currently possible given the contents of mxc_formats, though.) Silence the warning by bounds checking comp_planes for future robustness. Seen with GCC 13: In function 'mxc_jpeg_get_plane_size', inlined from 'mxc_jpeg_dec_irq' at ../drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c:729:14: ../drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c:641:42: warning: array subscript 2 is above array bounds of 'u32[2]' {aka 'unsigned int[2]'} [-Warray-bounds=] 641 | size += q_data->sizeimage[i]; | ~~~~~~~~~~~~~~~~~^~~ In file included from ../drivers/media/platform/nxp/imx-jpeg/mxc-jpeg-hw.h:112, from ../drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c:63: ../drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h: In function 'mxc_jpeg_dec_irq': ../drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.h:84:41: note: while referencing 'sizeimage' 84 | u32 sizeimage[MXC_JPEG_MAX_PLANES]; | ^~~~~~~~~ Cc: Mirela Rabulea Cc: NXP Linux Team Cc: Shawn Guo Cc: Sascha Hauer Cc: Pengutronix Kernel Team Cc: Fabio Estevam Cc: linux-arm-kernel@lists.infradead.org Signed-off-by: Kees Cook Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Sasha Levin --- drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c index f085f14d676ad..c898116b763a2 100644 --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c @@ -637,6 +637,11 @@ static u32 mxc_jpeg_get_plane_size(struct mxc_jpeg_q_data *q_data, u32 plane_no) return q_data->sizeimage[plane_no]; size = q_data->sizeimage[fmt->mem_planes - 1]; + + /* Should be impossible given mxc_formats. */ + if (WARN_ON_ONCE(fmt->comp_planes > ARRAY_SIZE(q_data->sizeimage))) + return size; + for (i = fmt->mem_planes; i < fmt->comp_planes; i++) size += q_data->sizeimage[i]; -- 2.39.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel