Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Apr 2021 18:32:23 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 4342ba184c15 - main - sysctl_handle_string: do not malloc when SYSCTL_IN cannot fault
Message-ID:  <202104191832.13JIWNPh046071@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib:

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

commit 4342ba184c15f3b8912e95f93fe313731963f065
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-04-18 16:09:30 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2021-04-19 18:32:01 +0000

    sysctl_handle_string: do not malloc when SYSCTL_IN cannot fault
    
    In particular, this avoids malloc(9) calls when from early tunable handling,
    with no working malloc yet.
    
    Reported and tested by: mav
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
---
 sys/kern/kern_sysctl.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c
index 011e3f44a124..e46584758c9b 100644
--- a/sys/kern/kern_sysctl.c
+++ b/sys/kern/kern_sysctl.c
@@ -1785,6 +1785,15 @@ sysctl_handle_string(SYSCTL_HANDLER_ARGS)
 		sx_xlock(&sysctlstringlock);
 		((char *)arg1)[0] = '\0';
 		sx_xunlock(&sysctlstringlock);
+	} else if (req->newfunc == sysctl_new_kernel) {
+		arg2 = req->newlen - req->newidx;
+		sx_xlock(&sysctlstringlock);
+		error = SYSCTL_IN(req, arg1, arg2);
+		if (error == 0) {
+			((char *)arg1)[arg2] = '\0';
+			req->newidx += arg2;
+		}
+		sx_xunlock(&sysctlstringlock);
 	} else {
 		arg2 = req->newlen - req->newidx;
 		tmparg = malloc(arg2, M_SYSCTLTMP, M_WAITOK);



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