Source-Changes-HG archive

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

[src/trunk]: src/tests/kernel Skip the curtain test case if curtain is not en...



details:   https://anonhg.NetBSD.org/src/rev/393f425197ef
branches:  trunk
changeset: 795760:393f425197ef
user:      martin <martin%NetBSD.org@localhost>
date:      Mon Apr 28 08:34:16 2014 +0000

description:
Skip the curtain test case if curtain is not enabled and we would not
be able to restore it to its old value later due to running at securelevel
above 0.
Previously this would fail and leave curtain enabled untill next reboot (but
causing further runs of the test to suceed, just to maximize confusion).
This went unnoticed initial since most modular test kernels run with options
INSECURE to allow exercising the kernel module loader.

diffstat:

 tests/kernel/t_kauth_pr_47598.c |  61 ++++++++++++++++++++++++++++++++++------
 1 files changed, 51 insertions(+), 10 deletions(-)

diffs (99 lines):

diff -r fb73177d1629 -r 393f425197ef tests/kernel/t_kauth_pr_47598.c
--- a/tests/kernel/t_kauth_pr_47598.c   Sun Apr 27 21:45:53 2014 +0000
+++ b/tests/kernel/t_kauth_pr_47598.c   Mon Apr 28 08:34:16 2014 +0000
@@ -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.3 2014/04/28 08:34:16 martin Exp $");
 
 #include <errno.h>
 #include <unistd.h>
@@ -40,6 +40,48 @@
 #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_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 @@
        /*
         * 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)



Home | Main Index | Thread Index | Old Index