Module Name: src
Committed By: snj
Date: Mon Jul 24 06:03:42 UTC 2017
Modified Files:
src/sys/uvm [netbsd-8]: uvm_fault.c
src/tests/lib/libc/sys [netbsd-8]: t_write.c
Log Message:
Pull up following revision(s) (requested by kamil in ticket #120):
sys/uvm/uvm_fault.c: revision 1.200
tests/lib/libc/sys/t_write.c: revision 1.4-1.6
PR/52384: make uvm_fault_check() return EFAULT not EACCES, like our man
pages
(but not OpenGroup which does not document EFAULT for read/write, and onl=
y
documents EACCES for sockets) say for read/write.
--
check for EFAULT on reads and writes to memory with not permission.
--
add munmap
#define for const.
--
add another missing munmap (Kamil)
To generate a diff of this commit:
cvs rdiff -u -r1.199 -r1.199.6.1 src/sys/uvm/uvm_fault.c
cvs rdiff -u -r1.3 -r1.3.6.1 src/tests/lib/libc/sys/t_write.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/uvm/uvm_fault.c
diff -u src/sys/uvm/uvm_fault.c:1.199 src/sys/uvm/uvm_fault.c:1.199.6.1
--- src/sys/uvm/uvm_fault.c:1.199 Mon Mar 20 15:51:41 2017
+++ src/sys/uvm/uvm_fault.c Mon Jul 24 06:03:42 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: uvm_fault.c,v 1.199 2017/03/20 15:51:41 skrll Exp $ */
+/* $NetBSD: uvm_fault.c,v 1.199.6.1 2017/07/24 06:03:42 snj Exp $ */
/*
* Copyright (c) 1997 Charles D. Cranor and Washington University.
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.199 2017/03/20 15:51:41 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uvm_fault.c,v 1.199.6.1 2017/07/24 06:03:42 snj Exp $");
#include "opt_uvmhist.h"
@@ -950,7 +950,7 @@ uvm_fault_check(
"<- protection failure (prot=%#x, access=%#x)",
ufi->entry->protection, flt->access_type, 0, 0);
uvmfault_unlockmaps(ufi, false);
- return EACCES;
+ return EFAULT;
}
/*
Index: src/tests/lib/libc/sys/t_write.c
diff -u src/tests/lib/libc/sys/t_write.c:1.3 src/tests/lib/libc/sys/t_write.c:1.3.6.1
--- src/tests/lib/libc/sys/t_write.c:1.3 Fri Jan 13 19:27:23 2017
+++ src/tests/lib/libc/sys/t_write.c Mon Jul 24 06:03:42 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: t_write.c,v 1.3 2017/01/13 19:27:23 christos Exp $ */
+/* $NetBSD: t_write.c,v 1.3.6.1 2017/07/24 06:03:42 snj Exp $ */
/*-
* Copyright (c) 2001, 2008 The NetBSD Foundation, Inc.
@@ -29,9 +29,10 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2008\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_write.c,v 1.3 2017/01/13 19:27:23 christos Exp $");
+__RCSID("$NetBSD: t_write.c,v 1.3.6.1 2017/07/24 06:03:42 snj Exp $");
#include <sys/uio.h>
+#include <sys/mman.h>
#include <atf-c.h>
#include <errno.h>
@@ -42,6 +43,7 @@ __RCSID("$NetBSD: t_write.c,v 1.3 2017/0
#include <stdint.h>
#include <string.h>
#include <unistd.h>
+#include <paths.h>
static void sighandler(int);
@@ -213,6 +215,60 @@ ATF_TC_BODY(writev_iovmax, tc)
ATF_REQUIRE_EQ_MSG(errno, EINVAL, "got: %s", strerror(errno));
}
+ATF_TC(write_fault);
+
+ATF_TC_HEAD(write_fault, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Check that writing to non-permitted space returns EFAULT");
+}
+
+#define SIZE 8192
+
+ATF_TC_BODY(write_fault, tc)
+{
+ int fd[2];
+ ATF_REQUIRE(pipe(fd) != -1);
+ // Can't use /dev/null cause it doesn't access the buffer.
+
+ void *map = mmap(NULL, SIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
+ ATF_REQUIRE(map != MAP_FAILED);
+
+ ssize_t retval = write(fd[1], map, SIZE);
+
+ ATF_REQUIRE_EQ_MSG(retval, -1, "got: %zd", retval);
+ ATF_REQUIRE_EQ_MSG(errno, EFAULT, "got: %s", strerror(errno));
+
+ munmap(map, SIZE);
+ close(fd[0]);
+ close(fd[1]);
+}
+
+ATF_TC(read_fault);
+
+ATF_TC_HEAD(read_fault, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Check that reading from non-permitted space returns EFAULT");
+}
+
+ATF_TC_BODY(read_fault, tc)
+{
+ int fd = open(_PATH_DEVZERO, O_RDONLY);
+ ATF_REQUIRE(fd != -1);
+
+ void *map = mmap(NULL, SIZE, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
+ ATF_REQUIRE(map != MAP_FAILED);
+
+ ssize_t retval = read(fd, map, SIZE);
+
+ ATF_REQUIRE_EQ_MSG(retval, -1, "got: %zd", retval);
+ ATF_REQUIRE_EQ_MSG(errno, EFAULT, "got: %s", strerror(errno));
+
+ munmap(map, SIZE);
+ close(fd);
+}
+
ATF_TP_ADD_TCS(tp)
{
@@ -221,6 +277,8 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, write_pos);
ATF_TP_ADD_TC(tp, write_ret);
ATF_TP_ADD_TC(tp, writev_iovmax);
+ ATF_TP_ADD_TC(tp, write_fault);
+ ATF_TP_ADD_TC(tp, read_fault);
return atf_no_error();
}