NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
kern/61119: micphy(4): 4-byte heap overflow, softc size does not include sc_lstype
>Number: 61119
>Category: kern
>Synopsis: micphy(4): 4-byte heap overflow, softc size does not include sc_lstype
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kern-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Dec 03 17:15:00 +0000 2026
>Originator: Denis Bodor
>Release:
>Organization:
>Environment:
NetBSD de1socnbsd 11.99.11 NetBSD 11.99.11 (DE1SOC) #1: Thu Dec 3 09:28:44 CET 2026 denis@newbeast:/mnt/SSD2T/de1-soc/NETBSD/usr/obj/sys/arch/evbarm/compile/DE1SOC evbarm
>Description:
mii_softc is allocated with/by CFATTACH_DECL_NEW(), but micphy_softc is bigger than that (+ one uint32_t) then used later by the driver (line 196 and 384).
So we have read/write out of bound here (kmem_alloc() round 108 bytes of mii_softc to 112 bytes, no real damage on armv7 but 64bit ARM systems may not like that. That's why i choose "serious").
micphy.c also have micphy_service() prototype twice.
>How-To-Repeat:
There is nothing to show, just code.
>Fix:
Use sizeof(struct micphy_softc) with CFATTACH_DECL_NEW() not struct mii_softc, and move the code a little :
diff --git a/sys/dev/mii/micphy.c b/sys/dev/mii/micphy.c
index bb4e76840..19cac7154 100644
--- a/sys/dev/mii/micphy.c
+++ b/sys/dev/mii/micphy.c
@@ -77,12 +77,16 @@ __KERNEL_RCSID(0, "$NetBSD: micphy.c,v 1.17 2026/04/21 19:10:32 nia Exp $");
#include <dev/mii/miivar.h>
#include <dev/mii/miidevs.h>
+struct micphy_softc {
+ struct mii_softc sc_mii;
+ uint32_t sc_lstype; /* Type of link status register */
+};
+
static int micphymatch(device_t, cfdata_t, void *);
static void micphyattach(device_t, device_t, void *);
static void micphy_reset(struct mii_softc *);
-static int micphy_service(struct mii_softc *, struct mii_data *, int);
-CFATTACH_DECL_NEW(micphy, sizeof(struct mii_softc),
+CFATTACH_DECL_NEW(micphy, sizeof(struct micphy_softc),
micphymatch, micphyattach, mii_phy_detach, mii_phy_activate);
static int micphy_service(struct mii_softc *, struct mii_data *, int);
@@ -93,11 +97,6 @@ static const struct mii_phy_funcs micphy_funcs = {
micphy_service, micphy_status, micphy_reset,
};
-struct micphy_softc {
- struct mii_softc sc_mii;
- uint32_t sc_lstype; /* Type of link status register */
-};
-
static const struct mii_phydesc micphys[] = {
MII_PHY_DESC(MICREL, KSZ8041),
MII_PHY_DESC(MICREL, KSZ8051), /* +8021,8031 */
Home |
Main Index |
Thread Index |
Old Index