tech-kern archive

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

posix_madvise(2) should fail with ENOMEM for invalid adresses range



Hi,

According the OpenGroup online document for posix_madvise[1], it
should fail with ENOMEM for invalid addresses ranges :

[ENOMEM]
    Addresses in the range starting at addr and continuing for len
    bytes are partly or completely outside the range allowed for the
    address space of the calling process.

But we currently fail with EINVAL (returned value from range_check()
function).

Ok to apply the attached patch to fix posix_madvise/madvise ?

Thanks.

[1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_madvise.html

-- 
Nicolas Joly

Biology IT Center
Institut Pasteur, Paris.
Index: sys/uvm/uvm_mmap.c
===================================================================
RCS file: /cvsroot/src/sys/uvm/uvm_mmap.c,v
retrieving revision 1.149
diff -u -p -r1.149 uvm_mmap.c
--- sys/uvm/uvm_mmap.c	5 Sep 2014 09:24:48 -0000	1.149
+++ sys/uvm/uvm_mmap.c	11 Nov 2014 11:21:23 -0000
@@ -843,7 +843,7 @@ sys_madvise(struct lwp *l, const struct 
 
 	error = range_test(addr, size, false);
 	if (error)
-		return error;
+		return ENOMEM;
 
 	switch (advice) {
 	case MADV_NORMAL:
Index: lib/libc/sys/madvise.2
===================================================================
RCS file: /cvsroot/src/lib/libc/sys/madvise.2,v
retrieving revision 1.28
diff -u -p -r1.28 madvise.2
--- lib/libc/sys/madvise.2	19 Jul 2014 19:26:47 -0000	1.28
+++ lib/libc/sys/madvise.2	11 Nov 2014 11:21:23 -0000
@@ -105,6 +105,13 @@ will fail if:
 .Bl -tag -width Er
 .It Bq Er EINVAL
 Invalid parameters were provided.
+.It Bq Er ENOMEM
+Addresses in the range starting at
+.Fa addr
+and continuing for
+.Fa len
+bytes are partly or completely outside the range allowed for the address
+space of the calling process.
 .El
 .Sh SEE ALSO
 .Xr mincore 2 ,


Home | Main Index | Thread Index | Old Index