diff options
author | mm <mm@FreeBSD.org> | 2012-01-24 08:04:38 +0000 |
---|---|---|
committer | mm <mm@FreeBSD.org> | 2012-01-24 08:04:38 +0000 |
commit | 1259ca3ed41459b062f700f4fcf99bc845e480c0 (patch) | |
tree | 5ead435642b13f3f3e7123f9902363c2e93bf423 /usr.sbin | |
parent | e8bf1256400ec5a8e0b447cb7a3dfca6f8e57089 (diff) | |
download | FreeBSD-src-1259ca3ed41459b062f700f4fcf99bc845e480c0.zip FreeBSD-src-1259ca3ed41459b062f700f4fcf99bc845e480c0.tar.gz |
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
MFC after: 2 weeks
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/jail/jail.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/usr.sbin/jail/jail.c b/usr.sbin/jail/jail.c index fc4f71c..69c5e53 100644 --- a/usr.sbin/jail/jail.c +++ b/usr.sbin/jail/jail.c @@ -508,6 +508,7 @@ static void set_param(const char *name, char *value) { struct jailparam *param; + char path[PATH_MAX]; int i; static int paramlistsize; @@ -520,8 +521,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++) |