[CRIU] [PATCH 3/4] remap: add a dead pid /proc remap

Tycho Andersen tycho.andersen at canonical.com
Fri Sep 19 06:58:53 PDT 2014


On Fri, Sep 19, 2014 at 05:47:21PM +0400, Pavel Emelyanov wrote:
> I've pushed the changes, looked at them and found 2 bugs :)

Agreed, I will send a patch for these.

Tycho

> > @@ -516,6 +550,20 @@ static int dump_linked_remap(char *path, int len, const struct stat *ost,
> >  			&rpe, PB_REMAP_FPATH);
> >  }
> >  
> > +static int dump_dead_process_remap(pid_t pid, char *path, int len, const struct stat *ost,
> > +				int lfd, u32 id, struct ns_id *nsid)
> > +{
> > +	RemapFilePathEntry rpe = REMAP_FILE_PATH_ENTRY__INIT;
> > +
> > +	rpe.orig_id = id;
> > +	rpe.remap_id = pid;
> > +	rpe.has_remap_type = true;
> > +	rpe.remap_type = REMAP_TYPE__PROCFS;
> 
> This code would produce duplicate entries if equal dead pids are 
> opened by more than one file.
> 
> > +
> > +	return pb_write_one(fdset_fd(glob_fdset, CR_FD_REMAP_FPATH),
> > +			&rpe, PB_REMAP_FPATH);
> > +}
> > +
> >  static bool is_sillyrename_name(char *name)
> >  {
> >  	int i;
> > @@ -557,6 +605,38 @@ static int check_path_remap(char *rpath, int plen, const struct fd_parms *parms,
> >  	struct stat pst;
> >  	const struct stat *ost = &parms->stat;
> >  
> > +	if (parms->fs_type == PROC_SUPER_MAGIC) {
> > +		/* The file points to /proc/pid/<foo> where pid is a dead
> > +		 * process. We remap this file by adding this pid to be
> > +		 * fork()ed into a TASK_HELPER state so that we can point to it
> > +		 * on restore.
> > +		 */
> > +		pid_t pid;
> > +		char *start, *end;
> > +
> > +		/* skip "./proc/" */
> > +		start = strstr(rpath, "/") + 1;
> > +		if (!start)
> > +			return -1;
> > +		start = strstr(start, "/") + 1;
> > +		if (!start)
> > +			return -1;
> > +		pid = strtol(start, &end, 10);
> > +
> > +		/* if we didn't find another /, this path something
> > +		 * like ./proc/kmsg, which we shouldn't mess with. */
> > +		if (*end == '/') {
> > +			*end = 0;
> > +			ret = access(rpath, F_OK);
> > +			*end = '/';
> > +
> > +			if (ret) {
> > +				pr_info("Dumping dead process remap of %d\n", pid);
> > +				return dump_dead_process_remap(pid, rpath + 1, plen - 1, ost, lfd, id, nsid);
> > +			}
> > +		}
> 
> On these else branches we would go and execute the rest of the
> remap code, while we shouldn't.
> 
> > +	}
> > +
> >  	if (ost->st_nlink == 0)
> >  		/*
> >  		 * Unpleasant, but easy case. File is completely invisible
> 


More information about the CRIU mailing list