Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3383587pxb; Mon, 17 Jan 2022 19:12:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJzSHc4DjWmbRL0aIky/y2wg7YOLDgoRwe/sBst2ydxvrQ9zHfSGG1G1CyPruSoq5D7NNBik X-Received: by 2002:a17:902:c102:b0:14a:8fda:e31f with SMTP id 2-20020a170902c10200b0014a8fdae31fmr18046262pli.108.1642475564358; Mon, 17 Jan 2022 19:12:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642475564; cv=none; d=google.com; s=arc-20160816; b=csPOZS0s1bnUJReklLgW1CrG4kLpZeBhPj2llBcBL1Bxef4ELALel/+HCjQpekoXNT Hft81p/arTCI5A7ZulCup9AELVkqxUFXxcQMyPjDWS4/2vZxdAyNfZXd7RciDI0Gjmc4 h8F/6A4nXpmXvywN8hDxCjaNE5QLb5JxY+bkImtKbhVbr4CwDBfwcXbqkcCQjZsQUYUQ GI+c0TaD2LyWoKNMnxZ0k4uh+NmKgIstIH0eTPYvj8C56H35jjihNsoOtZE76h/wac52 ObIQvJIwgKpvvPWPO9//X8ikgdVao/g/CS9h5cFU6ObzdCS6th8/gAmIQUlCYA6LKV9w Zv4w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=c8HQzlUK77tzrH3KfFLegELFu7/liimbJlqXkYp8RxE=; b=EPwHvN++LIIRsNm9TeeYkMTPr5/9maNa6t6jgQkkn3fFgjE8rDYgp+X8YSARPsH9DS 9bpcn3cq3DWuqm9voCu75zInhofWfNtH1FhEuDShvscLrcvDnbYAIc4ufDrZtXuM6+JI udDiEKnqZLa0pIIvkrH42o3lggCk/ufbNakizVa5jswnZy5ZF2YkjX7p0Gxc0G35qXCm LFn5y1q7/Dz1nzftUEnbJIy3plWWo73tCKUtsjtfeRLQXZUVdbE2LnyHC5z8X2Edmz/B LdoXMf7aHxMBG4foanOvK3GtMiIhCDNsy9QF9vT3ktkgws/D0P1LnhZRFeVKXjfj6Xzt LMyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=euTA7ZLX; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j8si14428983plx.362.2022.01.17.19.12.32; Mon, 17 Jan 2022 19:12:44 -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=@kernel.org header.s=k20201202 header.b=euTA7ZLX; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244419AbiARCT7 (ORCPT + 99 others); Mon, 17 Jan 2022 21:19:59 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:34726 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244332AbiARCTt (ORCPT ); Mon, 17 Jan 2022 21:19:49 -0500 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 EFA35B81232; Tue, 18 Jan 2022 02:19:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85D1CC36AEB; Tue, 18 Jan 2022 02:19:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642472386; bh=KgD6qxy+fP2fvSM/3e8PrWESYFntT/ISgWQqCE2FJS0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=euTA7ZLXr90l4pYuM6om2n6/wA6o8gZwVBPCYxn5Pig7zwTssCS6FH2UyIqRyDP2Q CF0KkH1aj287tLfn/Bmetp8uirul43gbc45Go7DTIpPUTqn2u0IJE0M52HTUAHp/R+ zL8RfQERrH+WWQgbxwHReO3ZY1Tn4OFi39KeMdcDF5P2htDAUJgZoillcqxPh8GOYv W+eGuKBukIY8oBTCJFsn/a0dGgaNfyFtJ/1udGLVB96P7tpLE4GIfBrtLIU/8i8qk2 EdKhoZwLzNPs1a0zqP/hRX1CZl8QVvKoQ/TvRfTdNIXHKI0tuC1ktL/BGVvW9+hleS cUywCW/hDkkfQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Wei Yongjun , Marcel Holtmann , Sasha Levin , johan.hedberg@gmail.com, luiz.dentz@gmail.com, davem@davemloft.net, kuba@kernel.org, linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH AUTOSEL 5.16 003/217] Bluetooth: Fix memory leak of hci device Date: Mon, 17 Jan 2022 21:16:06 -0500 Message-Id: <20220118021940.1942199-3-sashal@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220118021940.1942199-1-sashal@kernel.org> References: <20220118021940.1942199-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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