From nobody Tue Jan 14 08:57:17 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4YXNL55W48z5kPWq; Tue, 14 Jan 2025 08:57:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YXNL53RKjz42MT; Tue, 14 Jan 2025 08:57:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736845037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NEqgrSCqKDrusFBilzYTmEJpfXFQ6/Q7sY53tSYtB40=; b=Dv8PTF68NUffqGhUK8iviENrtTbDzqdv19ITgTw8UerXWios4G60nL8c4qT10rcZl7CuFu kyl1XzlrYRzDrcTPpjQiZxqfHhvS90twm820Rse/lxP/Duep1kClhtjMQK4WfNy0wyERoc sM2OB7LdGikUa4abNOiaZtzb0T/KZ5jHtbBu39dWgy5BJExpfOULV1YIADtytkIDojKvFF uZJnxlqkGn2OyOB9ejrQxCQYUf3vtb6CnS+nYyTs1Gz5+yL+FEWE/HEPjqngYESDYgjg72 uofJjKkOVNdAZjRG7n09bI9izg1awb/cGfkhSu83UCMNsvEPW9X6WMrCZRIwmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736845037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NEqgrSCqKDrusFBilzYTmEJpfXFQ6/Q7sY53tSYtB40=; b=LkG1wDoE567vV3rpWsoCCumSt4H+wvPaiD/ZXqy/tmVzLl2WMdvStEaLYu5UHpJqfWMEkd 4rI7Fe5isoR7sUUTAJTipBVDDEeVKRzA2P01f3J7Y4OGFmmEIe1V39msL07nDMfsKQijbm BkR3t1sbySsq3Z8qrqdaNOcIe20eh3tkfv6bmeU8iO7njTvPF99LEAcCmdBko7o1wMPk2o 4bMmQWx3C5+BwIxhsQZwxEb3fB3eWPneU4JTa+dTSH//jrPEmpfjgH/4ds9m5Hilo1XR2C 3BqJnCkPqomNWugGWIVdkMcyIPvAR3Q8fbf2axa6HvbhId/ajfYXzH3QsVNB+g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736845037; a=rsa-sha256; cv=none; b=NK5wdZCxtepBEgqpCNogrE8XjN1z6WF2hLfpcAFaA0KYq78qKRF3002c51/dTXjO4duthh lkyZZa3WtWmwrLsywtkwuAiMfKiYjEDahMMnZA0dL3ewEIMZ261ywLZ1MXCFWRShNTnzx5 WEbNFJsWIDCddDhD6IuEKo7AeumNK4EQPK28NihaCY+SdAGuLmi7HC/lmV4gWK9QiTwuIG 1Wfv1If14F05tY+8ZG2ULjKcJdJ9eBEnz3SA874x/UvPxDHocEaDddMetPA/0nJL7b3w6b /pb0mciCcUQWTqKvPqoO6cmLaJWbacZMnjQjjqNIBXe3/KefGO36qD0iizAkow== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4YXNL52yVmz18n7; Tue, 14 Jan 2025 08:57:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50E8vHRf059007; Tue, 14 Jan 2025 08:57:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50E8vHZu059004; Tue, 14 Jan 2025 08:57:17 GMT (envelope-from git) Date: Tue, 14 Jan 2025 08:57:17 GMT Message-Id: <202501140857.50E8vHZu059004@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: df3796cc68fc - stable/14 - pci_find_cap_method(): limit number of iterations for finding a capability List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: df3796cc68fc22fc164049ca25c45f646581203a Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=df3796cc68fc22fc164049ca25c45f646581203a commit df3796cc68fc22fc164049ca25c45f646581203a Author: Konstantin Belousov AuthorDate: 2025-01-06 23:29:18 +0000 Commit: Konstantin Belousov CommitDate: 2025-01-14 08:56:41 +0000 pci_find_cap_method(): limit number of iterations for finding a capability PR: 283815 (cherry picked from commit 6ba2c036a0117ac02f9979b7dc49f15e9c1ea9c9) --- sys/dev/pci/pci.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c index 8236b8bde41a..1a415f676ff7 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -1513,6 +1513,7 @@ pci_find_cap_method(device_t dev, device_t child, int capability, pcicfgregs *cfg = &dinfo->cfg; uint32_t status; uint8_t ptr; + int cnt; /* * Check the CAP_LIST bit of the PCI status register first. @@ -1539,9 +1540,11 @@ pci_find_cap_method(device_t dev, device_t child, int capability, ptr = pci_read_config(child, ptr, 1); /* - * Traverse the capabilities list. + * Traverse the capabilities list. Limit by total theoretical + * maximum number of caps: capability needs at least id and + * next registers, and any type X header cannot contain caps. */ - while (ptr != 0) { + for (cnt = 0; ptr != 0 && cnt < (PCIE_REGMAX - 0x40) / 2; cnt++) { if (pci_read_config(child, ptr + PCICAP_ID, 1) == capability) { if (capreg != NULL) *capreg = ptr;