From patchwork Fri Nov 6 09:24:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiqiang Liu X-Patchwork-Id: 11886473 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C691C697 for ; Fri, 6 Nov 2020 09:24:23 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 721052087E for ; Fri, 6 Nov 2020 09:24:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 721052087E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id DBF5C1674C0E0; Fri, 6 Nov 2020 01:24:22 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.191; helo=szxga05-in.huawei.com; envelope-from=liuzhiqiang26@huawei.com; receiver= Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6DFF91673C06A for ; Fri, 6 Nov 2020 01:24:19 -0800 (PST) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CSFMC1yvVzLvLj for ; Fri, 6 Nov 2020 17:24:07 +0800 (CST) Received: from [127.0.0.1] (10.174.176.238) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Fri, 6 Nov 2020 17:24:05 +0800 Subject: [ndctl PATCH 1/8] namespace: check whether pfn|dax|btt is NULL in setup_namespace To: References: From: Zhiqiang Liu Message-ID: <4f51f398-08d0-15c9-fdcb-27b73db78d24@huawei.com> Date: Fri, 6 Nov 2020 17:24:04 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Originating-IP: [10.174.176.238] X-CFilter-Loop: Reflected Message-ID-Hash: D35JIUS7T33H75KE56RXLU2Z3G4SSKRO X-Message-ID-Hash: D35JIUS7T33H75KE56RXLU2Z3G4SSKRO X-MailFrom: liuzhiqiang26@huawei.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: linux-nvdimm@lists.01.org, linfeilong X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: In setup_namespace(), pfn|dax|btt is obtained by calling ndctl_region_get_**_seed(), which may return NULL. So we need to check whether pfn|dax|btt is NULL before accessing them. Signed-off-by: Zhiqiang Liu Acked-by: Jeff Moyer --- ndctl/namespace.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index e946bb6..257384d 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -549,6 +549,8 @@ static int setup_namespace(struct ndctl_region *region, if (do_setup_pfn(ndns, p)) { struct ndctl_pfn *pfn = ndctl_region_get_pfn_seed(region); + if (!pfn) + return -ENXIO; rc = check_dax_align(ndns); if (rc) @@ -563,6 +565,8 @@ static int setup_namespace(struct ndctl_region *region, ndctl_pfn_set_namespace(pfn, NULL); } else if (p->mode == NDCTL_NS_MODE_DEVDAX) { struct ndctl_dax *dax = ndctl_region_get_dax_seed(region); + if (!dax) + return -ENXIO; rc = check_dax_align(ndns); if (rc) @@ -577,7 +581,8 @@ static int setup_namespace(struct ndctl_region *region, ndctl_dax_set_namespace(dax, NULL); } else if (p->mode == NDCTL_NS_MODE_SECTOR) { struct ndctl_btt *btt = ndctl_region_get_btt_seed(region); - + if (!btt) + return -ENXIO; /* * Handle the case of btt on a pmem namespace where the * pmem kernel support is pre-v1.2 namespace labels From patchwork Fri Nov 6 09:25:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiqiang Liu X-Patchwork-Id: 11886475 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33B786A2 for ; Fri, 6 Nov 2020 09:25:16 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CF86A20936 for ; Fri, 6 Nov 2020 09:25:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF86A20936 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1EDDB163F9794; Fri, 6 Nov 2020 01:25:15 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.191; helo=szxga05-in.huawei.com; envelope-from=liuzhiqiang26@huawei.com; receiver= Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 84850163F9792 for ; Fri, 6 Nov 2020 01:25:13 -0800 (PST) Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CSFNJ20VHzLsPY for ; Fri, 6 Nov 2020 17:25:04 +0800 (CST) Received: from [127.0.0.1] (10.174.176.238) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.487.0; Fri, 6 Nov 2020 17:25:03 +0800 Subject: [ndctl PATCH 2/8] lib/libndctl: fix memory leakage problem in add_bus To: References: From: Zhiqiang Liu Message-ID: <8caac123-9d45-c848-d45a-3cb8be5a2708@huawei.com> Date: Fri, 6 Nov 2020 17:25:03 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Originating-IP: [10.174.176.238] X-CFilter-Loop: Reflected Message-ID-Hash: CG5FBBEAESRGZURE5IPTNSLPTVEJWZ7C X-Message-ID-Hash: CG5FBBEAESRGZURE5IPTNSLPTVEJWZ7C X-MailFrom: liuzhiqiang26@huawei.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: linux-nvdimm@lists.01.org, linfeilong , liuzhiqiang26@huawei.com X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: In add_bus(), bus->bus_path is set by calling parent_dev_path(), which will finally adopt realpath(, NULL) to allocate new path. However, bus->bus_path will not be freed in err_read tag, then, memory leakage occurs. Signed-off-by: Zhiqiang Liu Acked-by: Jeff Moyer --- ndctl/lib/libndctl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index ad521d3..3926382 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -975,6 +975,7 @@ static void *add_bus(void *parent, int id, const char *ctl_base) free(bus->wait_probe_path); free(bus->scrub_path); free(bus->provider); + free(bus->bus_path); free(bus->bus_buf); free(bus); err_bus: From patchwork Fri Nov 6 09:25:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiqiang Liu X-Patchwork-Id: 11886481 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D3A23697 for ; Fri, 6 Nov 2020 09:25:46 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A788A2087E for ; Fri, 6 Nov 2020 09:25:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A788A2087E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 54A421673C07E; Fri, 6 Nov 2020 01:25:46 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.32; helo=szxga06-in.huawei.com; envelope-from=liuzhiqiang26@huawei.com; receiver= Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3FF90163F9794 for ; Fri, 6 Nov 2020 01:25:43 -0800 (PST) Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CSFNy1pp3zhdbZ for ; Fri, 6 Nov 2020 17:25:38 +0800 (CST) Received: from [127.0.0.1] (10.174.176.238) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Fri, 6 Nov 2020 17:25:32 +0800 Subject: [ndctl PATCH 3/8] libdaxctl: fix memory leakage in add_dax_region() To: References: From: Zhiqiang Liu Message-ID: <7ae72048-0c26-9da2-41a9-c1b63a8db117@huawei.com> Date: Fri, 6 Nov 2020 17:25:32 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Originating-IP: [10.174.176.238] X-CFilter-Loop: Reflected Message-ID-Hash: CIDKJXRYSFXY6YUOGO5YMZFIMKPNPPYX X-Message-ID-Hash: CIDKJXRYSFXY6YUOGO5YMZFIMKPNPPYX X-MailFrom: liuzhiqiang26@huawei.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: linux-nvdimm@lists.01.org, linfeilong , liuzhiqiang26@huawei.com X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: In add_dax_region(), region->devname is allocated by calling strdup(), which may return NULL. So, we need to check whether region->devname is NULL, and free region->devname in err_read tag. Signed-off-by: Zhiqiang Liu Acked-by: Jeff Moyer --- daxctl/lib/libdaxctl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c index ee4a069..d841b78 100644 --- a/daxctl/lib/libdaxctl.c +++ b/daxctl/lib/libdaxctl.c @@ -287,6 +287,8 @@ static struct daxctl_region *add_dax_region(void *parent, int id, region->refcount = 1; list_head_init(®ion->devices); region->devname = strdup(devpath_to_devname(base)); + if (!region->devname) + goto err_read; sprintf(path, "%s/%s/size", base, attrs); if (sysfs_read_attr(ctx, path, buf) == 0) @@ -314,6 +316,7 @@ static struct daxctl_region *add_dax_region(void *parent, int id, err_read: free(region->region_buf); free(region->region_path); + free(region->devname); free(region); err_region: free(path); From patchwork Fri Nov 6 09:26:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiqiang Liu X-Patchwork-Id: 11886483 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 555F316C1 for ; Fri, 6 Nov 2020 09:26:35 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 24F7D208B3 for ; Fri, 6 Nov 2020 09:26:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 24F7D208B3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 821F41674C0EE; Fri, 6 Nov 2020 01:26:34 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.32; helo=szxga06-in.huawei.com; envelope-from=liuzhiqiang26@huawei.com; receiver= Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 660B31673C07E for ; Fri, 6 Nov 2020 01:26:32 -0800 (PST) Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4CSFPm54vvzhgxr for ; Fri, 6 Nov 2020 17:26:20 +0800 (CST) Received: from [127.0.0.1] (10.174.176.238) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Fri, 6 Nov 2020 17:26:13 +0800 Subject: [ndctl PATCH 4/8] dimm: fix potential fd leakage in dimm_action() To: References: From: Zhiqiang Liu Message-ID: <1ca17cf4-a5fd-786d-fa50-8ed09ccd55e4@huawei.com> Date: Fri, 6 Nov 2020 17:26:12 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Originating-IP: [10.174.176.238] X-CFilter-Loop: Reflected Message-ID-Hash: K53J3EMKFP456D6ANRJ5DNDS2VZZQIV2 X-Message-ID-Hash: K53J3EMKFP456D6ANRJ5DNDS2VZZQIV2 X-MailFrom: liuzhiqiang26@huawei.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: linux-nvdimm@lists.01.org, linfeilong , liuzhiqiang26@huawei.com X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: In dimm_action(), actx.f_out and actx.f_in may be set by calling fopen(). If exceptions occur, we will directly goto out tag. However, we did not close actx.f_out|actx.f_in in out tag, which will cause fd leakage. Signed-off-by: Zhiqiang Liu Acked-by: Jeff Moyer --- ndctl/dimm.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ndctl/dimm.c b/ndctl/dimm.c index 90eb0b8..2f52cda 100644 --- a/ndctl/dimm.c +++ b/ndctl/dimm.c @@ -1352,7 +1352,7 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx, fprintf(stderr, "failed to open: %s: (%s)\n", param.infile, strerror(errno)); rc = -errno; - goto out; + goto out_close_fout; } } @@ -1371,7 +1371,7 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx, fprintf(stderr, "'%s' is not a valid label version\n", param.labelversion); rc = -EINVAL; - goto out; + goto out_close_fin_fout; } rc = 0; @@ -1423,12 +1423,14 @@ static int dimm_action(int argc, const char **argv, struct ndctl_ctx *ctx, util_display_json_array(actx.f_out, actx.jdimms, flags); } - if (actx.f_out != stdout) - fclose(actx.f_out); - + out_close_fin_fout: if (actx.f_in != stdin) fclose(actx.f_in); + out_close_fout: + if (actx.f_out != stdout) + fclose(actx.f_out); + out: /* * count if some actions succeeded, 0 if none were attempted, From patchwork Fri Nov 6 09:26:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiqiang Liu X-Patchwork-Id: 11886485 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 31D3B6A2 for ; Fri, 6 Nov 2020 09:26:54 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F36D72087E for ; Fri, 6 Nov 2020 09:26:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F36D72087E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 9D9771674C0F1; Fri, 6 Nov 2020 01:26:53 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.191; helo=szxga05-in.huawei.com; envelope-from=liuzhiqiang26@huawei.com; receiver= Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 3ACDA1674C0EF for ; Fri, 6 Nov 2020 01:26:50 -0800 (PST) Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CSFQ942QbzLtmq for ; Fri, 6 Nov 2020 17:26:41 +0800 (CST) Received: from [127.0.0.1] (10.174.176.238) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.487.0; Fri, 6 Nov 2020 17:26:39 +0800 Subject: [ndctl PATCH 5/8] util/help: check whether strdup returns NULL in exec_man_konqueror To: References: From: Zhiqiang Liu Message-ID: <889d3dc7-2532-9f91-b0d8-5eeab45d6bb7@huawei.com> Date: Fri, 6 Nov 2020 17:26:38 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Originating-IP: [10.174.176.238] X-CFilter-Loop: Reflected Message-ID-Hash: MS2AGY5AN4V7EAP275FP4TAMFWM6GOBG X-Message-ID-Hash: MS2AGY5AN4V7EAP275FP4TAMFWM6GOBG X-MailFrom: liuzhiqiang26@huawei.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: linux-nvdimm@lists.01.org, linfeilong , liuzhiqiang26@huawei.com X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: In exec_man_konqueror(), new is allocated by calling strdup(), which may return NULL. We should check whether new is NULL before using it. Signed-off-by: Zhiqiang Liu --- util/help.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/util/help.c b/util/help.c index 2d57fa1..f867944 100644 --- a/util/help.c +++ b/util/help.c @@ -44,8 +44,14 @@ static void exec_man_konqueror(const char *path, const char *page) if (path) { const char *file = strrchr(path, '/'); if (file && !strcmp(file + 1, "konqueror")) { + char *dest; char *new = strdup(path); - char *dest = strrchr(new, '/'); + if (!new) { + pr_err("strdup(path) fails.\n"); + exit(1); + } + + dest = strrchr(new, '/'); /* strlen("konqueror") == strlen("kfmclient") */ strcpy(dest + 1, "kfmclient"); From patchwork Fri Nov 6 09:27:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiqiang Liu X-Patchwork-Id: 11886487 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3ADB46A2 for ; Fri, 6 Nov 2020 09:27:23 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D6BF2087E for ; Fri, 6 Nov 2020 09:27:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0D6BF2087E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id BB6151674C0FD; Fri, 6 Nov 2020 01:27:22 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.190; helo=szxga04-in.huawei.com; envelope-from=liuzhiqiang26@huawei.com; receiver= Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C16811674C0FA for ; Fri, 6 Nov 2020 01:27:20 -0800 (PST) Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CSFQl3vVWzkfw1 for ; Fri, 6 Nov 2020 17:27:11 +0800 (CST) Received: from [127.0.0.1] (10.174.176.238) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.487.0; Fri, 6 Nov 2020 17:27:10 +0800 Subject: [ndctl PATCH 6/8] lib/inject: check whether cmd is created successfully To: References: From: Zhiqiang Liu Message-ID: <8e8a88ee-a792-dc86-0fa7-b2609588fc88@huawei.com> Date: Fri, 6 Nov 2020 17:27:09 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Originating-IP: [10.174.176.238] X-CFilter-Loop: Reflected Message-ID-Hash: 6ERQK2FU6K4XDAT36YP4DPO3FCHRMTGA X-Message-ID-Hash: 6ERQK2FU6K4XDAT36YP4DPO3FCHRMTGA X-MailFrom: liuzhiqiang26@huawei.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: linux-nvdimm@lists.01.org, linfeilong , liuzhiqiang26@huawei.com X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: ndctl_bus_cmd_new_ars_cp() is called to create cmd, which may return NULL. We need to check whether it is NULL in callers, such as ndctl_namespace_get_clear_uint and ndctl_namespace_injection_status. Signed-off-by: Zhiqiang Liu --- ndctl/lib/inject.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ndctl/lib/inject.c b/ndctl/lib/inject.c index 815f254..b543fc7 100644 --- a/ndctl/lib/inject.c +++ b/ndctl/lib/inject.c @@ -114,6 +114,10 @@ static int ndctl_namespace_get_clear_unit(struct ndctl_namespace *ndns) if (rc) return rc; cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size); + if (!cmd) { + err(ctx, "bus: %s failed to create cmd\n", ndctl_bus_get_provider(bus)); + return -ENOTTY; + } rc = ndctl_cmd_submit(cmd); if (rc < 0) { dbg(ctx, "Error submitting ars_cap: %d\n", rc); @@ -457,6 +461,10 @@ NDCTL_EXPORT int ndctl_namespace_injection_status(struct ndctl_namespace *ndns) return rc; cmd = ndctl_bus_cmd_new_ars_cap(bus, ns_offset, ns_size); + if (!cmd) { + err(ctx, "bus: %s failed to create cmd\n", ndctl_bus_get_provider(bus)); + return -ENOTTY; + } rc = ndctl_cmd_submit(cmd); if (rc < 0) { dbg(ctx, "Error submitting ars_cap: %d\n", rc); From patchwork Fri Nov 6 09:27:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiqiang Liu X-Patchwork-Id: 11886489 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E630F697 for ; Fri, 6 Nov 2020 09:27:50 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 773FD208B3 for ; Fri, 6 Nov 2020 09:27:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 773FD208B3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D829E1674C102; Fri, 6 Nov 2020 01:27:49 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.190; helo=szxga04-in.huawei.com; envelope-from=liuzhiqiang26@huawei.com; receiver= Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D4E241674C0FD for ; Fri, 6 Nov 2020 01:27:45 -0800 (PST) Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CSFRF39GMzkbyN for ; Fri, 6 Nov 2020 17:27:37 +0800 (CST) Received: from [127.0.0.1] (10.174.176.238) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Fri, 6 Nov 2020 17:27:36 +0800 Subject: [ndctl PATCH 7/8] Check whether ndctl_btt_get_namespace returns NULL in callers To: References: From: Zhiqiang Liu Message-ID: Date: Fri, 6 Nov 2020 17:27:35 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Originating-IP: [10.174.176.238] X-CFilter-Loop: Reflected Message-ID-Hash: VA55HJAXANYXP35DC5RSGTXFHC363OFC X-Message-ID-Hash: VA55HJAXANYXP35DC5RSGTXFHC363OFC X-MailFrom: liuzhiqiang26@huawei.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: linux-nvdimm@lists.01.org, linfeilong X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: ndctl_btt_get_namespace() may return NULL, so we need to check return value of ndctl_btt_get_namespace() before using the return value in callers. Signed-off-by: Zhiqiang Liu --- test/libndctl.c | 16 +++++++++++----- test/parent-uuid.c | 2 +- util/json.c | 3 +++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/test/libndctl.c b/test/libndctl.c index 994e0fa..a8db388 100644 --- a/test/libndctl.c +++ b/test/libndctl.c @@ -983,13 +983,19 @@ static int check_pfn_create(struct ndctl_region *region, static int check_btt_size(struct ndctl_btt *btt) { + unsigned long long ns_size; + unsigned long sect_size; + unsigned long long actual, expect; + int size_select, sect_select; struct ndctl_ctx *ctx = ndctl_btt_get_ctx(btt); struct ndctl_test *test = ndctl_get_private_data(ctx); struct ndctl_namespace *ndns = ndctl_btt_get_namespace(btt); - unsigned long long ns_size = ndctl_namespace_get_size(ndns); - unsigned long sect_size = ndctl_btt_get_sector_size(btt); - unsigned long long actual, expect; - int size_select, sect_select; + + if (!ndns) + return -ENXIO; + + ns_size = ndctl_namespace_get_size(ndns); + sect_size = ndctl_btt_get_sector_size(btt); unsigned long long expect_table[][2] = { [0] = { [0] = 0x11b5400, @@ -1461,7 +1467,7 @@ static int check_btt_autodetect(struct ndctl_bus *bus, if (!ndctl_btt_is_enabled(btt)) continue; btt_ndns = ndctl_btt_get_namespace(btt); - if (strcmp(ndctl_namespace_get_devname(btt_ndns), devname) != 0) + if (!btt_ndns || strcmp(ndctl_namespace_get_devname(btt_ndns), devname) != 0) continue; fprintf(stderr, "%s: btt_ndns: %p ndns: %p\n", __func__, btt_ndns, ndns); diff --git a/test/parent-uuid.c b/test/parent-uuid.c index f41ca2c..303b30b 100644 --- a/test/parent-uuid.c +++ b/test/parent-uuid.c @@ -115,7 +115,7 @@ static struct ndctl_btt *check_valid_btt(struct ndctl_region *region, if (!ndctl_btt_is_enabled(btt)) continue; btt_ndns = ndctl_btt_get_namespace(btt); - if (strcmp(ndctl_namespace_get_devname(btt_ndns), + if (!btt_ndns || strcmp(ndctl_namespace_get_devname(btt_ndns), ndctl_namespace_get_devname(ndns)) != 0) continue; return btt; diff --git a/util/json.c b/util/json.c index 77bd478..1392403 100644 --- a/util/json.c +++ b/util/json.c @@ -1004,6 +1004,9 @@ static void util_btt_badblocks_to_json(struct ndctl_btt *btt, struct ndctl_namespace *ndns = ndctl_btt_get_namespace(btt); unsigned long long begin, size; + if (!ndns) + return; + begin = ndctl_namespace_get_resource(ndns); if (begin == ULLONG_MAX) return; From patchwork Fri Nov 6 09:28:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiqiang Liu X-Patchwork-Id: 11886493 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C54CC697 for ; Fri, 6 Nov 2020 09:28:26 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 92E622087E for ; Fri, 6 Nov 2020 09:28:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 92E622087E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-nvdimm-bounces@lists.01.org Received: from ml01.vlan13.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 173621674C108; Fri, 6 Nov 2020 01:28:26 -0800 (PST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=45.249.212.35; helo=szxga07-in.huawei.com; envelope-from=liuzhiqiang26@huawei.com; receiver= Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 153431673C06B for ; Fri, 6 Nov 2020 01:28:23 -0800 (PST) Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CSFS11LGjz73TD for ; Fri, 6 Nov 2020 17:28:17 +0800 (CST) Received: from [127.0.0.1] (10.174.176.238) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Fri, 6 Nov 2020 17:28:12 +0800 Subject: [ndctl PATCH 8/8] Check whether seed is NULL in validate_namespace_options To: References: From: Zhiqiang Liu Message-ID: <685bde1f-1c64-28db-d20d-a0876a7ee76a@huawei.com> Date: Fri, 6 Nov 2020 17:28:11 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Originating-IP: [10.174.176.238] X-CFilter-Loop: Reflected Message-ID-Hash: 6QGO43VFZCVDFTSBD2YGNHFQETSOAZ4D X-Message-ID-Hash: 6QGO43VFZCVDFTSBD2YGNHFQETSOAZ4D X-MailFrom: liuzhiqiang26@huawei.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: linux-nvdimm@lists.01.org, linfeilong , liuzhiqiang26@huawei.com X-Mailman-Version: 3.1.1 Precedence: list List-Id: "Linux-nvdimm developer list." Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: In validate_namespace_options(), seed is obtained through calling ndctl_region_get_namespace_seed(), which may return NULL. If seed is NULL, we should return directly with error code. In addition, we can use region_name var rather than calling ndctl_region_get_devname() again. Signed-off-by: Zhiqiang Liu --- ndctl/namespace.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ndctl/namespace.c b/ndctl/namespace.c index 257384d..5a92d62 100644 --- a/ndctl/namespace.c +++ b/ndctl/namespace.c @@ -847,8 +847,7 @@ static int validate_namespace_options(struct ndctl_region *region, region_align = ndctl_region_get_align(region); if (region_align < ULONG_MAX && p->size % region_align) { err("%s: align setting is %#lx size %#llx is misaligned\n", - ndctl_region_get_devname(region), region_align, - p->size); + region_name, region_align, p->size); return -EINVAL; } @@ -924,8 +923,13 @@ static int validate_namespace_options(struct ndctl_region *region, } else { struct ndctl_namespace *seed = ndns; - if (!seed) + if (!seed) { seed = ndctl_region_get_namespace_seed(region); + if (!seed) { + err("%s: failed to get seed\n", region_name); + return -ENXIO; + } + } num = ndctl_namespace_get_num_sector_sizes(seed); for (i = 0; i < num; i++) if (ndctl_namespace_get_supported_sector_size(seed, i) @@ -953,9 +957,13 @@ static int validate_namespace_options(struct ndctl_region *region, struct ndctl_namespace *seed; seed = ndctl_region_get_namespace_seed(region); + if (!seed) { + err("%s: failed to get seed\n", region_name); + return -ENXIO; + } if (ndctl_namespace_get_type(seed) == ND_DEVICE_NAMESPACE_BLK) debug("%s: set_defaults() should preclude this?\n", - ndctl_region_get_devname(region)); + region_name); /* * Pick a default sector size for a pmem namespace based * on what the kernel supports.