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 81710C4321E for ; Fri, 26 Nov 2021 02:40:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358472AbhKZCng (ORCPT ); Thu, 25 Nov 2021 21:43:36 -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 S1358454AbhKZClS (ORCPT ); Thu, 25 Nov 2021 21:41:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 04B4561185; Fri, 26 Nov 2021 02:34:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1637894072; bh=1kqdhOluEWtrRbIzXXDi+UZkBE3XgsycI2GlIXBpo/I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IdiRtOGr8yIbWHEZNE+vS/IlGDzOKPWK3XI4o72VQv+UReXBaPTAGoZPbkDwJpP7N Nk2NyPvGnjyn/DVG9SwogEJ4HlrwL0PavEY6QFm2yCQ2+wyLlrA+n5FieG+RXKZqOT Cj0tETFlpttMjTdaZZ8j7EJIRZyBEuCzoPzv06Ptgeb+PHI+B/43PsATyn8MjNgjw/ FFcz/P2fWuP6T2a1yVomBuv5ii7tcT5MtXrV00oj/OqOfjFQ9laeU3035L2qkIvLwZ 0v17iGk3/ukOXMhm9CVWPVtcU3iG7SajCP8aOMnWhJjPrAfW1mfup/l4aRH2Aul+jS ICUzhaC8Gu1ag== 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.10 25/28] net: ethernet: dec: tulip: de4x5: fix possible array overflows in type3_infoblock() Date: Thu, 25 Nov 2021 21:33:40 -0500 Message-Id: <20211126023343.442045-25-sashal@kernel.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211126023343.442045-1-sashal@kernel.org> References: <20211126023343.442045-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: netdev@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 ffc25ecfa8d6a..8edd394bc3358 100644 --- a/drivers/net/ethernet/dec/tulip/de4x5.c +++ b/drivers/net/ethernet/dec/tulip/de4x5.c @@ -4706,6 +4706,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