Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp662110pxb; Mon, 25 Oct 2021 16:07:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAcWgtHffewptqGQPsh6QqVkoyeh7BGyfpqg6CqQwkfnSYbGRx+CrWSpBl7GIZbcj/622A X-Received: by 2002:a17:902:e848:b0:13e:f908:155a with SMTP id t8-20020a170902e84800b0013ef908155amr19208122plg.13.1635203243299; Mon, 25 Oct 2021 16:07:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635203243; cv=none; d=google.com; s=arc-20160816; b=AHu6n3PiMHoH1GE7G0BFca08CNKhfANDPdh5IBFQWfEoHNR5tIbfrncucCtXAj7qOR F0vYfL/3GPo2LzJmZh3aYxZYpJFP2yUKQpNP/4Nm8mix0Tgo/LgrkmHbalmZ3bemV/SA LHX6QUU1FIPNlTWx2dgnmeLvJ4Mm5Om1WN7sduUgUSFNe0emdQN9VixlMnp0HA3tv/cb 0StrgVGS6E67D5iQMfmH8d96USh33G3tdPkvuklccjvPD0lZWhf+NxlKNNZX29ClfJyH z8pXZsVsKNSb0Pdydu1IfM7KCOx4JN5OWa1P6ppPk5z+chg/QD0vz94nm5QAs7qoWoGf U81g== 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=iDEUet+MQa8fHAS8hU8+svHYnva0yIPpqRd1UHFp1Ak=; b=Pb62ENcVRbrBw143NI4YMFH9Wj9Rzm98HgreRLamWdcx/vL5YgW+xNMbAkd2NtOIn4 BzDgnpysYnr0TqCKgtSSoMKjyoxzyLrnOkiwJhlbMd/fuJ1wYa+d3bac0Z5/HVx4oxNr mwqaTyqf1QlLUNqIVvcNJCNXhn+8fw4iTVzMBJiWYCuuFntZrxCMj+O1THS018gRfJns Vq7kBpr3/tgFVXpey25J0fZsWzshIpuRIQkEPVJs6Wf7Sh07sNhKLQ1woiwcXWkqeUHT kSgaFVn7RjAry5ulvQrPhVxR7aVCuM/BQWBLuKYubO6mLLVEIaNoRg94Fl6bUrxmFi5Y 5OVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=xrRdoHLF; 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 e2si16244479plj.444.2021.10.25.16.07.08; Mon, 25 Oct 2021 16:07:23 -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=xrRdoHLF; 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 S234445AbhJYTUh (ORCPT + 99 others); Mon, 25 Oct 2021 15:20:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:36450 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234401AbhJYTTo (ORCPT ); Mon, 25 Oct 2021 15:19:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 854D9600D3; Mon, 25 Oct 2021 19:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635189442; bh=UX29GVLgTUqkqPqEQzyeMXZlua06QZfF+U2bnA6lMs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xrRdoHLFT6BCf1kntKxKiPfJ2z3cpgVcPoyMThxopUG9EOvySXfLrU6jnGZ8eyKX0 6wa0Kh3yGY404TrI7NCny4vnagvV58FheyfmTeLOn1Cu+NqvKWJoxrrH6Q7/HbhfwG 8vJ9zwV0NtNjDxEtMtaxv2zbpEarjx5kq1rw+dGk= 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.4 42/44] net: mdiobus: Fix memory leak in __mdiobus_register Date: Mon, 25 Oct 2021 21:14:23 +0200 Message-Id: <20211025190937.096515633@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211025190928.054676643@linuxfoundation.org> References: <20211025190928.054676643@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 @@ -274,6 +274,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; }