[CRIU] [PATCH 1/2] files: restore cwd after switching mntns
Andrew Vagin
avagin at virtuozzo.com
Thu Nov 19 04:37:05 PST 2015
On Thu, Nov 19, 2015 at 03:23:30PM +0300, Pavel Emelyanov wrote:
> On 11/18/2015 02:04 PM, Andrey Vagin wrote:
> > From: Andrew Vagin <avagin at virtuozzo.com>
>
> Comment required.
Here is a problem that restore_ns() restores a mount namespace, but
doesn't restore cwd, so cwd will be an root of the restired mntns.
CRIU doesn't expect this, so we will see errors. Fro example, Stas
reports an error that criu can't umount an roots yard.
>
> > Cc: Stanislav Kinsbursky <skinsbursky at openvz.org>
> > Reported-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
> > Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
> > ---
> > files-reg.c | 16 ++++++++++++++++
> > 1 file changed, 16 insertions(+)
> >
> > diff --git a/files-reg.c b/files-reg.c
> > index 1e2daa9..ac334e7 100644
> > --- a/files-reg.c
> > +++ b/files-reg.c
> > @@ -423,6 +423,7 @@ void try_clean_remaps(int ns_fd)
> > {
> > struct remap_info *ri;
> > int old_ns = -1;
> > + int cwd_fd = -1;
> >
> > if (list_empty(&remaps))
> > goto out;
> > @@ -436,6 +437,12 @@ void try_clean_remaps(int ns_fd)
> > return;
> > }
> >
> > + cwd_fd = open(".", O_DIRECTORY);
> > + if (cwd_fd < 0) {
> > + pr_perror("Unable to open cwd");
> > + return;
> > + }
> > +
> > if (setns(ns_fd, CLONE_NEWNS) < 0) {
> > close(old_ns);
> > pr_perror("`- Can't switch");
> > @@ -453,6 +460,15 @@ void try_clean_remaps(int ns_fd)
> > close(old_ns);
> > }
> >
> > + if (cwd_fd >= 0) {
> > + if (fchdir(cwd_fd)) {
> > + pr_perror("Unable to restore cwd");
> > + close(cwd_fd);
> > + return;
> > + }
> > + close(cwd_fd);
> > + }
> > +
> > out:
> > if (ns_fd >= 0)
> > close(ns_fd);
> >
>
More information about the CRIU
mailing list