Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp310666rdb; Thu, 30 Nov 2023 05:37:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHd8ofRzG9bD3JY0zRqQfQCBrVmlwN3n0TOCYSxVZ1tNiamBOtnGws9FS28bCrwucVkA2Kj X-Received: by 2002:a17:90a:1947:b0:280:215e:8855 with SMTP id 7-20020a17090a194700b00280215e8855mr20381270pjh.21.1701351421199; 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=PG/vZbXIINXJNqg/uBO0Mh0+nuuwux8y/N7QED+GklgyiAtnUthMwT1RVsOXHSv+MF 4JC/3Qgr1c7JpArKQliVHgxzmOIoxm74tO0vb+j06c9xsWxPuQlH5GHQcYRk3d83RGJm ZVHBRalIFz9TzvFuwmoVdDoqEG7+wOMqOCtoDAnVGBrbJwu/6vRXJrDDcmIqo+immbYe RwLIqK9cqo1bzrwV6YKTYAP+Uq7qz3zK99j3YFIH0UaFDKLbVtUpwdZqHrEaRiIRsSxq hnzJzdD95fHGIlavuZWqukCpm5gXvHHSnssVtUKGBQLq4mEKFzTCXminR5Nbc5XwfH5q 9dpA== 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 header.s=2020e header.b=fuXRn3Ei; 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 Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id z21-20020a17090ad79500b00262e5a82047si399258pju.44.2023.11.30.05.37.00 (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 header.s=2020e header.b=fuXRn3Ei; 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 855E7826EE1B; Thu, 30 Nov 2023 05:36:58 -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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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:58 -0800 (PST) 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: