Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1913237rwi; Thu, 20 Oct 2022 19:49:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7igXx0EO1+tNYdpimR7ztTwQ4qoc57ycFUQdvHlERyGokWzhHn9gXKZ85DzjpkIUh3/xtL X-Received: by 2002:a17:903:2307:b0:181:e618:b4c5 with SMTP id d7-20020a170903230700b00181e618b4c5mr16501292plh.172.1666320593713; Thu, 20 Oct 2022 19:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666320593; cv=none; d=google.com; s=arc-20160816; b=aNRXmZwKlFhrbTZV2NdPEMO+yBOK+R0WYSyEFagy94ZYv0DbSgimy1SuqQbWIwxDS3 DVHMGgRgfJNRTBS1HFvZfZlU3qc1q8yu/BtBOBOZweVdwNPcehZrrpYkq02kZYr0RbNc DhZYobxjAhlo99ZFO6t+1tjkl9q83WyenfEH+mNndJ5YotxgYjy1UgOIqTG9xLlAas/i VRq2tslHM6/+tIdlYMP2VrEDrRDVBX6+1fY6IZFpcXr7vQgdwQSub2MI2Z7lSnhHXKKx gdBrFP8fNSGmNNvL3ZLxyxtTtG2lXpkgYJWdTZmL75yIVKIaHgUCUW82taa4uYaSVLgc LpDA== 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; bh=xzMFxLeFKUbQzHCjgeZFy2Z3JsN/mOjM/Yn4m8OkMjM=; b=oLU8G2PuqH9HTfURjujq4IY5D0s2icMR5bEuEv6wmjcebYTNto9GOywIhfEieEJaH4 wRotnZw9Fb4S4SVVctBTyZPcOZgtwtKhIYKgwZCx3gPlwbECnRJJFZ+n15DLGUf9TXOz T0NnqOTkRX04HiLMHTj01u0D85ON9QomevTry81+ReVFBQrRzClE15x/Uxwi4DTKkKHc ubfu3bd9h7sjK2JpRw9z74NkNRN2CVYxC41se1pxt5gNmqBkugztF31fIKyUsgR+Q3M4 Rv+xKW3g18xOjrgENwdhIZiIJZhUt8B5iidLL+rbcliWtWFGkKRfeda9eQibSXoLUT0J hPyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x7-20020a628607000000b0052dccbf4079si21403175pfd.220.2022.10.20.19.49.42; Thu, 20 Oct 2022 19:49:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229719AbiJUCYM (ORCPT + 99 others); Thu, 20 Oct 2022 22:24:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230056AbiJUCXl (ORCPT ); Thu, 20 Oct 2022 22:23:41 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1327204AD0 for ; Thu, 20 Oct 2022 19:23:20 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Mtp6h64dWzVj27; Fri, 21 Oct 2022 10:18:36 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:45 +0800 Received: from huawei.com (10.175.103.91) by dggpemm500007.china.huawei.com (7.185.36.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Fri, 21 Oct 2022 10:22:44 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 09/11] ocfs2: possible memory leak in mlog_sys_init() Date: Fri, 21 Oct 2022 10:21:00 +0800 Message-ID: <20221021022102.2231464-10-yangyingliang@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221021022102.2231464-1-yangyingliang@huawei.com> References: <20221021022102.2231464-1-yangyingliang@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500007.china.huawei.com (7.185.36.183) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Inject fault while loading module, kset_register() may fail, if it fails, but the refcount of kobject is not decreased to 0, the name allocated in kobject_set_name() is leaked. Fix this by calling kset_put(), so that name can be freed in callback function kobject_cleanup(). unreferenced object 0xffff888100da9348 (size 8): comm "modprobe", pid 257, jiffies 4294701096 (age 33.334s) hex dump (first 8 bytes): 6c 6f 67 6d 61 73 6b 00 logmask. backtrace: [<00000000306e441c>] __kmalloc_node_track_caller+0x44/0x1b0 [<000000007c491a9e>] kstrdup+0x3a/0x70 [<0000000015719a3b>] kstrdup_const+0x63/0x80 [<0000000084e458ea>] kvasprintf_const+0x149/0x180 [<0000000091302b42>] kobject_set_name_vargs+0x56/0x150 [<000000005f48eeac>] kobject_set_name+0xab/0xe0 Fixes: 34980ca8faeb ("Drivers: clean up direct setting of the name of a kset") Signed-off-by: Yang Yingliang --- fs/ocfs2/cluster/masklog.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/cluster/masklog.c b/fs/ocfs2/cluster/masklog.c index 563881ddbf00..7f9ba816d955 100644 --- a/fs/ocfs2/cluster/masklog.c +++ b/fs/ocfs2/cluster/masklog.c @@ -156,6 +156,7 @@ static struct kset mlog_kset = { int mlog_sys_init(struct kset *o2cb_kset) { int i = 0; + int ret; while (mlog_attrs[i].attr.mode) { mlog_default_attrs[i] = &mlog_attrs[i].attr; @@ -165,7 +166,11 @@ int mlog_sys_init(struct kset *o2cb_kset) kobject_set_name(&mlog_kset.kobj, "logmask"); mlog_kset.kobj.kset = o2cb_kset; - return kset_register(&mlog_kset); + ret = kset_register(&mlog_kset); + if (ret) + kset_put(&mlog_kset); + + return ret; } void mlog_sys_shutdown(void) -- 2.25.1