linux-uconsole/drivers/net/phy
Yanfei Xu 3a0dc2e35a net: mdiobus: Fix memory leak in __mdiobus_register
commit ab609f25d1 upstream.

Once device_register() failed, we should call put_device() to
decrement reference count for cleanup. Or it will cause memory
leak.

BUG: memory leak
unreferenced object 0xffff888114032e00 (size 256):
  comm "kworker/1:3", pid 2960, jiffies 4294943572 (age 15.920s)
  hex dump (first 32 bytes):
    00 00 00 00 00 00 00 00 08 2e 03 14 81 88 ff ff  ................
    08 2e 03 14 81 88 ff ff 90 76 65 82 ff ff ff ff  .........ve.....
  backtrace:
    [<ffffffff8265cfab>] kmalloc include/linux/slab.h:591 [inline]
    [<ffffffff8265cfab>] kzalloc include/linux/slab.h:721 [inline]
    [<ffffffff8265cfab>] device_private_init drivers/base/core.c:3203 [inline]
    [<ffffffff8265cfab>] device_add+0x89b/0xdf0 drivers/base/core.c:3253
    [<ffffffff828dd643>] __mdiobus_register+0xc3/0x450 drivers/net/phy/mdio_bus.c:537
    [<ffffffff828cb835>] __devm_mdiobus_register+0x75/0xf0 drivers/net/phy/mdio_devres.c:87
    [<ffffffff82b92a00>] ax88772_init_mdio drivers/net/usb/asix_devices.c:676 [inline]
    [<ffffffff82b92a00>] ax88772_bind+0x330/0x480 drivers/net/usb/asix_devices.c:786
    [<ffffffff82baa33f>] usbnet_probe+0x3ff/0xdf0 drivers/net/usb/usbnet.c:1745
    [<ffffffff82c36e17>] usb_probe_interface+0x177/0x370 drivers/usb/core/driver.c:396
    [<ffffffff82661d17>] call_driver_probe drivers/base/dd.c:517 [inline]
    [<ffffffff82661d17>] really_probe.part.0+0xe7/0x380 drivers/base/dd.c:596
    [<ffffffff826620bc>] really_probe drivers/base/dd.c:558 [inline]
    [<ffffffff826620bc>] __driver_probe_device+0x10c/0x1e0 drivers/base/dd.c:751
    [<ffffffff826621ba>] driver_probe_device+0x2a/0x120 drivers/base/dd.c:781
    [<ffffffff82662a26>] __device_attach_driver+0xf6/0x140 drivers/base/dd.c:898
    [<ffffffff8265eca7>] bus_for_each_drv+0xb7/0x100 drivers/base/bus.c:427
    [<ffffffff826625a2>] __device_attach+0x122/0x260 drivers/base/dd.c:969
    [<ffffffff82660916>] bus_probe_device+0xc6/0xe0 drivers/base/bus.c:487
    [<ffffffff8265cd0b>] device_add+0x5fb/0xdf0 drivers/base/core.c:3359
    [<ffffffff82c343b9>] usb_set_configuration+0x9d9/0xb90 drivers/usb/core/message.c:2170
    [<ffffffff82c4473c>] usb_generic_driver_probe+0x8c/0xc0 drivers/usb/core/generic.c:238

BUG: memory leak
unreferenced object 0xffff888116f06900 (size 32):
  comm "kworker/0:2", pid 2670, jiffies 4294944448 (age 7.160s)
  hex dump (first 32 bytes):
    75 73 62 2d 30 30 31 3a 30 30 33 00 00 00 00 00  usb-001:003.....
    00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
  backtrace:
    [<ffffffff81484516>] kstrdup+0x36/0x70 mm/util.c:60
    [<ffffffff814845a3>] kstrdup_const+0x53/0x80 mm/util.c:83
    [<ffffffff82296ba2>] kvasprintf_const+0xc2/0x110 lib/kasprintf.c:48
    [<ffffffff82358d4b>] kobject_set_name_vargs+0x3b/0xe0 lib/kobject.c:289
    [<ffffffff826575f3>] dev_set_name+0x63/0x90 drivers/base/core.c:3147
    [<ffffffff828dd63b>] __mdiobus_register+0xbb/0x450 drivers/net/phy/mdio_bus.c:535
    [<ffffffff828cb835>] __devm_mdiobus_register+0x75/0xf0 drivers/net/phy/mdio_devres.c:87
    [<ffffffff82b92a00>] ax88772_init_mdio drivers/net/usb/asix_devices.c:676 [inline]
    [<ffffffff82b92a00>] ax88772_bind+0x330/0x480 drivers/net/usb/asix_devices.c:786
    [<ffffffff82baa33f>] usbnet_probe+0x3ff/0xdf0 drivers/net/usb/usbnet.c:1745
    [<ffffffff82c36e17>] usb_probe_interface+0x177/0x370 drivers/usb/core/driver.c:396
    [<ffffffff82661d17>] call_driver_probe drivers/base/dd.c:517 [inline]
    [<ffffffff82661d17>] really_probe.part.0+0xe7/0x380 drivers/base/dd.c:596
    [<ffffffff826620bc>] really_probe drivers/base/dd.c:558 [inline]
    [<ffffffff826620bc>] __driver_probe_device+0x10c/0x1e0 drivers/base/dd.c:751
    [<ffffffff826621ba>] driver_probe_device+0x2a/0x120 drivers/base/dd.c:781
    [<ffffffff82662a26>] __device_attach_driver+0xf6/0x140 drivers/base/dd.c:898
    [<ffffffff8265eca7>] bus_for_each_drv+0xb7/0x100 drivers/base/bus.c:427
    [<ffffffff826625a2>] __device_attach+0x122/0x260 drivers/base/dd.c:969

