Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3669354pxb; Mon, 24 Jan 2022 14:57:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwGM4tMJ2FYAU3c9GOzh9fKOYQTI18mOGvVK5fDSNhjl1o6yKZNAt7/i5ANs16D6/NlSSct X-Received: by 2002:a63:4e58:: with SMTP id o24mr13123524pgl.525.1643065050919; Mon, 24 Jan 2022 14:57:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643065050; cv=none; d=google.com; s=arc-20160816; b=t9+uRR/YUeti2NWE8a+XNgZNGCNPekx+diqUv5E1zISnAGZJqX1DQMfy5cx3lgLpUB ldKoDRcXUumN9lXmILf+qnHMrBRu+wiDfSfd3etjW0aY3ClyaJLMwHMJAXPYp5KDJP+g KRzd84Ajp3gvvlUG+tVrgzOZoZSgVDPHUEeH3O0L61iDKOLlxajSFkQgaCUKihk//c4C GmNSWMP7Y9kWdo/lUfPOhDMvT/IOQix3EtkgadyAW+v6NdIHo2mGc+W4cmLRFQJIpLe5 SVTxtsj2l1/uHWgKP/2GwiHa8kzVh5ro4kaQWTRI7uy/xPQcyRUsUWIoWRFN0pl5iccC 5Eag== 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=c8HQzlUK77tzrH3KfFLegELFu7/liimbJlqXkYp8RxE=; b=jcpLLF0t0ods31+o/VDbKfZ6H0OBZO9nOiK7dJQYn8+x3Ajth5tllcehvqOyV7E7xk xw/PQ2c51+lbDHHp+Vj48C02DhqhPBNrzYhE8PLZz4EJoOzX20ADVeyJ6AFJICLeTz4u UTTkIXnlJzVeI/xUtml45SBBkjcS5uqLlmw3qfi2q438pOUn19wXuOQ1sfL7B2ksDvl4 iIf08Cy7bUU9jt5u/HVIiaBS+s/C0PLk6vzlN/awiMtJlWX+m/ZDi71pLJqgkhn/GXNa 4SYLaLlVMy1VEQjilEyLQ55ds+TH7dLDkwGXeZDIa8kVJIvMkkwvGLR1X6D2pUQcPQGY Sk4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EXpw256D; 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 ju17si519007pjb.151.2022.01.24.14.57.19; Mon, 24 Jan 2022 14:57:30 -0800 (PST) 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=EXpw256D; 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 S1840440AbiAXWx2 (ORCPT + 99 others); Mon, 24 Jan 2022 17:53:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1573983AbiAXVrD (ORCPT ); Mon, 24 Jan 2022 16:47:03 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF0CFC081184; Mon, 24 Jan 2022 12:32:48 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B62FBB815A6; Mon, 24 Jan 2022 20:32:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DDE03C340E5; Mon, 24 Jan 2022 20:32:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056366; bh=KgD6qxy+fP2fvSM/3e8PrWESYFntT/ISgWQqCE2FJS0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EXpw256DssrdG8k1A80cNhpForiHdvH5hC73+omf0cmqw+fkxpzJId9QGKWKxWJi8 6LSO44n/hCQHzBe5GbUUxPSpQGdembr6I37BgeFC4WhB3C8PZQhKR85hGrFHpYZrvy 3sNEAHpY0ptGlqTiJSY2A6mfJfED33SyZgN77R2Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wei Yongjun , Marcel Holtmann , Sasha Levin Subject: [PATCH 5.15 460/846] Bluetooth: Fix memory leak of hci device Date: Mon, 24 Jan 2022 19:39:37 +0100 Message-Id: <20220124184116.850102578@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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: Wei Yongjun [ Upstream commit 75d9b8559ac36e059238ee4f8e33cd86086586ba ] Fault injection test reported memory leak of hci device as follows: unreferenced object 0xffff88800b858000 (size 8192): comm "kworker/0:2", pid 167, jiffies 4294955747 (age 557.148s) hex dump (first 32 bytes): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ 00 00 00 00 00 00 00 00 00 00 00 00 ad 4e ad de .............N.. backtrace: [<0000000070eb1059>] kmem_cache_alloc_trace mm/slub.c:3208 [<00000000015eb521>] hci_alloc_dev_priv include/linux/slab.h:591 [<00000000dcfc1e21>] bpa10x_probe include/net/bluetooth/hci_core.h:1240 [<000000005d3028c7>] usb_probe_interface drivers/usb/core/driver.c:397 [<00000000cbac9243>] really_probe drivers/base/dd.c:517 [<0000000024cab3f0>] __driver_probe_device drivers/base/dd.c:751 [<00000000202135cb>] driver_probe_device drivers/base/dd.c:782 [<000000000761f2bc>] __device_attach_driver drivers/base/dd.c:899 [<00000000f7d63134>] bus_for_each_drv drivers/base/bus.c:427 [<00000000c9551f0b>] __device_attach drivers/base/dd.c:971 [<000000007f79bd16>] bus_probe_device drivers/base/bus.c:487 [<000000007bb8b95a>] device_add drivers/base/core.c:3364 [<000000009564d9ea>] usb_set_configuration drivers/usb/core/message.c:2171 [<00000000e4657087>] usb_generic_driver_probe drivers/usb/core/generic.c:239 [<0000000071ede518>] usb_probe_device drivers/usb/core/driver.c:294 [<00000000cbac9243>] really_probe drivers/base/dd.c:517 hci_alloc_dev() do not init the device's flag. And hci_free_dev() using put_device() to free the memory allocated for this device, but it calls just put_device(dev) only in case of HCI_UNREGISTER flag is set, So any error handing before hci_register_dev() success will cause memory leak. To avoid this behaviour we can using kfree() to release dev before hci_register_dev() success. Signed-off-by: Wei Yongjun Signed-off-by: Marcel Holtmann Signed-off-by: Sasha Levin --- net/bluetooth/hci_sysfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c index 7827639ecf5c3..4e3e0451b08c1 100644 --- a/net/bluetooth/hci_sysfs.c +++ b/net/bluetooth/hci_sysfs.c @@ -86,6 +86,8 @@ static void bt_host_release(struct device *dev) if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) hci_release_dev(hdev); + else + kfree(hdev); module_put(THIS_MODULE); } -- 2.34.1