git: 8399d923a569 - main - hwpmc_intel: assert for correct nclasses value

Mitchell Horne mhorne at FreeBSD.org
Wed Aug 4 18:24:32 UTC 2021


The branch main has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=8399d923a5697b7c194dbd44c33018c94ec42c4e

commit 8399d923a5697b7c194dbd44c33018c94ec42c4e
Author:     Mitchell Horne <mhorne at FreeBSD.org>
AuthorDate: 2021-08-04 17:37:05 +0000
Commit:     Mitchell Horne <mhorne at FreeBSD.org>
CommitDate: 2021-08-04 18:23:22 +0000

    hwpmc_intel: assert for correct nclasses value
    
    This variable is set based on the exact CPU model detected. If this
    value is set too small, it could lead to a NULL-dereference from an
    improperly initialized pmc_rowindex_to_classdep array.
    
    Though it has been fixed, this was previously the case for Broadwell.
    Add two asserts to catch this in DEBUG kernels, as it represents a
    configuration error that may be hard to uncover otherwise.
    
    PR:             253687
    Reported by:    Zhenlei Huang <zlei.huang at gmail.com>
    Sponsored by:   The FreeBSD Foundation
---
 sys/dev/hwpmc/hwpmc_intel.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sys/dev/hwpmc/hwpmc_intel.c b/sys/dev/hwpmc/hwpmc_intel.c
index 02b8fd9431d1..6cc6ae3b50d6 100644
--- a/sys/dev/hwpmc/hwpmc_intel.c
+++ b/sys/dev/hwpmc/hwpmc_intel.c
@@ -255,6 +255,7 @@ pmc_intel_initialize(void)
 	case PMC_CPU_INTEL_IVYBRIDGE_XEON:
 	case PMC_CPU_INTEL_HASWELL:
 	case PMC_CPU_INTEL_HASWELL_XEON:
+		MPASS(nclasses >= PMC_MDEP_CLASS_INDEX_IAF);
 		error = pmc_core_initialize(pmc_mdep, ncpus, verov);
 		break;
 
@@ -296,6 +297,7 @@ pmc_intel_initialize(void)
 	case PMC_CPU_INTEL_BROADWELL:
 	case PMC_CPU_INTEL_SANDYBRIDGE:
 #endif
+		MPASS(nclasses >= PMC_MDEP_CLASS_INDEX_UCF);
 		error = pmc_uncore_initialize(pmc_mdep, ncpus);
 		break;
 	default:


More information about the dev-commits-src-all mailing list