From patchwork Tue May 31 06:49:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Guanghao X-Patchwork-Id: 12865120 X-Patchwork-Delegate: jes@trained-monkey.org 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 B9F35C433F5 for ; Tue, 31 May 2022 06:49:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244357AbiEaGtU (ORCPT ); Tue, 31 May 2022 02:49:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244329AbiEaGtU (ORCPT ); Tue, 31 May 2022 02:49:20 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7838F703DD for ; Mon, 30 May 2022 23:49:19 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LC2sj4K08zjXDX; Tue, 31 May 2022 14:48:09 +0800 (CST) Received: from dggpemm500014.china.huawei.com (7.185.36.153) 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.24; Tue, 31 May 2022 14:49:17 +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, 31 May 2022 14:49:17 +0800 Message-ID: Date: Tue, 31 May 2022 14:49:17 +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] parse_layout_faulty: fix memleak From: Wu Guanghao To: , CC: , References: <00992179-9572-ceb4-eb49-492c42e67695@huawei.com> In-Reply-To: <00992179-9572-ceb4-eb49-492c42e67695@huawei.com> X-Originating-IP: [10.174.177.211] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 --- util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/util.c b/util.c index cc94f96e..da18a68d 100644 --- a/util.c +++ b/util.c @@ -429,6 +429,7 @@ int parse_layout_faulty(char *layout) int mode; m[ln] = 0; mode = map_name(faultylayout, m); + free(m); if (mode == UnSet) return -1; From patchwork Tue May 31 06:49:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Guanghao X-Patchwork-Id: 12865121 X-Patchwork-Delegate: jes@trained-monkey.org 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 0A027C433EF for ; Tue, 31 May 2022 06:49:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244359AbiEaGtu (ORCPT ); Tue, 31 May 2022 02:49:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240423AbiEaGtt (ORCPT ); Tue, 31 May 2022 02:49:49 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB3A1703DD for ; Mon, 30 May 2022 23:49:48 -0700 (PDT) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LC2td4KxLzjX1F; Tue, 31 May 2022 14:48:57 +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, 31 May 2022 14:49:46 +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, 31 May 2022 14:49:46 +0800 Message-ID: Date: Tue, 31 May 2022 14:49:46 +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] Detail: fix memleak From: Wu Guanghao To: , CC: , References: <00992179-9572-ceb4-eb49-492c42e67695@huawei.com> In-Reply-To: <00992179-9572-ceb4-eb49-492c42e67695@huawei.com> X-Originating-IP: [10.174.177.211] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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@linux.intel.com --- Detail.c | 1 + 1 file changed, 1 insertion(+) 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 May 31 06:50:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Guanghao X-Patchwork-Id: 12865122 X-Patchwork-Delegate: jes@trained-monkey.org 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 DEB69C433F5 for ; Tue, 31 May 2022 06:50:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244360AbiEaGuX (ORCPT ); Tue, 31 May 2022 02:50:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237850AbiEaGuW (ORCPT ); Tue, 31 May 2022 02:50:22 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7081D703DD for ; Mon, 30 May 2022 23:50:21 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4LC2tv3D2DzQjCD; Tue, 31 May 2022 14:49:11 +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, 31 May 2022 14:50:19 +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, 31 May 2022 14:50:19 +0800 Message-ID: <4ded262a-9313-d328-a3e1-fca56210bf62@huawei.com> Date: Tue, 31 May 2022 14:50:19 +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] load_imsm_mpb: fix double free From: Wu Guanghao To: , CC: , References: <00992179-9572-ceb4-eb49-492c42e67695@huawei.com> In-Reply-To: <00992179-9572-ceb4-eb49-492c42e67695@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 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 --- super-intel.c | 1 - 1 file changed, 1 deletion(-) diff --git a/super-intel.c b/super-intel.c index ba3bd41f..ef21ffba 100644 --- a/super-intel.c +++ b/super-intel.c @@ -4452,7 +4452,6 @@ static int load_imsm_mpb(int fd, struct intel_super *super, char *devname) if (posix_memalign(&super->migr_rec_buf, MAX_SECTOR_SIZE, MIGR_REC_BUF_SECTORS*MAX_SECTOR_SIZE) != 0) { pr_err("could not allocate migr_rec buffer\n"); - free(super->buf); return 2; } super->clean_migration_record_by_mdmon = 0; From patchwork Tue May 31 06:50:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Guanghao X-Patchwork-Id: 12865123 X-Patchwork-Delegate: jes@trained-monkey.org 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 CE3B3C433EF for ; Tue, 31 May 2022 06:50:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244362AbiEaGut (ORCPT ); Tue, 31 May 2022 02:50:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244361AbiEaGur (ORCPT ); Tue, 31 May 2022 02:50:47 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB3757093E for ; Mon, 30 May 2022 23:50:46 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4LC2tp5Dk3zgYCj; Tue, 31 May 2022 14:49:06 +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, 31 May 2022 14:50:45 +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, 31 May 2022 14:50:44 +0800 Message-ID: <12e34ddf-6e60-ab5f-020d-bd004fbbef06@huawei.com> Date: Tue, 31 May 2022 14:50:44 +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] find_disk_attached_hba: fix memleak From: Wu Guanghao To: , CC: , References: <00992179-9572-ceb4-eb49-492c42e67695@huawei.com> In-Reply-To: <00992179-9572-ceb4-eb49-492c42e67695@huawei.com> X-Originating-IP: [10.174.177.211] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) 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 --- super-intel.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/super-intel.c b/super-intel.c index ef21ffba..98fb63d5 100644 --- a/super-intel.c +++ b/super-intel.c @@ -700,8 +700,11 @@ static struct sys_dev* find_disk_attached_hba(int fd, const char *devname) return 0; for (elem = list; elem; elem = elem->next) - if (path_attached_to_hba(disk_path, elem->path)) + if (path_attached_to_hba(disk_path, elem->path)) { + if (disk_path != devname) + free(disk_path); return elem; + } if (disk_path != devname) free(disk_path); From patchwork Tue May 31 06:51:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Guanghao X-Patchwork-Id: 12865124 X-Patchwork-Delegate: jes@trained-monkey.org 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 2D581C433EF for ; Tue, 31 May 2022 06:51:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244367AbiEaGvT (ORCPT ); Tue, 31 May 2022 02:51:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244361AbiEaGvS (ORCPT ); Tue, 31 May 2022 02:51:18 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A16067628E for ; Mon, 30 May 2022 23:51:17 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4LC2vP33Dbz1JCYJ; Tue, 31 May 2022 14:49:37 +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, 31 May 2022 14:51:13 +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, 31 May 2022 14:51:13 +0800 Message-ID: Date: Tue, 31 May 2022 14:51:13 +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] get_vd_num_of_subarray: fix memleak From: Wu Guanghao To: , CC: , References: <00992179-9572-ceb4-eb49-492c42e67695@huawei.com> In-Reply-To: <00992179-9572-ceb4-eb49-492c42e67695@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@linux.intel.com Acked-by: Name
Acked-by: Mariusz Tkaczyk --- super-ddf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/super-ddf.c b/super-ddf.c index 8cda23a7..827e4ae7 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; }