From patchwork Thu Oct 1 19:38:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 11812381 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 D2C9413B2 for ; Thu, 1 Oct 2020 19:38:30 +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 8131C20759 for ; Thu, 1 Oct 2020 19:38:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8131C20759 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.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 5D757156349CD; Thu, 1 Oct 2020 12:38:30 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=vishal.l.verma@intel.com; receiver= Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 D2BB0155D74E9 for ; Thu, 1 Oct 2020 12:38:26 -0700 (PDT) IronPort-SDR: E8Lq29IfNFzMTNlDPFdKZeZCkjt/X71xw9WI2jyIeiyXLziTg3x1wkynl2ctvWyT4pPPN8skpd 5wWcyQ8obSDw== X-IronPort-AV: E=McAfee;i="6000,8403,9761"; a="226944931" X-IronPort-AV: E=Sophos;i="5.77,324,1596524400"; d="scan'208";a="226944931" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2020 12:38:23 -0700 IronPort-SDR: EaJqXmGt5JpOurRC0SA1mqsWyvOeuKAeeD1r9El4O+yaXt9i1xNAHzbC4gvxl+SL5Fuslyc6Vu Aty6llrqNvIA== X-IronPort-AV: E=Sophos;i="5.77,324,1596524400"; d="scan'208";a="351279749" Received: from loppedah-mobl.amr.corp.intel.com (HELO omniknight.intel.com) ([10.212.30.3]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2020 12:38:22 -0700 From: Vishal Verma To: Cc: Dan Williams , Vishal Verma Subject: [ndctl PATCH 1/2] libndctl: fix a potential buffer overflow Date: Thu, 1 Oct 2020 13:38:15 -0600 Message-Id: <20201001193816.975987-1-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Message-ID-Hash: ZMJO6ZCWLRAKSNZ3544FUVXG5OOWITF2 X-Message-ID-Hash: ZMJO6ZCWLRAKSNZ3544FUVXG5OOWITF2 X-MailFrom: vishal.l.verma@intel.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 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: Static analysis points out that the 'buf' in ndctl_dimm_is_active was inappropriately sized. We already have 'SYSFS_ATTR_SIZE' for such buffers, and it looks like this was just an oversight. Fixes: 0a4509d7de2f ("ndctl: enumerate interleave sets") Cc: Dan Williams Signed-off-by: Vishal Verma --- ndctl/lib/libndctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c index 6556b33..5546963 100644 --- a/ndctl/lib/libndctl.c +++ b/ndctl/lib/libndctl.c @@ -3675,8 +3675,8 @@ NDCTL_EXPORT int ndctl_dimm_is_active(struct ndctl_dimm *dimm) { struct ndctl_ctx *ctx = ndctl_dimm_get_ctx(dimm); char *path = dimm->dimm_buf; + char buf[SYSFS_ATTR_SIZE]; int len = dimm->buf_len; - char buf[20]; if (snprintf(path, len, "%s/state", dimm->dimm_path) >= len) { err(ctx, "%s: buffer too small!\n", From patchwork Thu Oct 1 19:38:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 11812379 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 0D17E139A for ; Thu, 1 Oct 2020 19:38:30 +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 94E4620759 for ; Thu, 1 Oct 2020 19:38:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 94E4620759 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.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 2F5AD155D74EB; Thu, 1 Oct 2020 12:38:29 -0700 (PDT) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=vishal.l.verma@intel.com; receiver= Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 C12D5155D74E9 for ; Thu, 1 Oct 2020 12:38:26 -0700 (PDT) IronPort-SDR: KJMqu4Y4pmLhmq+rQmOxcCOSkYSX1/U9EjuJN9k1FVWW7IaLmpiEkeQGCXWrXStoqz0h2JPpZC 9pHrf9FSs9ow== X-IronPort-AV: E=McAfee;i="6000,8403,9761"; a="226944934" X-IronPort-AV: E=Sophos;i="5.77,324,1596524400"; d="scan'208";a="226944934" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2020 12:38:23 -0700 IronPort-SDR: eKgkDWww0mzeNYx2OhFK+78ELAwMQs75cTF2UIhoXQyFR9A6Jz1bP9nd0EBPArQ6c0GlQDrGdw dGHjkOV39OVw== X-IronPort-AV: E=Sophos;i="5.77,324,1596524400"; d="scan'208";a="351279753" Received: from loppedah-mobl.amr.corp.intel.com (HELO omniknight.intel.com) ([10.212.30.3]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2020 12:38:23 -0700 From: Vishal Verma To: Cc: Dan Williams , Vishal Verma Subject: [ndctl PATCH 2/2] ndctl/inject-error: remove logically dead code Date: Thu, 1 Oct 2020 13:38:16 -0600 Message-Id: <20201001193816.975987-2-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201001193816.975987-1-vishal.l.verma@intel.com> References: <20201001193816.975987-1-vishal.l.verma@intel.com> MIME-Version: 1.0 Message-ID-Hash: DJLG3EUYUWBSQ3UZPXC5O5SETTACIXIV X-Message-ID-Hash: DJLG3EUYUWBSQ3UZPXC5O5SETTACIXIV X-MailFrom: vishal.l.verma@intel.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 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: Static analysis reports that the bb != NULL check is redundant because ndctl_namespace_bb_foreach already uses that as a loop condition. Remove it. Signed-off-by: Vishal Verma --- ndctl/inject-error.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/ndctl/inject-error.c b/ndctl/inject-error.c index fe599ef..f6be6a5 100644 --- a/ndctl/inject-error.c +++ b/ndctl/inject-error.c @@ -255,9 +255,6 @@ static int injection_status(struct ndctl_namespace *ndns) } ndctl_namespace_bb_foreach(ndns, bb) { - if (!bb) - break; - block = ndctl_bb_get_block(bb); count = ndctl_bb_get_count(bb); jbb = util_badblock_rec_to_json(block, count, ictx.json_flags);