[CRIU] [PATCH] kerndat: set uffd features to 0 before querying kernel

Mike Rapoport rppt at linux.vnet.ibm.com
Mon Aug 21 15:37:30 MSK 2017


On Mon, Aug 21, 2017 at 03:00:43PM +0300, Pavel Emelyanov wrote:
> On 08/21/2017 06:53 AM, Mike Rapoport wrote:
> > When there is a stale kdat cache file it's contents is read into the memory
> 
> This cannot (shouldn't) happen. If the cache file is from different criu version
> it's detected and file is ignored.

The file is ignored, but kdat is not reset:

	fd = open(KERNDAT_CACHE_FILE, O_RDONLY);

	ret = read(fd, &kdat, sizeof(kdat));

	if (ret != sizeof(kdat) ||
			kdat.magic1 != KDAT_MAGIC ||
			kdat.magic2 != KDAT_MAGIC_2) {
		pr_warn("Stale %s file\n", KERNDAT_CACHE_FILE);
		unlink(KERNDAT_CACHE_FILE);
		return 1;
	}

That said, if kdat cache file exists, but it has a wrong magic, the
in-memory kdat will have the contents from file which will be gradually
overwritten by the kerndat_* calls.

However, in kerndat_uffd we assume that kdat.uffd_features is 0 before
actually querying the kernel.
 
> > and we end up requesting random userfaultfd features. Explicitly set the
> > kdat.uffd_features to zero before querying the kernel resolves the issue.
> > 
> > Signed-off-by: Mike Rapoport <rppt at linux.vnet.ibm.com>
> > ---
> >  criu/kerndat.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/criu/kerndat.c b/criu/kerndat.c
> > index 31eaddb..0c8588a 100644
> > --- a/criu/kerndat.c
> > +++ b/criu/kerndat.c
> > @@ -874,6 +874,7 @@ int kerndat_uffd(void)
> >  {
> >  	int uffd;
> >  
> > +	kdat.uffd_features = 0;
> >  	uffd = uffd_open(0, &kdat.uffd_features);
> >  
> >  	/*
> > 
> 

-- 
Sincerely yours,
Mike.



More information about the CRIU mailing list