Reported-by: syzbot+398e7dc692ddbbb4cfec@syzkaller.appspotmail.com
Signed-off-by: Yanfei Xu <yanfei.xu@windriver.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-10-27 09:56:56 +02:00
..
mscc net: phy: mscc: fix macsec key length 2021-07-14 16:56:28 +02:00
adin.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
amd.c
aquantia.h
aquantia_hwmon.c
aquantia_main.c
at803x.c net: phy: at803x: constify static regulator_ops 2020-08-26 16:21:17 -07:00
ax88796b.c
bcm-cygnus.c
bcm-phy-lib.c net: phy: broadcom: Only advertise EEE for supported modes 2021-04-14 08:42:08 +02:00
bcm-phy-lib.h
bcm7xxx.c net: phy: bcm7xxx: Fixed indirect MMD operations 2021-10-06 15:55:58 +02:00
bcm63xx.c
bcm87xx.c
bcm54140.c
bcm84881.c
broadcom.c net: phy: broadcom: Fix RGMII delays for BCM50160 and BCM50610M 2021-03-30 14:32:05 +02:00
cicada.c
cortina.c
davicom.c
dp83tc811.c
dp83640.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-09-04 21:28:59 -07:00
dp83640_reg.h ptp: dp83640: don't define PAGE0 2021-09-22 12:27:56 +02:00
dp83822.c net: phy: Fix data type in DP83822 dp8382x_disable_wol() 2021-09-18 13:40:18 +02:00
dp83848.c
dp83867.c net: phy: dp83867: perform soft reset and retain established link 2021-06-30 08:47:21 -04:00
dp83869.c net: phy: introduce phydev->port 2021-03-30 14:32:05 +02:00
et1011c.c
fixed_phy.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
icplus.c
intel-xway.c net: phy: intel-xway: enable integrated led functions 2021-05-14 09:50:41 +02:00
Kconfig mdio: fix mdio-thunder.c dependency & build error 2020-09-27 13:21:28 -07:00
linkmode.c
lxt.c net: phy: introduce phydev->port 2021-03-30 14:32:05 +02:00
Makefile net: phy: Sort Kconfig and Makefile 2020-08-27 06:55:51 -07:00
marvell.c net: phy: marvell: fix m88e1111_set_downshift 2021-05-14 09:50:42 +02:00
marvell10g.c net: phy: introduce phydev->port 2021-03-30 14:32:05 +02:00
mdio-boardinfo.c
mdio-boardinfo.h
mdio_bus.c net: mdiobus: Fix memory leak in __mdiobus_register 2021-10-27 09:56:56 +02:00
mdio_device.c net: mdio: introduce a shutdown method to mdio device drivers 2021-10-09 14:40:56 +02:00
mdio_devres.c
meson-gxl.c
micrel.c net: phy: micrel: Fix link detection on ksz87xx switch" 2021-08-18 08:59:10 +02:00
microchip.c
microchip_t1.c
mii_timestamper.c
national.c
nxp-tja11xx.c
phy-c45.c
phy-core.c net: phy: Document core PHY structures 2020-09-23 18:02:49 -07:00
phy.c net: phy: introduce phydev->port 2021-03-30 14:32:05 +02:00
phy_device.c net: phy: introduce phydev->port 2021-03-30 14:32:05 +02:00
phy_led_triggers.c
phylink.c net: phylink: Update SFP selected interface on advertising changes 2021-09-30 10:11:05 +02:00
qsemi.c
realtek.c net: phy: realtek: add delay to fix RXC generation issue 2021-07-19 09:44:49 +02:00
rockchip.c
sfp-bus.c net: sfp: relax bitrate-derived mode check 2021-04-16 11:43:22 +02:00
sfp.c net: sfp: Fix typo in state machine debug string 2021-10-13 10:04:27 +02:00
sfp.h
smsc.c net: phy: lan87xx: fix access to wrong register of LAN87xx 2021-05-14 09:50:31 +02:00
spi_ks8995.c net: Use kobj_to_dev() API 2020-09-28 15:14:42 -07:00
ste10Xp.c
swphy.c
swphy.h
teranetics.c
uPD60620.c
vitesse.c
xilinx_gmii2rgmii.c