Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-8]: src Pull up following revision(s) (requested by kamil in tick...
details: https://anonhg.NetBSD.org/src/rev/103ab04ba40b
branches: netbsd-8
changeset: 434128:103ab04ba40b
user: snj <snj%NetBSD.org@localhost>
date: Mon Jul 24 06:03:42 2017 +0000
description:
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)
diffstat:
sys/uvm/uvm_fault.c | 6 ++--
tests/lib/libc/sys/t_write.c | 62 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 5 deletions(-)
diffs (126 lines):
diff -r 0556a332af48 -r 103ab04ba40b sys/uvm/uvm_fault.c
--- a/sys/uvm/uvm_fault.c Mon Jul 24 05:47:59 2017 +0000
+++ b/sys/uvm/uvm_fault.c Mon Jul 24 06:03:42 2017 +0000
@@ -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 @@
"<- protection failure (prot=%#x, access=%#x)",
ufi->entry->protection, flt->access_type, 0, 0);
uvmfault_unlockmaps(ufi, false);
- return EACCES;
+ return EFAULT;
}
/*
diff -r 0556a332af48 -r 103ab04ba40b tests/lib/libc/sys/t_write.c
--- a/tests/lib/libc/sys/t_write.c Mon Jul 24 05:47:59 2017 +0000
+++ b/tests/lib/libc/sys/t_write.c Mon Jul 24 06:03:42 2017 +0000
@@ -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 @@
#include <stdint.h>
#include <string.h>
#include <unistd.h>
+#include <paths.h>
static void sighandler(int);
@@ -213,6 +215,60 @@
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_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();
}
Home |
Main Index |
Thread Index |
Old Index