From nobody Tue Oct 10 05:16:16 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4S4PJK0bDWz4x7SJ; Tue, 10 Oct 2023 05:16:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4S4PJK00Rjz4gKt; Tue, 10 Oct 2023 05:16:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696914977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BtF/1YKTZHiOnIb6dBu6mEWqSzezXXib4ezMKRtSdmE=; b=WhIYgpXja6eGGsk88XuBeXpucA26rZRJRbN2hFFGklKFrgcoh4+4EQYAEX+YyUBdgoiM/M 9vtmwqZTNiZO3kvNO3lf3GCihhvrnI+Mr+Cw1U3m92DEwR1QcQw0juyvWntWZh7SrAuvs3 EUb/zc1pFC8fQGSbevXxw6M6UwcNct6Zq4Bg3hKZjQqdT4A5/Wf0MWhcmAhEPK9VsAXRNs pHhNngrjpA9GHMYyXQ+D0hSHcmhXZNj5R41IUcvz9St2lllr9C+252U4mKoBYp0uUuxgZV c4GY3kjU9NZLG7ZHenQBJocqNxtcwWAJQcgHhQjUtoCYgxsRLg+afGZ1iEsaoQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1696914977; a=rsa-sha256; cv=none; b=EG05Rys5CI3kuVNLsRUkzr0BMsSyscPVM1fvGWc31UYZHQUu7UNoWbucfxq8Y40p1e0hM7 IJk/dXHsU1nnAK+2uC9O+WTNpQFX2mCHifujXIna3N1xEtvO0PPMir6ibEIoIUxmC1xHCF VI2yrA8cythtjSI28KwhTbEn52effGzrQ0sTjuDKh5D1tVwE4JxIuWmIn9qqavKPe08lEQ iifQrSD9K5t1Lo4PAPyDsmSCHh4rWHnFGp4AZWC5v2QbgOHcXUOB21lDuCoJsTiC/qT32V lgdwr0RRXOPR7+N1Oa61iDylOxtMdWwlDCW06R3jHa3ZpjrcuQrp02oVLpjuVQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1696914977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=BtF/1YKTZHiOnIb6dBu6mEWqSzezXXib4ezMKRtSdmE=; b=U6/zh1itTBeuuFeBxtmLAnqx3DwUGh3ifpAZZYodKThgiu5RX/Ck+NxC+Ib+QyIkmA6/Ce jmzzexL4OfBdPfGf7FoDH3wc9JaF18nkt6d65sA0JLjXIy5gfl0v8Kn5BUUK1lGa5/UJ6G r/bJ+pGfLbZOA1reVkB//YoQfKR2UKjGBa0Y4xGIklxYcA+4+59ci+hxnjm60o1KHK4mkF +YE/1Oaq/1WvBQukPNDsI/W5hlp6Y/Hlo4p2SFJ4cC39mUlzqJJB9WnQPyJpRLYecyOPKI rt2Hck7zHN7DPjRo0lPOjgqhEPiOewTPn86dv0zclKKCzPdU1NaU/DnHs8scTw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4S4PJJ69rgzBMF; Tue, 10 Oct 2023 05:16:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39A5GGRe072401; Tue, 10 Oct 2023 05:16:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39A5GGXl072398; Tue, 10 Oct 2023 05:16:16 GMT (envelope-from git) Date: Tue, 10 Oct 2023 05:16:16 GMT Message-Id: <202310100516.39A5GGXl072398@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Dmitry Chagin Subject: git: f9d36fa86cdd - stable/13 - tests: Test that SIGSYS is not delivered if kern.signosys knob is off List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: f9d36fa86cdd458c00c74b8a211d049a560af322 Auto-Submitted: auto-generated The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=f9d36fa86cdd458c00c74b8a211d049a560af322 commit f9d36fa86cdd458c00c74b8a211d049a560af322 Author: Dmitry Chagin AuthorDate: 2023-10-03 07:38:02 +0000 Commit: Dmitry Chagin CommitDate: 2023-10-10 05:15:57 +0000 tests: Test that SIGSYS is not delivered if kern.signosys knob is off Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D41979 MFC after: 1 week (cherry picked from commit b67c0ba4613861f8245ce835081311aef1c19bae) --- tests/sys/kern/Makefile | 1 + tests/sys/kern/sigsys.c | 101 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 88 insertions(+), 14 deletions(-) diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile index ec2bbd742956..16faeeb40421 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -41,6 +41,7 @@ ATF_TESTS_C+= unix_socketpair_test 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 index 75e3816fc158..8554a646ebc6 100644 --- a/tests/sys/kern/sigsys.c +++ b/tests/sys/kern/sigsys.c @@ -7,31 +7,29 @@ * under sponsorship from the FreeBSD Foundation. */ +#include #include +#include #include #include #include #include #include +#include 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_TC_BODY(sigsys_test, tc) 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()); }