Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Feb 2012 17:47:04 +0000 (UTC)
From:      Martin Matuska <mm@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r231139 - stable/8/usr.sbin/jail
Message-ID:  <201202071747.q17Hl4qK000211@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mm
Date: Tue Feb  7 17:47:04 2012
New Revision: 231139
URL: http://svn.freebsd.org/changeset/base/231139

Log:
  MFC r230495:
  Try resolving jail path with realpath(3).
  
  jail(8) does a chdir(2) to the given path argument. Kernel evaluates the
  jail path from the new cwd and not from the original cwd, which leads to
  undesired behavior if given a relative path.
  
  Reviewed by:	jamie

Modified:
  stable/8/usr.sbin/jail/jail.c
Directory Properties:
  stable/8/usr.sbin/jail/   (props changed)

Modified: stable/8/usr.sbin/jail/jail.c
==============================================================================
--- stable/8/usr.sbin/jail/jail.c	Tue Feb  7 17:46:02 2012	(r231138)
+++ stable/8/usr.sbin/jail/jail.c	Tue Feb  7 17:47:04 2012	(r231139)
@@ -500,6 +500,7 @@ static void
 set_param(const char *name, char *value)
 {
 	struct jailparam *param;
+	char path[PATH_MAX];
 	int i;
 
 	static int paramlistsize;
@@ -512,8 +513,13 @@ set_param(const char *name, char *value)
 	}
 
 	/* jail_set won't chdir along with its chroot, so do it here. */
-	if (!strcmp(name, "path") && chdir(value) < 0)
-		err(1, "chdir: %s", value);
+	if (!strcmp(name, "path")) {
+		/* resolve the path with realpath(3) */
+		if (realpath(value, path) != NULL)
+			value = path;
+		if (chdir(value) < 0)
+			err(1, "chdir: %s", value);
+	}
 
 	/* Check for repeat parameters */
 	for (i = 0; i < nparams; i++)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202071747.q17Hl4qK000211>