From owner-svn-src-head@freebsd.org Sat Aug 18 19:45:57 2018 Return-Path: Delivered-To: svn-src-head@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 B8FB4107420B; Sat, 18 Aug 2018 19:45:57 +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 51309738B6; Sat, 18 Aug 2018 19:45:57 +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 2CC0B1BF80; Sat, 18 Aug 2018 19:45:57 +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 w7IJjusD075818; Sat, 18 Aug 2018 19:45:56 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7IJjuos075817; Sat, 18 Aug 2018 19:45:56 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201808181945.w7IJjuos075817@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Sat, 18 Aug 2018 19:45:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r338020 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 338020 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.27 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, 18 Aug 2018 19:45:58 -0000 Author: kevans Date: Sat Aug 18 19:45:56 2018 New Revision: 338020 URL: https://svnweb.freebsd.org/changeset/base/338020 Log: res_find: Fix fallback logic The fallback logic was broken if hints were found in multiple environments. If we found a hint in either the loader environment or the static environment, fallback would be incremented excessively when we returned to the environment-selection bits. These checks should have also been guarded by the fbacklvl checks. As a result, fbacklvl could quickly get to a point where we skip either the static environment and/or the static hints depending on which environments contained valid hints. The impact of this bug is minimal, mostly affecting mips boards that use static hints and may have hints in either the loader environment or the static environment. There may be better ways to express the searchable environments and describing their characteristics (immutable, already searched, etc.) but this may be revisited after 12 branches. Reported by: Dan Nelson Triaged by: Dan Nelson MFC after: 3 days Modified: head/sys/kern/subr_hints.c Modified: head/sys/kern/subr_hints.c ============================================================================== --- head/sys/kern/subr_hints.c Sat Aug 18 19:14:06 2018 (r338019) +++ head/sys/kern/subr_hints.c Sat Aug 18 19:45:56 2018 (r338020) @@ -174,30 +174,37 @@ fallback: if (dyn_used || fbacklvl >= FBACK_STATIC) return (ENOENT); - if (fbacklvl <= FBACK_MDENV && - _res_checkenv(md_envp)) { - hintp = md_envp; - goto found; - } - fbacklvl++; + switch (fbacklvl) { + case FBACK_MDENV: + fbacklvl++; + if (_res_checkenv(md_envp)) { + hintp = md_envp; + break; + } - if (!stenv_skip && fbacklvl <= FBACK_STENV && - _res_checkenv(kern_envp)) { - hintp = kern_envp; - goto found; - } else - stenv_skip = true; + /* FALLTHROUGH */ + case FBACK_STENV: + fbacklvl++; + if (!stenv_skip && _res_checkenv(kern_envp)) { + hintp = kern_envp; + break; + } else + stenv_skip = true; - fbacklvl++; + /* FALLTHROUGH */ + case FBACK_STATIC: + fbacklvl++; + /* We'll fallback to static_hints if needed/can */ + if (!sthints_skip && + _res_checkenv(static_hints)) + hintp = static_hints; + else + sthints_skip = true; - /* We'll fallback to static_hints if needed/can */ - if (!sthints_skip && fbacklvl <= FBACK_STATIC && - _res_checkenv(static_hints)) - hintp = static_hints; - else - sthints_skip = true; -found: - fbacklvl++; + break; + default: + return (ENOENT); + } } if (hintp == NULL)