From patchwork Thu Mar 21 16:47:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Kobuk X-Patchwork-Id: 13599243 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 2F7E1C54E58 for ; Thu, 21 Mar 2024 16:48:07 +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: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:In-Reply-To:References: List-Owner; bh=wSNxqIpt/5ZbOea+WiXY/m7zu7ktyBRUD6MkPF+tuns=; b=i3MIU9G+tEZ8/h blmv6cnK7a0YD2s8sNTHE94lHnMztgt2yulIzVp3Kz5Z7Z5g/6H9Dj9zeKL7zM4EUqidH9xjDtrdk jt6RFrKHkd3m2vfCeY4d2Z+KyyAMUCjGxTMzMldIll3WtfFauHiZMFYhaBrY/szwKa5TApxDOVMYd X9bqqT3ONFXsQGoDQBg6rXJZjcN10f0vkADPcIncbDVuNRQ9kwUmFFhnB/eYKHVrrwoLyJzh5EB0m CI3+4puMYb5K6YNZgsSIBhF1XPkmCycG8woVr5wECC7PmdN+tm2VNTBfk+C0aHTfS5xV3xifZzOTw E+PB5lLcfRNEw2JtNuDA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnLaI-00000003tUR-2YNb; Thu, 21 Mar 2024 16:48:06 +0000 Received: from mail.ispras.ru ([83.149.199.84]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnLaD-00000003tHm-4AJo for linux-phy@lists.infradead.org; Thu, 21 Mar 2024 16:48:04 +0000 Received: from tundra.lovozera (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id F250040762DC; Thu, 21 Mar 2024 16:47:34 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru F250040762DC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1711039655; bh=rS+8oI4jnnlG0/QZtTc1eLuWcBGGVJJauaKM2Qw7ri8=; h=From:To:Cc:Subject:Date:From; b=BDfOSsfVeGPh5T+R82Aje3euP6f6ftZ+CKtxP5L1EhePArHYJkbCD9gA2hcrC/x74 nvlTSpqLefevcP/JPjm1V6SXYEel4zVaC9vA16bWILz4ml+/B6l/JMTJumfCgSb4fh R7c4xUg2F+danH1/bxbOgILAFnr4LcrIHnvh+7cM= From: Mikhail Kobuk To: Miquel Raynal Cc: Mikhail Kobuk , Vinod Koul , Kishon Vijay Abraham I , =?utf-8?q?Marek_Beh=C3=BAn?= , =?utf-8?q?Pali_Roh=C3=A1r?= , linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org, Alexey Khoroshilov Subject: [PATCH 1/2] phy: marvell: a3700-comphy: Fix out of bounds read Date: Thu, 21 Mar 2024 19:47:30 +0300 Message-ID: <20240321164734.49273-1-m.kobuk@ispras.ru> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240321_094802_669534_8E8292CA X-CRM114-Status: UNSURE ( 8.87 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org There is an out of bounds read access of 'gbe_phy_init_fix[fix_idx].addr' every iteration after 'fix_idx' reaches 'ARRAY_SIZE(gbe_phy_init_fix)'. Make sure 'gbe_phy_init[addr]' is used when all elements of 'gbe_phy_init_fix' array are handled. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 934337080c6c ("phy: marvell: phy-mvebu-a3700-comphy: Add native kernel implementation") Signed-off-by: Mikhail Kobuk Reviewed-by: Miquel Raynal --- drivers/phy/marvell/phy-mvebu-a3700-comphy.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c index 15bf10710de0..1d1db1737422 100644 --- a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c +++ b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c @@ -611,11 +611,12 @@ static void comphy_gbe_phy_init(struct mvebu_a3700_comphy_lane *lane, * comparison to 3.125 Gbps values. These register values are * stored in "gbe_phy_init_fix" array. */ - if (!is_1gbps && gbe_phy_init_fix[fix_idx].addr == addr) { + if (!is_1gbps && + fix_idx < ARRAY_SIZE(gbe_phy_init_fix) && + gbe_phy_init_fix[fix_idx].addr == addr) { /* Use new value */ val = gbe_phy_init_fix[fix_idx].value; - if (fix_idx < ARRAY_SIZE(gbe_phy_init_fix)) - fix_idx++; + fix_idx++; } else { val = gbe_phy_init[addr]; } From patchwork Thu Mar 21 16:47:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikhail Kobuk X-Patchwork-Id: 13599242 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 76033C6FD1F for ; Thu, 21 Mar 2024 16:48:05 +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=OlvGJXnf00GWk5RW++eX/0YoyJp8K/x9MTkhxIKx5xM=; b=GQA8bohLl+zXHp 7kFM99lt3MSanSNEE7IlcV44+ealVsY/0KQqxPrM/cirYKeHGIOV1IpyBxtCscZCzFwlj0p0+IY5y Lrb86ssxOvmdaIOiQ9vCbO9uFxa+q+wzWCB+B80SAWPl0kxwgV/X2VDHuzD5kVf+yb1tdCku241SL U5YAbocxq6bPdTsAzdBR4pum+9fYNm34xha/HwfsfimvG/gJ5lk1Jq+gxI+BmHpkph6wFE9CXbtA8 Si2xpElRKqP3CcTcjqG+YyXf8O7DJQFLRG97pBGBaoN+AnDYrMUbt5Tb+qqDdwTv6NSDkA4kGvyEi BEFoAfjRS4yqdebKn3zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnLaH-00000003tTa-0huS; Thu, 21 Mar 2024 16:48:05 +0000 Received: from mail.ispras.ru ([83.149.199.84]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnLaD-00000003tIT-44Rj for linux-phy@lists.infradead.org; Thu, 21 Mar 2024 16:48:04 +0000 Received: from tundra.lovozera (unknown [83.149.199.65]) by mail.ispras.ru (Postfix) with ESMTPSA id CB3A74076740; Thu, 21 Mar 2024 16:47:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru CB3A74076740 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1711039655; bh=r2m1IFOo39rYh7Yqg1o38OZbzAZc486wtJtHt6GKQN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e/IoVVTmJcjYmoIvO2d8hMVtfnMzisXAIkALho404ABalv/p1MYVojBoqBYofIZCU 6OsYZtHgKk26MxAe/VkoFI4rcAY0B0UlTSUPWs+cXZH6nAR7QgVRbtwhpxKZrB1rmh IVgkNjmcazOJjWGj9olJPuX826H8+xk551pjtIgE= From: Mikhail Kobuk To: Miquel Raynal Cc: Mikhail Kobuk , Vinod Koul , Kishon Vijay Abraham I , =?utf-8?q?Marek_Beh=C3=BAn?= , =?utf-8?q?Pali_Roh=C3=A1r?= , linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org, lvc-project@linuxtesting.org, Alexey Khoroshilov Subject: [PATCH 2/2] phy: marvell: a3700-comphy: Fix hardcoded array size Date: Thu, 21 Mar 2024 19:47:31 +0300 Message-ID: <20240321164734.49273-2-m.kobuk@ispras.ru> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240321164734.49273-1-m.kobuk@ispras.ru> References: <20240321164734.49273-1-m.kobuk@ispras.ru> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240321_094802_619488_86AF2243 X-CRM114-Status: UNSURE ( 9.60 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-phy@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux Phy Mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-phy" Errors-To: linux-phy-bounces+linux-phy=archiver.kernel.org@lists.infradead.org Replace hardcoded 'gbe_phy_init' array size by explicit one. Fixes: 934337080c6c ("phy: marvell: phy-mvebu-a3700-comphy: Add native kernel implementation") Signed-off-by: Mikhail Kobuk --- drivers/phy/marvell/phy-mvebu-a3700-comphy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c index 41162d7228c9..15bf10710de0 100644 --- a/drivers/phy/marvell/phy-mvebu-a3700-comphy.c +++ b/drivers/phy/marvell/phy-mvebu-a3700-comphy.c @@ -603,7 +603,7 @@ static void comphy_gbe_phy_init(struct mvebu_a3700_comphy_lane *lane, u16 val; fix_idx = 0; - for (addr = 0; addr < 512; addr++) { + for (addr = 0; addr < ARRAY_SIZE(gbe_phy_init); addr++) { /* * All PHY register values are defined in full for 3.125Gbps * SERDES speed. The values required for 1.25 Gbps are almost