Commit e0e15e6c authored by Vladimir Oltean's avatar Vladimir Oltean Committed by Zheng Zengkai
Browse files

net: dsa: mv88e6xxx: fix use-after-free in mv88e6xxx_mdios_unregister

stable inclusion
from stable-v5.10.101
commit 22249886dc5bc3d6bcc212f07e65b49d85c582fe
bugzilla: https://gitee.com/openeuler/kernel/issues/I5669Z

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=22249886dc5bc3d6bcc212f07e65b49d85c582fe



--------------------------------

[ Upstream commit 51a04ebf ]

Since struct mv88e6xxx_mdio_bus *mdio_bus is the bus->priv of something
allocated with mdiobus_alloc_size(), this means that mdiobus_free(bus)
will free the memory backing the mdio_bus as well. Therefore, the
mdio_bus->list element is freed memory, but we continue to iterate
through the list of MDIO buses using that list element.

To fix this, use the proper list iterator that handles element deletion
by keeping a copy of the list element next pointer.

Fixes: f53a2ce8 ("net: dsa: mv88e6xxx: don't use devres for mdiobus")
Reported-by: default avatarRafael Richter <rafael.richter@gin.de>
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20220210174017.3271099-1-vladimir.oltean@nxp.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarYu Liao <liaoyu15@huawei.com>
Reviewed-by: default avatarWei Li <liwei391@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 3e7ea4d9
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment