From nobody Fri Sep 30 20:45:05 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 4MfMg60Nfwz4YNS2; Fri, 30 Sep 2022 20:45:06 +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 4MfMg56V0Hz3Y1D; Fri, 30 Sep 2022 20:45:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664570705; 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=ckTP/ft5CCHOMN186UqZAKpPP8ltPRPLEuWdFr7+YXg=; b=a14raHrDw0k1+Gr7blInrghTAz9HX1p1oGUw5/pv+HSNsv/1gDe/zB/UQ9JZMfQ64Vv0W1 v5+69TxIe4iSbgy6UZnWr5zBweE/1IG/dt3Gj9Ves1HzDm0xF5ZhFGIRUOI/sCTFenw/Sk CIQjHvpQM9NfsWVtxTpP6WdFKZjEC1NC53r4WN+oNvzpIoT46snFA8y50H5CtCB6d3ZDnS A9GesaQf4p6kqHt7hG2dbY2u53Zqln9I6wsIIrzPWAD925d4vi5LyxZqwA+/yiAR1DlYco YcPK5+7xMp00aj1u8CVWZe5VXEJq0mBQkIvqzHx3m1bOLuBhSF3FMJxzt+BmQg== 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 4MfMg55ZSwzHts; Fri, 30 Sep 2022 20:45:05 +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 28UKj5JV093557; Fri, 30 Sep 2022 20:45:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28UKj5XF093556; Fri, 30 Sep 2022 20:45:05 GMT (envelope-from git) Date: Fri, 30 Sep 2022 20:45:05 GMT Message-Id: <202209302045.28UKj5XF093556@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: 69d79ceb2c01 - main - tests/unix_passfd: add test case against 636420bde36 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: 69d79ceb2c01931c129c5bafc300c33f3e106efd Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664570705; 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=ckTP/ft5CCHOMN186UqZAKpPP8ltPRPLEuWdFr7+YXg=; b=Ad/vdeHnx6R9nA4j943Za35MAJOqeRdXiRUe1CkqgrdvaiVfd6zIMTJNMZSeHhUKfyiyt6 p+dwpFjhr3RY/ouieahvIhqBPkTaATxqQXADhENwVjU4eLfZnX1a7eDcmC0NrFPUOPIyME bAnMNjP8EfcT3mvVQxV/1mEYbsPllZDnKnsumHW55xIguAv8QY0tJwovppdV7Tya15HxA3 ITwmYc2qX4TtkSI5nMaAykcMjbzAUrDt2dwbaSsqwc7yQ5F+z5BlrEbleti+Tv/EKAHNG3 S7NAKM/gB2spLZTtkUC+Jtq3IkAJUOTZe7I7oZpROymdEteXj3g1GjEDG+U/iA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664570705; a=rsa-sha256; cv=none; b=mHolpLy2BXjmkKkeAkOI7AtviaH6z3QMYBNNNAmIeDFN+wzanLaKok5cYHhMcZPV1KvCcj BrSoes4l3fxuXlVP7nlDDQmHUaoABa0WXKbXA+HdKqvz6vWv7eSxLR4KtFcLzkg+VZzbZl rHg45TblGPBwyP+SSGrxMGbU5/TLpCzm4tzDSK80bmjY2t2MKOCjNZW9cMFG2xjMWqnOxR EjxHhbGHBcyOKtMl08uN20BwoW2QL+daX5L3diVDvwAnWpVRmsaEoF6j7UT/gncSORGWYr hhrB9mXgwyEkmvzgkkrGG5iLnI/jJv6PtXQhY+/XaXJM1LGziJpU6LcCZxCGqg== 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=69d79ceb2c01931c129c5bafc300c33f3e106efd commit 69d79ceb2c01931c129c5bafc300c33f3e106efd Author: Gleb Smirnoff AuthorDate: 2022-09-30 20:41:41 +0000 Commit: Gleb Smirnoff CommitDate: 2022-09-30 20:43:37 +0000 tests/unix_passfd: add test case against 636420bde36 --- tests/sys/kern/unix_passfd_test.c | 72 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/tests/sys/kern/unix_passfd_test.c b/tests/sys/kern/unix_passfd_test.c index 875201c4702e..92b8d73f2f4a 100644 --- a/tests/sys/kern/unix_passfd_test.c +++ b/tests/sys/kern/unix_passfd_test.c @@ -270,8 +270,10 @@ recvfd(int sockfd, int *recv_fd, int flags) #if TEST_PROTO == SOCK_STREAM #define LOCAL_SENDSPACE_SYSCTL "net.local.stream.sendspace" +#define LOCAL_RECVSPACE_SYSCTL "net.local.stream.recvspace" #elif TEST_PROTO == SOCK_DGRAM #define LOCAL_SENDSPACE_SYSCTL "net.local.dgram.maxdgram" +#define LOCAL_RECVSPACE_SYSCTL "net.local.dgram.recvspace" #endif static u_long @@ -286,6 +288,46 @@ getsendspace(void) return (sendspace); } +static u_long +getrecvspace(void) +{ + u_long recvspace; + + ATF_REQUIRE_MSG(sysctlbyname(LOCAL_RECVSPACE_SYSCTL, &recvspace, + &(size_t){sizeof(u_long)}, NULL, 0) != -1, + "sysctl %s failed: %s", LOCAL_RECVSPACE_SYSCTL, strerror(errno)); + + return (recvspace); +} + +/* + * Fill socket to a state when next max sized send would fail with EAGAIN. + */ +static void +fill(int fd) +{ + u_long sendspace; + void *buf; + + sendspace = getsendspace(); + ATF_REQUIRE((buf = malloc(sendspace)) != NULL); + + ATF_REQUIRE_MSG(fcntl(fd, F_SETFL, O_NONBLOCK) != -1, + "fcntl(O_NONBLOCK) failed: %s", strerror(errno)); + +#if TEST_PROTO == SOCK_STREAM + do {} while (send(fd, buf, sendspace, 0) == (ssize_t)sendspace); +#elif TEST_PROTO == SOCK_DGRAM + u_long recvspace = getrecvspace(); + + for (ssize_t sent = 0; + sent + sendspace + sizeof(struct sockaddr) < recvspace; + sent += sendspace + sizeof(struct sockaddr)) + ATF_REQUIRE(send(fd, buf, sendspace, 0) == (ssize_t)sendspace); +#endif + free(buf); +} + /* * Put a temporary file into a UNIX domain socket, then take it out and make * sure it's the same file. First time around, don't close the reference @@ -469,6 +511,35 @@ ATF_TC_BODY(send_a_lot, tc) #endif } +/* + * Exersize condition when SCM_RIGHTS is successfully internalized, but + * message delivery fails due to receive buffer overflow. Check that no + * file descriptors are leaked. + */ +ATF_TC_WITHOUT_HEAD(send_overflow); +ATF_TC_BODY(send_overflow, tc) +{ + void *buf; + ssize_t len; + int fd[2], putfd, nfiles; + int sendspace; + + sendspace = (int)getsendspace(); + ATF_REQUIRE((buf = malloc(sendspace)) != NULL); + + domainsocketpair(fd); + fill(fd[0]); + nfiles = openfiles(); + tempfile(&putfd); + len = sendfd_payload(fd[0], putfd, buf, sendspace); + ATF_REQUIRE_MSG(len == -1 && errno == EAGAIN, + "sendmsg: %zu bytes sent, errno %d", len, errno); + close(putfd); + ATF_REQUIRE(nfiles == openfiles()); + closesocketpair(fd); +} + + /* * Send two files. Then receive them. Make sure they are returned in the * right order, and both get there. @@ -881,6 +952,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, send_and_cancel); ATF_TP_ADD_TC(tp, send_and_shutdown); ATF_TP_ADD_TC(tp, send_a_lot); + ATF_TP_ADD_TC(tp, send_overflow); ATF_TP_ADD_TC(tp, two_files); ATF_TP_ADD_TC(tp, bundle); ATF_TP_ADD_TC(tp, bundle_cancel);