From patchwork Tue Aug 2 02:15:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Guanghao X-Patchwork-Id: 12934204 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 42736C00144 for ; Tue, 2 Aug 2022 02:15:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233923AbiHBCPc (ORCPT ); Mon, 1 Aug 2022 22:15:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231374AbiHBCPb (ORCPT ); Mon, 1 Aug 2022 22:15:31 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1E661CB1D for ; Mon, 1 Aug 2022 19:15:30 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Lxdmv5hDszlVmZ; Tue, 2 Aug 2022 10:12:47 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 2 Aug 2022 10:15:28 +0800 Received: from [10.174.177.211] (10.174.177.211) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 2 Aug 2022 10:15:28 +0800 Message-ID: <19e8b467-a786-f42d-f07e-dfacae4f57c9@huawei.com> Date: Tue, 2 Aug 2022 10:15:28 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.0.3 Subject: [PATCH 1/5 v2] parse_layout_faulty: fix memleak From: Wu Guanghao To: Jes Sorensen , , Mariusz Tkaczyk CC: linfeilong , References: <11b7eff6-56a0-49ee-b2fd-50b402c3dde1@huawei.com> In-Reply-To: <11b7eff6-56a0-49ee-b2fd-50b402c3dde1@huawei.com> X-Originating-IP: [10.174.177.211] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org char *m is allocated by xstrdup but not free() before return, will cause a memory leak Signed-off-by: Wu Guanghao Acked-by: Mariusz Tkaczyk Acked-by: Coly Li --- util.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.27.0 diff --git a/util.c b/util.c index 38f0420e..2e0f1de7 100644 --- a/util.c +++ b/util.c @@ -427,8 +427,11 @@ int parse_layout_faulty(char *layout) int ln = strcspn(layout, "0123456789"); char *m = xstrdup(layout); int mode; + m[ln] = 0; mode = map_name(faultylayout, m); + free(m); + if (mode == UnSet) return -1; From patchwork Tue Aug 2 02:15:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Guanghao X-Patchwork-Id: 12934205 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 73F5BC00144 for ; Tue, 2 Aug 2022 02:15:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235630AbiHBCPy (ORCPT ); Mon, 1 Aug 2022 22:15:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235563AbiHBCPx (ORCPT ); Mon, 1 Aug 2022 22:15:53 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACBCB43E65 for ; Mon, 1 Aug 2022 19:15:52 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Lxdmy1jXDz1M8NT; Tue, 2 Aug 2022 10:12:50 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) 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.24; Tue, 2 Aug 2022 10:15:50 +0800 Received: from [10.174.177.211] (10.174.177.211) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 2 Aug 2022 10:15:50 +0800 Message-ID: <32551992-ff6d-3d42-51dd-54e0a69e0cfd@huawei.com> Date: Tue, 2 Aug 2022 10:15:50 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.0.3 Subject: [PATCH 2/5 v2] Detail: fix memleak From: Wu Guanghao To: Jes Sorensen , , Mariusz Tkaczyk CC: linfeilong , References: <11b7eff6-56a0-49ee-b2fd-50b402c3dde1@huawei.com> In-Reply-To: <11b7eff6-56a0-49ee-b2fd-50b402c3dde1@huawei.com> X-Originating-IP: [10.174.177.211] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org char *sysdev = xstrdup() but not free() in for loop, will cause memory leak Signed-off-by: Wu Guanghao Acked-by: Mariusz Tkaczyk Acked-by: Coly Li --- Detail.c | 1 + 1 file changed, 1 insertion(+) -- 2.27.0 diff --git a/Detail.c b/Detail.c index ce7a8445..4ef26460 100644 --- a/Detail.c +++ b/Detail.c @@ -303,6 +303,7 @@ int Detail(char *dev, struct context *c) if (path) printf("MD_DEVICE_%s_DEV=%s\n", sysdev, path); + free(sysdev); } } goto out; From patchwork Tue Aug 2 02:16:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Guanghao X-Patchwork-Id: 12934206 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 DC458C19F2A for ; Tue, 2 Aug 2022 02:16:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235658AbiHBCQT (ORCPT ); Mon, 1 Aug 2022 22:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231986AbiHBCQR (ORCPT ); Mon, 1 Aug 2022 22:16:17 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 278A443E65 for ; Mon, 1 Aug 2022 19:16:17 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4LxdqR0G1czGpKD; Tue, 2 Aug 2022 10:14:59 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 2 Aug 2022 10:16:15 +0800 Received: from [10.174.177.211] (10.174.177.211) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 2 Aug 2022 10:16:14 +0800 Message-ID: <2b2cdeac-d052-bd11-a3d6-d82d9b3fe10e@huawei.com> Date: Tue, 2 Aug 2022 10:16:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.0.3 Subject: [PATCH 3/5 v2] load_imsm_mpb: fix double free From: Wu Guanghao To: Jes Sorensen , , Mariusz Tkaczyk CC: linfeilong , References: <11b7eff6-56a0-49ee-b2fd-50b402c3dde1@huawei.com> In-Reply-To: <11b7eff6-56a0-49ee-b2fd-50b402c3dde1@huawei.com> X-Originating-IP: [10.174.177.211] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org When free(super->buf) but not set super->buf = NULL, will be double free get_super_block err = load_and_parse_mpb load_imsm_mpb(.., s, ..) if (posix_memalign(&super->buf, MAX_SECTOR_SIZE, super->len) != 0) // true, super->buf != NULL if (posix_memalign(&super->migr_rec_buf, MAX_SECTOR_SIZE,); // false free(super->buf); //but super->buf not set NULL return 2; if err ! = 0 if (s) free_imsm(s) __free_imsm(s) if (s) free(s->buf); //double free Signed-off-by: Wu Guanghao Reviewed-by: Mariusz Tkaczyk Acked-by: Coly Li --- super-intel.c | 1 + 1 file changed, 1 insertion(+) -- 2.27.0 diff --git a/super-intel.c b/super-intel.c index 4ddfcf94..ddbdd3e1 100644 --- a/super-intel.c +++ b/super-intel.c @@ -4510,6 +4510,7 @@ static int load_imsm_mpb(int fd, struct intel_super *super, char *devname) MIGR_REC_BUF_SECTORS*MAX_SECTOR_SIZE) != 0) { pr_err("could not allocate migr_rec buffer\n"); free(super->buf); + super->buf = NULL; return 2; } super->clean_migration_record_by_mdmon = 0; From patchwork Tue Aug 2 02:16:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Guanghao X-Patchwork-Id: 12934207 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 D1E6BC00144 for ; Tue, 2 Aug 2022 02:16:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235372AbiHBCQn (ORCPT ); Mon, 1 Aug 2022 22:16:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231986AbiHBCQm (ORCPT ); Mon, 1 Aug 2022 22:16:42 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06DCB43E6B for ; Mon, 1 Aug 2022 19:16:42 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Lxdqw11f2zGpKT; Tue, 2 Aug 2022 10:15:24 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 2 Aug 2022 10:16:40 +0800 Received: from [10.174.177.211] (10.174.177.211) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 2 Aug 2022 10:16:40 +0800 Message-ID: Date: Tue, 2 Aug 2022 10:16:39 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.0.3 Subject: [PATCH 4/5 v2] find_disk_attached_hba: fix memleak From: Wu Guanghao To: Jes Sorensen , , Mariusz Tkaczyk CC: linfeilong , References: <11b7eff6-56a0-49ee-b2fd-50b402c3dde1@huawei.com> In-Reply-To: <11b7eff6-56a0-49ee-b2fd-50b402c3dde1@huawei.com> X-Originating-IP: [10.174.177.211] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org If disk_path = diskfd_to_devpath(), we need free(disk_path) before return, otherwise there will be a memory leak Signed-off-by: Wu Guanghao Reviewed-by: Mariusz Tkaczyk Acked-by: Coly Li --- super-intel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.27.0 diff --git a/super-intel.c b/super-intel.c index ddbdd3e1..2a4019e7 100644 --- a/super-intel.c +++ b/super-intel.c @@ -713,12 +713,12 @@ static struct sys_dev* find_disk_attached_hba(int fd, const char *devname) for (elem = list; elem; elem = elem->next) if (path_attached_to_hba(disk_path, elem->path)) - return elem; + break; if (disk_path != devname) free(disk_path); - return NULL; + return elem; } static int find_intel_hba_capability(int fd, struct intel_super *super, From patchwork Tue Aug 2 02:17:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Guanghao X-Patchwork-Id: 12934208 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 24232C00144 for ; Tue, 2 Aug 2022 02:17:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235496AbiHBCRR (ORCPT ); Mon, 1 Aug 2022 22:17:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231986AbiHBCRP (ORCPT ); Mon, 1 Aug 2022 22:17:15 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B14E243E6F for ; Mon, 1 Aug 2022 19:17:14 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Lxdpv3BkZzlVmX; Tue, 2 Aug 2022 10:14:31 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) 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.24; Tue, 2 Aug 2022 10:17:12 +0800 Received: from [10.174.177.211] (10.174.177.211) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 2 Aug 2022 10:17:12 +0800 Message-ID: <62b32172-f3b5-8c32-0a74-77e8b18927d1@huawei.com> Date: Tue, 2 Aug 2022 10:17:11 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.0.3 Subject: [PATCH 5/5 v2] get_vd_num_of_subarray: fix memleak From: Wu Guanghao To: Jes Sorensen , , Mariusz Tkaczyk CC: linfeilong , References: <11b7eff6-56a0-49ee-b2fd-50b402c3dde1@huawei.com> In-Reply-To: <11b7eff6-56a0-49ee-b2fd-50b402c3dde1@huawei.com> X-Originating-IP: [10.174.177.211] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org sra = sysfs_read() should be free before return in get_vd_num_of_subarray() Signed-off-by: Wu Guanghao Acked-by: Mariusz Tkaczyk --- super-ddf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) -- 2.27.0 diff --git a/super-ddf.c b/super-ddf.c index abbc8b09..6d4618fe 100644 --- a/super-ddf.c +++ b/super-ddf.c @@ -1599,15 +1599,20 @@ static unsigned int get_vd_num_of_subarray(struct supertype *st) sra = sysfs_read(-1, st->devnm, GET_VERSION); if (!sra || sra->array.major_version != -1 || sra->array.minor_version != -2 || - !is_subarray(sra->text_version)) + !is_subarray(sra->text_version)) { + if (sra) + sysfs_free(sra); return DDF_NOTFOUND; + } sub = strchr(sra->text_version + 1, '/'); if (sub != NULL) vcnum = strtoul(sub + 1, &end, 10); if (sub == NULL || *sub == '\0' || *end != '\0' || - vcnum >= be16_to_cpu(ddf->active->max_vd_entries)) + vcnum >= be16_to_cpu(ddf->active->max_vd_entries)) { + sysfs_free(sra); return DDF_NOTFOUND; + } return vcnum; }