Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Jun 2020 04:58:03 +0200
From:      Alfonso Siciliano <alfix86@gmail.com>
To:        freebsd-hackers@freebsd.org
Subject:   Re: An option to ignore sysctl CTLFLAG_ANYBODY
Message-ID:  <20200621045803.70a373337b6df186fabc54ac@gmail.com>
In-Reply-To: <20200618172721.GA28529@daemon>
References:  <20200618172721.GA28529@daemon>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 20 Jun 2020 19:38:12 +0000
Teran McKinney <sega01@go-beyond.org> wrote:

> I have tried that and it does work. The problem is that even a
> simple read call like `sysctl hw.ncpu` will return an error for
> non-root users. Which, while not essential, would be nice to
> keep.

This new change to kern_sysctl.c should solve the problem:

https://github.com/freebsd/freebsd/blob/master/sys/kern/kern_sysctl.c#L2122
from
	/* Is this sysctl writable by only privileged users? */
	if (req->newptr && !(oid->oid_kind & CTLFLAG_ANYBODY)) {
to
	/*
	 * Is this sysctl writable? Does it belong to the undocumented interface
	 * or sysctlinfo?
	 */
	if (req->newptr && !(SYSCTL_CHILDREN(&sysctl___sysctl) == oid->oid_parent)) {


Testing

	% uname -K
	1300093
	% sysctl hw.ncpu
	hw.ncpu: 1
	% nsysctl -NatGv hw.snd.default_unit
	hw.snd.default_unit: integer:  RD WR RW ANYBODY TUN RDTUN RWTUN NOFETCH: 0
	% sysctl hw.snd.default_unit
	hw.snd.default_unit: 0
	% sysctl hw.snd.default_unit=1
	hw.snd.default_unit: 0
	sysctl: hw.snd.default_unit=1: Operation not permitted


Alfonso

--- 
Alfonso S. Siciliano 
   http://alfix.gitlab.io



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20200621045803.70a373337b6df186fabc54ac>