From patchwork Tue Jan 10 23:09:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 13095757 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 2CE62C54EBC for ; Tue, 10 Jan 2023 23:10:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235071AbjAJXKA (ORCPT ); Tue, 10 Jan 2023 18:10:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234942AbjAJXJy (ORCPT ); Tue, 10 Jan 2023 18:09:54 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B612659514 for ; Tue, 10 Jan 2023 15:09:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673392193; x=1704928193; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=Gtf6WAW/csOf427X3LRR5XcQfg7g7JRMlkKoYsNZ8zk=; b=XGQHG+ZIssvH4ZhbWH5ZfXTZm6X/o71zNqppDr6lTvE2NSOWs+Qz8Sq1 wCDbkRMZqnEsP+N7pAFYarwkUFDCQ6v969dCR0AMZvTrA3e4sAW7LKGrH TUtgsNU3R7p4ZraQUA2oBO1l54sgVY00vEbzV5FMnxCAVQkMzOiHDrk6S +KYSJQYMOU6qjarba83sSUSsHYg8A36Jc5Yqh/jLZZr0i/0bLCuXwLo1e FTV1Ah9J2EX4tjATEdJqyfYRlerQotLYlBY84EVuTmJAPPCmkOT8Mxgso L775xdd5BGa1Rdq3haxYgcaoqZZmn4vpClAWV+hagzQf87YlZrNiDP/Vy g==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="321981265" X-IronPort-AV: E=Sophos;i="5.96,315,1665471600"; d="scan'208";a="321981265" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2023 15:09:52 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="659155904" X-IronPort-AV: E=Sophos;i="5.96,315,1665471600"; d="scan'208";a="659155904" Received: from ffallaha-mobl.amr.corp.intel.com (HELO vverma7-desk1.local) ([10.212.116.179]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2023 15:09:52 -0800 From: Vishal Verma Date: Tue, 10 Jan 2023 16:09:14 -0700 Subject: [PATCH ndctl 1/4] ndctl/lib: fix usage of a non NUL-terminated string MIME-Version: 1.0 Message-Id: <20230110-vv-coverity-fixes-v1-1-c7ee6c76b200@intel.com> References: <20230110-vv-coverity-fixes-v1-0-c7ee6c76b200@intel.com> In-Reply-To: <20230110-vv-coverity-fixes-v1-0-c7ee6c76b200@intel.com> To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev Cc: Dave Jiang , Dan Williams , Vishal Verma X-Mailer: b4 0.12-dev-cc11a X-Developer-Signature: v=1; a=openpgp-sha256; l=872; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=Gtf6WAW/csOf427X3LRR5XcQfg7g7JRMlkKoYsNZ8zk=; b=owGbwMvMwCXGf25diOft7jLG02pJDMl7P9irFeUyXWHr15r8dsMkn/UNJ6wnKFrKaMzPzi6K353o bvito5SFQYyLQVZMkeXvno+Mx+S25/MEJjjCzGFlAhnCwMUpABPRnMPwT/lQ6enUJdbypnX9c9Q9XX ZctvxccnjyacUlbnVd26euXwJU0a3cvUFfdS+DSUjX+/NFs5TP+j35525+ni37eI6prAcnAA== X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Static analysis reports that in add_region(), a buffer from pread() won't have NUL-termination. Hence passing it to strtol subsequently can be wrong. Manually add the termination after pread() to fix this. Fixes: c64cc150a21e ("ndctl: add support in libndctl to provide deep flush") Cc: Dave Jiang Signed-off-by: Vishal Verma Reviewed-by: Alison Schofield --- ndctl/lib/libndctl.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index f32f704..ddbdd9a 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -2750,6 +2750,8 @@ static void *add_region(void *parent, int id, const char *region_base) goto out; } + /* pread() doesn't add NUL termination */ + buf[1] = 0; perm = strtol(buf, NULL, 0); if (perm == 0) { close(region->flush_fd); From patchwork Tue Jan 10 23:09:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 13095758 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 86C50C61DB3 for ; Tue, 10 Jan 2023 23:10:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231654AbjAJXKA (ORCPT ); Tue, 10 Jan 2023 18:10:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234848AbjAJXJz (ORCPT ); Tue, 10 Jan 2023 18:09:55 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CDAA5566E for ; Tue, 10 Jan 2023 15:09:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673392194; x=1704928194; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=t2rn+Iy4jdDZV+5z4dc6ZLrjqjVRNl6oqWZfHBzRwBA=; b=U53m4qffQPdg5IwQjwZRJlqoPvwJcPSltiSHNMGuywPFWnzhBY/BTba6 HWjqsKRIyICkSx1DKsE7z5fReH64BYgngEAjqRO6ciphcVsgWRioxKc0e HQlqWDNxjl2iHP55FNlq4M2fz1thR2PYQCBLuzKz/ihznjwRMKA1HvTsA ypvr8dhDcTBbvCdbLx8B8hpqW6nyNDUYo+1m2+5RR72UtbxE0SiXk9oV0 dApysWPkIu2C83OD+2RGmi6252ZSbmdWXoNt+FkDJB3tc2hus8SMe99Yi OxEVTSaPEbOnJzrgA8Ccay/Gh772lZvBSjxBIihxfnoqOIbW4wsQPlhUb g==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="321981267" X-IronPort-AV: E=Sophos;i="5.96,315,1665471600"; d="scan'208";a="321981267" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2023 15:09:52 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="659155907" X-IronPort-AV: E=Sophos;i="5.96,315,1665471600"; d="scan'208";a="659155907" Received: from ffallaha-mobl.amr.corp.intel.com (HELO vverma7-desk1.local) ([10.212.116.179]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2023 15:09:52 -0800 From: Vishal Verma Date: Tue, 10 Jan 2023 16:09:15 -0700 Subject: [PATCH ndctl 2/4] cxl/region: fix a resource leak in to_csv() MIME-Version: 1.0 Message-Id: <20230110-vv-coverity-fixes-v1-2-c7ee6c76b200@intel.com> References: <20230110-vv-coverity-fixes-v1-0-c7ee6c76b200@intel.com> In-Reply-To: <20230110-vv-coverity-fixes-v1-0-c7ee6c76b200@intel.com> To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev Cc: Dave Jiang , Dan Williams , Vishal Verma X-Mailer: b4 0.12-dev-cc11a X-Developer-Signature: v=1; a=openpgp-sha256; l=984; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=t2rn+Iy4jdDZV+5z4dc6ZLrjqjVRNl6oqWZfHBzRwBA=; b=owGbwMvMwCXGf25diOft7jLG02pJDMl7P9jzLc3u1Z8pvcD56LEnYR6pE2Yk3PjykifSs+AH06TK ppKKjlIWBjEuBlkxRZa/ez4yHpPbns8TmOAIM4eVCWQIAxenAExEcDojw87Y75XR26fyRHLtVFdqTr A9ffBWspXkmsXvvyz/8eJY1QNGhg3JbBy/rzxmzuF2fynFJu20L29yA49FzdSmKWnGAlLXGAA= X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Static analysis reports there can be a memory leak in to_csv as an exit path returns from the function before freeing 'csv'. Since this is the only errpr path exit point after the allocation, just free() before returning. Fixes: 3d6cd829ec08 ("cxl/region: Use cxl_filter_walk() to gather create-region targets") Cc: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Alison Schofield --- cxl/region.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cxl/region.c b/cxl/region.c index bb3a10a..9a81113 100644 --- a/cxl/region.c +++ b/cxl/region.c @@ -146,8 +146,10 @@ static const char *to_csv(int *count, const char **strings) return NULL; for (i = 0; i < *count; i++) { list = strdup(strings[i]); - if (!list) + if (!list) { + free(csv); return NULL; + } for (arg = strtok_r(list, which_sep(list), &save); arg; arg = strtok_r(NULL, which_sep(list), &save)) { From patchwork Tue Jan 10 23:09:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 13095759 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 9DE9AC46467 for ; Tue, 10 Jan 2023 23:10:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235153AbjAJXKB (ORCPT ); Tue, 10 Jan 2023 18:10:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235068AbjAJXJz (ORCPT ); Tue, 10 Jan 2023 18:09:55 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95F5A5951B for ; Tue, 10 Jan 2023 15:09:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673392194; x=1704928194; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=mL6lmpUYl41ULhtrwC9KKvuRtlC9LZqv9zJejcRxHKI=; b=MYKpfl+5038HGEZGym8ke5hCeJAedJUleond+Z+gmCV/Pffs0eTC3Oqi TBFFIQNFFAZR7zz2ZG5mjdjGPGsuymizgRyDn6b6EtqO6hA+ItXwbcf2S EU/4yWVnqQSwlQgW8Uo3BSwzA49O4Fyi0dgdNqjQ/iKmHJIROzJX51v7J FwM0lZhpNWTnFj4i007/B0lqw9Hq3DydcgQQFICVZdK/3qaWpgZjA5ZDu JjceIIls0lgAJ5+IhrOf9P0Jz8M26hxKoPnAQhhdoq0qDch595k7flG0N MWJNbhvrtZLMkvSwxcRoBQrvSprpzrVj5eLmNYjWB9gnR2PRRqpkEcGRU Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="321981272" X-IronPort-AV: E=Sophos;i="5.96,315,1665471600"; d="scan'208";a="321981272" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2023 15:09:53 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="659155910" X-IronPort-AV: E=Sophos;i="5.96,315,1665471600"; d="scan'208";a="659155910" Received: from ffallaha-mobl.amr.corp.intel.com (HELO vverma7-desk1.local) ([10.212.116.179]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2023 15:09:52 -0800 From: Vishal Verma Date: Tue, 10 Jan 2023 16:09:16 -0700 Subject: [PATCH ndctl 3/4] cxl/region: fix an out of bounds access in to_csv() MIME-Version: 1.0 Message-Id: <20230110-vv-coverity-fixes-v1-3-c7ee6c76b200@intel.com> References: <20230110-vv-coverity-fixes-v1-0-c7ee6c76b200@intel.com> In-Reply-To: <20230110-vv-coverity-fixes-v1-0-c7ee6c76b200@intel.com> To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev Cc: Dave Jiang , Dan Williams , Vishal Verma X-Mailer: b4 0.12-dev-cc11a X-Developer-Signature: v=1; a=openpgp-sha256; l=943; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=mL6lmpUYl41ULhtrwC9KKvuRtlC9LZqv9zJejcRxHKI=; b=owGbwMvMwCXGf25diOft7jLG02pJDMl7P9i71vl8ObSwPOnXlmuyv2yt/Z9MWTHb5+5O3axzGi5H 62f1d5SyMIhxMciKKbL83fOR8Zjc9nyewARHmDmsTCBDGLg4BWAitb8YGQ6c2zHdzpLbs1ezdop3+4 TVx3fLHuqO+hc5xYXzUnZssRUjw6TFNt9nfPX/1ZawhNnqZ/vr1QdfP6mwcXmxb/PStuAF51gA X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Static analysis reports that when 'csv' is allocated for 'len' bytes, writing to csv[len] results in an out of bounds access. Fix this truncation operation to instead write the NUL terminator to csv[len - 1], which is the last byte of the memory allocated. Fixes: 3d6cd829ec08 ("cxl/region: Use cxl_filter_walk() to gather create-region targets") Cc: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Alison Schofield --- cxl/region.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cxl/region.c b/cxl/region.c index 9a81113..89be9b5 100644 --- a/cxl/region.c +++ b/cxl/region.c @@ -156,7 +156,7 @@ static const char *to_csv(int *count, const char **strings) cursor += snprintf(csv + cursor, len - cursor, "%s%s", arg, i + 1 < new_count ? "," : ""); if (cursor >= len) { - csv[len] = 0; + csv[len - 1] = 0; break; } } From patchwork Tue Jan 10 23:09:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 13095760 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 C9383C54EBC for ; Tue, 10 Jan 2023 23:10:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234339AbjAJXKD (ORCPT ); Tue, 10 Jan 2023 18:10:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234570AbjAJXJz (ORCPT ); Tue, 10 Jan 2023 18:09:55 -0500 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBB29DEB7 for ; Tue, 10 Jan 2023 15:09:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673392194; x=1704928194; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=P4hPdW8+bePoAaxzhoqscfaaJ238PGmVdQhKGufS+7Y=; b=bPkspPORTOYXqHYrSYOpr3bUUj1cfNzhmIjLOiO+U4snCbEayd8lJWBh BWZCISiAMEGXU1EMh0YpDiO+rMWEuWMAW2dwoeeINNfWDLAXYb65ST8LH TfOxe7qLZtzPXbGTzOlBdbhny12fLguP7yroNofFPp/pbJMJ/jmgu8ONb e2Xk/5iVcUG0al7tuR837EPG26sDqCjAlkA/ENOjfqXIy3EGHpPIfCNnV W8VYW/45Adr6ZZ0ujTQ459A8qUHaUzhECkDP8d4YyH88cCAihWw5F6pG9 Z7UHagb9spaCEpRJOWY5RAw07AhtLX4eKmybmmvRM2z8AH0OgI92acIN2 g==; X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="321981273" X-IronPort-AV: E=Sophos;i="5.96,315,1665471600"; d="scan'208";a="321981273" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2023 15:09:53 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10586"; a="659155916" X-IronPort-AV: E=Sophos;i="5.96,315,1665471600"; d="scan'208";a="659155916" Received: from ffallaha-mobl.amr.corp.intel.com (HELO vverma7-desk1.local) ([10.212.116.179]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jan 2023 15:09:52 -0800 From: Vishal Verma Date: Tue, 10 Jan 2023 16:09:17 -0700 Subject: [PATCH ndctl 4/4] cxl/region: fix a comment typo MIME-Version: 1.0 Message-Id: <20230110-vv-coverity-fixes-v1-4-c7ee6c76b200@intel.com> References: <20230110-vv-coverity-fixes-v1-0-c7ee6c76b200@intel.com> In-Reply-To: <20230110-vv-coverity-fixes-v1-0-c7ee6c76b200@intel.com> To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev Cc: Dave Jiang , Dan Williams , Vishal Verma X-Mailer: b4 0.12-dev-cc11a X-Developer-Signature: v=1; a=openpgp-sha256; l=813; i=vishal.l.verma@intel.com; h=from:subject:message-id; bh=P4hPdW8+bePoAaxzhoqscfaaJ238PGmVdQhKGufS+7Y=; b=owGbwMvMwCXGf25diOft7jLG02pJDMl7P9j/r16f9PzrvM5ly4XUb3J2ZxTtZuTbwnm5JnjBxVsp WVtndpSyMIhxMciKKbL83fOR8Zjc9nyewARHmDmsTCBDGLg4BWAiRnMZGbY/O7iLP3LWkt25mcxZ5f eeaIaI9LgWVXoeyTju12Q5SZmR4eP8cx/tX2y9N29qZ8x+Zp6HG753JGTNqzpbs/dos26DJysA X-Developer-Key: i=vishal.l.verma@intel.com; a=openpgp; fpr=F8682BE134C67A12332A2ED07AFA61BEA3B84DFF Precedence: bulk List-ID: X-Mailing-List: linux-cxl@vger.kernel.org Fix a typo: s/separted/separated/ Cc: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Alison Schofield --- cxl/region.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cxl/region.c b/cxl/region.c index 89be9b5..efe05aa 100644 --- a/cxl/region.c +++ b/cxl/region.c @@ -103,7 +103,7 @@ static const struct option destroy_options[] = { /* * Convert an array of strings that can be a mixture of single items, a - * command separted list, or a space separated list, into a flattened + * command separated list, or a space separated list, into a flattened * comma-separated string. That single string can then be used as a * filter argument to cxl_filter_walk(), or an ordering constraint for * json_object_array_sort()