git: f7dd97b7e227 - stable/13 - Allow sysctl hw.machine/hw.machine_arch in capability mode

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Fri, 20 Sep 2024 12:19:45 UTC
The branch stable/13 has been updated by emaste:

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

commit f7dd97b7e227016a3fac4616307d871af3011dfe
Author:     Val Packett <val@packett.cool>
AuthorDate: 2023-02-05 20:52:50 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-09-20 11:19:41 +0000

    Allow sysctl hw.machine/hw.machine_arch in capability mode
    
    There's no harm in reading strings like 'amd64'.
    
    Reviewed by: emaste, manu
    Sponsored by: https://www.patreon.com/valpackett
    Differential Revision: https://reviews.freebsd.org/D28703
    
    (cherry picked from commit 4a1c4de232af202aa5fa02c7adaa97174997ae61)
---
 sys/arm/arm/identcpu-v6.c     | 2 +-
 sys/arm64/arm64/identcpu.c    | 3 ++-
 sys/kern/kern_mib.c           | 2 +-
 sys/powerpc/powerpc/machdep.c | 2 +-
 sys/riscv/riscv/identcpu.c    | 2 +-
 sys/x86/x86/identcpu.c        | 4 ++--
 6 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/sys/arm/arm/identcpu-v6.c b/sys/arm/arm/identcpu-v6.c
index baae9ac360ad..6293a5ccaceb 100644
--- a/sys/arm/arm/identcpu-v6.c
+++ b/sys/arm/arm/identcpu-v6.c
@@ -52,7 +52,7 @@
 
 char machine[] = "arm";
 
-SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD,
+SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD,
 	machine, 0, "Machine class");
 
 static char cpu_model[64];
diff --git a/sys/arm64/arm64/identcpu.c b/sys/arm64/arm64/identcpu.c
index fcbf607b8fef..e913154f9956 100644
--- a/sys/arm64/arm64/identcpu.c
+++ b/sys/arm64/arm64/identcpu.c
@@ -96,7 +96,8 @@ sysctl_hw_machine(SYSCTL_HANDLER_ARGS)
 }
 
 SYSCTL_PROC(_hw, HW_MACHINE, machine, CTLTYPE_STRING | CTLFLAG_RD |
-	CTLFLAG_MPSAFE, NULL, 0, sysctl_hw_machine, "A", "Machine class");
+	 CTLFLAG_CAPRD | CTLFLAG_MPSAFE, NULL, 0, sysctl_hw_machine, "A",
+	 "Machine class");
 
 static char cpu_model[64];
 SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD | CTLFLAG_CAPRD,
diff --git a/sys/kern/kern_mib.c b/sys/kern/kern_mib.c
index b2e9e06f5793..ee3e36c0b5a8 100644
--- a/sys/kern/kern_mib.c
+++ b/sys/kern/kern_mib.c
@@ -317,7 +317,7 @@ sysctl_hw_machine_arch(SYSCTL_HANDLER_ARGS)
 	return (SYSCTL_OUT(req, machine_arch, strlen(machine_arch) + 1));
 }
 SYSCTL_PROC(_hw, HW_MACHINE_ARCH, machine_arch, CTLTYPE_STRING | CTLFLAG_RD |
-    CTLFLAG_MPSAFE, NULL, 0, sysctl_hw_machine_arch, "A",
+    CTLFLAG_CAPRD | CTLFLAG_MPSAFE, NULL, 0, sysctl_hw_machine_arch, "A",
     "System architecture");
 
 #ifndef MACHINE_ARCHES
diff --git a/sys/powerpc/powerpc/machdep.c b/sys/powerpc/powerpc/machdep.c
index 96084aea6fcf..85d741d11b1a 100644
--- a/sys/powerpc/powerpc/machdep.c
+++ b/sys/powerpc/powerpc/machdep.c
@@ -149,7 +149,7 @@ static char init_kenv[2048];
 static struct trapframe frame0;
 
 char		machine[] = "powerpc";
-SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, "");
+SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD, machine, 0, "");
 
 static void	cpu_startup(void *);
 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
diff --git a/sys/riscv/riscv/identcpu.c b/sys/riscv/riscv/identcpu.c
index 6a63d39d66aa..39bc0e3b91af 100644
--- a/sys/riscv/riscv/identcpu.c
+++ b/sys/riscv/riscv/identcpu.c
@@ -62,7 +62,7 @@
 
 char machine[] = "riscv";
 
-SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0,
+SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD, machine, 0,
     "Machine class");
 
 /* Hardware implementation info. These values may be empty. */
diff --git a/sys/x86/x86/identcpu.c b/sys/x86/x86/identcpu.c
index 8a5d74ca5a2d..450df6807920 100644
--- a/sys/x86/x86/identcpu.c
+++ b/sys/x86/x86/identcpu.c
@@ -152,9 +152,9 @@ sysctl_hw_machine(SYSCTL_HANDLER_ARGS)
 
 }
 SYSCTL_PROC(_hw, HW_MACHINE, machine, CTLTYPE_STRING | CTLFLAG_RD |
-    CTLFLAG_MPSAFE, NULL, 0, sysctl_hw_machine, "A", "Machine class");
+    CTLFLAG_CAPRD | CTLFLAG_MPSAFE, NULL, 0, sysctl_hw_machine, "A", "Machine class");
 #else
-SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD,
+SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD | CTLFLAG_CAPRD,
     machine, 0, "Machine class");
 #endif