From nobody Mon Apr 08 20:29:40 2024 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 4VD10j1Ms6z5HjS6; Mon, 8 Apr 2024 20:29:41 +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 4VD10h6dngz45w1; Mon, 8 Apr 2024 20:29:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712608180; 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=ndrFoBWr6XRIejsviyWkk5iZ+drLQG6GrqHTlVTIap0=; b=ewm4yU/zdJWaAHy5mNQGpF7OyE7HB1FUHgqvlTuDiOMQkY63jp+L3S9cXpqMQqeqhVR4nh fxTc8a97j+F9O26VOpfpQsIxka3Aos0TAw36ZKbYJmzs9J3Cp3s3+/EAvrZwQu/ts1uXLZ VbqDXy3XiopugXZi48XPSIm58w6IX5d1bBEJ3HFrDQfJwMVsGUNwZR+zEANjgl1RKEIQ/m c/mzGhJeJxC4/9EqeYyEBlyzjnSmXYhMV4dmGO5prCRxqEH7yp1RzUO736uZqDuih0MHfG hlVRJj4YSkduO94S4Wep0h391mfS1lnVMdl/t2BgrPtnuHjSc/qq1HJ8xN0t4g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712608180; a=rsa-sha256; cv=none; b=cX7/fGfpGbEjz2ks3zv8t5/t/MexD5JtoWatSsqA3t/IZNvAa1fMODdWOYB0VBAdVXKraQ WEitF0q3QGuG1jU6N5yaXb7wsLJ87tB3fQHktiJnYTHsB38wHBhf1XD1qbAON73eRfwLyp LlRH5KoKnUJYSQ7O0awxcghHkHpKkgfSALDVR6c8w8BH3+lZU+UB0nLdLz0MTdiIGFqPzx XcchGa04jtpwzR4URZtUOQiFQnG4B97TZHBfzmX6m3Rtp3jMftffI0a9SHooV4SckRBtGU OhpVx+j11SAEI3YjJkI0oS/y+SvWSYOqMRGS4OqQHLfMDk26g0hqQ8TAjqsCWA== 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=1712608180; 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=ndrFoBWr6XRIejsviyWkk5iZ+drLQG6GrqHTlVTIap0=; b=TrfIJt7FcdnAFBSbSTVLLS1DkDbO70E7Y4T1gh1xxHuyh21jfXl5HCpRsKCGuTruXr1Bd4 fs5FVjCBRhzAinQq9O1t5QGctoJczRNStVlTq/1DxDRKhSsWBT7mg4NVGbQ/zxthggJnWk 1AFzf9xhgzqK/X4dUpZFZC0W6jhNdV8irftaJd/XAwSFr2GyIuniZlECbpSTswcXAg7A3Q OHYcc/fyOxFNcDi/fWEcAwIqoJDTY+xN7AohpWyn1GkskzFM1RyZOTkG/ObdNYO1Blo2dX 9OvFb9cdBiA2iOEw3/nowTIDNp74A/vQ2NajSfhLmEDH26Cnz8AlM1DF+2IDFQ== 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 4VD10h6F3vzQS5; Mon, 8 Apr 2024 20:29:40 +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 438KTefC041496; Mon, 8 Apr 2024 20:29:40 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 438KTeu1041493; Mon, 8 Apr 2024 20:29:40 GMT (envelope-from git) Date: Mon, 8 Apr 2024 20:29:40 GMT Message-Id: <202404082029.438KTeu1041493@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: f9927821240a - main - tests/unix_seqpacket: test send(2) to a closed or aborted peer socket 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: f9927821240aae9083a56ea66c4725e7f0082461 Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=f9927821240aae9083a56ea66c4725e7f0082461 commit f9927821240aae9083a56ea66c4725e7f0082461 Author: Gleb Smirnoff AuthorDate: 2024-04-08 20:16:50 +0000 Commit: Gleb Smirnoff CommitDate: 2024-04-08 20:16:50 +0000 tests/unix_seqpacket: test send(2) to a closed or aborted peer socket In both cases the kernel returns EPIPE and delivers SIGPIPE, unless blocked or disabled. The test isn't specific to SOCK_SEQPACKET, it is the same for SOCK_STREAM. Put the test into this file, since it has all primitives to write this test tersely. Reviewed by: tuexen Differential Revision: https://reviews.freebsd.org/D44146 --- tests/sys/kern/unix_seqpacket_test.c | 48 ++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/sys/kern/unix_seqpacket_test.c b/tests/sys/kern/unix_seqpacket_test.c index d463ae9b3ce6..7c7c37a3cf0a 100644 --- a/tests/sys/kern/unix_seqpacket_test.c +++ b/tests/sys/kern/unix_seqpacket_test.c @@ -530,6 +530,53 @@ ATF_TC_BODY(send_before_accept, tc) close(a); } +/* + * Test that close(2) of the peer ends in EPIPE when we try to send(2). + * Test both normal case as well as a peer that was not accept(2)-ed. + */ +static bool sigpipe_received = false; +static void +sigpipe_handler(int signo __unused) +{ + sigpipe_received = true; +} + +ATF_TC_WITHOUT_HEAD(send_to_closed); +ATF_TC_BODY(send_to_closed, tc) +{ + struct sigaction sa = { + .sa_handler = sigpipe_handler, + }; + const struct sockaddr_un *sun; + int l, s, a; + + ATF_REQUIRE(sigemptyset(&sa.sa_mask) == 0); + ATF_REQUIRE(sigaction(SIGPIPE, &sa, NULL) == 0); + + sun = mk_listening_socket(&l); + + ATF_REQUIRE((s = socket(PF_LOCAL, SOCK_SEQPACKET, 0)) > 0); + ATF_REQUIRE(connect(s, (struct sockaddr *)sun, sizeof(*sun)) == 0); + ATF_REQUIRE((a = accept(l, NULL, NULL)) != 1); + close(a); + ATF_REQUIRE(send(s, &s, sizeof(s), 0) == -1); + ATF_REQUIRE(errno == EPIPE); + ATF_REQUIRE(sigpipe_received == true); + close(s); + + ATF_REQUIRE((s = socket(PF_LOCAL, SOCK_SEQPACKET, 0)) > 0); + ATF_REQUIRE(connect(s, (struct sockaddr *)sun, sizeof(*sun)) == 0); + close(l); + sigpipe_received = false; + ATF_REQUIRE(send(s, &s, sizeof(s), 0) == -1); + ATF_REQUIRE(errno == EPIPE); + ATF_REQUIRE(sigpipe_received == true); + close(s); + + sa.sa_handler = SIG_DFL; + ATF_REQUIRE(sigaction(SIGPIPE, &sa, NULL) == 0); +} + /* Implied connect is unix/dgram only feature. Fails on stream or seqpacket. */ ATF_TC_WITHOUT_HEAD(implied_connect); ATF_TC_BODY(implied_connect, tc) @@ -1264,6 +1311,7 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, send_recv_with_connect); ATF_TP_ADD_TC(tp, sendto_recvfrom); ATF_TP_ADD_TC(tp, send_before_accept); + ATF_TP_ADD_TC(tp, send_to_closed); ATF_TP_ADD_TC(tp, implied_connect); ATF_TP_ADD_TC(tp, shutdown_send); ATF_TP_ADD_TC(tp, shutdown_send_sigpipe);