Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp3220471pxb; Sun, 26 Sep 2021 08:36:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJys2BeFspTu9vu3fy0uxkB1Xhztub6UrsxrLs1j7D6bNCrnCnrEUtaYacTgVhkW0N7nLbr6 X-Received: by 2002:a05:6402:16c8:: with SMTP id r8mr18043357edx.101.1632670595235; Sun, 26 Sep 2021 08:36:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632670595; cv=none; d=google.com; s=arc-20160816; b=nmrvSf4TzNBqzDzTxJfuZbhkhRRcn0LBgy+k5U8oSrsj/jDFFcWky65s337sXYJFgr sz5kXp/GWTMt0kADigzvgBLkl3avrmRNFy3sXxD9/Y2AVuPDWMPGE6csdtjjJR+G1YC3 l9iRtYkB6a4AdrgdPhsp/to7kVXu/NnIG4PcWK+XNGenHmBEaeTMnNeuxfhkW1K1R/cN GOkOwpE6NWetMRkqKbxlyTRZ8SBnb1Cic8y/TklzNEQo+j8tYx6ddsfHli6WW1Aivw14 6noURLqZtuwBWPUI3XTaZAtg4HHApnN+LzUQBBYLjSZ2tm3wOjnhibpLm6Jj+MwynpXO JSdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=TosYvN8F9XPmP2GdzsLirbdEDXWltKbq+jzLBYNs1uA=; b=APMCCt3604JsEsJQP2GJGOUbe2rmPyYLc6OQEa27SuZZ6gCZtr54TvMcPsmmn/2lCm G7ANyb3BG2HqN0hCQ6zzZimrTaZYO/bjR4t5Q5yyUT7If4mKZ3mU4aefoKyKHymJqgqg cZ4QOSJaPxl9FcMIgpcJxLDLLPvUmuCh+t/xHpSxmEiYlkeXk+EI66cQw/gy6w2mz2tl NeQp1w9Q0N6nFC+b5IX0xtL1scKLLoKXAVGBZ8JuNGgO0dE1gVIP3XG95/aTPkR5YnR1 XKpXMB7j6rQRLuGDd4U8o8Ry0b8o87eGcSiJNIlI/GJC2TVgPcMCzrLWps1bdHHKH3C+ qy3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lunn.ch header.s=20171124 header.b=lgXgaJU+; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 15si16116618ejg.670.2021.09.26.08.36.10; Sun, 26 Sep 2021 08:36:35 -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=@lunn.ch header.s=20171124 header.b=lgXgaJU+; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232013AbhIZPg2 (ORCPT + 99 others); Sun, 26 Sep 2021 11:36:28 -0400 Received: from vps0.lunn.ch ([185.16.172.187]:60994 "EHLO vps0.lunn.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231992AbhIZPg0 (ORCPT ); Sun, 26 Sep 2021 11:36:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lunn.ch; s=20171124; h=In-Reply-To:Content-Disposition:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:From:Sender:Reply-To:Subject: Date:Message-ID:To:Cc:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Content-Disposition:In-Reply-To:References; bh=TosYvN8F9XPmP2GdzsLirbdEDXWltKbq+jzLBYNs1uA=; b=lgXgaJU+NygoIGrLWqijxOM0sL GuI0Bb1HdLDi/QnP2HF0Sxusj8NJZDd4GT21+o8sJSrlH6GGn+Sm91A7DzilAjbs/8VUlhsP+QzP7 daB/Lrp6rLQKIXx+d2Hrln3dxyslJ7lf11LUVljQMpg+mKjKtYjx9qVLFgCf4cqc1ILg=; Received: from andrew by vps0.lunn.ch with local (Exim 4.94.2) (envelope-from ) id 1mUWAq-008KRH-As; Sun, 26 Sep 2021 17:34:40 +0200 Date: Sun, 26 Sep 2021 17:34:40 +0200 From: Andrew Lunn To: Yanfei Xu Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net, kuba@kernel.org, p.zabel@pengutronix.de, syzbot+398e7dc692ddbbb4cfec@syzkaller.appspotmail.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: Re: [PATCH] net: mdiobus: Fix memory leak in __mdiobus_register Message-ID: References: <20210926045313.2267655-1-yanfei.xu@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210926045313.2267655-1-yanfei.xu@windriver.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 26, 2021 at 12:53:13PM +0800, Yanfei Xu wrote: > 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 Andrew