Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Apr 2020 16:33:55 +0000 (UTC)
From:      Pawel Biernacki <kaktus@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r359975 - head/sys/kern
Message-ID:  <202004151633.03FGXtBJ050923@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kaktus
Date: Wed Apr 15 16:33:55 2020
New Revision: 359975
URL: https://svnweb.freebsd.org/changeset/base/359975

Log:
  sysctl(9): fix handling string tunables.
  
  r357614 changed internals of handling string sysctls, and inadvertently
  broke setting string tunables.  Take them into account.
  
  PR:		245463
  Reported by:	jhb, np
  Reviewed by:	imp, jhb, kib
  Approved by:	kib (mentor)
  Differential Revision:	https://reviews.freebsd.org/D24429

Modified:
  head/sys/kern/kern_sysctl.c

Modified: head/sys/kern/kern_sysctl.c
==============================================================================
--- head/sys/kern/kern_sysctl.c	Wed Apr 15 16:33:27 2020	(r359974)
+++ head/sys/kern/kern_sysctl.c	Wed Apr 15 16:33:55 2020	(r359975)
@@ -1648,13 +1648,15 @@ sysctl_handle_string(SYSCTL_HANDLER_ARGS)
 	int error = 0, ro_string = 0;
 
 	/*
-	 * If the sysctl isn't writable, microoptimise and treat it as a
-	 * const string.
+	 * If the sysctl isn't writable and isn't a preallocated tunable that
+	 * can be modified by kenv(2), microoptimise and treat it as a
+	 * read-only string.
 	 * A zero-length buffer indicates a fixed size read-only
 	 * string.  In ddb, don't worry about trying to make a malloced
 	 * snapshot.
 	 */
-	if (!(oidp->oid_kind & CTLFLAG_WR) || arg2 == 0 || kdb_active) {
+	if ((oidp->oid_kind & CTLFLAG_WR | CTLFLAG_TUN) == 0 || arg2 == 0
+	    || kdb_active) {
 		arg2 = strlen((char *)arg1) + 1;
 		ro_string = 1;
 	}
@@ -1697,8 +1699,7 @@ sysctl_handle_string(SYSCTL_HANDLER_ARGS)
 		arg2 = req->newlen - req->newidx;
 		tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK);
 
-		error = copyin((const char *)req->newptr + req->newidx,
-		    tmparg, arg2);
+		error = SYSCTL_IN(req, tmparg, arg2);
 		if (error) {
 			free(tmparg, M_SYSCTLTMP);
 			return (error);



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