Commit 72a9372a authored by Pavel Emelyanov's avatar Pavel Emelyanov

fs: Opening FE-s after fchdir doesn't work

It uses absolute file names, so any open-s should happen _before_
we change tasks' root.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Acked-by: 's avatarAndrew Vagin <avagin@parallels.com>
parent 7aa7e95f
...@@ -1020,7 +1020,7 @@ static int fchroot(int fd) ...@@ -1020,7 +1020,7 @@ static int fchroot(int fd)
int prepare_fs(int pid) int prepare_fs(int pid)
{ {
int ifd, dd, ret, err = -1; int ifd, dd_root, dd_cwd, ret, err = -1;
FsEntry *fe; FsEntry *fe;
ifd = open_image(CR_FD_FS, O_RSTR, pid); ifd = open_image(CR_FD_FS, O_RSTR, pid);
...@@ -1031,34 +1031,37 @@ int prepare_fs(int pid) ...@@ -1031,34 +1031,37 @@ int prepare_fs(int pid)
goto out_i; goto out_i;
/* /*
* Restore root * First -- open both descriptors. We will not
* be able to open the cwd one after we chroot.
*/ */
dd = open_reg_by_id(fe->root_id); dd_root = open_reg_by_id(fe->root_id);
if (dd < 0) { if (dd_root < 0) {
pr_err("Can't open root %#x\n", fe->root_id); pr_err("Can't open root %#x\n", fe->root_id);
goto err; goto err;
} }
ret = fchroot(dd); dd_cwd = open_reg_by_id(fe->cwd_id);
close(dd); if (dd_cwd < 0) {
if (ret < 0) { pr_err("Can't open cwd %#x\n", fe->cwd_id);
pr_perror("Can't change root");
goto err; goto err;
} }
/* /*
* Restore CWD * Now do chroot/chdir. Chroot goes first as it
* calls chdir into proc service descriptor so
* we'd need to fix chdir after it anyway.
*/ */
dd = open_reg_by_id(fe->cwd_id); ret = fchroot(dd_root);
if (dd < 0) { close(dd_root);
pr_err("Can't open cwd %#x\n", fe->cwd_id); if (ret < 0) {
pr_perror("Can't change root");
goto err; goto err;
} }
ret = fchdir(dd); ret = fchdir(dd_cwd);
close(dd); close(dd_cwd);
if (ret < 0) { if (ret < 0) {
pr_perror("Can't change cwd"); pr_perror("Can't change cwd");
goto err; goto err;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment