From nobody Tue Oct 17 13:37:10 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 4S8w530C02z4xWrQ; Tue, 17 Oct 2023 13:37:11 +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 4S8w525dcSz3GG0; Tue, 17 Oct 2023 13:37:10 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697549830; 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=z05AGBtfV5p0MGWgHu8wVZ7VlSzmkyGQEDSQ8AJz1vk=; b=IrFruGjowKTCkarKhasAtjh1M/R3jBk3BbMWty1rduJYxTilkseWtEknGwSYj0EO2KsaGG ZMkB+2SPxmA83xezFJDp4t2oKP/qQ0IC4ePfhIhRxXnYhpcJIudohkWFw2Y8ZfkDJpFj2P 1OvFBtDn1cB+LZ73hMdVkG6jScjHW22WH+byXFW2jTPbMqW6q/c7OyQT44ZvACBr9g5T/1 4wVojWU4nlAp+Ak7Qe30A9PK7hYMbV86WvWA2UlpJO+0GwLYt6WdUC1PjsaXPVXvAI3Iuq hTVcgTs7I06l+un4l5aTQbMJCESkpv+NCCDjDzui8vWB0mr+rBsGr27ofOcdXQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697549830; a=rsa-sha256; cv=none; b=M8TicKHvNvQ6QOI+SjkZ2xnB7OxugGLa20sAwWMG6ZYn9nsftQdQGKOf8wNmbps5V648zr cOm5XVWxepzyWNXBF6kICs/Nyw0kwcAZ58idLPhE8GcDFNwTCcKm1V5+acOp0zAONWT425 Ct1ahGHqL8WtxOfMmVdvEz3Qsis/TqZKwRrxnHSwv8NAr13sdgKKTnU5SFYUFoqa3Ayt6v Jdr/bdJqUPTwN7HEMiVX+KFWoQ2GzOIFaOcdqSK9YLPVyO6/ZMLgVNwnqVLJ1xS4KLC6Yt bq+V+e1RgIOdgGqxOValhtVJy+Wap5gqsndiReZ3nM8iLbpqQKVQB8X23TuBJw== 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=1697549830; 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=z05AGBtfV5p0MGWgHu8wVZ7VlSzmkyGQEDSQ8AJz1vk=; b=AV6TEWlHCiUjae/XoPjuVfYapHUvigUjEX+NrXxtQuOoSSlfbgFKTrvc4FCwsp/Q63ixfr 62gaPkdX+/tl5ZX71cJcgOil0EZd0J+FGT8hPmlaS2pIJNfBlxsNRk1f9tBuAI46aV8ysu tAcs55tG80CVMga4NBqYPqJv7Xut7s1Aa280hS5gvKY4atys0x/736CPcH1wGhk9UlLgDA HU4YXcgfddKw4DtABsOkZtLQHiihEEAi4NIFH2FnCPMEpTyo8EcRrm79OdkdoNMNQ1bnSb sBkLt2yf3KVQRZjOLlC+Q4hoLDfHe+kyK4Hscy5qWcZgv5SjYOY/md/4z0SMxQ== 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 4S8w524SvZz9hr; Tue, 17 Oct 2023 13:37:10 +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 39HDbABm095932; Tue, 17 Oct 2023 13:37:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39HDbAKs095929; Tue, 17 Oct 2023 13:37:10 GMT (envelope-from git) Date: Tue, 17 Oct 2023 13:37:10 GMT Message-Id: <202310171337.39HDbAKs095929@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: d8735eb7acc0 - main - socket tests: Add a regression test for ktrace+recv(MSG_TRUNC) 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: d8735eb7acc0613fd19f74a49d3bdcb7ed0e9b0e Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=d8735eb7acc0613fd19f74a49d3bdcb7ed0e9b0e commit d8735eb7acc0613fd19f74a49d3bdcb7ed0e9b0e Author: Mark Johnston AuthorDate: 2023-10-16 22:23:36 +0000 Commit: Mark Johnston CommitDate: 2023-10-17 13:12:57 +0000 socket tests: Add a regression test for ktrace+recv(MSG_TRUNC) MFC after: 1 week --- tests/sys/kern/socket_msg_trunc.c | 57 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/sys/kern/socket_msg_trunc.c b/tests/sys/kern/socket_msg_trunc.c index 469b9e1503cd..279170158643 100644 --- a/tests/sys/kern/socket_msg_trunc.c +++ b/tests/sys/kern/socket_msg_trunc.c @@ -27,11 +27,13 @@ #include #include +#include #include #include #include +#include #include #include #include @@ -182,12 +184,67 @@ ATF_TC_BODY(recv_trunc_afunix_seqpacket, tc) ATF_REQUIRE(close(ss) == 0); } +/* + * Exercise the case where ktrace was used to dump a truncated buffer. + */ +ATF_TC_WITHOUT_HEAD(recvmsg_trunc_ktrace_uio); +ATF_TC_BODY(recvmsg_trunc_ktrace_uio, tc) +{ + struct ktr_header ktr; + struct msghdr msg; + struct iovec iov; + const char *tracepath; + char buf[128]; + ssize_t nbytes; + int error, fd, sd[2]; + + tracepath = "ktrace"; + + error = socketpair(AF_UNIX, SOCK_DGRAM, 0, sd); + ATF_REQUIRE(error == 0); + + memset(buf, 0, sizeof(buf)); + nbytes = send(sd[0], buf, sizeof(buf), 0); + ATF_REQUIRE_MSG(nbytes >= 0, "send failed: %s", strerror(errno)); + ATF_REQUIRE((size_t)nbytes == sizeof(buf)); + + fd = open(tracepath, O_RDWR | O_CREAT | O_TRUNC, 0644); + ATF_REQUIRE_MSG(fd >= 0, "open failed: %s", strerror(errno)); + error = ktrace(tracepath, KTROP_SET, KTRFAC_GENIO, getpid()); + ATF_REQUIRE_MSG(error == 0, + "ktrace(SET) failed: %s", strerror(errno)); + + iov.iov_base = buf; + iov.iov_len = sizeof(buf) - 1; /* truncate */ + memset(&msg, 0, sizeof(msg)); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + nbytes = recvmsg(sd[1], &msg, MSG_TRUNC); + ATF_REQUIRE_MSG(nbytes >= 0, "recvmsg failed: %s", strerror(errno)); + ATF_REQUIRE((size_t)nbytes == sizeof(buf)); + ATF_REQUIRE((msg.msg_flags & MSG_TRUNC) != 0); + + error = ktrace(tracepath, KTROP_CLEARFILE, 0, getpid()); + ATF_REQUIRE_MSG(error == 0, + "ktrace(CLEARFILE) failed: %s", strerror(errno)); + + nbytes = read(fd, &ktr, sizeof(ktr)); + ATF_REQUIRE_MSG(nbytes >= 0, "read failed: %s", strerror(errno)); + ATF_REQUIRE((size_t)nbytes == sizeof(ktr)); + ATF_REQUIRE_MSG((ktr.ktr_type & ~KTR_TYPE) == KTR_GENIO); + + ATF_REQUIRE(close(fd) == 0); + ATF_REQUIRE(close(sd[0]) == 0); + ATF_REQUIRE(close(sd[1]) == 0); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, recv_trunc_afinet_udp); ATF_TP_ADD_TC(tp, recv_trunc_afinet6_udp); ATF_TP_ADD_TC(tp, recv_trunc_afunix_dgram); ATF_TP_ADD_TC(tp, recv_trunc_afunix_seqpacket); + ATF_TP_ADD_TC(tp, recvmsg_trunc_ktrace_uio); return (atf_no_error()); }