Module Name: src
Committed By: tls
Date: Sun Aug 10 06:57:19 UTC 2014
Modified Files:
src/tests/kernel [tls-earlyentropy]: Makefile t_kauth_pr_47598.c
src/tests/kernel/tty [tls-earlyentropy]: Makefile
Added Files:
src/tests/kernel [tls-earlyentropy]: t_sysctl.c
Log Message:
Rebase.
To generate a diff of this commit:
cvs rdiff -u -r1.33.4.1 -r1.33.4.2 src/tests/kernel/Makefile
cvs rdiff -u -r1.2 -r1.2.8.1 src/tests/kernel/t_kauth_pr_47598.c
cvs rdiff -u -r0 -r1.1.2.2 src/tests/kernel/t_sysctl.c
cvs rdiff -u -r1.1 -r1.1.22.1 src/tests/kernel/tty/Makefile
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/kernel/Makefile
diff -u src/tests/kernel/Makefile:1.33.4.1 src/tests/kernel/Makefile:1.33.4.2
--- src/tests/kernel/Makefile:1.33.4.1 Mon Apr 7 19:32:15 2014
+++ src/tests/kernel/Makefile Sun Aug 10 06:57:19 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.33.4.1 2014/04/07 19:32:15 tls Exp $
+# $NetBSD: Makefile,v 1.33.4.2 2014/08/10 06:57:19 tls Exp $
NOMAN= # defined
@@ -14,6 +14,7 @@ TESTS_C+= t_mqueue
TESTS_C+= t_sysv
TESTS_C+= t_subr_prf
TESTS_C+= t_kauth_pr_47598
+TESTS_C+= t_sysctl
TESTS_SH= t_umount
TESTS_SH+= t_umountstress
@@ -32,9 +33,11 @@ TESTS_SUBDIRS+= tty
TESTS_C+= t_extattrctl
TESTS_C+= t_filedesc
TESTS_C+= t_rnd
-LDADD.t_extattrctl+= -lrumpvfs -lrump -lrumpuser -lpthread
+LDADD.t_extattrctl+= -lrumpvfs -lrump -lrumpuser
+LDADD.t_extattrctl+= -lrump -lpthread
LDADD.t_filedesc+= ${LDADD.t_rnd}
-LDADD.t_rnd+= -lrumpvfs -lrumpdev_rnd -lrumpdev -lrump -lrumpuser -lpthread
+LDADD.t_rnd+= -lrumpvfs -lrumpdev_rnd -lrumpdev -lrump -lrumpuser
+LDADD.t_rnd+= -lrump -lpthread
.endif
Index: src/tests/kernel/t_kauth_pr_47598.c
diff -u src/tests/kernel/t_kauth_pr_47598.c:1.2 src/tests/kernel/t_kauth_pr_47598.c:1.2.8.1
--- src/tests/kernel/t_kauth_pr_47598.c:1.2 Thu Feb 28 20:41:21 2013
+++ src/tests/kernel/t_kauth_pr_47598.c Sun Aug 10 06:57:19 2014
@@ -27,7 +27,7 @@
#include <sys/cdefs.h>
__COPYRIGHT("@(#) Copyright (c) 2013\
The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_kauth_pr_47598.c,v 1.2 2013/02/28 20:41:21 martin Exp $");
+__RCSID("$NetBSD: t_kauth_pr_47598.c,v 1.2.8.1 2014/08/10 06:57:19 tls Exp $");
#include <errno.h>
#include <unistd.h>
@@ -40,6 +40,48 @@ __RCSID("$NetBSD: t_kauth_pr_47598.c,v 1
#include <atf-c.h>
/*
+ * helper function
+ */
+static const char curtain_name[] = "security.models.bsd44.curtain";
+static const char securelevel_name[] = "security.models.bsd44.securelevel";
+
+static bool may_lower_curtain(void);
+static int get_curtain(void);
+static void set_curtain(int newval);
+
+static bool
+may_lower_curtain(void)
+{
+ int seclevel;
+ size_t len = sizeof(seclevel);
+
+ if (sysctlbyname(securelevel_name, &seclevel, &len, NULL, 0) != 0)
+ atf_tc_fail("failed to read %s", securelevel_name);
+
+ return seclevel <= 0;
+}
+
+static int
+get_curtain(void)
+{
+ int curtain;
+ size_t len = sizeof(curtain);
+
+ if (sysctlbyname(curtain_name, &curtain, &len, NULL, 0) != 0)
+ atf_tc_fail("failed to read %s", curtain_name);
+
+ return curtain;
+}
+
+static void
+set_curtain(int newval)
+{
+
+ if (sysctlbyname(curtain_name, NULL, 0, &newval, sizeof(newval)) != 0)
+ atf_tc_fail("failed to set %s to %d", curtain_name, newval);
+}
+
+/*
* PR kern/47598: if security.models.extensions.curtain = 1 we crash when
* doing a netstat while an embryonic (not yet fully accepted) connection
* exists.
@@ -59,19 +101,20 @@ ATF_TC_HEAD(kauth_curtain, tc)
ATF_TC_BODY(kauth_curtain, tc)
{
- static const char curtain_name[] = "security.models.bsd44.curtain";
- int old_curtain, new_curtain = 1, s, s2, err;
- size_t old_curtain_len = sizeof(old_curtain);
+ int old_curtain, s, s2, err;
socklen_t slen;
struct sockaddr_in sa;
/*
* save old value of "curtain" and enable it
*/
- if (sysctlbyname(curtain_name, &old_curtain, &old_curtain_len,
- &new_curtain, sizeof(new_curtain)) != 0)
- atf_tc_fail("failed to enable %s", curtain_name);
+ old_curtain = get_curtain();
+ if (old_curtain < 1 && !may_lower_curtain())
+ atf_tc_skip("curtain is not enabled and we would not be able"
+ " to drop it later due to securelevel settings");
+
+ set_curtain(1);
/*
* create a socket and bind it to some arbitray free port
@@ -113,9 +156,7 @@ ATF_TC_BODY(kauth_curtain, tc)
/*
* restore old value of curtain
*/
- if (sysctlbyname(curtain_name, NULL, 0,
- &old_curtain, sizeof(old_curtain)) != 0)
- atf_tc_fail("failed to restore %s", curtain_name);
+ set_curtain(old_curtain);
}
ATF_TP_ADD_TCS(tp)
Index: src/tests/kernel/tty/Makefile
diff -u src/tests/kernel/tty/Makefile:1.1 src/tests/kernel/tty/Makefile:1.1.22.1
--- src/tests/kernel/tty/Makefile:1.1 Mon Jun 28 19:04:00 2010
+++ src/tests/kernel/tty/Makefile Sun Aug 10 06:57:19 2014
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2010/06/28 19:04:00 pooka Exp $
+# $NetBSD: Makefile,v 1.1.22.1 2014/08/10 06:57:19 tls Exp $
.include <bsd.own.mk>
@@ -6,6 +6,8 @@ TESTSDIR= ${TESTSBASE}/kernel/tty
TESTS_C= t_pr
-LDADD+= -lrumpkern_tty -lrumpvfs -lrump -lrumpuser -lpthread
+LDADD+= -lrumpkern_tty -lrumpvfs -lrump -lrumpuser
+LDADD+= -lrump
+LDADD+= -lpthread
.include <bsd.test.mk>
Added files:
Index: src/tests/kernel/t_sysctl.c
diff -u /dev/null src/tests/kernel/t_sysctl.c:1.1.2.2
--- /dev/null Sun Aug 10 06:57:19 2014
+++ src/tests/kernel/t_sysctl.c Sun Aug 10 06:57:19 2014
@@ -0,0 +1,74 @@
+/* $NetBSD: t_sysctl.c,v 1.1.2.2 2014/08/10 06:57:19 tls Exp $ */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__COPYRIGHT("@(#) Copyright (c) 2014\
+ The NetBSD Foundation, inc. All rights reserved.");
+__RCSID("$NetBSD: t_sysctl.c,v 1.1.2.2 2014/08/10 06:57:19 tls Exp $");
+
+#include <sys/sysctl.h>
+#include <errno.h>
+#include <memory.h>
+
+#include <atf-c.h>
+
+ATF_TC(bufsize);
+ATF_TC_HEAD(bufsize, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test sysctl integer reads with different buffer sizes");
+}
+ATF_TC_BODY(bufsize, tc)
+{
+ union {
+ int int_val;
+ unsigned char space[256];
+ } buf;
+ size_t len;
+ for (len = 0; len < sizeof(buf); len++) {
+ size_t oldlen = len;
+ int r;
+ memset(&buf, 0xFF, sizeof(buf));
+ r = sysctlbyname("kern.job_control", &buf, &oldlen, 0, (size_t) 0);
+ if (len < sizeof(int)) {
+ ATF_REQUIRE_EQ(r, -1);
+ ATF_REQUIRE_EQ(errno, ENOMEM);
+ } else {
+ ATF_REQUIRE_EQ(r, 0);
+ ATF_REQUIRE_EQ(buf.int_val, 1);
+ ATF_REQUIRE_EQ(oldlen, sizeof(int));
+ }
+ }
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, bufsize);
+
+ return atf_no_error();
+}