View | Details | Raw Unified | Return to bug 214881 | Differences between
and this patch

Collapse All | Expand All

(-)sys/kern/kern_jail.c (-33 / +37 lines)
Lines 978-1017 Link Here
978
			error = EINVAL;
978
			error = EINVAL;
979
			goto done_free;
979
			goto done_free;
980
		}
980
		}
981
		NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE,
981
		if(len < 2 || (len == 2 && path[0] == '/'))
982
		    path, td);
982
			path = NULL;
983
		error = namei(&nd);
983
		else {
984
		if (error)
984
			NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE,
985
			goto done_free;
985
			    path, td);
986
		root = nd.ni_vp;
986
			error = namei(&nd);
987
		NDFREE(&nd, NDF_ONLY_PNBUF);
987
			if (error)
988
		g_path = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
989
		strlcpy(g_path, path, MAXPATHLEN);
990
		error = vn_path_to_global_path(td, root, g_path, MAXPATHLEN);
991
		if (error == 0)
992
			path = g_path;
993
		else if (error == ENODEV) {
994
			/* proceed if sysctl debug.disablefullpath == 1 */
995
			fullpath_disabled = 1;
996
			if (len < 2 || (len == 2 && path[0] == '/'))
997
				path = NULL;
998
		} else {
999
			/* exit on other errors */
1000
			goto done_free;
1001
		}
1002
		if (root->v_type != VDIR) {
1003
			error = ENOTDIR;
1004
			vput(root);
1005
			goto done_free;
1006
		}
1007
		VOP_UNLOCK(root, 0);
1008
		if (fullpath_disabled) {
1009
			/* Leave room for a real-root full pathname. */
1010
			if (len + (path[0] == '/' && strcmp(mypr->pr_path, "/")
1011
			    ? strlen(mypr->pr_path) : 0) > MAXPATHLEN) {
1012
				error = ENAMETOOLONG;
1013
				vrele(root);
1014
				goto done_free;
988
				goto done_free;
989
			root = nd.ni_vp;
990
			NDFREE(&nd, NDF_ONLY_PNBUF);
991
			g_path = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
992
			strlcpy(g_path, path, MAXPATHLEN);
993
			error = vn_path_to_global_path(td, root, g_path,
994
			    MAXPATHLEN);
995
			if (error == 0)
996
				path = g_path;
997
			else if (error == ENODEV) {
998
				/* means sysctl debug.disablefullpath == 1 */
999
				fullpath_disabled = 1;
1000
			} else {
1001
				/* exit on other errors */
1002
				goto done_free;
1003
			}
1004
			if (root->v_type != VDIR) {
1005
				error = ENOTDIR;
1006
				vput(root);
1007
				goto done_free;
1008
			}
1009
			VOP_UNLOCK(root, 0);
1010
			if (fullpath_disabled) {
1011
				/* Leave room for a real-root full pathname. */
1012
				if (len + (path[0] == '/' &&
1013
				     strcmp(mypr->pr_path, "/")
1014
				    ? strlen(mypr->pr_path) : 0) > MAXPATHLEN) {
1015
					error = ENAMETOOLONG;
1016
					vrele(root);
1017
					goto done_free;
1018
				}
1015
			}
1019
			}
1016
		}
1020
		}
1017
	}
1021
	}

Return to bug 214881