Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp3311865rdh; Mon, 27 Nov 2023 10:53:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IExsFhm5ZUdg2BhBaul1m0e62Uwkxy3kAb3sc9JR1MbPB/RDEISPqNgAbm0ptMJw57Bk2Z3 X-Received: by 2002:aca:1c09:0:b0:3b6:b069:80f8 with SMTP id c9-20020aca1c09000000b003b6b06980f8mr13820823oic.52.1701111198653; Mon, 27 Nov 2023 10:53:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701111198; cv=none; d=google.com; s=arc-20160816; b=oeIpy1Q0fVxzNxBf64KDL7R+bL7bjlKbGPDPQPmxhIA8vyN9/pJafiHH73d6Xwg5Bt 1KZVN+gq+5nCCyXuyeGBBZXhCpmoGPEezKMGLVGkc8it52YbUOQx1tI8MTwv7eRVovMo e+uuO/lpVeYuAaOrrHScrPbiUvpQBwBT5Kk6AAiulCdvPnFjdlPCtPkPhCxIQaQLqw/G M7CUXEjCY83Xy6dUttDnp/3X6ZFbeb1Ky526cyE3gNG5EDBNt+Q715jZwlOfg1zyE83d 0wZvc+iGLSlvM4tcS/nQQdYnsPaLDwKTqOhXn1x0sFWutKqg6j/rfdGPnt8sYFIwj2Qv PZ+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TEGj3fs2ySS6aLIgRXBqIJnYag2jLlFIY+dcOKeZoO0=; fh=lcgkX3gSKg+C9MFv8z2bC5+7VXMYhKxZwUwm9UN+Oww=; b=oNiemOG5YJctj6R5cmti/4mGmBarQfSobNYyDDzt2auCO15/ShX2p+LaFap8hLoUPn 6GAWwJqQW2GVvEsDKXZzdkZJb8Zm3YwA1ThhOU5ZQf1z5ZDGMXYQovq8DBGm7T6jBJ1x B2evggZe4PMj5hDxT4CQ8A3+TtvtYDu4VB6xlKewgvrQqE0XofsF0Ery2/565C/3uinq O8bI02u2D6HZCnPb3vY2FHDlCRQeivDvzFK/XBk3dfIlqIK8cMcys8XB9XOWpx7eDCaw oYr7jkZ9MSp20ZbVTlj0AZ3fsuMFdYyj3Bl1zLvbomwdrvUEjy+bgUBS1eeaFU0GrRqC yoNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IwiI9jsK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id e25-20020a656899000000b005be10ed80d9si10455330pgt.177.2023.11.27.10.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Nov 2023 10:53:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=IwiI9jsK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 9C6688181B8F; Mon, 27 Nov 2023 10:53:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232521AbjK0Swn (ORCPT + 99 others); Mon, 27 Nov 2023 13:52:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37134 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231339AbjK0Swm (ORCPT ); Mon, 27 Nov 2023 13:52:42 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C2264D5A for ; Mon, 27 Nov 2023 10:52:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701111168; x=1732647168; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2N32HLIztMEKcqTYWVW9WXnQpGFYXa8KEDFLkMLSGiU=; b=IwiI9jsK5zpNcnZR7hLRSbf9NHn2IS0m4ZPnK3Z+ApULVI5qDRwiT9Je jpe+/YtsYmaUcUFGow8qr02DSofVqTPx71tmyL9Ei41jRBO7CHyLzWoMG bG0oNR94cp5tA30pMSiDkK2+vVkJvpUTwpqYGR/h1L7DmKX3SWzv5nf3T sP8XBTZVBd2+zRY2Jngb/UnjwqTDY447Z/dLVt1q5CwUj+CMtABSkDoe/ 9d4zWfgXLII+Efu5gEvXwIknyXeREMNpiUdW7EYqW7vpMOZxnDHHjqjcm O7jyl2MrFFTx8O/2V2O8VrCeTPc2HYtUE6Ix0LIflU1lJNSZHFZ/Za5HJ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="457099429" X-IronPort-AV: E=Sophos;i="6.04,231,1695711600"; d="scan'208";a="457099429" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Nov 2023 10:52:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10907"; a="772021666" X-IronPort-AV: E=Sophos;i="6.04,231,1695711600"; d="scan'208";a="772021666" Received: from jfdev013vml03.jf.intel.com ([10.165.161.72]) by fmsmga007.fm.intel.com with ESMTP; 27 Nov 2023 10:52:47 -0800 From: alexander.antonov@linux.intel.com To: peterz@infradead.org, linux-kernel@vger.kernel.org Cc: kan.liang@linux.intel.com, kyle.meyer@hpe.com, alexey.v.bayduraev@linux.intel.com, alexander.antonov@linux.intel.com Subject: [PATCH v2 1/2] perf/x86/intel/uncore: Fix NULL pointer dereference issue in upi_fill_topology() Date: Mon, 27 Nov 2023 10:52:45 -0800 Message-Id: <20231127185246.2371939-2-alexander.antonov@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231127185246.2371939-1-alexander.antonov@linux.intel.com> References: <20231127185246.2371939-1-alexander.antonov@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 27 Nov 2023 10:53:05 -0800 (PST) From: Alexander Antonov Get logical socket id instead of physical id in discover_upi_topology() to avoid out-of-bound access on 'upi = &type->topology[nid][idx];' line that leads to NULL pointer dereference in upi_fill_topology() Fixes: f680b6e6062e ("perf/x86/intel/uncore: Enable UPI topology discovery for Icelake Server") Reported-by: Kyle Meyer Tested-by: Kyle Meyer Signed-off-by: Alexander Antonov --- arch/x86/events/intel/uncore_snbep.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/events/intel/uncore_snbep.c b/arch/x86/events/intel/uncore_snbep.c index 8250f0f59c2b..49bc27ab26ad 100644 --- a/arch/x86/events/intel/uncore_snbep.c +++ b/arch/x86/events/intel/uncore_snbep.c @@ -5596,7 +5596,7 @@ static int discover_upi_topology(struct intel_uncore_type *type, int ubox_did, i struct pci_dev *ubox = NULL; struct pci_dev *dev = NULL; u32 nid, gid; - int i, idx, ret = -EPERM; + int i, idx, lgc_pkg, ret = -EPERM; struct intel_uncore_topology *upi; unsigned int devfn; @@ -5614,8 +5614,13 @@ static int discover_upi_topology(struct intel_uncore_type *type, int ubox_did, i for (i = 0; i < 8; i++) { if (nid != GIDNIDMAP(gid, i)) continue; + lgc_pkg = topology_phys_to_logical_pkg(i); + if (lgc_pkg < 0) { + ret = -EPERM; + goto err; + } for (idx = 0; idx < type->num_boxes; idx++) { - upi = &type->topology[nid][idx]; + upi = &type->topology[lgc_pkg][idx]; devfn = PCI_DEVFN(dev_link0 + idx, ICX_UPI_REGS_ADDR_FUNCTION); dev = pci_get_domain_bus_and_slot(pci_domain_nr(ubox->bus), ubox->bus->number, @@ -5626,6 +5631,7 @@ static int discover_upi_topology(struct intel_uncore_type *type, int ubox_did, i goto err; } } + break; } } err: -- 2.25.1