Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3923274pxb; Mon, 4 Oct 2021 12:44:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7kjh4+D7+Y/NQXeadcpRTTr9xnbjvkvMbq2fkMGx57yhehDccfRgsz9sj3nJJnFTpiuVA X-Received: by 2002:a17:906:4c8c:: with SMTP id q12mr19330540eju.254.1633376688808; Mon, 04 Oct 2021 12:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633376688; cv=none; d=google.com; s=arc-20160816; b=OmPZOLS2b/wjIpKahTm3hc/PDpVrmJzqjPNUha7Y/xkq5KQxKT/+DImPe27dpntHt/ HRgjs7kdWJU9G6QYyig8lCINWckRqYyMub4IZTs5uE6f6VEB8uBhQXf/8WZy5R5wxOMB DVFSH7lOXcf/Exk8mIFo0oF7gfniVieN+4Mfh5VtLUts982HlTPEzdjVULL3pY8U9ayF v0Qg7Jp5bishh30m9wTLIWlkMXd89R9f2xPC6MxFoDLu1KUbP3f8JldJi7gkfaEnUtmf lWotjgn+WQBkgJCcJdMKCjSPHAVuYcvewL/qgNKDnfcm6TlW/7/p6zjyX3QLUM9xTe8m r78g== 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=LtAo+r4lOlmS6yS2HJ4a3V9JvvmQdsDVhbGCEeQpJJA=; b=he2EE01oZwKZcJ92de4aoiAPks38/YMdVvu54qyXMaI/q0RgmjVfa2Rt2MAFkyV6mi NUNet+e2aDjLc87hq+S/nJ+6I9ytg33QfMfyIXuPcqU/KjWmwMuQX6ek7XISRV4q0f0x H7Hq1fdc8gpoWtTZUNQfcbdsSA7fR+X5Th23JMHa61UFHcFFfCPyMnlyE7HYLJnQVa8A vhbL5rLeO9gfbmdYhRrjvDJRmWBRlMjh9RMwZuFF/VxMV3+wGdhGVywbzTiqdBvbFTla VJ4iJkOUlcmnCfCWfLIG3FPNP5GCy9RibRiFvSAvBthCCZdPeR0pNehxjVw2IHwNNvhh Ct/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=IpyxLNRN; 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 16si17450244ejf.565.2021.10.04.12.44.24; Mon, 04 Oct 2021 12:44:48 -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=IpyxLNRN; 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 S235395AbhJDNQG (ORCPT + 99 others); Mon, 4 Oct 2021 09:16:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:53702 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235600AbhJDNOK (ORCPT ); Mon, 4 Oct 2021 09:14:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DA6BE619E9; Mon, 4 Oct 2021 13:05:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633352739; bh=cEi2Zz9fecudZ3IftRcBMYyRKog8MuWhtFtLwqNd6Dw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IpyxLNRNprhg55XlkxafplC95+jAXwMod93ZIm5sfiYgh5sge61nTcWVsOusT6wKO BL8HObDsHdHOldgjOI3dH6qRWxPtsdZY0UWKKutWuJFZKSvNEn6MHAlKAcYN55Eh/Q dL9Ph/yJO8o2cC3beyN1W/NxkuMLH9FsCFo7mIro= 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 4.19 95/95] net: mdiobus: Fix memory leak in __mdiobus_register Date: Mon, 4 Oct 2021 14:53:05 +0200 Message-Id: <20211004125036.677573066@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125033.572932188@linuxfoundation.org> References: <20211004125033.572932188@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 @@ -381,6 +381,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; }