From nobody Fri Sep 5 20:20:15 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C60CC3F6B0 for ; Tue, 23 Aug 2022 11:21:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357995AbiHWLVa (ORCPT ); Tue, 23 Aug 2022 07:21:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357463AbiHWLRg (ORCPT ); Tue, 23 Aug 2022 07:17:36 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 599477FE79; Tue, 23 Aug 2022 02:20:59 -0700 (PDT) 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 D5E57608D5; Tue, 23 Aug 2022 09:20:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4E93C433D7; Tue, 23 Aug 2022 09:20:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661246458; bh=xhWZwq/HUtoLagsr8FhoEe1WFz99DlirWBij+9n3rrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EExflo9u+7BXW/Lha0FaP05UuW1XnYcsVYG4cwk87ocZ/idxBnQqU9SqTovayZNSb B5xEX8WeAVyNeexNKJzh+ZBiuzhHOaIWKOdYPJNWEM8Dd6N/nk+b0SDlWdVwJM+cY5 Htqap8d0vBb24LUcJCJpbh/yE7j1N7/jK7Z11chY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hangyu Hua , Andrzej Hajda , Robert Foss , Sasha Levin Subject: [PATCH 5.4 116/389] drm: bridge: sii8620: fix possible off-by-one Date: Tue, 23 Aug 2022 10:23:14 +0200 Message-Id: <20220823080120.461751167@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080115.331990024@linuxfoundation.org> References: <20220823080115.331990024@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Hangyu Hua [ Upstream commit 21779cc21c732c5eff8ea1624be6590450baa30f ] The next call to sii8620_burst_get_tx_buf will result in off-by-one When ctx->burst.tx_count + size =3D=3D ARRAY_SIZE(ctx->burst.tx_buf). The s= ame thing happens in sii8620_burst_get_rx_buf. This patch also change tx_count and tx_buf to rx_count and rx_buf in sii8620_burst_get_rx_buf. It is unreasonable to check tx_buf's size and use rx_buf. Fixes: e19e9c692f81 ("drm/bridge/sii8620: add support for burst eMSC transm= issions") Signed-off-by: Hangyu Hua Reviewed-by: Andrzej Hajda Signed-off-by: Robert Foss Link: https://patchwork.freedesktop.org/patch/msgid/20220518065856.18936-1-= hbh25y@gmail.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/bridge/sil-sii8620.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/bridge/sil-sii8620.c b/drivers/gpu/drm/bridge/= sil-sii8620.c index fb0b64c965b7..970bc00d2aaf 100644 --- a/drivers/gpu/drm/bridge/sil-sii8620.c +++ b/drivers/gpu/drm/bridge/sil-sii8620.c @@ -604,7 +604,7 @@ static void *sii8620_burst_get_tx_buf(struct sii8620 *c= tx, int len) u8 *buf =3D &ctx->burst.tx_buf[ctx->burst.tx_count]; int size =3D len + 2; =20 - if (ctx->burst.tx_count + size > ARRAY_SIZE(ctx->burst.tx_buf)) { + if (ctx->burst.tx_count + size >=3D ARRAY_SIZE(ctx->burst.tx_buf)) { dev_err(ctx->dev, "TX-BLK buffer exhausted\n"); ctx->error =3D -EINVAL; return NULL; @@ -621,7 +621,7 @@ static u8 *sii8620_burst_get_rx_buf(struct sii8620 *ctx= , int len) u8 *buf =3D &ctx->burst.rx_buf[ctx->burst.rx_count]; int size =3D len + 1; =20 - if (ctx->burst.tx_count + size > ARRAY_SIZE(ctx->burst.tx_buf)) { + if (ctx->burst.rx_count + size >=3D ARRAY_SIZE(ctx->burst.rx_buf)) { dev_err(ctx->dev, "RX-BLK buffer exhausted\n"); ctx->error =3D -EINVAL; return NULL; --=20 2.35.1