Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F107282180
D41979.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D41979.diff
View Options
diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile
--- a/tests/sys/kern/Makefile
+++ b/tests/sys/kern/Makefile
@@ -49,6 +49,7 @@
ATF_TESTS_C+= waitpid_nohang
ATF_TESTS_C+= pdeathsig
ATF_TESTS_C+= sigsys
+TEST_METADATA.sigsys+= is_exclusive="true"
ATF_TESTS_SH+= coredump_phnum_test
ATF_TESTS_SH+= sonewconn_overflow
diff --git a/tests/sys/kern/sigsys.c b/tests/sys/kern/sigsys.c
--- a/tests/sys/kern/sigsys.c
+++ b/tests/sys/kern/sigsys.c
@@ -7,31 +7,29 @@
* under sponsorship from the FreeBSD Foundation.
*/
+#include <sys/param.h>
#include <sys/syscall.h>
+#include <sys/sysctl.h>
#include <atf-c.h>
#include <errno.h>
#include <signal.h>
#include <stdatomic.h>
#include <stdbool.h>
+#include <stdio.h>
static sig_atomic_t sigsys_cnt;
+#define SAVEDVALUE "savedsignosys"
+
static void
sigsys_handler(int signo, siginfo_t *si, void *ucp)
{
sigsys_cnt++;
}
-ATF_TC(sigsys_test);
-
-ATF_TC_HEAD(sigsys_test, tc)
-{
- atf_tc_set_md_var(tc, "descr",
- "Testing delivery of SIGSYS on invalid syscalls");
-}
-
-ATF_TC_BODY(sigsys_test, tc)
+static void
+sigsys_test(int knob)
{
struct sigaction sa;
@@ -43,27 +41,102 @@
ATF_REQUIRE(syscall(273) == -1); /* reserved */
ATF_CHECK_ERRNO(ENOSYS, true);
atomic_signal_fence(memory_order_seq_cst);
- ATF_CHECK_EQ(1, sigsys_cnt);
+ ATF_CHECK_EQ(1 * knob, sigsys_cnt * knob);
ATF_REQUIRE(syscall(440) == -1); /* SYS_kse_switchin */
ATF_CHECK_ERRNO(ENOSYS, true);
atomic_signal_fence(memory_order_seq_cst);
- ATF_CHECK_EQ(2, sigsys_cnt);
+ ATF_CHECK_EQ(2 * knob, sigsys_cnt * knob);
/* Hope this is enough for say next two months */
ATF_REQUIRE(syscall(3000000) == -1);
ATF_CHECK_ERRNO(ENOSYS, true);
atomic_signal_fence(memory_order_seq_cst);
- ATF_CHECK_EQ(3, sigsys_cnt);
+ ATF_CHECK_EQ(3 * knob, sigsys_cnt * knob);
ATF_REQUIRE(syscall(SYS_afs3_syscall) == -1);
ATF_CHECK_ERRNO(ENOSYS, true);
atomic_signal_fence(memory_order_seq_cst);
- ATF_CHECK_EQ(4, sigsys_cnt);
+ ATF_CHECK_EQ(4 * knob, sigsys_cnt * knob);
+}
+
+static void
+sysctlset(const char *name, int val)
+{
+ size_t oldlen;
+ int oldval;
+ char buf[80];
+
+ ATF_REQUIRE(sysctlbyname(name, &oldval, &oldlen, NULL, 0) == 0);
+
+ /* Store old %name in a symlink for cleanup */
+ snprintf(buf, sizeof(buf), "%d", oldval);
+ ATF_REQUIRE(symlink(buf, SAVEDVALUE) == 0);
+
+ ATF_REQUIRE(sysctlbyname(name, NULL, NULL, &val, sizeof(val)) == 0);
+}
+
+static void
+sysctlcleanup(const char *name)
+{
+ size_t oldlen;
+ int n, oldval;
+ char buf[80];
+
+ if ((n = readlink(SAVEDVALUE, buf, sizeof(buf))) > 0) {
+ buf[MIN((size_t)n, sizeof(buf) - 1)] = '\0';
+ if (sscanf(buf, "%d", &oldval) == 1) {
+ oldlen = sizeof(oldval);
+ (void)sysctlbyname(name, NULL, 0,
+ &oldval, oldlen);
+ }
+ }
+ (void)unlink(SAVEDVALUE);
+}
+
+ATF_TC_WITH_CLEANUP(sigsys_test_on);
+ATF_TC_HEAD(sigsys_test_on, tc)
+{
+ atf_tc_set_md_var(tc, "require.user", "root");
+ atf_tc_set_md_var(tc, "require.config", "allow_sysctl_side_effects");
+ atf_tc_set_md_var(tc, "descr",
+ "Testing delivery of SIGSYS on invalid syscalls");
+}
+
+ATF_TC_BODY(sigsys_test_on, tc)
+{
+ sysctlset("kern.signosys", 1);
+ sigsys_test(1);
+}
+
+ATF_TC_CLEANUP(sigsys_test_on, tc)
+{
+ sysctlcleanup("kern.signosys");
+}
+
+ATF_TC_WITH_CLEANUP(sigsys_test_off);
+ATF_TC_HEAD(sigsys_test_off, tc)
+{
+ atf_tc_set_md_var(tc, "require.user", "root");
+ atf_tc_set_md_var(tc, "require.config", "allow_sysctl_side_effects");
+ atf_tc_set_md_var(tc, "descr",
+ "Testing SIGSYS silence on invalid syscalls");
+}
+
+ATF_TC_BODY(sigsys_test_off, tc)
+{
+ sysctlset("kern.signosys", 0);
+ sigsys_test(0);
+}
+
+ATF_TC_CLEANUP(sigsys_test_off, tc)
+{
+ sysctlcleanup("kern.signosys");
}
ATF_TP_ADD_TCS(tp)
{
- ATF_TP_ADD_TC(tp, sigsys_test);
+ ATF_TP_ADD_TC(tp, sigsys_test_on);
+ ATF_TP_ADD_TC(tp, sigsys_test_off);
return (atf_no_error());
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Jan 12, 10:54 PM (21 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
15773534
Default Alt Text
D41979.diff (3 KB)
Attached To
Mode
D41979: tests: Test that SIGSYS is not delivered if kern.signosys knob is off
Attached
Detach File
Event Timeline
Log In to Comment