From nobody Mon Dec 23 10:06:50 2024 X-Original-To: dev-commits-src-main@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 4YGtwW1NzFz5gXlB; Mon, 23 Dec 2024 10:06:51 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YGtwW0q0fz4F4C; Mon, 23 Dec 2024 10:06:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734948411; 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=V2NAoj5EZCHg0x9tzo7mWFOI1pWSKMBQ7mMicBO/ZXc=; b=kEOJ9tsNa0BxVpCL2grj5dmRI19mkHlotPYy7Ty1Af+C53FwT+WOFwr0nLr4dcjSYkec7B +2MFe9xn1VAP8nsSMX6+LM5AlxhagkHiwU221516nJ9YRzK7sJfaOsrZLew6FuXjbxfe6k KRCPbezMPH3F+6REcBhP/KVyxDEjKCusiwQ32t3A0jilmE5FckqTEwHLWFsgXIfXMM+ymI X9qTWOFUWFfQlegOOII5smy3VPGzOjE4sq98f8XwR+ld6ciLgmidLqcteU/zR2jaxuOPDp eVldKvDdFVS/reQctneAKyXBsB7BtQUjU4ZFSOGbSVIeIbTqG1BeJu1d9yZcMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734948411; 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=V2NAoj5EZCHg0x9tzo7mWFOI1pWSKMBQ7mMicBO/ZXc=; b=qiEBZHk9WGY9NJUpWM85LKb19zftL8J7CmC8fppDxzReqZOF2D39TS9KqDbPeSB031Frmr pXy8dCYkG/0LMA985OHW4uhJrG/ETq7RfG3hUCUH+UJaoav7RMrxBK1BKTcYF/rdYEGkTf fFV0EPUEcvYiMkyOUQPHciRE5DIAHufA6iLrAoovYxgZHrvhUKiTYxwmshMWZkfw9zn3OW JKLhiQxRt5Lu/Xry9iOHb8j37ZMJuK5DCUk3uViNgqJXiy3Jc1kaUTj1/HyeEA6LdApwWQ MBrtIHxCRioERyYwlaK2UTqZf4bgKshSottOIrv7L8XFnjV/RRN8Y5UMJuunBQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734948411; a=rsa-sha256; cv=none; b=fuWnr7/i23B6NFtXW67UxV60dZMuKvgoE61y5pdItJ4BJFYO63koMvIjqqvuJzxGFQ8Wqq XwtY/G0cGAUudL66qUdPXdkq0zHc7ZN2lCnf84PPIPazpRHxh9uTeM6FQX/l/gd9ydU3us 92ujWWhswZ10yW02oA3eVhwnlRCa7P0nWzCeKfLRuTUhMzG9hSuLXefALTkLgenFCKLY0Q d0RdOzwKCpfhRd9jktFlM4227kZwBIoPdMpPjdwHWfJ19MjuS0u5CeRw0WL1O5F22c/XQ8 N41iXgTk+eGLoC+NLVMXESXdjs6RkZB5pelzlkxY0Ilpp9BS1dEPJBH6Jinejg== 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 4YGtwW02Gjzpqk; Mon, 23 Dec 2024 10:06:51 +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 4BNA6o5n074066; Mon, 23 Dec 2024 10:06:50 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BNA6o0r074063; Mon, 23 Dec 2024 10:06:50 GMT (envelope-from git) Date: Mon, 23 Dec 2024 10:06:50 GMT Message-Id: <202412231006.4BNA6o0r074063@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Bojan =?utf-8?Q?Novkovi=C4=87?= Subject: git: 6e8233df18c8 - main - hwpmc_x86: Fix NULL deref when loading on unsupported hardware List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bnovkov X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6e8233df18c8008e1a244c8528521a0369f61369 Auto-Submitted: auto-generated The branch main has been updated by bnovkov: URL: https://cgit.FreeBSD.org/src/commit/?id=6e8233df18c8008e1a244c8528521a0369f61369 commit 6e8233df18c8008e1a244c8528521a0369f61369 Author: Bojan Novković AuthorDate: 2024-12-21 10:55:57 +0000 Commit: Bojan Novković CommitDate: 2024-12-23 10:00:57 +0000 hwpmc_x86: Fix NULL deref when loading on unsupported hardware The pmc_md_{intialize, finalize} routines rely on a machine-dependent structure to register the appropriate PMC interrupt handler. However, the vendor-specific routines that allocate this structure may return NULL for unsupported hardware, leading to a panic when the hwpmc module gets loaded. This patch adds additional checks that fix this issue. Reported by: Michael Butler (imb@protected-networks.net) Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D48168 --- sys/dev/hwpmc/hwpmc_x86.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/sys/dev/hwpmc/hwpmc_x86.c b/sys/dev/hwpmc/hwpmc_x86.c index 2c6c4cd148bf..2903c25ef5c9 100644 --- a/sys/dev/hwpmc/hwpmc_x86.c +++ b/sys/dev/hwpmc/hwpmc_x86.c @@ -230,7 +230,7 @@ struct pmc_mdep * pmc_md_initialize(void) { int i; - struct pmc_mdep *md; + struct pmc_mdep *md = NULL; /* determine the CPU kind */ if (cpu_vendor_id == CPU_VENDOR_AMD || @@ -238,17 +238,18 @@ pmc_md_initialize(void) md = pmc_amd_initialize(); else if (cpu_vendor_id == CPU_VENDOR_INTEL) md = pmc_intel_initialize(); - else + + if (md == NULL) return (NULL); + nmi_register_handler(md->pmd_intr); /* disallow sampling if we do not have an LAPIC */ - if (md != NULL && !lapic_enable_pcint()) + if (!lapic_enable_pcint()) for (i = 0; i < md->pmd_nclass; i++) { if (i == PMC_CLASS_INDEX_SOFT) continue; md->pmd_classdep[i].pcd_caps &= ~PMC_CAP_INTERRUPT; } - nmi_register_handler(md->pmd_intr); return (md); } @@ -256,9 +257,10 @@ pmc_md_initialize(void) void pmc_md_finalize(struct pmc_mdep *md) { - - lapic_disable_pcint(); - nmi_remove_handler(md->pmd_intr); + if (md != NULL) { + lapic_disable_pcint(); + nmi_remove_handler(md->pmd_intr); + } if (cpu_vendor_id == CPU_VENDOR_AMD || cpu_vendor_id == CPU_VENDOR_HYGON) pmc_amd_finalize(md);