From patchwork Fri Oct 21 02:20:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Yingliang X-Patchwork-Id: 6481 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp437807wrr; Thu, 20 Oct 2022 19:25:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM41jKXgtYfulq+/QTa97F0FH+KvW76o59QRzPbKzlmD6z3u58XNVx+4DjPFGZafesGaxNmX X-Received: by 2002:a17:90b:17cf:b0:20d:b274:6f50 with SMTP id me15-20020a17090b17cf00b0020db2746f50mr45565118pjb.231.1666319134652; Thu, 20 Oct 2022 19:25:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666319134; cv=none; d=google.com; s=arc-20160816; b=p0D5+tAvmpML+eazVmS2UgMBNlq4gH1GfdSZ89Dx30RscOihrEy8ZLEhJsLLGUQVk/ r/Iqi4qpcE37adrnp+hupx8CcjhE93hKLwhYDldmQwJCvU7fyBhHpKR6AtyKJTrbJPN4 g/IkytBmMIHhtQ2aFV4zhntBfCizHWqWjWDNv98Eayhysh3/kEVoOUb1VQJgw+E7jft2 gYo2riM+NHSxbvBsc9AvsYN5bhgXAAEsyFhncSrusfBXtde67T22JjSUtQmQJWXEiLbl cn+u+hjOpXCozyyoquIjwotR65tJzzGNUI9G8wA9/kEorL4o0NMMYkwxuoxSFY6/MUk5 M3Pg== 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=anE6kFKk4KL8osB9HOW0knNDcuVxgwcI8Ym8jD8Lx2Y=; b=aC/kAERt4ojV7x9cPXDxILiVImC47qbNy4QRU/Eq1afYireoygLqo7Co3H1tIT9YBH hHfrWgOgzDc5cBilVzzJpDCOHz/7BRYst9U8xizzFl1CGXJOAkoKMiZs4htsdimIaqwf ihRCbALD4YkaaK/MvoXHcSDjXduLpjjNYiCCdN84GFrWLzHE+t9JsbHAAXyUf7AhVu3d 73baCpBwkbLesBBRuCe4Mv0aOOlZ3VUO25bMjbDpPnCowTqTqC1FDDRFnRYIognnKuKw P3BlkT1tHVsJqUpugIYr/9ARyYtijTL3mCemh349fJxQFqEqvYlhjxKYUX5yzB9Qn2WG kSCQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l4-20020a17090a660400b00202c7f4631esi5407535pjj.19.2022.10.20.19.25.21; Thu, 20 Oct 2022 19:25:34 -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 S230039AbiJUCXX (ORCPT + 99 others); Thu, 20 Oct 2022 22:23:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbiJUCWz (ORCPT ); Thu, 20 Oct 2022 22:22:55 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EE54232E4F for ; Thu, 20 Oct 2022 19:22:50 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MtpCN18FmzHvCF; Fri, 21 Oct 2022 10:22:40 +0800 (CST) Received: from dggpemm500007.china.huawei.com (7.185.36.183) by dggpemm500022.china.huawei.com (7.185.36.162) 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 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:43 +0800 From: Yang Yingliang To: , , , , , , CC: , , , , , , , , , , , , , , , Subject: [PATCH 08/11] erofs: fix possible memory leak in erofs_init_sysfs() Date: Fri, 21 Oct 2022 10:20:59 +0800 Message-ID: <20221021022102.2231464-9-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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747262252690959766?= X-GMAIL-MSGID: =?utf-8?q?1747262252690959766?= 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 0xffff888101d228c0 (size 8): comm "modprobe", pid 276, jiffies 4294722700 (age 13.151s) hex dump (first 8 bytes): 65 72 6f 66 73 00 ff ff erofs... backtrace: [<00000000e2a9a4a6>] __kmalloc_node_track_caller+0x44/0x1b0 [<00000000b8ce02de>] kstrdup+0x3a/0x70 [<000000004a0e01d2>] kstrdup_const+0x63/0x80 [<00000000051b6cda>] kvasprintf_const+0x149/0x180 [<000000004dc51dad>] kobject_set_name_vargs+0x56/0x150 [<00000000b30f0bad>] kobject_set_name+0xab/0xe0 Fixes: 168e9a76200c ("erofs: add sysfs interface") Signed-off-by: Yang Yingliang --- fs/erofs/sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c index 783bb7b21b51..653b35001bc5 100644 --- a/fs/erofs/sysfs.c +++ b/fs/erofs/sysfs.c @@ -254,8 +254,10 @@ int __init erofs_init_sysfs(void) kobject_set_name(&erofs_root.kobj, "erofs"); erofs_root.kobj.parent = fs_kobj; ret = kset_register(&erofs_root); - if (ret) + if (ret) { + kset_put(&erofs_root); goto root_err; + } ret = kobject_init_and_add(&erofs_feat, &erofs_feat_ktype, NULL, "features");