Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3964990pxb; Mon, 4 Oct 2021 13:53:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQuPacfIuu4o7KdIjmIA2Ilv2zY8t7tV8bWxp1lQ8uk9sCGV4aTDu3+6rziW2LyAz1wkdt X-Received: by 2002:a05:6402:16d8:: with SMTP id r24mr20444860edx.47.1633380784290; Mon, 04 Oct 2021 13:53:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633380784; cv=none; d=google.com; s=arc-20160816; b=VQgNchbqckdRORbiglvld3ICrP+ujTWeLGXPSR9RYsnsn94gAl6EU48qNXdDUw6Kd0 zQTb8OIZSnZDMVf0S/LchDXyzpazOulQYawYx0w++ewzIRL82Ni6hjBF5Ohfi/Xzp5md 4vkrKYkhxy8yYYrtGNazvSWr8Dhy3vuE90GHjlpgbX8X4sTuwp+pmGLEiVzvVoeiwwpT FDZr732t4uvzuZi5VUVGJNZF+mHVOjCnleTOsVvi4gnZGD5kX5G49O7LnuI9C4fGhhs9 xn6GkIJLukvXfoI5gG6G6GcYwwU17bFjHROsMYQ5np/MJk+EF6f+Ge4hgViGtIHytHAF IEvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=X2y/7yf53laDA8A4HXMOs+Q+sl70AwUC94DT5saOTZI=; b=KKcYB0vursGmKLar6SEutBMgEZZEPFuzBEmD3Fj1EWXD4UHw9dYq+4rb/El5rTZBkD nrX5BnFT/J1PAcrtTUHZIXj8f59PHGpVYkmO5hp7dxfh/DtCJf7Vk2RAIRv/WwdGkNwr 1iDdWffSXrEdrLH5+ZVzZAmMG5/byLluk2yMw6id/70vhco0wtnYk30UfJGBRioKyun1 5HtnqbBo7ShKfz3UFUU6/c3wZVaCVVN1lJ1mnTlUW/FN8yAhchipIIQlSkwA7VJYVjxC Xr7ulBGjsbk0JFZIOm6OVjb6sg1JYfSo3gSCuYmehRM/AMHhb9xoriB7p8cP1u7oX+Fm 3ApA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="DdgG/H8R"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c7si21259578ejc.571.2021.10.04.13.52.40; Mon, 04 Oct 2021 13:53:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="DdgG/H8R"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238330AbhJDNpP (ORCPT + 99 others); Mon, 4 Oct 2021 09:45:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:51976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238303AbhJDNmB (ORCPT ); Mon, 4 Oct 2021 09:42:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3CAD061B54; Mon, 4 Oct 2021 13:19:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633353556; bh=2vaWSAwtKFQgoNsEpv8flNrzNeXvQRSpz0z6rQodcuQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DdgG/H8RANSHk2wvVIiLYvyWXJMx+12SjpfNoKMkiHyK8EZL1T8m+GS7Qj9A/T7w8 gSR7gfJ5Hk/Gi+/CGgY0poqM1JhsjJqBC230xWYrcgreK+kvtK/XpuRbNVT25CD+fV vF2cLWevYnDZvFrtPw8U8DDmYxQX4PFg/WcDkPvo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+398e7dc692ddbbb4cfec@syzkaller.appspotmail.com, Yanfei Xu , Andrew Lunn , "David S. Miller" Subject: [PATCH 5.14 168/172] net: mdiobus: Fix memory leak in __mdiobus_register Date: Mon, 4 Oct 2021 14:53:38 +0200 Message-Id: <20211004125050.398226757@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125044.945314266@linuxfoundation.org> References: <20211004125044.945314266@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yanfei Xu commit ab609f25d19858513919369ff3d9a63c02cd9e2e 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: [] kmalloc include/linux/slab.h:591 [inline] [] kzalloc include/linux/slab.h:721 [inline] [] device_private_init drivers/base/core.c:3203 [inline] [] device_add+0x89b/0xdf0 drivers/base/core.c:3253 [] __mdiobus_register+0xc3/0x450 drivers/net/phy/mdio_bus.c:537 [] __devm_mdiobus_register+0x75/0xf0 drivers/net/phy/mdio_devres.c:87 [] ax88772_init_mdio drivers/net/usb/asix_devices.c:676 [inline] [] ax88772_bind+0x330/0x480 drivers/net/usb/asix_devices.c:786 [] usbnet_probe+0x3ff/0xdf0 drivers/net/usb/usbnet.c:1745 [] usb_probe_interface+0x177/0x370 drivers/usb/core/driver.c:396 [] call_driver_probe drivers/base/dd.c:517 [inline] [] really_probe.part.0+0xe7/0x380 drivers/base/dd.c:596 [] really_probe drivers/base/dd.c:558 [inline] [] __driver_probe_device+0x10c/0x1e0 drivers/base/dd.c:751 [] driver_probe_device+0x2a/0x120 drivers/base/dd.c:781 [] __device_attach_driver+0xf6/0x140 drivers/base/dd.c:898 [] bus_for_each_drv+0xb7/0x100 drivers/base/bus.c:427 [] __device_attach+0x122/0x260 drivers/base/dd.c:969 [] bus_probe_device+0xc6/0xe0 drivers/base/bus.c:487 [] device_add+0x5fb/0xdf0 drivers/base/core.c:3359 [] usb_set_configuration+0x9d9/0xb90 drivers/usb/core/message.c:2170 [] 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: [] kstrdup+0x36/0x70 mm/util.c:60 [] kstrdup_const+0x53/0x80 mm/util.c:83 [] kvasprintf_const+0xc2/0x110 lib/kasprintf.c:48 [] kobject_set_name_vargs+0x3b/0xe0 lib/kobject.c:289 [] dev_set_name+0x63/0x90 drivers/base/core.c:3147 [] __mdiobus_register+0xbb/0x450 drivers/net/phy/mdio_bus.c:535 [] __devm_mdiobus_register+0x75/0xf0 drivers/net/phy/mdio_devres.c:87 [] ax88772_init_mdio drivers/net/usb/asix_devices.c:676 [inline] [] ax88772_bind+0x330/0x480 drivers/net/usb/asix_devices.c:786 [] usbnet_probe+0x3ff/0xdf0 drivers/net/usb/usbnet.c:1745 [] usb_probe_interface+0x177/0x370 drivers/usb/core/driver.c:396 [] call_driver_probe drivers/base/dd.c:517 [inline] [] really_probe.part.0+0xe7/0x380 drivers/base/dd.c:596 [] really_probe drivers/base/dd.c:558 [inline] [] __driver_probe_device+0x10c/0x1e0 drivers/base/dd.c:751 [] driver_probe_device+0x2a/0x120 drivers/base/dd.c:781 [] __device_attach_driver+0xf6/0x140 drivers/base/dd.c:898 [] bus_for_each_drv+0xb7/0x100 drivers/base/bus.c:427 [] __device_attach+0x122/0x260 drivers/base/dd.c:969 Reported-by: syzbot+398e7dc692ddbbb4cfec@syzkaller.appspotmail.com Signed-off-by: Yanfei Xu Reviewed-by: Andrew Lunn Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/phy/mdio_bus.c | 1 + 1 file changed, 1 insertion(+) --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -541,6 +541,7 @@ int __mdiobus_register(struct mii_bus *b err = device_register(&bus->dev); if (err) { pr_err("mii_bus %s failed to register\n", bus->id); + put_device(&bus->dev); return -EINVAL; }