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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF0C1C433F5 for ; Fri, 26 Nov 2021 02:42:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358958AbhKZCp0 (ORCPT ); Thu, 25 Nov 2021 21:45:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:50250 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358648AbhKZCnS (ORCPT ); Thu, 25 Nov 2021 21:43:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id C3C5961265; Fri, 26 Nov 2021 02:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637894122; bh=Ax+mzh3O/LR+EVqEKIJkihsoy88c801hBicX0PEHIjQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qR4+ySsEkMgwcyZ8nxQWT492R8ynQRXHer7g57AJGshqirn+YB36W8JVBrvAWpcRE bwUCJqueZ5jR4KdVw/NZuz01xxfPgJaid6eC2bzldUdnkKyFxOa5KIueuySWhpliQw vXCtggPpoU9iuhgP1BPk9NT0WdrG68JmbPK0JArOP1q5N2z4w+NNslOTKvWycb7G/J hVvHKFtqlkZXUxB0Sp0WrsonlBWN0bPPvgkVAoj/66YlSjdn+cFilfXgWVjzGkFiOh npEFII+aca42rfDdqeV0Cyr7JRKAmEiw6Yi/ZFGBVfeBGqiPAJjlSBv7Za9dDV3Vdz xvyoOWWShWR3w== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Teng Qi , TOTE Robot , Arnd Bergmann , "David S . Miller" , Sasha Levin , kuba@kernel.org, tanghui20@huawei.com, zhangyue1@kylinos.cn, netdev@vger.kernel.org, linux-parisc@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 17/19] net: ethernet: dec: tulip: de4x5: fix possible array overflows in type3_infoblock() Date: Thu, 25 Nov 2021 21:34:46 -0500 Message-Id: <20211126023448.442529-17-sashal@kernel.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211126023448.442529-1-sashal@kernel.org> References: <20211126023448.442529-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Teng Qi [ Upstream commit 0fa68da72c3be09e06dd833258ee89c33374195f ] The definition of macro MOTO_SROM_BUG is: #define MOTO_SROM_BUG (lp->active == 8 && (get_unaligned_le32( dev->dev_addr) & 0x00ffffff) == 0x3e0008) and the if statement if (MOTO_SROM_BUG) lp->active = 0; using this macro indicates lp->active could be 8. If lp->active is 8 and the second comparison of this macro is false. lp->active will remain 8 in: lp->phy[lp->active].gep = (*p ? p : NULL); p += (2 * (*p) + 1); lp->phy[lp->active].rst = (*p ? p : NULL); p += (2 * (*p) + 1); lp->phy[lp->active].mc = get_unaligned_le16(p); p += 2; lp->phy[lp->active].ana = get_unaligned_le16(p); p += 2; lp->phy[lp->active].fdx = get_unaligned_le16(p); p += 2; lp->phy[lp->active].ttm = get_unaligned_le16(p); p += 2; lp->phy[lp->active].mci = *p; However, the length of array lp->phy is 8, so array overflows can occur. To fix these possible array overflows, we first check lp->active and then return -EINVAL if it is greater or equal to ARRAY_SIZE(lp->phy) (i.e. 8). Reported-by: TOTE Robot Signed-off-by: Teng Qi Reviewed-by: Arnd Bergmann Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/dec/tulip/de4x5.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c index a80252973171f..c97fc0e384ca6 100644 --- a/drivers/net/ethernet/dec/tulip/de4x5.c +++ b/drivers/net/ethernet/dec/tulip/de4x5.c @@ -4708,6 +4708,10 @@ type3_infoblock(struct net_device *dev, u_char count, u_char *p) lp->ibn = 3; lp->active = *p++; if (MOTO_SROM_BUG) lp->active = 0; + /* if (MOTO_SROM_BUG) statement indicates lp->active could + * be 8 (i.e. the size of array lp->phy) */ + if (WARN_ON(lp->active >= ARRAY_SIZE(lp->phy))) + return -EINVAL; lp->phy[lp->active].gep = (*p ? p : NULL); p += (2 * (*p) + 1); lp->phy[lp->active].rst = (*p ? p : NULL); p += (2 * (*p) + 1); lp->phy[lp->active].mc = get_unaligned_le16(p); p += 2; -- 2.33.0