From patchwork Thu Nov 30 13:36:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 171883 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp390874vqy; Thu, 30 Nov 2023 05:37:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+YuAJfJmr20yHKiXoEVQxKSGlLuc11+MDBh2PO44Ji+hqOBRMTcy5NDn6Bm+oHsBWbVMV X-Received: by 2002:a17:903:2286:b0:1cf:ba46:e402 with SMTP id b6-20020a170903228600b001cfba46e402mr18465791plh.54.1701351421206; Thu, 30 Nov 2023 05:37:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701351421; cv=none; d=google.com; s=arc-20160816; b=Ws7DBuLQwk9DEPqlIzwitpjomkUWEZeZINwIwFWsC/91l/tArWDUMPxI9VMiZaDy4L wnogUvU8ynB47Tu5Xb9/FiH9KquZchkPSHqROFW0SPEMnduQteoU7O5Z7D6CnaGi2yCY kLGPur0VsoYoPvudnp4Z83iWLlbij+flR2vyK60lFDWssuOu6hQM10u2gPl8oNURjOk4 xhb6ZfdSullthxTsve6Ajhywv8Hqk7SQe8XLknwhPjHafvSvM5a1whrNXExPtIdxjd7r 0ioDU1ppWHh9ym7A8FFAXHxrUW2OrRbNNDX42UvGV/DWNeBKXcvlITp6h0cLscgYPueL 3b9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=6K7kd2z3kKnUokpb+0NcJO6tvamF5TDjcjebi3KIdqc=; fh=vH2I44YxRvQH5UJVl6OKVp3U37bxS3ItXYxtwSPOSZY=; b=xz22FJEoLEbD6XBntiRCDb6wul2KKCPm5bdrTm2h5Ltnc8/LZ6FlvRDozAj9SaDOTX 6qz4JZy4vco1JZN0C2QhGO3iRUUm+5spAIo/5C5aSuT2/ZGyyeJe+fB8XZV0/Q6/WHBZ lC2EHKSqGi+z/BkewDc3giizjPC5cJl1TQwEgM4u00ux5nzVWBKar52bEWJELNFV3Cs0 5VRm0fPIP++3lLRcSQgJ8SZsyK8NRtuyHxC4xCRj5A6QkhK99svBwHX516dwgtEs3o4C 41lWebmGEK4kbcnICPZDc8/yOCW/2BvOvTmDv8wFkjsbAWAfQEAgk72z6ccNyQJakLGP 3eiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=iEQD2jW+; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id p7-20020a1709028a8700b001c383a64ebesi1157614plo.319.2023.11.30.05.36.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 05:37:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=iEQD2jW+; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id CB1E8826EE18; Thu, 30 Nov 2023 05:36:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345607AbjK3Ngh (ORCPT + 99 others); Thu, 30 Nov 2023 08:36:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345581AbjK3Ngf (ORCPT ); Thu, 30 Nov 2023 08:36:35 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1232790; Thu, 30 Nov 2023 05:36:41 -0800 (PST) Date: Thu, 30 Nov 2023 13:36:39 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1701351400; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6K7kd2z3kKnUokpb+0NcJO6tvamF5TDjcjebi3KIdqc=; b=iEQD2jW+DhKq7megFOrR7h4hOkpEvBpmbGC4TLamh8x5nyKYRvh4T0wM5VceYBMg/LDKqc lVr/GAgVLbYsIQGKHzYmLcK5gDtBtkrt80HNC0o80Q3MjpYYkgl9KuO0CoICQNAe1laa1I K1VYV47Shsa5O+3BNYT2R4NG8VsBpQ+bx0yd2p6g/azqQ4MPwY1R3nVC9AO3ZUDvdmnGyl vPCf5QXUUkq51rTAoASi9qqoxZdb4kCCmFEqMBMJq0gzbSV/E57KQecxzG9MM0I0Fngu/B g12XFIng4bbAeSr8HdXTVVd4QJzhvtwq3BW4FIccGf4YR2rYmxEozW0c9RsDIw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1701351400; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6K7kd2z3kKnUokpb+0NcJO6tvamF5TDjcjebi3KIdqc=; b=fuXRn3EiFJ+BulRBIxVFbwLX6fGXfv737gRrWs7PLVCO8qv1biZrWZq2HR66EWOarAYe6u L/GZwf8dKpZButDQ== From: "tip-bot2 for Alexander Antonov" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: perf/core] perf/x86/intel/uncore: Fix NULL pointer dereference issue in upi_fill_topology() Cc: Kyle Meyer , Alexander Antonov , "Peter Zijlstra (Intel)" , Kan Liang , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231127185246.2371939-2-alexander.antonov@linux.intel.com> References: <20231127185246.2371939-2-alexander.antonov@linux.intel.com> MIME-Version: 1.0 Message-ID: <170135139956.398.13686814243901771133.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 30 Nov 2023 05:36:54 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783744357836366008 X-GMAIL-MSGID: 1783996267971703089 The following commit has been merged into the perf/core branch of tip: Commit-ID: 1692cf434ba13ee212495b5af795b6a07e986ce4 Gitweb: https://git.kernel.org/tip/1692cf434ba13ee212495b5af795b6a07e986ce4 Author: Alexander Antonov AuthorDate: Mon, 27 Nov 2023 10:52:45 -08:00 Committer: Peter Zijlstra CommitterDate: Thu, 30 Nov 2023 14:29:52 +01:00 perf/x86/intel/uncore: Fix NULL pointer dereference issue in upi_fill_topology() 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 Signed-off-by: Alexander Antonov Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Kan Liang Tested-by: Kyle Meyer Link: https://lore.kernel.org/r/20231127185246.2371939-2-alexander.antonov@linux.intel.com --- 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 aeaa8ef..1efbacf 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: