From patchwork Thu Apr 6 11:40:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guanqin Miao X-Patchwork-Id: 13203251 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 C4446C761A6 for ; Thu, 6 Apr 2023 12:05:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237590AbjDFMF0 (ORCPT ); Thu, 6 Apr 2023 08:05:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238774AbjDFMFG (ORCPT ); Thu, 6 Apr 2023 08:05:06 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE2C49EEE for ; Thu, 6 Apr 2023 05:03:51 -0700 (PDT) Received: from kwepemi500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Psfdh0WVyzKwyt; Thu, 6 Apr 2023 19:38:32 +0800 (CST) Received: from huawei.com (10.175.101.6) by kwepemi500002.china.huawei.com (7.221.188.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 6 Apr 2023 19:41:01 +0800 From: Guanqin Miao To: , , , CC: , , Subject: [PATCH 1/4] Fix memory leak in file Assemble Date: Thu, 6 Apr 2023 19:40:08 +0800 Message-ID: <20230406114011.3297545-2-miaoguanqin@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230406114011.3297545-1-miaoguanqin@huawei.com> References: <20230406114011.3297545-1-miaoguanqin@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500002.china.huawei.com (7.221.188.171) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org When we test mdadm with asan, we found some memory leaks in Assemble.c We fix these memory leaks based on code logic. Signed-off-by: Guanqin Miao Signed-off-by: Li Xiao Keng --- Assemble.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Assemble.c b/Assemble.c index 49804941..574865eb 100644 --- a/Assemble.c +++ b/Assemble.c @@ -341,8 +341,10 @@ static int select_devices(struct mddev_dev *devlist, st->ss->free_super(st); dev_policy_free(pol); domain_free(domains); - if (tst) + if (tst) { tst->ss->free_super(tst); + free(tst); + } return -1; } @@ -417,6 +419,7 @@ static int select_devices(struct mddev_dev *devlist, st->ss->free_super(st); dev_policy_free(pol); domain_free(domains); + free(st); return -1; } if (c->verbose > 0) @@ -425,6 +428,8 @@ static int select_devices(struct mddev_dev *devlist, /* make sure we finished the loop */ tmpdev = NULL; + if (st) + free(st); goto loop; } else { content = *contentp; @@ -533,6 +538,7 @@ static int select_devices(struct mddev_dev *devlist, st->ss->free_super(st); dev_policy_free(pol); domain_free(domains); + free(tst); return -1; } tmpdev->used = 1; @@ -546,8 +552,10 @@ static int select_devices(struct mddev_dev *devlist, } dev_policy_free(pol); pol = NULL; - if (tst) + if (tst) { tst->ss->free_super(tst); + free(tst); + } } /* Check if we found some imsm spares but no members */ @@ -839,6 +847,7 @@ static int load_devices(struct devs *devices, char *devmap, close(mdfd); free(devices); free(devmap); + free(best); *stp = st; return -1; } @@ -1950,6 +1959,8 @@ out: } else if (mdfd >= 0) close(mdfd); + if (best) + free(best); /* '2' means 'OK, but not started yet' */ if (rv == -1) { free(devices); From patchwork Thu Apr 6 11:40:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guanqin Miao X-Patchwork-Id: 13203248 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 2C794C761A6 for ; Thu, 6 Apr 2023 12:03:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235839AbjDFMDI (ORCPT ); Thu, 6 Apr 2023 08:03:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236881AbjDFMCt (ORCPT ); Thu, 6 Apr 2023 08:02:49 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74F9FBBAE for ; Thu, 6 Apr 2023 05:00:25 -0700 (PDT) Received: from kwepemi500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4PsfcC0xCtzSqsF; Thu, 6 Apr 2023 19:37:15 +0800 (CST) Received: from huawei.com (10.175.101.6) by kwepemi500002.china.huawei.com (7.221.188.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 6 Apr 2023 19:41:02 +0800 From: Guanqin Miao To: , , , CC: , , Subject: [PATCH 2/4] Fix memory leak in file Kill Date: Thu, 6 Apr 2023 19:40:09 +0800 Message-ID: <20230406114011.3297545-3-miaoguanqin@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230406114011.3297545-1-miaoguanqin@huawei.com> References: <20230406114011.3297545-1-miaoguanqin@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500002.china.huawei.com (7.221.188.171) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org When we test mdadm with asan, we found some memory leaks in Kill.c We fix these memory leaks based on code logic. Signed-off-by: Guanqin Miao Signed-off-by: Li Xiao Keng --- Kill.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Kill.c b/Kill.c index bfd0efdc..43c9abed 100644 --- a/Kill.c +++ b/Kill.c @@ -41,6 +41,7 @@ int Kill(char *dev, struct supertype *st, int force, int verbose, int noexcl) * 4 - failed to find a superblock. */ + bool free_super = false; int fd, rv = 0; if (force) @@ -52,8 +53,10 @@ int Kill(char *dev, struct supertype *st, int force, int verbose, int noexcl) dev); return 2; } - if (st == NULL) + if (st == NULL) { st = guess_super(fd); + free_super = true; + } if (st == NULL || st->ss->init_super == NULL) { if (verbose >= 0) pr_err("Unrecognised md component device - %s\n", dev); @@ -77,6 +80,10 @@ int Kill(char *dev, struct supertype *st, int force, int verbose, int noexcl) rv = 0; } } + if (free_super && st) { + st->ss->free_super(st); + free(st); + } close(fd); return rv; } From patchwork Thu Apr 6 11:40:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guanqin Miao X-Patchwork-Id: 13203247 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 513EDC76196 for ; Thu, 6 Apr 2023 12:02:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238152AbjDFMCs (ORCPT ); Thu, 6 Apr 2023 08:02:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229710AbjDFMCc (ORCPT ); Thu, 6 Apr 2023 08:02:32 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66F43BB9E for ; Thu, 6 Apr 2023 04:59:57 -0700 (PDT) Received: from kwepemi500002.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Psfdj2cH0zKx6c; Thu, 6 Apr 2023 19:38:33 +0800 (CST) Received: from huawei.com (10.175.101.6) by kwepemi500002.china.huawei.com (7.221.188.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 6 Apr 2023 19:41:02 +0800 From: Guanqin Miao To: , , , CC: , , Subject: [PATCH 3/4] Fix memory leak in file Manage Date: Thu, 6 Apr 2023 19:40:10 +0800 Message-ID: <20230406114011.3297545-4-miaoguanqin@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230406114011.3297545-1-miaoguanqin@huawei.com> References: <20230406114011.3297545-1-miaoguanqin@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500002.china.huawei.com (7.221.188.171) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org When we test mdadm with asan, we found some memory leaks in Manage.c We fix these memory leaks based on code logic. Signed-off-by: Guanqin Miao Signed-off-by: Li Xiao Keng --- Manage.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Manage.c b/Manage.c index fde6aba3..82bcb255 100644 --- a/Manage.c +++ b/Manage.c @@ -222,6 +222,8 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry) if (verbose >= 0) pr_err("Cannot get exclusive access to %s:Perhaps a running process, mounted filesystem or active volume group?\n", devname); + if (mdi) + sysfs_free(mdi); return 1; } /* If this is an mdmon managed array, just write 'inactive' @@ -818,8 +820,15 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv, rdev, update, devname, verbose, array); dev_st->ss->free_super(dev_st); - if (rv) + if (rv) { + free(dev_st); return rv; + } + } + if (dev_st) { + if (dev_st->sb) + dev_st->ss->free_super(dev_st); + free(dev_st); } } if (dv->disposition == 'M') { @@ -1716,6 +1725,8 @@ int Manage_subdevs(char *devname, int fd, break; } } + if (tst) + free(tst); if (frozen > 0) sysfs_set_str(&info, NULL, "sync_action","idle"); if (test && count == 0) @@ -1723,6 +1734,8 @@ int Manage_subdevs(char *devname, int fd, return 0; abort: + if (tst) + free(tst); if (frozen > 0) sysfs_set_str(&info, NULL, "sync_action","idle"); return !test && busy ? 2 : 1; From patchwork Thu Apr 6 11:40:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guanqin Miao X-Patchwork-Id: 13203249 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 49CF5C7618D for ; Thu, 6 Apr 2023 12:03:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236899AbjDFMDu (ORCPT ); Thu, 6 Apr 2023 08:03:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236968AbjDFMD3 (ORCPT ); Thu, 6 Apr 2023 08:03:29 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EADCCA3C for ; Thu, 6 Apr 2023 05:01:09 -0700 (PDT) Received: from kwepemi500002.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4Psfgt1lchzKqnf; Thu, 6 Apr 2023 19:40:26 +0800 (CST) Received: from huawei.com (10.175.101.6) by kwepemi500002.china.huawei.com (7.221.188.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 6 Apr 2023 19:41:03 +0800 From: Guanqin Miao To: , , , CC: , , Subject: [PATCH 4/4] Fix memory leak in file mdadm Date: Thu, 6 Apr 2023 19:40:11 +0800 Message-ID: <20230406114011.3297545-5-miaoguanqin@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230406114011.3297545-1-miaoguanqin@huawei.com> References: <20230406114011.3297545-1-miaoguanqin@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.101.6] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500002.china.huawei.com (7.221.188.171) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-raid@vger.kernel.org When we test mdadm with asan, we found some memory leaks in mdadm.c We fix these memory leaks based on code logic. Signed-off-by: Guanqin Miao Signed-off-by: Li Xiao Keng --- mdadm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mdadm.c b/mdadm.c index 4685ad6b..19d7916b 100644 --- a/mdadm.c +++ b/mdadm.c @@ -1709,6 +1709,10 @@ int main(int argc, char *argv[]) autodetect(); break; } + if (ss) { + ss->ss->free_super(ss); + free(ss); + } if (locked) cluster_release_dlmlock(); close_fd(&mdfd);