From nobody Sat Sep 27 13:54:05 2025 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 4cYppP1hZpz69MbB; Sat, 27 Sep 2025 13:54:05 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4cYppP1X1kz3rnf; Sat, 27 Sep 2025 13:54:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758981245; 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=sHRDcagtEOZHXdobV7/ZO+TQGRymic4noxlbwzxdr9g=; b=EMbWP2Mx+Iy7usCzG2Gko11l8dE2ej+wimRGfhL/t/lRa0YLpCtcoQlIIfsY/H9OsvpUR6 Is9VGZ9Q1HPxJUUSNRGQnMcpFUMzwC5MbiWYII6ZmsgksN2wGiWs3hN7rFwVy/4/Z+bEEZ 5pRxhNQuEwHh1IHVTp3jRS3AbT23feojxYl0AmZeMTOPdU5ohbBulBPVEnvjykCPX/CHNa rhwZPhCTCaCfOj7kQGCBXePgtTaertCNV1IjREzqSKoSkT76Gtog7y2Uho6lHWvwR6shfv EmpDc6XpEB0qHXvoOxUVLgieuF1JYBnNlSzKjkt3Qb2JhOFAaOwZkukrsPEVYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1758981245; 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=sHRDcagtEOZHXdobV7/ZO+TQGRymic4noxlbwzxdr9g=; b=v8uxqANc+howiLAroL6mO/WBw2OmxlC5S1PnTqW+vg242AgmHDEzalQdYXXa/EHkx4Hep4 QnWiSWuAZ4Q2BZz4UglnJWoVwwVSZRpwEtTtIqgFMdFIAN62DAY8fhIV31zYgP9PjKvYki 6keNEpa4cv6FQz3+UD49XC2XBgBD6BCJ/zkpPZlncnCXNBcuFkw7vvKePT3oXHgTWnMIdS 3oMmMub1Id/jWbQzVmDhcZibirirx/O2cRKQGFCP1j2V4N7C9xalVhEDoY5/hFjiojWqPL 2Jo030fMlKseLTUxm3lVeKpLjuyaNqER42ucUSjto+EsYm6KQIPqyonH747iBg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1758981245; a=rsa-sha256; cv=none; b=iu0f4sl0AImA4hj+pcrlJIrTe+4TtLRqJum02DxP6ztvR2/DKQe7Nyn5+61q1gNsfTgjqm gZu7cZIoWUChLeXMSrY5Uc4mK/9YcAAdz1ReqMp3Pz3l8Q8+brEEzJecZ74eChumC3nb5/ yIYjIiv7cZYat9bLtAD9W9syJa8GGrDwsEGe5fZaCcC+lSGqWBVr6dvnzpYbiW930wh56x Tx9QOrGF8avbsKFhXuJyJbNqxG9w5cIzS8fOqH1nhuXUNusyqWUvkRJwaxVopHfhiB4EYO YdF0qtlKsjDUCC7pk3NicY3K6yYFN+Yvct4eIOYJM09Rz630lvJhF3j9FEQ/eg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4cYppP0wL2zcsM; Sat, 27 Sep 2025 13:54:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 58RDs5QI030217; Sat, 27 Sep 2025 13:54:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 58RDs5Bn030214; Sat, 27 Sep 2025 13:54:05 GMT (envelope-from git) Date: Sat, 27 Sep 2025 13:54:05 GMT Message-Id: <202509271354.58RDs5Bn030214@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alan Somers Subject: git: 8b66d677a99b - stable/14 - ctl: add ATF tests for SCSI PERSISTENT RESERVE IN/OUT 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 8b66d677a99be46ddd3b0698e6727f65e8efee7e Auto-Submitted: auto-generated The branch stable/14 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=8b66d677a99be46ddd3b0698e6727f65e8efee7e commit 8b66d677a99be46ddd3b0698e6727f65e8efee7e Author: Alan Somers AuthorDate: 2024-10-03 21:52:44 +0000 Commit: Alan Somers CommitDate: 2025-09-27 13:53:55 +0000 ctl: add ATF tests for SCSI PERSISTENT RESERVE IN/OUT These commands are complicated, and the test suite isn't complete. But it's a start. And it includes a regression test for HYP-08 (commit 64b0f52be2c9d7bcecebfeef393f8ec56cb85f47). Security: HYP-08 Sponsored by: ConnectWise Differential Revision: https://reviews.freebsd.org/D46947 (cherry picked from commit ece617cda6b5999e6e57c2227f98c18c1ca1d79d) --- tests/sys/cam/ctl/Makefile | 6 + tests/sys/cam/ctl/persist.sh | 349 ++++++++++++++++++++++++++++ tests/sys/cam/ctl/prout_register_huge_cdb.c | 88 +++++++ 3 files changed, 443 insertions(+) diff --git a/tests/sys/cam/ctl/Makefile b/tests/sys/cam/ctl/Makefile index 1333397af464..05f0831fc8b0 100644 --- a/tests/sys/cam/ctl/Makefile +++ b/tests/sys/cam/ctl/Makefile @@ -1,13 +1,19 @@ PACKAGE= tests TESTSDIR= ${TESTSBASE}/sys/cam/ctl +BINDIR=${TESTSDIR} ${PACKAGE}FILES+= ctl.subr +ATF_TESTS_SH+= persist ATF_TESTS_SH+= prevent ATF_TESTS_SH+= read_buffer ATF_TESTS_SH+= start_stop_unit +PROGS+= prout_register_huge_cdb +LIBADD+= cam +CFLAGS+= -I${SRCTOP}/sys + # Must be exclusive because it disables/enables camsim TEST_METADATA+= is_exclusive="true" diff --git a/tests/sys/cam/ctl/persist.sh b/tests/sys/cam/ctl/persist.sh new file mode 100644 index 000000000000..2a350ee4775a --- /dev/null +++ b/tests/sys/cam/ctl/persist.sh @@ -0,0 +1,349 @@ +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 ConnectWise +# 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 DOCUMENTATION IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + +. $(atf_get_srcdir)/ctl.subr + +# TODO +# * PRIN READ RESERVATION, with one reservation +# * PROUT with illegal type +# * PROUT REGISTER AND IGNORE EXISTING KEY +# * PROUT REGISTER AND IGNORE EXISTING KEY with a RESERVATION KEY that isn't registered +# * PROUT REGISTER AND IGNORE EXISTING KEY to unregister +# * PROUT CLEAR allows previously prevented medium removal +# * PROUT PREEMPT +# * PROUT PREEMPT with a RESERVATION KEY that isn't registered +# * PROUT PREEMPT_AND_ABORT +# * PROUT PREEMPT_AND_ABORT with a RESERVATION KEY that isn't registered +# * PROUT REGISTER AND MOVE +# * PROUT REGISTER AND MOVE with a RESERVATION KEY that isn't registered +# * multiple initiators + +# Not Tested +# * PROUT REPLACE LOST RESERVATION (not supported by ctl) +# * Specify Initiator Ports bit (not supported by ctl) +# * Activate Persist Through Power Loss bit (not supported by ctl) +# * All Target Ports bit (not supported by ctl) + +RESERVATION_KEY=0xdeadbeef1a7ebabe + +atf_test_case prin_read_full_status_empty cleanup +prin_read_full_status_empty_head() +{ + atf_set "descr" "PERSISTENT RESERVATION IN with the READ FULL STATUS service action, with no status descriptors" + atf_set "require.user" "root" + atf_set "require.progs" sg_persist ctladm +} +prin_read_full_status_empty_body() +{ + create_ramdisk + + atf_check -o match:"No full status descriptors" sg_persist -ns /dev/$dev +} +prin_read_full_status_empty_cleanup() +{ + cleanup +} + +atf_test_case prin_read_keys_empty cleanup +prin_read_keys_empty_head() +{ + atf_set "descr" "PERSISTENT RESERVATION IN with the READ KEYS service action, with no registered keys" + atf_set "require.user" "root" + atf_set "require.progs" sg_persist ctladm +} +prin_read_keys_empty_body() +{ + create_ramdisk + + atf_check -o match:"there are NO registered reservation keys" sg_persist -nk /dev/$dev +} +prin_read_keys_empty_cleanup() +{ + cleanup +} + +atf_test_case prin_read_reservation_empty cleanup +prin_read_reservation_empty_head() +{ + atf_set "descr" "PERSISTENT RESERVATION IN with the READ RESERVATION service action, with no reservations" + atf_set "require.user" "root" + atf_set "require.progs" sg_persist ctladm +} +prin_read_reservation_empty_body() +{ + create_ramdisk + + atf_check -o match:"there is NO reservation held" sg_persist -nr /dev/$dev +} +prin_read_reservation_empty_cleanup() +{ + cleanup +} + +atf_test_case prin_report_capabilities cleanup +prin_report_capabilities_head() +{ + atf_set "descr" "PERSISTENT RESERVATION IN with the REPORT CAPABILITIES service action" + atf_set "require.user" "root" + atf_set "require.progs" sg_persist ctladm +} +prin_report_capabilities_body() +{ + create_ramdisk + + cat > expected < expected <> + scope: LU_SCOPE, type: Exclusive Access, all registrants + Transport Id of initiator: + Parallel SCSI initiator SCSI address: 0x1 + relative port number (of corresponding target): 0x0 +HERE + atf_check -o file:expected sg_persist -ns /dev/$dev +} +prout_reserve_cleanup() +{ + cleanup +} + +atf_test_case prout_reserve_bad_scope cleanup +prout_reserve_bad_scope_head() +{ + atf_set "descr" "PERSISTENT RESERVATION OUT will be rejected with an unknown scope field" + atf_set "require.user" "root" + atf_set "require.progs" sg_persist camcontrol ctladm +} +prout_reserve_bad_scope_body() +{ + create_ramdisk + # First register a key + atf_check sg_persist -n --out --param-rk=0 --param-sark=$RESERVATION_KEY -G /dev/$dev + + # Then make a reservation using that key + atf_check -s exit:1 -e match:"ILLEGAL REQUEST asc:24,0 .Invalid field in CDB." camcontrol persist $dev -o reserve -k $RESERVATION_KEY -T read_shared -s 15 -v + + # Finally, check that nothing has been reserved + atf_check -o match:"there is NO reservation held" sg_persist -nr /dev/$dev +} +prout_reserve_bad_scope_cleanup() +{ + cleanup +} + + +atf_init_test_cases() +{ + atf_add_test_case prin_read_full_status_empty + atf_add_test_case prin_read_keys_empty + atf_add_test_case prin_read_reservation_empty + atf_add_test_case prin_report_capabilities + atf_add_test_case prout_clear + atf_add_test_case prout_register + atf_add_test_case prout_register_duplicate + atf_add_test_case prout_register_huge_cdb + atf_add_test_case prout_register_unregister + atf_add_test_case prout_release + atf_add_test_case prout_reserve + atf_add_test_case prout_reserve_bad_scope +} diff --git a/tests/sys/cam/ctl/prout_register_huge_cdb.c b/tests/sys/cam/ctl/prout_register_huge_cdb.c new file mode 100644 index 000000000000..951da0628830 --- /dev/null +++ b/tests/sys/cam/ctl/prout_register_huge_cdb.c @@ -0,0 +1,88 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 ConnectWise + * 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 DOCUMENTATION IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +/* + * Helper that sends a PERSISTENT RESERVATION OUT command to CTL with a + * ridiculously huge size for the length of the CDB. This is not possible with + * ctladm, for good reason. + */ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +int +main(int argc, char **argv) +{ + union ctl_io *io; + int fd = open("/dev/cam/ctl", O_RDWR); + int r; + uint32_t targ_port; + + if (argc < 2) + errx(2, "usage: prout_register_huge_cdb \n"); + + targ_port = strtoul(argv[1], NULL, 10); + + io = calloc(1, sizeof(*io)); + io->io_hdr.nexus.initid = 7; /* 7 is ctladm's default initiator id */ + io->io_hdr.nexus.targ_port = targ_port; + io->io_hdr.nexus.targ_mapped_lun = 0; + io->io_hdr.nexus.targ_lun = 0; + io->io_hdr.io_type = CTL_IO_SCSI; + io->taskio.tag_type = CTL_TAG_UNTAGGED; + uint8_t cdb[32] = {}; + // ctl_persistent_reserve_out// 5f 00 + cdb[0] = 0x5f; + cdb[1] = 0x00; + struct scsi_per_res_out *cdb_ = ( struct scsi_per_res_out *)cdb; + // Claim an enormous size of the CDB, but don't actually alloc it all. + cdb_->length[0] = 0xff; + cdb_->length[1] = 0xff; + cdb_->length[2] = 0xff; + cdb_->length[3] = 0xff; + io->scsiio.cdb_len = sizeof(cdb); + memcpy(io->scsiio.cdb, cdb, sizeof(cdb)); + io->io_hdr.flags |= CTL_FLAG_DATA_IN; + r = ioctl(fd, CTL_IO, io); + if (r == -1) + err(1, "ioctl"); + if ((io->io_hdr.status & CTL_STATUS_MASK) == CTL_SUCCESS) { + return (0); + } else { + return (1); + } +}