Date: Sat, 16 May 2020 17:05:44 +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: r361113 - head/sys/net Message-ID: <202005161705.04GH5iWE053309@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kaktus Date: Sat May 16 17:05:44 2020 New Revision: 361113 URL: https://svnweb.freebsd.org/changeset/base/361113 Log: sysctl: fix setting net.isr.dispatch during early boot Fix another collateral damage of r357614: netisr is initialised way before malloc() is available hence it can't use sysctl_handle_string() that allocates temporary buffer. Handle that internally in sysctl_netisr_dispatch_policy(). PR: 246114 Reported by: delphij Reviewed by: kib Approved by: kib (mentor) Differential Revision: https://reviews.freebsd.org/D24858 Modified: head/sys/net/netisr.c Modified: head/sys/net/netisr.c ============================================================================== --- head/sys/net/netisr.c Sat May 16 16:29:23 2020 (r361112) +++ head/sys/net/netisr.c Sat May 16 17:05:44 2020 (r361113) @@ -345,19 +345,34 @@ static int sysctl_netisr_dispatch_policy(SYSCTL_HANDLER_ARGS) { char tmp[NETISR_DISPATCH_POLICY_MAXSTR]; + size_t len; u_int dispatch_policy; int error; netisr_dispatch_policy_to_str(netisr_dispatch_policy, tmp, sizeof(tmp)); - error = sysctl_handle_string(oidp, tmp, sizeof(tmp), req); - if (error == 0 && req->newptr != NULL) { - error = netisr_dispatch_policy_from_str(tmp, - &dispatch_policy); - if (error == 0 && dispatch_policy == NETISR_DISPATCH_DEFAULT) - error = EINVAL; - if (error == 0) - netisr_dispatch_policy = dispatch_policy; + /* + * netisr is initialised very early during the boot when malloc isn't + * available yet so we can't use sysctl_handle_string() to process + * any non-default value that was potentially set via loader. + */ + if (req->newptr != NULL) { + len = req->newlen - req->newidx; + if (len >= NETISR_DISPATCH_POLICY_MAXSTR) + return (EINVAL); + error = SYSCTL_IN(req, tmp, len); + if (error == 0) { + tmp[len] = '\0'; + error = netisr_dispatch_policy_from_str(tmp, + &dispatch_policy); + if (error == 0 && + dispatch_policy == NETISR_DISPATCH_DEFAULT) + error = EINVAL; + if (error == 0) + netisr_dispatch_policy = dispatch_policy; + } + } else { + error = sysctl_handle_string(oidp, tmp, sizeof(tmp), req); } return (error); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005161705.04GH5iWE053309>