git: e3212b779ae2 - stable/13 - linprocfs: Avoid using a sysctl to get the CPU model string

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Thu, 11 Jan 2024 14:35:22 UTC
The branch stable/13 has been updated by markj:

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

commit e3212b779ae2938428e087ac05c52e484cf2a6c2
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-01-04 13:25:05 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-01-11 14:33:15 +0000

    linprocfs: Avoid using a sysctl to get the CPU model string
    
    This will fail if the reading process is in capability mode.  Just copy
    the string directly.
    
    PR:             276043
    Reviewed by:    emaste, imp, kib
    Reported and tested by: Ricardo Branco <rbranco@suse.com>
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D43281
    
    (cherry picked from commit d74a742704eb81f0c6f4aa83e4cb0de26a81c400)
---
 sys/compat/linprocfs/linprocfs.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c
index 3608a800dc9c..f8bbb0d8fbfc 100644
--- a/sys/compat/linprocfs/linprocfs.c
+++ b/sys/compat/linprocfs/linprocfs.c
@@ -202,10 +202,7 @@ linprocfs_domeminfo(PFS_FILL_ARGS)
 static int
 linprocfs_docpuinfo(PFS_FILL_ARGS)
 {
-	int hw_model[2];
-	char model[128];
 	uint64_t freq;
-	size_t size;
 	u_int cache_size[4];
 	u_int regs[4] = { 0 };
 	int fqmhz, fqkhz;
@@ -305,12 +302,6 @@ linprocfs_docpuinfo(PFS_FILL_ARGS)
 		"acc_power",
 	};
 
-	hw_model[0] = CTL_HW;
-	hw_model[1] = HW_MODEL;
-	model[0] = '\0';
-	size = sizeof(model);
-	if (kernel_sysctl(td, hw_model, 2, &model, &size, 0, 0, 0, 0) != 0)
-		strcpy(model, "unknown");
 #ifdef __i386__
 	switch (cpu_vendor_id) {
 	case CPU_VENDOR_AMD:
@@ -354,7 +345,7 @@ linprocfs_docpuinfo(PFS_FILL_ARGS)
 		    "cpuid level\t: %d\n"
 		    "wp\t\t: %s\n",
 		    i, cpu_vendor, CPUID_TO_FAMILY(cpu_id),
-		    CPUID_TO_MODEL(cpu_id), model, cpu_id & CPUID_STEPPING,
+		    CPUID_TO_MODEL(cpu_id), cpu_model, cpu_id & CPUID_STEPPING,
 		    fqmhz, fqkhz,
 		    (cache_size[2] >> 16), 0, mp_ncpus, i, mp_ncpus,
 		    i, i, /*cpu_id & CPUID_LOCAL_APIC_ID ??*/