From patchwork Wed Nov 9 08:58:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen Zhongjin X-Patchwork-Id: 623414 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A938C4332F for ; Wed, 9 Nov 2022 09:01:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230194AbiKIJB4 (ORCPT ); Wed, 9 Nov 2022 04:01:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230228AbiKIJBw (ORCPT ); Wed, 9 Nov 2022 04:01:52 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52D72192A8; Wed, 9 Nov 2022 01:01:51 -0800 (PST) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N6f4w1rlBzpWCG; Wed, 9 Nov 2022 16:58:08 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 17:01:48 +0800 Received: from ubuntu1804.huawei.com (10.67.175.36) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 9 Nov 2022 17:01:48 +0800 From: Chen Zhongjin To: , , CC: , , , , , , , , Subject: [PATCH] Bluetooth: selftest: Fix memleak in test_ecdh() Date: Wed, 9 Nov 2022 16:58:35 +0800 Message-ID: <20221109085835.213252-1-chenzhongjin@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.175.36] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org kmemleak reported: Bluetooth: ECDH sample 1 failed kmemleak: 2 new suspected memory leaks (see /sys/kernel/debug/kmemleak) unreferenced object 0xffff888102149100 (size 96): comm "modprobe", pid 418, jiffies 4295082093 (age 610.644s) ... backtrace: [<00000000c8e4e5a6>] __kmalloc_node+0x4c/0x1c0 [<000000006cdcfddc>] crypto_create_tfm_node+0x89/0x320 [<00000000e222ad46>] crypto_alloc_tfm_node+0xfd/0x2f0 [<00000000871fc045>] 0xffffffffc05c94ab [<00000000e889f45e>] 0xffffffffc05c8024 [<000000001ff0c346>] do_one_initcall+0xd0/0x4e0 ... In test_ecdh(), when test sample fails, crypto_free_kpp(tfm) is not called, which makes tfm memory leaked. Fix it by moving crypto_free_kpp behind done label. Fixes: 47eb2ac80918 ("Bluetooth: move ecdh allocation outside of ecdh_helper") Signed-off-by: Chen Zhongjin --- net/bluetooth/selftest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/selftest.c b/net/bluetooth/selftest.c index f49604d44b87..586125a611dd 100644 --- a/net/bluetooth/selftest.c +++ b/net/bluetooth/selftest.c @@ -233,8 +233,6 @@ static int __init test_ecdh(void) goto done; } - crypto_free_kpp(tfm); - rettime = ktime_get(); delta = ktime_sub(rettime, calltime); duration = (unsigned long long) ktime_to_ns(delta) >> 10; @@ -248,6 +246,8 @@ static int __init test_ecdh(void) else snprintf(test_ecdh_buffer, sizeof(test_ecdh_buffer), "FAIL\n"); + crypto_free_kpp(tfm); + debugfs_create_file("selftest_ecdh", 0444, bt_debugfs, NULL, &test_ecdh_fops);