NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/57622: memfd mmap does not work for requests < page size



The following reply was made to PR kern/57622; it has been noted by GNATS.

From: Michael van Elst <mlelstv%serpens.de@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: 
Subject: Re: kern/57622: memfd mmap does not work for requests < page size
Date: Sun, 17 Mar 2024 09:51:05 +0100

 Maybe this:
 
 Index: sys/kern/sys_memfd.c
 ===================================================================
 RCS file: /cvsroot/src/sys/kern/sys_memfd.c,v
 retrieving revision 1.11
 diff -p -u -r1.11 sys_memfd.c
 --- sys/kern/sys_memfd.c	12 Aug 2023 23:22:49 -0000	1.11
 +++ sys/kern/sys_memfd.c	17 Mar 2024 08:46:34 -0000
 @@ -348,7 +348,7 @@ memfd_mmap(file_t *fp, off_t *offp, size
  		error = EINVAL;
  		goto leave;
  	}
 -	if (*offp + size > mfd->mfd_size) {
 +	if (*offp + size < 0) {
  		error = EINVAL;
  		goto leave;
  	}
 @@ -359,6 +359,12 @@ memfd_mmap(file_t *fp, off_t *offp, size
  		goto leave;
  	}
  
 +	/* Zero fill end of partial page */
 +	if (*offp + size > mfd->mfd_size) {
 +		ubc_zerorange(mfd->mfd_uobj, mfd->mfd_size,
 +		    *offp + size - mfd->mfd_size, 0);
 +	}
 +
  	uao_reference(fp->f_memfd->mfd_uobj);
  	*uobjp = fp->f_memfd->mfd_uobj;
  
 
 Greetings,
 -- 
                                 Michael van Elst
 Internet: mlelstv%serpens.de@localhost
                                 "A potential Snark may lurk in every tree."
 


Home | Main Index | Thread Index | Old Index