From: Teng Qi <redacted>
[ 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 <redacted>
Signed-off-by: Teng Qi <redacted>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/net/ethernet/dec/tulip/de4x5.c | 4 ++++
1 file changed, 4 insertions(+)
From: zhangyue <redacted>
[ Upstream commit 61217be886b5f7402843677e4be7e7e83de9cb41 ]
In line 5001, if all id in the array 'lp->phy[8]' is not 0, when the
'for' end, the 'k' is 8.
At this time, the array 'lp->phy[8]' may be out of bound.
Signed-off-by: zhangyue <redacted>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/net/ethernet/dec/tulip/de4x5.c | 30 +++++++++++++++-----------
1 file changed, 17 insertions(+), 13 deletions(-)
@@ -4992,19 +4992,23 @@ mii_get_phy(struct net_device *dev)}if((j==limit)&&(i<DE4X5_MAX_MII)){for(k=0;k<DE4X5_MAX_PHY&&lp->phy[k].id;k++);-lp->phy[k].addr=i;-lp->phy[k].id=id;-lp->phy[k].spd.reg=GENERIC_REG;/* ANLPA register */-lp->phy[k].spd.mask=GENERIC_MASK;/* 100Mb/s technologies */-lp->phy[k].spd.value=GENERIC_VALUE;/* TX & T4, H/F Duplex */-lp->mii_cnt++;-lp->active++;-printk("%s: Using generic MII device control. If the board doesn't operate,\nplease mail the following dump to the author:\n",dev->name);-j=de4x5_debug;-de4x5_debug|=DEBUG_MII;-de4x5_dbg_mii(dev,k);-de4x5_debug=j;-printk("\n");+if(k<DE4X5_MAX_PHY){+lp->phy[k].addr=i;+lp->phy[k].id=id;+lp->phy[k].spd.reg=GENERIC_REG;/* ANLPA register */+lp->phy[k].spd.mask=GENERIC_MASK;/* 100Mb/s technologies */+lp->phy[k].spd.value=GENERIC_VALUE;/* TX & T4, H/F Duplex */+lp->mii_cnt++;+lp->active++;+printk("%s: Using generic MII device control. If the board doesn't operate,\nplease mail the following dump to the author:\n",dev->name);+j=de4x5_debug;+de4x5_debug|=DEBUG_MII;+de4x5_dbg_mii(dev,k);+de4x5_debug=j;+printk("\n");+}else{+gotopurgatory;+}}}purgatory: