From nobody Tue Jan 07 15:35:25 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 4YSFVk2D0yz5kkkl; Tue, 07 Jan 2025 15:35:26 +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 4YSFVk1RvVz4RbZ; Tue, 7 Jan 2025 15:35:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736264126; 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=C7zBORBgVVN+CjiO0a9cXorC0Fr9ambzcqniVg3wJ9g=; b=GNkApk2AAc/EhLYWv8MkXK21XNiG5OKA/tilvyKvLZDb1+Zz6CQfSdcXK10UIW6BW4ysUs XKAM4T0hxBSNgtA91v0zvQyr/D2Hs7NH3ly2sOHR/ixeJ/cn1ihADEBInSric+f9RRaSoa 9X8SPqbXO7R1F+h9rem72zFLs4oS+7sXbXtwIYVk8AktNdGL/WxblHtUsVqiOlfUCzGv8E dyNRBbA60oWseZYOMSRggVv/qtD23fsQl+c65Y5LgNxZNVvsWbDJzvVir0XZK0khYtAlgj Cv0ylVAO1DtO49uEjMocPDIwRaGywjNkUJPt8xE0BgzNxMwJp2zHJ5hmDQFF7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1736264126; 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=C7zBORBgVVN+CjiO0a9cXorC0Fr9ambzcqniVg3wJ9g=; b=vm3N41c9Y9ZK1kJPxLcLx7lNg628h3RjSny0m4v1NKEmKtoRn3zWit3bP3IRK1ggAOWBgj mHeQPB3Llw72pY5s9TbNgSqnccZRd0zqWlN+lkSBU1tjVz76w5Lcti2g0uBvQeuJ+KQ1hA HVYZKYxF6iBfd0j06R1ZUiPvfTAMIhe7J324e8tAL+V4Pbl7tPhFW/T8MdvaxM9WcJF5Tz khPatb6k+/tHJdFQW2rAzqbpFale+Q0uEdvSHY0fMM0PvnUSk2nI0nAc8N3qla/n2CxBdo 9G4lse2455uVzzVYKUsq/wlHH6FGLnlVCT4OSg2UBB+ZhrzWV/0GFBoX8qhnIA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1736264126; a=rsa-sha256; cv=none; b=UgNfb9dp2N0iAvHqjPcCnh7+ZoKvVz/tzzqdaJt82EWnm5N64nBD/eQERvs1GTaGHJsRtB sMEfiln7scpTrp38IU/yvrcwCyoSsxhNthoePS3oAiotWUE19Eybsk8S0oDqS2265PnKjK OKYFdS4KYhoPaYxTDKB7dO0z68bTXE194ro104a1rACfDy54U5G8WrnkZbDe1rvyK9r5hH wH8BaTLfglwUbZ3xXna7VKGEGYkcQTI2UJXs/1FEjFrFcURmanuIBmzkJ6R8wVLuvIYn0E +dPB6jCI8Mzf1Y205SHzxUzjj/jfWHbaxhdTWeevc9cfss1oXip/Tic6Qu/A+Q== 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 4YSFVk12KRz1H6; Tue, 07 Jan 2025 15:35:26 +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 507FZP9C029067; Tue, 7 Jan 2025 15:35:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 507FZPJv029064; Tue, 7 Jan 2025 15:35:25 GMT (envelope-from git) Date: Tue, 7 Jan 2025 15:35:25 GMT Message-Id: <202501071535.507FZPJv029064@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 6ba2c036a011 - main - 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/main X-Git-Reftype: branch X-Git-Commit: 6ba2c036a0117ac02f9979b7dc49f15e9c1ea9c9 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=6ba2c036a0117ac02f9979b7dc49f15e9c1ea9c9 commit 6ba2c036a0117ac02f9979b7dc49f15e9c1ea9c9 Author: Konstantin Belousov AuthorDate: 2025-01-06 23:29:18 +0000 Commit: Konstantin Belousov CommitDate: 2025-01-07 15:34:59 +0000 pci_find_cap_method(): limit number of iterations for finding a capability Powered down device might return 0xff of extended config registers reads, causing loop. PR: 283815 Reviewed by: imp Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D48348 --- 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 cf01115581e1..0b02d873c5a1 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -1519,6 +1519,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. @@ -1545,9 +1546,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;