From patchwork Tue Aug 23 07:45:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 12951816 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 E2F90C32793 for ; Tue, 23 Aug 2022 07:45:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231827AbiHWHpj (ORCPT ); Tue, 23 Aug 2022 03:45:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241195AbiHWHpd (ORCPT ); Tue, 23 Aug 2022 03:45:33 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EA8B6110A for ; Tue, 23 Aug 2022 00:45:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661240732; x=1692776732; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=86SwdVxA7TMFpmryejfDk5NOkDpXUJW5f4die9B9dY0=; b=V6WECukLOwH9NtuLosK2loG95uhp9iFGUrhIO0xmMhpKixTubLFoHYcW 5jLAXvPgNpLwX+ND38RKGVUO9ipkKJMH8cjzDdwyc6Rk0A7Q140HGX5LP aElUVxBuxyB48Vw3CIUhc1M3wiKutDxez1y5TIRGZ2iLKely4+yPb6bwl La04C3B7QIo8Om07WAhfjhdSuHYXo0o/VopVnND45a7OxJQbflVvtZZ5T KLvVpenY4wovhjrnEaw8xp6sze+BVuJt+Z+pkyGeWric7fV3E2onoVd3L k/yuBCGbCJpv2j4ScffiVEnV+rywzOe5QWoOiDAhGVdPFyPjcGTJumN4+ A==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="280590970" X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="280590970" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:45:31 -0700 X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="609254280" Received: from skummith-mobl1.amr.corp.intel.com (HELO vverma7-desk1.intel.com) ([10.212.54.206]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:45:31 -0700 From: Vishal Verma To: Cc: , Dan Williams , Vishal Verma Subject: [ndctl PATCH v2 1/3] cxl/region: fix a dereferecnce after NULL check Date: Tue, 23 Aug 2022 01:45:25 -0600 Message-Id: <20220823074527.404435-2-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823074527.404435-1-vishal.l.verma@intel.com> References: <20220823074527.404435-1-vishal.l.verma@intel.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1092; h=from:subject; bh=86SwdVxA7TMFpmryejfDk5NOkDpXUJW5f4die9B9dY0=; b=owGbwMvMwCXGf25diOft7jLG02pJDMksrdNOqVVaba4I4r7asfpm9O6cndzzq7nE7/8+6y45815v wpZDHaUsDGJcDLJiiix/93xkPCa3PZ8nMMERZg4rE8gQBi5OAZjI9okMfwW1vZ5IMrSe/zufR6ea+9 nDtcXuhz3/CJx1mnZd1cLTjoPhf7aJmpfBvNpNjPPXymoosq+z2BexfOnVAyw5bw+6c0mY8AEA 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 A NULL check in region_action() implies that 'decoder' might be NULL, but later we dereference it during cxl_decoder_foreach(). The NULL check is valid because it was the filter result being checked, however, while doing this, the original 'decoder' variable was being clobbered. Check the filter results independently of the original decoder variable. Cc: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Dan Williams Reviewed-by: Dave Jiang --- cxl/region.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cxl/region.c b/cxl/region.c index a30313c..334fcc2 100644 --- a/cxl/region.c +++ b/cxl/region.c @@ -686,9 +686,8 @@ static int region_action(int argc, const char **argv, struct cxl_ctx *ctx, continue; cxl_decoder_foreach (port, decoder) { - decoder = util_cxl_decoder_filter(decoder, - param.root_decoder); - if (!decoder) + if (!util_cxl_decoder_filter(decoder, + param.root_decoder)) continue; rc = decoder_region_action(p, decoder, action, count); if (rc) From patchwork Tue Aug 23 07:45:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 12951817 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 DFAEDC32789 for ; Tue, 23 Aug 2022 07:45:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240751AbiHWHpk (ORCPT ); Tue, 23 Aug 2022 03:45:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241198AbiHWHpd (ORCPT ); Tue, 23 Aug 2022 03:45:33 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51481642F1 for ; Tue, 23 Aug 2022 00:45:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661240733; x=1692776733; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/9z/gQg3nRurW7/yKCKgoDtKwuWnKKZassG/KM8FQgQ=; b=g/VQuU2j4Tl8l82OiuF5DAawXywUyyl8xsLFQJ4UY/G3NrnxTNobfHZU ap9a4bn7l9vM1QrwRznJy6UQGAoFHtSBHNs6xPvhJ2WdZUobrvqlwBz8F 69ddWNqkWv9QGAPaYLNPB94oHBHCxRF/aIB4PMoWCCLPbiqnVcFY5Spla WwigEqqfePe7b+FoPJCvMaNbzCQ/Ed9l35DMSawtnVRVBu1WRBdVsT4iH COe8yXgpYpg8pEuHLjWql8AkoAunCe6YSCx4IVy0UhUjXTRx8HSGxSyZG G+S1t/HT+5oRXIwPcEOghJtY0h9hkd++Z96qM+1MR4MVDzOYxKIAL8mf6 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="280590975" X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="280590975" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:45:32 -0700 X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="609254286" Received: from skummith-mobl1.amr.corp.intel.com (HELO vverma7-desk1.intel.com) ([10.212.54.206]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:45:31 -0700 From: Vishal Verma To: Cc: , Dan Williams , Vishal Verma Subject: [ndctl PATCH v2 2/3] libcxl: fox a resource leak and a forward NULL check Date: Tue, 23 Aug 2022 01:45:26 -0600 Message-Id: <20220823074527.404435-3-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823074527.404435-1-vishal.l.verma@intel.com> References: <20220823074527.404435-1-vishal.l.verma@intel.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1260; h=from:subject; bh=/9z/gQg3nRurW7/yKCKgoDtKwuWnKKZassG/KM8FQgQ=; b=owGbwMvMwCXGf25diOft7jLG02pJDMksrdOaby6tVC0KOGu4b4ntucdlXALP7nBtN6q5pzJl+mOt tNlJHaUsDGJcDLJiiix/93xkPCa3PZ8nMMERZg4rE8gQBi5OAZjI7DcM/1QSxKbuucf87o6XxbNA7R fvZG04avl/BjFai5k5X+Bvz2dkWCd/bL96nHE/D1s0q9DlnGV3onwXbHi1qSXi6HOF3xvn8gAA 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 a couple of issues in add_cxl_region(). Firstly, 'path' wasn't freed in the success case, only in the error case. Secondly, the error handling after 'calloc()'ing the region object erroneously jumped to the error path which tried to free the region object. Add anew error label to just free 'path' and return for this exit case. Cc: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Dan Williams Reviewed-by: Dave Jiang --- cxl/lib/libcxl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c index 021d59f..e8c5d44 100644 --- a/cxl/lib/libcxl.c +++ b/cxl/lib/libcxl.c @@ -482,7 +482,7 @@ static void *add_cxl_region(void *parent, int id, const char *cxlregion_base) region = calloc(1, sizeof(*region)); if (!region) - goto err; + goto err_path; region->id = id; region->ctx = ctx; @@ -551,11 +551,13 @@ static void *add_cxl_region(void *parent, int id, const char *cxlregion_base) list_add_sorted(&decoder->regions, region, list, region_start_cmp); + free(path); return region; err: free(region->dev_path); free(region->dev_buf); free(region); +err_path: free(path); return NULL; } From patchwork Tue Aug 23 07:45:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Verma, Vishal L" X-Patchwork-Id: 12951818 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 6C738C3F6B0 for ; Tue, 23 Aug 2022 07:45:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241066AbiHWHpj (ORCPT ); Tue, 23 Aug 2022 03:45:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241208AbiHWHpf (ORCPT ); Tue, 23 Aug 2022 03:45:35 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EA116069C for ; Tue, 23 Aug 2022 00:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661240735; x=1692776735; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8rJ8gEEBtVLYGXTt1L5arjJ8aeJKmNlD+4PYtRRCVes=; b=I9hT4zIgRBMFiT5iqJAYXsHYuS+E7xVe4U6m2RT8rIribp+CXhZym0NS vGHhRz9FsYrehl6MDLISfc/M0tJoo0x5e9kxHJtY8RYgwacVHVvb0fZxO 0QZ2CjEQv6pfEsPtYBvB4IsuhpQWctBvTuq7WlfrAONRWMyc2sgrbm1UG tu9JEE3GsuJLKSIh1xoyyb+xDcbmwfpXKnXFw4fSA2LqTJvYixKm+2vJo q+PaaHKqhQzFHiMzyxZ+S3fS37OlJcu/0vWD3xVVbVvHPvi54FNmwkCj5 s44tArhgYYt052HhOBfdU3Fyj/gc8cFYoNA9Fr5JMYepXoRHy8UkYQx81 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10447"; a="280590978" X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="280590978" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:45:32 -0700 X-IronPort-AV: E=Sophos;i="5.93,256,1654585200"; d="scan'208";a="609254291" Received: from skummith-mobl1.amr.corp.intel.com (HELO vverma7-desk1.intel.com) ([10.212.54.206]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Aug 2022 00:45:32 -0700 From: Vishal Verma To: Cc: , Dan Williams , Vishal Verma Subject: [ndctl PATCH v2 3/3] cxl/filter: Fix an uninitialized pointer dereference Date: Tue, 23 Aug 2022 01:45:27 -0600 Message-Id: <20220823074527.404435-4-vishal.l.verma@intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823074527.404435-1-vishal.l.verma@intel.com> References: <20220823074527.404435-1-vishal.l.verma@intel.com> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=837; h=from:subject; bh=8rJ8gEEBtVLYGXTt1L5arjJ8aeJKmNlD+4PYtRRCVes=; b=owGbwMvMwCXGf25diOft7jLG02pJDMksrdM3rpzD9XiPz/5/vlEpvj4ZhrEnntescBLlLH+lvv2L 0NGTHaUsDGJcDLJiiix/93xkPCa3PZ8nMMERZg4rE8gQBi5OAZiIyiOG/wX/NYz45jFHbWr5+WSb+n OdS7/OXvjpeWjSLc3QKTH7Za4x/JXbVLHZoVGZ7/kyYz+B535NvI8U37H1mP8scRNc++L1CyYA 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 points out that there was a chance that 'jdecoder' could be used while uninitialized in walk_decoders(). Initialize it to NULL to avoid this. Cc: Dan Williams Signed-off-by: Vishal Verma Reviewed-by: Dan Williams Reviewed-by: Dave Jiang --- cxl/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cxl/filter.c b/cxl/filter.c index 9a3de8c..56c6599 100644 --- a/cxl/filter.c +++ b/cxl/filter.c @@ -796,7 +796,7 @@ static void walk_decoders(struct cxl_port *port, struct cxl_filter_params *p, cxl_decoder_foreach(port, decoder) { const char *devname = cxl_decoder_get_devname(decoder); struct json_object *jchildregions = NULL; - struct json_object *jdecoder; + struct json_object *jdecoder = NULL; if (!p->decoders) goto walk_children;