From nobody Thu Mar 03 14:20:44 2022 X-Original-To: dev-commits-src-branches@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 96E3619E6291; Thu, 3 Mar 2022 14:20:46 +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 4K8Y7143BMz3Ldx; Thu, 3 Mar 2022 14:20:45 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646317245; 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=V5tmMG9u8ABhIbSPfJovJrxr7aUQVYSk8BsyBanSaOk=; b=Yi2l9LQ4SXzw4R4gex/IYgZLC8tky3Koihv5PoB7jLMxbDz+3VsrmfkXcx3JbyPIxHXnhz 13+cE1O/OBDgVZk1zSvEcxSZQsk2s38E1A150LvaBO6NAlQYBJJyO34yj6n/LsuCe8Z6fX MQG5xScoFg3LO2VQyDeWPu4vAiJDkaims5/AmWy7WrQXPml+UTxcdEPOdszl1Z2W4jWAqq DWWyy/2pA3MAxNBWWrpZpBE1lVdSlaWaOXOwYlunJ/XD+qvEvRRdNY/cqXrc/AZuF31ebi 6QaCmXsUILWG6p4KAD4OGR9NsVRzlV8Rda5/Oy3CWGU39ctdscGa0Y+A71OH5A== 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 CEDF01968C; Thu, 3 Mar 2022 14:20:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 223EKiFU090781; Thu, 3 Mar 2022 14:20:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 223EKiTQ090780; Thu, 3 Mar 2022 14:20:44 GMT (envelope-from git) Date: Thu, 3 Mar 2022 14:20:44 GMT Message-Id: <202203031420.223EKiTQ090780@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Eric van Gyzen Subject: git: 6a73d96ac4de - stable/13 - mmap map_at_zero test: handle W^X List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: vangyzen X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 6a73d96ac4def6ba03788ed0914aa994c037778a Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646317245; 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=V5tmMG9u8ABhIbSPfJovJrxr7aUQVYSk8BsyBanSaOk=; b=t00O+NI2nGvG8XQ2l8lfGa7g4eXp0fPLLlapsSLEPVjifad6FQPFXHE1oGwL2CTyxOR9AM c1pJY7vzIHJee5AKP0iNeEtv4BAVpyZ9mM/Z4AECQBrYrEDpx9O2/6N+eKJxsqfg8yXk8O 2Yh+9+vy/veVEujdnMh2Ltj0jhquGtppCWPovQ9mHMBZvb5LfQY5oVUGwpCT7udN7Hv9P2 RLbfanajVz2mqtIlp2mpDqq0SaHFMG24lGoxiT1rsU93+jgP4XtZGS/tfRUiv/nniuj0Yn wAhb8Q6H1v1Borjol8OmJqsJUqUzqyedFc0prvHMUIhgNeLBYnioAfFWingcFQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646317245; a=rsa-sha256; cv=none; b=GlDq5pF4cbGdooGjnZ8fMqsl/Hd+z23hOKtRsHI5XZ6msYYEu0vFnlIHIDSppv/8uCqFTP iOqTk30KByq+ur0+x+RILNTdOITUHwbtslWjbVOGyEa559/gF360TNzhy0Sr0IhV7Guf3o /VEz5Gmg8R3I3L8u2UzWHfNWHJrQe4fD9kqAMPoia7aprfyW5U2suncl/PsqFdpSuQFgnF +1qWqnMsSQiIKTUeP7DaGCSv6QcUnlQTFp9mG/6AQvm9VMzCWdMw5ulyF6/oVOeuH1Za1r RQSvuzt4HRa/8BwKRd8xmmGf1YgSvZE13Y33pKWcu3PYDD9UYVXuFooWfREmiA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by vangyzen: URL: https://cgit.FreeBSD.org/src/commit/?id=6a73d96ac4def6ba03788ed0914aa994c037778a commit 6a73d96ac4def6ba03788ed0914aa994c037778a Author: Arka Sharma AuthorDate: 2022-02-18 15:34:15 +0000 Commit: Eric van Gyzen CommitDate: 2022-03-03 14:20:07 +0000 mmap map_at_zero test: handle W^X Use kern.elfXX.allow_wx to decide whether to map W+X or W-only memory. Future work could expand this test to add an "allow_wx" axis to the test matrix, but I would argue that a separate test should be written, since that's orthogonal to map_at_zero. MFC after: 1 week Sponsored by: Dell EMC Isilon (cherry picked from commit 766c2466ff465b3c7c1a46be729b42a6da47de03) --- tests/sys/vm/mmap_test.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/sys/vm/mmap_test.c b/tests/sys/vm/mmap_test.c index 61ede96fc49b..dc01a23fff21 100644 --- a/tests/sys/vm/mmap_test.c +++ b/tests/sys/vm/mmap_test.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -54,6 +55,12 @@ static const struct { #define MAP_AT_ZERO "security.bsd.map_at_zero" +#ifdef __LP64__ +#define ALLOW_WX "kern.elf64.allow_wx" +#else +#define ALLOW_WX "kern.elf32.allow_wx" +#endif + ATF_TC_WITHOUT_HEAD(mmap__map_at_zero); ATF_TC_BODY(mmap__map_at_zero, tc) { @@ -61,6 +68,8 @@ ATF_TC_BODY(mmap__map_at_zero, tc) size_t len; unsigned int i; int map_at_zero; + bool allow_wx; + int prot_flags; len = sizeof(map_at_zero); if (sysctlbyname(MAP_AT_ZERO, &map_at_zero, &len, NULL, 0) == -1) { @@ -69,13 +78,27 @@ ATF_TC_BODY(mmap__map_at_zero, tc) return; } + len = sizeof(allow_wx); + if (sysctlbyname(ALLOW_WX, &allow_wx, &len, NULL, 0) == -1) { + if (errno == ENOENT) { + /* Allow W+X if sysctl isn't present */ + allow_wx = true; + } else { + atf_tc_skip("sysctl for %s failed: %s\n", ALLOW_WX, + strerror(errno)); + return; + } + } + /* Normalize to 0 or 1 for array access. */ map_at_zero = !!map_at_zero; for (i = 0; i < nitems(map_at_zero_tests); i++) { + prot_flags = PROT_READ | PROT_WRITE; + if (allow_wx) + prot_flags |= PROT_EXEC; p = mmap((void *)map_at_zero_tests[i].addr, PAGE_SIZE, - PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_FIXED, - -1, 0); + prot_flags, MAP_ANON | MAP_FIXED, -1, 0); if (p == MAP_FAILED) { ATF_CHECK_MSG(map_at_zero_tests[i].ok[map_at_zero] == 0, "mmap(%p, ...) failed", map_at_zero_tests[i].addr);