fsdev: fix virtfs-proxy-helper cwd

Since chroot() doesn't change the current directory, it is indeed a good
practice to chdir() to the target directory and then then chroot(), or
to chroot() to the target directory and then chdir("/").

The current code does neither of them actually. Let's go for the latter.

This doesn't fix any security issue since all of this takes place before
the helper begins to process requests.

Signed-off-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Greg Kurz 2017-05-25 10:30:13 +02:00
parent 6a87e7929f
commit 4be56c1959

View File

@ -1129,14 +1129,14 @@ int main(int argc, char **argv)
}
}
if (chdir("/") < 0) {
do_perror("chdir");
goto error;
}
if (chroot(rpath) < 0) {
do_perror("chroot");
goto error;
}
if (chdir("/") < 0) {
do_perror("chdir");
goto error;
}
get_version = false;
#ifdef FS_IOC_GETVERSION