From nobody Fri Jun 24 16:10:43 2022 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 0694D86626B; Fri, 24 Jun 2022 16:10:45 +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 4LV2Cm1ZtCz3Jnt; Fri, 24 Jun 2022 16:10:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656087044; 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=I1qkO9PcNuMrG8I41EG0v8bpyi36JDyyRgEThaAP3SQ=; b=wnTvt+fVNfkIM3pFcsWTMdHN8ALb9YodPRX1UfLEppKaWhtQuldZD87SA4BNis+X7pEKdr cY/CwiQ6JE3jL6c/Q8QC8fVQCawqlwqh5if/Diz6/fQQ+G/plcuex+TBLWdk3RroxhXG7I Q2lTyS0pPcjUPgPVRqgsaReAqc8s7ETJ0xmtr+L9u3RF19qbFD2Ge90WpPrj6wqjSf4rlf iSyia8ExeNV/oDrqHiT7RK4KVjLIiLl+uf1vnaZT2wXkuC8J5b9V9urOrrKcVIM/+edr3Y JHAb9HmPXCdhaAh6+3R9MziEHqcwDUG5gIibsQbOeJeEYbD/xfor+g2iYlHwiw== 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 77E4F12E4B; Fri, 24 Jun 2022 16:10:43 +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 25OGAh5D006394; Fri, 24 Jun 2022 16:10:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25OGAhTV006393; Fri, 24 Jun 2022 16:10:43 GMT (envelope-from git) Date: Fri, 24 Jun 2022 16:10:43 GMT Message-Id: <202206241610.25OGAhTV006393@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 235d960aae75 - main - tests/unix_passfd: compile SOCK_STREAM and SOCK_DGRAM versions 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: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 235d960aae754b1e4ace559050e94ae99c3a9a91 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656087044; 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=I1qkO9PcNuMrG8I41EG0v8bpyi36JDyyRgEThaAP3SQ=; b=acTp1yI97EcHqMNNrJJ9z/BrQcuf+3H7deL1LFA1DksyOw8IUzcj+uHqHizyiY+/+Mm8XQ Tlx15NKKoSZdqwpsue6B2NBq7efpl0kHR/W+AKpnfHm1wx10SThtTyjUX+//JzhryKac4J Qsd8SgXjeqTxCv8TzhloIL4FEgZnrGhvbggRElsh4swpJr7kzc12X4Ed2ysjses1xsglU/ NV8WWe3Sx+DRQw3FrECU/g9k8jLZGzg/zhX/fAncm9n0/TrGVMZ+LFwWQEsH4gPtybbAit l9dE61g4ENVQoFLPMXgyQJOnvomextMMoOCqMUW93DNG5rTY0dGIG5EhxTHnmA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656087044; a=rsa-sha256; cv=none; b=vOmjfXO3MiZyas4aBzwitA+KHYY1Urynet1NUefJhYAciFp68UL3i87w71X/T8Lj4OnsCD BJ1lFXjDOse178dk/ZZ5HbHXNBbReM9jQehbWFZOTn9vn2UjSmbqYuaTU5L0n5oQA8WhzP 1bCmVAlu+hEQVkBzx9+sp5e5OzXk1KXba9vJIc0w6jrW4zAlS1voXSJzLrZJMC0+7dIeSG Tb1IRwmrpYWdGXB3kOIu7i1DW3LWTTOiQzAzbBtG56pSBbGpVo/hAf+y+9hqrq1GZeeK+H oJsP8iqUmFd6mc3RwqPwKscW7TOV2js7cuDpJBActaXC87BXiTnFalWNYCfi0A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=235d960aae754b1e4ace559050e94ae99c3a9a91 commit 235d960aae754b1e4ace559050e94ae99c3a9a91 Author: Gleb Smirnoff AuthorDate: 2022-06-24 16:09:11 +0000 Commit: Gleb Smirnoff CommitDate: 2022-06-24 16:09:11 +0000 tests/unix_passfd: compile SOCK_STREAM and SOCK_DGRAM versions Most test pass identically on different kinds of sockets. However, few edge cases work differently on stream and datagram sockets. We want to exercise this and document. Differential revision: https://reviews.freebsd.org/D35420 --- ObsoleteFiles.inc | 2 ++ tests/sys/kern/Makefile | 6 ++-- tests/sys/kern/unix_passfd_dgram.c | 2 ++ tests/sys/kern/unix_passfd_stream.c | 2 ++ tests/sys/kern/unix_passfd_test.c | 56 +++++++++++++++++++++++++++++-------- 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc index 3b906ed221d2..baebba86a42c 100644 --- a/ObsoleteFiles.inc +++ b/ObsoleteFiles.inc @@ -52,6 +52,8 @@ # xargs -n1 | sort | uniq -d; # done +# 20220624: unix_passfd_test -> unix_passfd_stream/unix_passfd_dgram +OLD_FILES+=usr/tests/sys/kern/unix_passfd_test # 20220621: ISA sound card drivers removed OLD_FILES+=usr/share/man/man4/snd_ad1816.4 diff --git a/tests/sys/kern/Makefile b/tests/sys/kern/Makefile index 221684842a3e..93f62022a0f2 100644 --- a/tests/sys/kern/Makefile +++ b/tests/sys/kern/Makefile @@ -37,8 +37,10 @@ PLAIN_TESTS_C+= subr_unit_test ATF_TESTS_C+= sysctl_kern_proc ATF_TESTS_C+= sys_getrandom ATF_TESTS_C+= unix_dgram -ATF_TESTS_C+= unix_passfd_test -TEST_METADATA.unix_passfd_test+= is_exclusive="true" +ATF_TESTS_C+= unix_passfd_dgram +TEST_METADATA.unix_passfd_dgram+= is_exclusive="true" +ATF_TESTS_C+= unix_passfd_stream +TEST_METADATA.unix_passfd_stream+= is_exclusive="true" ATF_TESTS_C+= unix_seqpacket_test TEST_METADATA.unix_seqpacket_test+= timeout="15" ATF_TESTS_C+= unix_socketpair_test diff --git a/tests/sys/kern/unix_passfd_dgram.c b/tests/sys/kern/unix_passfd_dgram.c new file mode 100644 index 000000000000..d61b761d0f72 --- /dev/null +++ b/tests/sys/kern/unix_passfd_dgram.c @@ -0,0 +1,2 @@ +#define TEST_PROTO SOCK_DGRAM +#include "unix_passfd_test.c" diff --git a/tests/sys/kern/unix_passfd_stream.c b/tests/sys/kern/unix_passfd_stream.c new file mode 100644 index 000000000000..e3612bf8da7e --- /dev/null +++ b/tests/sys/kern/unix_passfd_stream.c @@ -0,0 +1,2 @@ +#define TEST_PROTO SOCK_STREAM +#include "unix_passfd_test.c" diff --git a/tests/sys/kern/unix_passfd_test.c b/tests/sys/kern/unix_passfd_test.c index fe46d815c6a1..bbd298f9a26f 100644 --- a/tests/sys/kern/unix_passfd_test.c +++ b/tests/sys/kern/unix_passfd_test.c @@ -1,6 +1,7 @@ /*- * Copyright (c) 2005 Robert N. M. Watson * Copyright (c) 2015 Mark Johnston + * Copyright (c) 2022 Gleb Smirnoff * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -46,6 +47,10 @@ __FBSDID("$FreeBSD$"); #include +#if !defined(TEST_PROTO) +#error Need TEST_PROTO defined to SOCK_STREAM or SOCK_DGRAM +#endif + /* * UNIX domain sockets allow file descriptors to be passed via "ancillary * data", or control messages. This regression test is intended to exercise @@ -59,8 +64,8 @@ static void domainsocketpair(int *fdp) { - ATF_REQUIRE_MSG(socketpair(PF_UNIX, SOCK_STREAM, 0, fdp) != -1, - "socketpair(PF_UNIX, SOCK_STREAM) failed: %s", strerror(errno)); + ATF_REQUIRE_MSG(socketpair(PF_UNIX, TEST_PROTO, 0, fdp) != -1, + "socketpair(PF_UNIX, %u) failed: %s", TEST_PROTO, strerror(errno)); } static void @@ -153,13 +158,12 @@ samefile(struct stat *sb1, struct stat *sb2) ATF_REQUIRE_MSG(sb1->st_ino == sb2->st_ino, "different inode"); } -static size_t +static ssize_t sendfd_payload(int sockfd, int send_fd, void *payload, size_t paylen) { struct iovec iovec; char message[CMSG_SPACE(sizeof(int))]; struct msghdr msghdr; - ssize_t len; bzero(&msghdr, sizeof(msghdr)); bzero(&message, sizeof(message)); @@ -174,9 +178,7 @@ sendfd_payload(int sockfd, int send_fd, void *payload, size_t paylen) msghdr.msg_iovlen = 1; putfds(message, send_fd, 1); - len = sendmsg(sockfd, &msghdr, 0); - ATF_REQUIRE_MSG(len != -1, "sendmsg failed: %s", strerror(errno)); - return ((size_t)len); + return (sendmsg(sockfd, &msghdr, 0)); } static void @@ -253,6 +255,9 @@ recvfd_payload(int sockfd, int *recv_fd, void *buf, size_t buflen, "recvmsg: did not receive single-fd message"); ATF_REQUIRE_MSG(!localcreds(sockfd) || foundcreds, "recvmsg: expected credentials were not received"); + if (recvmsg_flags & MSG_TRUNC) + ATF_REQUIRE_MSG(msghdr.msg_flags & MSG_TRUNC, + "recvmsg: expected MSG_TRUNC missing"); } static void @@ -426,13 +431,25 @@ ATF_TC_BODY(send_a_lot, tc) /* Such attempt shall fail with EMSGSIZE. */ ATF_REQUIRE(errno == EMSGSIZE); ATF_REQUIRE(getnfds() == nfds); +#if TEST_PROTO == SOCK_STREAM /* * For the SOCK_STREAM the above attempt shall free the control in * the kernel, so that socket isn't left in a stuck state. Next read - * shall bring us the normal data only. + * shall bring us the normal data only. The stream data shall not + * miss a byte. */ ATF_REQUIRE(recvmsg(fd[1], &msghdr, 0) == 1); ATF_REQUIRE(msghdr.msg_controllen == 0); +#elif TEST_PROTO == SOCK_DGRAM + /* + * For SOCK_DGRAM there are two options for the previously failed + * syscall: strip the control leaving datagram in the socket or + * drop the whole datagram. Our implementation drops the whole + * datagram. + */ + ATF_REQUIRE(recvmsg(fd[1], &msghdr, MSG_DONTWAIT) == -1); + ATF_REQUIRE(errno == EAGAIN); +#endif } /* @@ -514,7 +531,11 @@ ATF_TC_BODY(devfs_orphan, tc) closesocketpair(fd); } +#if TEST_PROTO == SOCK_STREAM #define LOCAL_SENDSPACE_SYSCTL "net.local.stream.sendspace" +#elif TEST_PROTO == SOCK_DGRAM +#define LOCAL_SENDSPACE_SYSCTL "net.local.dgram.maxdgram" +#endif /* * Test for PR 181741. Receiver sets LOCAL_CREDS, and kernel prepends a @@ -527,7 +548,7 @@ ATF_TC_BODY(rights_creds_payload, tc) { const int on = 1; u_long sendspace; - size_t len; + ssize_t len; void *buf; int fd[2], getfd, putfd, rc; @@ -551,9 +572,21 @@ ATF_TC_BODY(rights_creds_payload, tc) strerror(errno)); len = sendfd_payload(fd[0], putfd, buf, sendspace); - ATF_REQUIRE_MSG(len < sendspace, "sendmsg: %zu bytes sent", len); +#if TEST_PROTO == SOCK_STREAM + ATF_REQUIRE_MSG(len != -1 , "sendmsg failed: %s", strerror(errno)); + ATF_REQUIRE_MSG((size_t)len < sendspace, + "sendmsg: %zu bytes sent", len); recvfd_payload(fd[1], &getfd, buf, len, CMSG_SPACE(SOCKCREDSIZE(CMGROUP_MAX)) + CMSG_SPACE(sizeof(int)), 0); +#endif +#if TEST_PROTO == SOCK_DGRAM + ATF_REQUIRE_MSG(len != -1 , "sendmsg failed: %s", strerror(errno)); + ATF_REQUIRE_MSG((size_t)len == sendspace, + "sendmsg: %zu bytes sent", len); + recvfd_payload(fd[1], &getfd, buf, len, + CMSG_SPACE(SOCKCREDSIZE(CMGROUP_MAX)) + CMSG_SPACE(sizeof(int)), + MSG_TRUNC); +#endif close(putfd); close(getfd); @@ -719,7 +752,8 @@ ATF_TC_BODY(copyout_rights_error, tc) devnull(&putfd); nfds = getnfds(); - sendfd_payload(fd[0], putfd, buf, sizeof(buf)); + len = sendfd_payload(fd[0], putfd, buf, sizeof(buf)); + ATF_REQUIRE_MSG(len != -1, "sendmsg failed: %s", strerror(errno)); bzero(&msghdr, sizeof(msghdr));