From owner-svn-src-stable@freebsd.org Thu Dec 6 19:18:53 2018 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CB2AB130FDAA; Thu, 6 Dec 2018 19:18:52 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 6DD977B9B1; Thu, 6 Dec 2018 19:18:52 +0000 (UTC) (envelope-from kevans@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 4F02327F34; Thu, 6 Dec 2018 19:18:52 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id wB6JIqhP010553; Thu, 6 Dec 2018 19:18:52 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id wB6JIq8P010552; Thu, 6 Dec 2018 19:18:52 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201812061918.wB6JIq8P010552@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Thu, 6 Dec 2018 19:18:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r341644 - stable/11/sys/kern X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/11/sys/kern X-SVN-Commit-Revision: 341644 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 6DD977B9B1 X-Spamd-Result: default: False [-1.90 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.87)[-0.868,0]; NEURAL_HAM_LONG(-0.07)[-0.070,0]; NEURAL_HAM_SHORT(-0.96)[-0.965,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-Rspamd-Server: mx1.freebsd.org X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Dec 2018 19:18:53 -0000 Author: kevans Date: Thu Dec 6 19:18:51 2018 New Revision: 341644 URL: https://svnweb.freebsd.org/changeset/base/341644 Log: Fix kenv handling in stable/11 following r337333 The aforementioned commit merged revised static_env/static_hint handling to allow static_env and loader env to coexist with the variable loader_env.disabled=0. init_static_kenv had been rewritten slighly in an attempt to maintain historical behavior: the static environment and loader environment are mutually exclusive, unless the latter disables the former. The rewritten version botched this by only setting up the loader environment if the static environment was empty or if the loader environment was specifically enabled. It was never given a chance to disable the static environment, so the default behavior was broken unless the loader environment was specifically enabled by the static environment. Rewrite this again to do the right thing: - Setup the static environment and check loader_env.disabled; if it's explicitly enabled, we're done. - Check static_{env,hints}.disabled and "empty out" the respective environments as needed - Finally, check: if the static environment is not empty and we've not explicitly re-enabled the static environment with loader_env.disabled=0, we tear the loader environment (which was setup to 'keep things simple') down again. Future commits to head (and subsequently MFC'd) will likely zero these environments out if they're disabled since this normally happens when they're merged into the dynamic environment. This is a direct commit to stable/11 because this particular bug does not apply to head. Fixes: r337333 Reported by: bde Modified: stable/11/sys/kern/kern_environment.c Modified: stable/11/sys/kern/kern_environment.c ============================================================================== --- stable/11/sys/kern/kern_environment.c Thu Dec 6 18:59:33 2018 (r341643) +++ stable/11/sys/kern/kern_environment.c Thu Dec 6 19:18:51 2018 (r341644) @@ -245,7 +245,7 @@ done: void init_static_kenv(char *buf, size_t len) { - char *eval; + char *eval, *loader_eval; KASSERT(!dynamic_kenv, ("kenv: dynamic_kenv already initialized")); /* @@ -264,21 +264,43 @@ init_static_kenv(char *buf, size_t len) * * As a warning, the static environment may not be disabled in any way * if the static environment has disabled the loader environment. + * + * We're setting up the static environment early here because it will + * either be used or empty. */ kern_envp = static_env; - eval = kern_getenv("loader_env.disabled"); - if (*kern_envp == '\0' || (eval != NULL && strcmp(eval, "0") == 0)) { - md_envp = buf; - md_env_len = len; - md_env_pos = 0; + loader_eval = kern_getenv("loader_env.disabled"); + if (loader_eval != NULL && strcmp(loader_eval, "1") == 0) + /* Bail out early, the loader environment is disabled. */ + return; - eval = kern_getenv("static_env.disabled"); - if (eval != NULL && strcmp(eval, "1") == 0) - *kern_envp = '\0'; - } + /* + * Next, the loader env is checked for the status of the static env. We + * are allowing static_env and static_hints to disable themselves here for + * the sake of simplicity. + */ + md_envp = buf; + md_env_len = len; + md_env_pos = 0; + + eval = kern_getenv("static_env.disabled"); + if (eval != NULL && strcmp(eval, "1") == 0) + *static_env = '\0'; + eval = kern_getenv("static_hints.disabled"); if (eval != NULL && strcmp(eval, "1") == 0) *static_hints = '\0'; + + /* + * Now we see if we need to tear the loader environment back down due + * to the presence of a non-empty static environment and lack of request + * to keep it enabled. + */ + if (*static_env != '\0' && + (loader_eval == NULL || strcmp(loader_eval, "0") != 0)) { + md_envp = NULL; + md_env_len = 0; + } } static void