From owner-svn-src-head@freebsd.org Sat May 16 17:05:44 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 98EF92F7500; Sat, 16 May 2020 17:05:44 +0000 (UTC) (envelope-from kaktus@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) server-signature RSA-PSS (4096 bits) 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 49PWr83ZsGz3G21; Sat, 16 May 2020 17:05:44 +0000 (UTC) (envelope-from kaktus@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 73A46192B1; Sat, 16 May 2020 17:05:44 +0000 (UTC) (envelope-from kaktus@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04GH5iP4053310; Sat, 16 May 2020 17:05:44 GMT (envelope-from kaktus@FreeBSD.org) Received: (from kaktus@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04GH5iWE053309; Sat, 16 May 2020 17:05:44 GMT (envelope-from kaktus@FreeBSD.org) Message-Id: <202005161705.04GH5iWE053309@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kaktus set sender to kaktus@FreeBSD.org using -f From: Pawel Biernacki Date: Sat, 16 May 2020 17:05:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361113 - head/sys/net X-SVN-Group: head X-SVN-Commit-Author: kaktus X-SVN-Commit-Paths: head/sys/net X-SVN-Commit-Revision: 361113 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, 16 May 2020 17:05:44 -0000 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); }