From owner-svn-src-stable-12@freebsd.org Sat Aug 29 22:09:37 2020 Return-Path: Delivered-To: svn-src-stable-12@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 18F8B3BF35C; Sat, 29 Aug 2020 22:09:37 +0000 (UTC) (envelope-from jamie@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 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 4Bf9cJ70LGz48d7; Sat, 29 Aug 2020 22:09:36 +0000 (UTC) (envelope-from jamie@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 D47D8C820; Sat, 29 Aug 2020 22:09:36 +0000 (UTC) (envelope-from jamie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 07TM9aKj065430; Sat, 29 Aug 2020 22:09:36 GMT (envelope-from jamie@FreeBSD.org) Received: (from jamie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 07TM9a48065429; Sat, 29 Aug 2020 22:09:36 GMT (envelope-from jamie@FreeBSD.org) Message-Id: <202008292209.07TM9a48065429@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jamie set sender to jamie@FreeBSD.org using -f From: Jamie Gritton Date: Sat, 29 Aug 2020 22:09:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r364969 - stable/12/sys/kern X-SVN-Group: stable-12 X-SVN-Commit-Author: jamie X-SVN-Commit-Paths: stable/12/sys/kern X-SVN-Commit-Revision: 364969 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Aug 2020 22:09:37 -0000 Author: jamie Date: Sat Aug 29 22:09:36 2020 New Revision: 364969 URL: https://svnweb.freebsd.org/changeset/base/364969 Log: Fix a null dereference when debug.disablefullpath=1 and jail created with path=/. PR: 214881 Submitted by: aler (at) playground.ru Reported by: aler (at) playground.ru Modified: stable/12/sys/kern/kern_jail.c Modified: stable/12/sys/kern/kern_jail.c ============================================================================== --- stable/12/sys/kern/kern_jail.c Sat Aug 29 21:47:49 2020 (r364968) +++ stable/12/sys/kern/kern_jail.c Sat Aug 29 22:09:36 2020 (r364969) @@ -943,40 +943,45 @@ kern_jail_set(struct thread *td, struct uio *optuio, i error = EINVAL; goto done_free; } - NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, - path, td); - error = namei(&nd); - if (error) - goto done_free; - root = nd.ni_vp; - NDFREE(&nd, NDF_ONLY_PNBUF); - g_path = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); - strlcpy(g_path, path, MAXPATHLEN); - error = vn_path_to_global_path(td, root, g_path, MAXPATHLEN); - if (error == 0) - path = g_path; - else if (error == ENODEV) { - /* proceed if sysctl debug.disablefullpath == 1 */ - fullpath_disabled = 1; - if (len < 2 || (len == 2 && path[0] == '/')) - path = NULL; - } else { - /* exit on other errors */ - goto done_free; - } - if (root->v_type != VDIR) { - error = ENOTDIR; - vput(root); - goto done_free; - } - VOP_UNLOCK(root, 0); - if (fullpath_disabled) { - /* Leave room for a real-root full pathname. */ - if (len + (path[0] == '/' && strcmp(mypr->pr_path, "/") - ? strlen(mypr->pr_path) : 0) > MAXPATHLEN) { - error = ENAMETOOLONG; - vrele(root); + if (len < 2 || (len == 2 && path[0] == '/')) + path = NULL; + else + { + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, + path, td); + error = namei(&nd); + if (error) goto done_free; + root = nd.ni_vp; + NDFREE(&nd, NDF_ONLY_PNBUF); + g_path = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); + strlcpy(g_path, path, MAXPATHLEN); + error = vn_path_to_global_path(td, root, g_path, + MAXPATHLEN); + if (error == 0) + path = g_path; + else if (error == ENODEV) { + /* means sysctl debug.disablefullpath == 1 */ + fullpath_disabled = 1; + } else { + /* exit on other errors */ + goto done_free; + } + if (root->v_type != VDIR) { + error = ENOTDIR; + vput(root); + goto done_free; + } + VOP_UNLOCK(root, 0); + if (fullpath_disabled) { + /* Leave room for a real-root full pathname. */ + if (len + (path[0] == '/' && + strcmp(mypr->pr_path, "/") + ? strlen(mypr->pr_path) : 0) > MAXPATHLEN) { + error = ENAMETOOLONG; + vrele(root); + goto done_free; + } } } }