-/* $OpenBSD: machdep.c,v 1.275 2021/10/06 15:46:03 claudio Exp $ */
+/* $OpenBSD: machdep.c,v 1.276 2022/01/25 04:04:40 gnezdo Exp $ */
/* $NetBSD: machdep.c,v 1.3 2003/05/07 22:58:18 fvdl Exp $ */
/*-
case CPU_CPUVENDOR:
return (sysctl_rdstring(oldp, oldlenp, newp, cpu_vendor));
case CPU_KBDRESET:
- if (securelevel > 0)
- return (sysctl_rdint(oldp, oldlenp, newp,
- kbd_reset));
- else
- return (sysctl_int(oldp, oldlenp, newp, newlen,
- &kbd_reset));
+ return (sysctl_securelevel_int(oldp, oldlenp, newp, newlen,
+ &kbd_reset));
case CPU_ALLOWAPERTURE:
if (namelen != 1)
return (ENOTDIR); /* overloaded */
-/* $OpenBSD: machdep.c,v 1.646 2021/10/06 15:46:03 claudio Exp $ */
+/* $OpenBSD: machdep.c,v 1.647 2022/01/25 04:04:40 gnezdo Exp $ */
/* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */
/*-
case CPU_CPUFEATURE:
return (sysctl_rdint(oldp, oldlenp, newp, curcpu()->ci_feature_flags));
case CPU_KBDRESET:
- if (securelevel > 0)
- return (sysctl_rdint(oldp, oldlenp, newp,
- kbd_reset));
- else
- return (sysctl_int(oldp, oldlenp, newp, newlen,
- &kbd_reset));
+ return (sysctl_securelevel_int(oldp, oldlenp, newp, newlen,
+ &kbd_reset));
#if NPCKBC > 0 && NUKBD > 0
case CPU_FORCEUKBD:
{
-/* $OpenBSD: kern_sysctl.c,v 1.398 2021/12/23 10:17:01 bluhm Exp $ */
+/* $OpenBSD: kern_sysctl.c,v 1.399 2022/01/25 04:04:40 gnezdo Exp $ */
/* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */
/*-
return (0);
#if NDT > 0
case KERN_ALLOWDT:
- if (securelevel > 0)
- return (sysctl_rdint(oldp, oldlenp, newp, allowdt));
- return (sysctl_int(oldp, oldlenp, newp, newlen, &allowdt));
+ return (sysctl_securelevel_int(oldp, oldlenp, newp, newlen,
+ &allowdt));
#endif
case KERN_ALLOWKMEM:
- if (securelevel > 0)
- return (sysctl_rdint(oldp, oldlenp, newp, allowkmem));
- return (sysctl_int(oldp, oldlenp, newp, newlen, &allowkmem));
+ return (sysctl_securelevel_int(oldp, oldlenp, newp, newlen,
+ &allowkmem));
case KERN_HOSTNAME:
error = sysctl_tstring(oldp, oldlenp, newp, newlen,
hostname, sizeof(hostname));
return (sysctl_rdquad(oldp, oldlenp, newp,
ptoa((psize_t)physmem - uvmexp.wired)));
case HW_ALLOWPOWERDOWN:
- if (securelevel > 0)
- return (sysctl_rdint(oldp, oldlenp, newp,
- allowpowerdown));
- return (sysctl_int(oldp, oldlenp, newp, newlen,
+ return (sysctl_securelevel_int(oldp, oldlenp, newp, newlen,
&allowpowerdown));
#ifdef __HAVE_CPU_TOPOLOGY
case HW_SMT:
return (error);
}
+/*
+ * Selects between sysctl_rdint and sysctl_int according to securelevel.
+ */
+int
+sysctl_securelevel_int(void *oldp, size_t *oldlenp, void *newp, size_t newlen,
+ int *valp)
+{
+ if (securelevel > 0)
+ return (sysctl_rdint(oldp, oldlenp, newp, *valp));
+ return (sysctl_int(oldp, oldlenp, newp, newlen, valp));
+}
+
/*
* Read-only or bounded integer values.
*/
int adjustment_seconds, error, new_offset_minutes, old_offset_minutes;
old_offset_minutes = utc_offset / 60; /* seconds -> minutes */
- if (securelevel > 0)
- return sysctl_rdint(oldp, oldlenp, newp, old_offset_minutes);
-
new_offset_minutes = old_offset_minutes;
- error = sysctl_int(oldp, oldlenp, newp, newlen, &new_offset_minutes);
+ error = sysctl_securelevel_int(oldp, oldlenp, newp, newlen,
+ &new_offset_minutes);
if (error)
return error;
if (new_offset_minutes < -24 * 60 || new_offset_minutes > 24 * 60)
-/* $OpenBSD: vfs_subr.c,v 1.313 2021/10/25 10:24:54 claudio Exp $ */
+/* $OpenBSD: vfs_subr.c,v 1.314 2022/01/25 04:04:40 gnezdo Exp $ */
/* $NetBSD: vfs_subr.c,v 1.53 1996/04/22 01:39:13 christos Exp $ */
/*
switch (name[0]) {
case FS_POSIX_SETUID:
- if (newp && securelevel > 0)
- return (EPERM);
- return(sysctl_int(oldp, oldlenp, newp, newlen, &suid_clear));
+ return (sysctl_securelevel_int(oldp, oldlenp, newp, newlen,
+ &suid_clear));
default:
return (EOPNOTSUPP);
}
-/* $OpenBSD: ip_input.c,v 1.364 2021/11/22 13:47:10 bluhm Exp $ */
+/* $OpenBSD: ip_input.c,v 1.365 2022/01/25 04:04:40 gnezdo Exp $ */
/* $NetBSD: ip_input.c,v 1.30 1996/03/16 23:53:58 christos Exp $ */
/*
switch (name[0]) {
case IPCTL_SOURCEROUTE:
- /*
- * Don't allow this to change in a secure environment.
- */
- if (newp && securelevel > 0)
- return (EPERM);
NET_LOCK();
- error = sysctl_int(oldp, oldlenp, newp, newlen,
+ error = sysctl_securelevel_int(oldp, oldlenp, newp, newlen,
&ip_dosourceroute);
NET_UNLOCK();
return (error);
-/* $OpenBSD: sysctl.h,v 1.221 2022/01/11 23:59:55 jsg Exp $ */
+/* $OpenBSD: sysctl.h,v 1.222 2022/01/25 04:04:41 gnezdo Exp $ */
/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
/*
int sysctl_int_lower(void *, size_t *, void *, size_t, int *);
int sysctl_int(void *, size_t *, void *, size_t, int *);
int sysctl_rdint(void *, size_t *, void *, int);
+int sysctl_securelevel_int(void *, size_t *, void *, size_t, int *);
int sysctl_int_bounded(void *, size_t *, void *, size_t, int *, int, int);
int sysctl_bounded_arr(const struct sysctl_bounded_args *, u_int,
int *, u_int, void *, size_t *, void *, size_t);