* [PATCH net-next v2 0/2] vsock: handle writes to shutdowned socket
@ 2023-09-11 20:20 Arseniy Krasnov
2023-09-11 20:20 ` [PATCH net-next v2 1/2] vsock: send SIGPIPE on write " Arseniy Krasnov
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Arseniy Krasnov @ 2023-09-11 20:20 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Michael S. Tsirkin,
Jason Wang, Bobby Eshleman
Cc: kvm, virtualization, netdev, linux-kernel, kernel, oxffffaa,
avkrasnov
Hello,
this small patchset adds POSIX compliant behaviour on writes to the
socket which was shutdowned with 'shutdown()' (both sides - local with
SHUT_WR flag, peer - with SHUT_RD flag). According POSIX we must send
SIGPIPE in such cases (but SIGPIPE is not send when MSG_NOSIGNAL is set).
First patch is implemented in the same way as net/ipv4/tcp.c:tcp_sendmsg_locked().
It uses 'sk_stream_error()' function which handles EPIPE error. Another
way is to use code from net/unix/af_unix.c:unix_stream_sendmsg() where
same logic from 'sk_stream_error()' is implemented "from scratch", but
it doesn't check 'sk_err' field. I think error from this field has more
priority to be returned from syscall. So I guess it is better to reuse
currently implemented 'sk_stream_error()' function.
Test is also added.
Head for this patchset is:
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?id=73be7fb14e83d24383f840a22f24d3ed222ca319
Link to v1:
https://lore.kernel.org/netdev/20230801141727.481156-1-AVKrasnov@sberdevices.ru/
Link to v2 (RFC):
https://lore.kernel.org/netdev/20230826175900.3693844-1-avkrasnov@salutedevices.com/
Changelog:
v1 -> v2:
* 0001 stills the same - SIGPIPE is sent only for SOCK_STREAM as discussed in v1
with Stefano Garzarella <sgarzare@redhat.com>.
* 0002 - use 'sig_atomic_t' instead of 'bool' for flag variables updated from
signal handler.
Arseniy Krasnov (2):
vsock: send SIGPIPE on write to shutdowned socket
test/vsock: shutdowned socket test
net/vmw_vsock/af_vsock.c | 3 +
tools/testing/vsock/vsock_test.c | 138 +++++++++++++++++++++++++++++++
2 files changed, 141 insertions(+)
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net-next v2 1/2] vsock: send SIGPIPE on write to shutdowned socket
2023-09-11 20:20 [PATCH net-next v2 0/2] vsock: handle writes to shutdowned socket Arseniy Krasnov
@ 2023-09-11 20:20 ` Arseniy Krasnov
2023-09-11 20:20 ` [PATCH net-next v2 2/2] test/vsock: shutdowned socket test Arseniy Krasnov
2023-09-14 6:40 ` [PATCH net-next v2 0/2] vsock: handle writes to shutdowned socket patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Arseniy Krasnov @ 2023-09-11 20:20 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Michael S. Tsirkin,
Jason Wang, Bobby Eshleman
Cc: kvm, virtualization, netdev, linux-kernel, kernel, oxffffaa,
avkrasnov
POSIX requires to send SIGPIPE on write to SOCK_STREAM socket which was
shutdowned with SHUT_WR flag or its peer was shutdowned with SHUT_RD
flag. Also we must not send SIGPIPE if MSG_NOSIGNAL flag is set.
Signed-off-by: Arseniy Krasnov <avkrasnov@salutedevices.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
---
net/vmw_vsock/af_vsock.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 020cf17ab7e4..013b65241b65 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -1921,6 +1921,9 @@ static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg,
err = total_written;
}
out:
+ if (sk->sk_type == SOCK_STREAM)
+ err = sk_stream_error(sk, msg->msg_flags, err);
+
release_sock(sk);
return err;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next v2 2/2] test/vsock: shutdowned socket test
2023-09-11 20:20 [PATCH net-next v2 0/2] vsock: handle writes to shutdowned socket Arseniy Krasnov
2023-09-11 20:20 ` [PATCH net-next v2 1/2] vsock: send SIGPIPE on write " Arseniy Krasnov
@ 2023-09-11 20:20 ` Arseniy Krasnov
2023-09-14 6:40 ` [PATCH net-next v2 0/2] vsock: handle writes to shutdowned socket patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Arseniy Krasnov @ 2023-09-11 20:20 UTC (permalink / raw)
To: Stefan Hajnoczi, Stefano Garzarella, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Michael S. Tsirkin,
Jason Wang, Bobby Eshleman
Cc: kvm, virtualization, netdev, linux-kernel, kernel, oxffffaa,
avkrasnov
This adds two tests for 'shutdown()' call. It checks that SIGPIPE is
sent when MSG_NOSIGNAL is not set and vice versa. Both flags SHUT_WR
and SHUT_RD are tested.
Signed-off-by: Arseniy Krasnov <avkrasnov@salutedevices.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
---
tools/testing/vsock/vsock_test.c | 138 +++++++++++++++++++++++++++++++
1 file changed, 138 insertions(+)
diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
index 90718c2fd4ea..148fc9c47c50 100644
--- a/tools/testing/vsock/vsock_test.c
+++ b/tools/testing/vsock/vsock_test.c
@@ -19,6 +19,7 @@
#include <time.h>
#include <sys/mman.h>
#include <poll.h>
+#include <signal.h>
#include "timeout.h"
#include "control.h"
@@ -1170,6 +1171,133 @@ static void test_seqpacket_msg_peek_server(const struct test_opts *opts)
return test_msg_peek_server(opts, true);
}
+static sig_atomic_t have_sigpipe;
+
+static void sigpipe(int signo)
+{
+ have_sigpipe = 1;
+}
+
+static void test_stream_check_sigpipe(int fd)
+{
+ ssize_t res;
+
+ have_sigpipe = 0;
+
+ res = send(fd, "A", 1, 0);
+ if (res != -1) {
+ fprintf(stderr, "expected send(2) failure, got %zi\n", res);
+ exit(EXIT_FAILURE);
+ }
+
+ if (!have_sigpipe) {
+ fprintf(stderr, "SIGPIPE expected\n");
+ exit(EXIT_FAILURE);
+ }
+
+ have_sigpipe = 0;
+
+ res = send(fd, "A", 1, MSG_NOSIGNAL);
+ if (res != -1) {
+ fprintf(stderr, "expected send(2) failure, got %zi\n", res);
+ exit(EXIT_FAILURE);
+ }
+
+ if (have_sigpipe) {
+ fprintf(stderr, "SIGPIPE not expected\n");
+ exit(EXIT_FAILURE);
+ }
+}
+
+static void test_stream_shutwr_client(const struct test_opts *opts)
+{
+ int fd;
+
+ struct sigaction act = {
+ .sa_handler = sigpipe,
+ };
+
+ sigaction(SIGPIPE, &act, NULL);
+
+ fd = vsock_stream_connect(opts->peer_cid, 1234);
+ if (fd < 0) {
+ perror("connect");
+ exit(EXIT_FAILURE);
+ }
+
+ if (shutdown(fd, SHUT_WR)) {
+ perror("shutdown");
+ exit(EXIT_FAILURE);
+ }
+
+ test_stream_check_sigpipe(fd);
+
+ control_writeln("CLIENTDONE");
+
+ close(fd);
+}
+
+static void test_stream_shutwr_server(const struct test_opts *opts)
+{
+ int fd;
+
+ fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL);
+ if (fd < 0) {
+ perror("accept");
+ exit(EXIT_FAILURE);
+ }
+
+ control_expectln("CLIENTDONE");
+
+ close(fd);
+}
+
+static void test_stream_shutrd_client(const struct test_opts *opts)
+{
+ int fd;
+
+ struct sigaction act = {
+ .sa_handler = sigpipe,
+ };
+
+ sigaction(SIGPIPE, &act, NULL);
+
+ fd = vsock_stream_connect(opts->peer_cid, 1234);
+ if (fd < 0) {
+ perror("connect");
+ exit(EXIT_FAILURE);
+ }
+
+ control_expectln("SHUTRDDONE");
+
+ test_stream_check_sigpipe(fd);
+
+ control_writeln("CLIENTDONE");
+
+ close(fd);
+}
+
+static void test_stream_shutrd_server(const struct test_opts *opts)
+{
+ int fd;
+
+ fd = vsock_stream_accept(VMADDR_CID_ANY, 1234, NULL);
+ if (fd < 0) {
+ perror("accept");
+ exit(EXIT_FAILURE);
+ }
+
+ if (shutdown(fd, SHUT_RD)) {
+ perror("shutdown");
+ exit(EXIT_FAILURE);
+ }
+
+ control_writeln("SHUTRDDONE");
+ control_expectln("CLIENTDONE");
+
+ close(fd);
+}
+
static struct test_case test_cases[] = {
{
.name = "SOCK_STREAM connection reset",
@@ -1250,6 +1378,16 @@ static struct test_case test_cases[] = {
.run_client = test_seqpacket_msg_peek_client,
.run_server = test_seqpacket_msg_peek_server,
},
+ {
+ .name = "SOCK_STREAM SHUT_WR",
+ .run_client = test_stream_shutwr_client,
+ .run_server = test_stream_shutwr_server,
+ },
+ {
+ .name = "SOCK_STREAM SHUT_RD",
+ .run_client = test_stream_shutrd_client,
+ .run_server = test_stream_shutrd_server,
+ },
{},
};
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2 0/2] vsock: handle writes to shutdowned socket
2023-09-11 20:20 [PATCH net-next v2 0/2] vsock: handle writes to shutdowned socket Arseniy Krasnov
2023-09-11 20:20 ` [PATCH net-next v2 1/2] vsock: send SIGPIPE on write " Arseniy Krasnov
2023-09-11 20:20 ` [PATCH net-next v2 2/2] test/vsock: shutdowned socket test Arseniy Krasnov
@ 2023-09-14 6:40 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-09-14 6:40 UTC (permalink / raw)
To: Arseniy Krasnov
Cc: stefanha, sgarzare, davem, edumazet, kuba, pabeni, mst, jasowang,
bobby.eshleman, kvm, virtualization, netdev, linux-kernel, kernel,
oxffffaa
Hello:
This series was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Mon, 11 Sep 2023 23:20:25 +0300 you wrote:
> Hello,
>
> this small patchset adds POSIX compliant behaviour on writes to the
> socket which was shutdowned with 'shutdown()' (both sides - local with
> SHUT_WR flag, peer - with SHUT_RD flag). According POSIX we must send
> SIGPIPE in such cases (but SIGPIPE is not send when MSG_NOSIGNAL is set).
>
> [...]
Here is the summary with links:
- [net-next,v2,1/2] vsock: send SIGPIPE on write to shutdowned socket
https://git.kernel.org/netdev/net-next/c/8ecf0cedc08a
- [net-next,v2,2/2] test/vsock: shutdowned socket test
https://git.kernel.org/netdev/net-next/c/b698bd97c571
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-14 6:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-11 20:20 [PATCH net-next v2 0/2] vsock: handle writes to shutdowned socket Arseniy Krasnov
2023-09-11 20:20 ` [PATCH net-next v2 1/2] vsock: send SIGPIPE on write " Arseniy Krasnov
2023-09-11 20:20 ` [PATCH net-next v2 2/2] test/vsock: shutdowned socket test Arseniy Krasnov
2023-09-14 6:40 ` [PATCH net-next v2 0/2] vsock: handle writes to shutdowned socket patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).