From owner-svn-src-head@freebsd.org Sat Oct 31 23:48:42 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 4119C45961E; Sat, 31 Oct 2020 23:48:42 +0000 (UTC) (envelope-from se@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CNwqZ13z9z47V5; Sat, 31 Oct 2020 23:48:42 +0000 (UTC) (envelope-from se@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 04B8DF1FF; Sat, 31 Oct 2020 23:48:42 +0000 (UTC) (envelope-from se@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 09VNmfBW009775; Sat, 31 Oct 2020 23:48:41 GMT (envelope-from se@FreeBSD.org) Received: (from se@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 09VNmfWN009773; Sat, 31 Oct 2020 23:48:41 GMT (envelope-from se@FreeBSD.org) Message-Id: <202010312348.09VNmfWN009773@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: se set sender to se@FreeBSD.org using -f From: =?UTF-8?Q?Stefan_E=c3=9fer?= Date: Sat, 31 Oct 2020 23:48:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367243 - in head: lib/libc/gen sys/kern X-SVN-Group: head X-SVN-Commit-Author: se X-SVN-Commit-Paths: in head: lib/libc/gen sys/kern X-SVN-Commit-Revision: 367243 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Oct 2020 23:48:42 -0000 Author: se Date: Sat Oct 31 23:48:41 2020 New Revision: 367243 URL: https://svnweb.freebsd.org/changeset/base/367243 Log: Make sysctl user.local a tunable that can be written at run-time This sysctl value had been provided as a read-only variable that is compiled into the C library based on the value of _PATH_LOCALBASE in paths.h. After this change, the value is compiled into the kernel as an empty string, which is translated to _PATH_LOCALBASE by the C library. This empty string can be overridden at boot time or by a privileged user at run time and will then be returned by sysctl. When set to an empty string, the value returned by sysctl reverts to _PATH_LOCALBASE. This update does not change the behavior on any system that does not modify the default value of user.localbase. I consider this change as experimental and would prefer if the run-time write permission was reconsidered and the sysctl variable defined with CLFLAG_RDTUN instead to restrict it to be set at boot time. MFC after: 1 month Modified: head/lib/libc/gen/sysctl.c head/sys/kern/kern_mib.c Modified: head/lib/libc/gen/sysctl.c ============================================================================== --- head/lib/libc/gen/sysctl.c Sat Oct 31 23:19:59 2020 (r367242) +++ head/lib/libc/gen/sysctl.c Sat Oct 31 23:48:41 2020 (r367243) @@ -68,14 +68,14 @@ sysctl(const int *name, u_int namelen, void *oldp, siz if (retval || name[0] != CTL_USER) return (retval); - if (newp != NULL) { - errno = EPERM; - return (-1); - } if (namelen != 2) { errno = EINVAL; return (-1); } + if (newp != NULL && name[1] != USER_LOCALBASE) { + errno = EPERM; + return (-1); + } switch (name[1]) { case USER_CS_PATH: @@ -88,13 +88,21 @@ sysctl(const int *name, u_int namelen, void *oldp, siz memmove(oldp, _PATH_STDPATH, sizeof(_PATH_STDPATH)); return (0); case USER_LOCALBASE: - if (oldp != NULL && orig_oldlen < sizeof(_PATH_LOCALBASE)) { - errno = ENOMEM; - return (-1); + if (oldlenp != NULL) { + if (oldp == NULL) { + if (*oldlenp == 1) + *oldlenp = sizeof(_PATH_LOCALBASE); + } else { + if (*oldlenp != 1) + return (retval); + if (orig_oldlen < sizeof(_PATH_LOCALBASE)) { + errno = ENOMEM; + return (-1); + } + *oldlenp = sizeof(_PATH_LOCALBASE); + memmove(oldp, _PATH_LOCALBASE, sizeof(_PATH_LOCALBASE)); + } } - *oldlenp = sizeof(_PATH_LOCALBASE); - if (oldp != NULL) - memmove(oldp, _PATH_LOCALBASE, sizeof(_PATH_LOCALBASE)); return (0); } Modified: head/sys/kern/kern_mib.c ============================================================================== --- head/sys/kern/kern_mib.c Sat Oct 31 23:19:59 2020 (r367242) +++ head/sys/kern/kern_mib.c Sat Oct 31 23:48:41 2020 (r367243) @@ -652,8 +652,11 @@ SYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG SYSCTL_NULL_INT_PTR, 0, "Min Maximum number of streams a process may have open at one time"); SYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, 0, "Min Maximum number of types supported for timezone names"); -SYSCTL_STRING(_user, USER_LOCALBASE, localbase, CTLFLAG_RD, - "", 0, "Prefix used to install and locate add-on packages"); + +static char localbase[MAXPATHLEN] = ""; + +SYSCTL_STRING(_user, USER_LOCALBASE, localbase, CTLFLAG_RWTUN, + localbase, sizeof(localbase), "Prefix used to install and locate add-on packages"); #include SYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD,