mbox series

[RFC,v2,0/2] vsock: handle writes to shutdowned socket

Message ID 20230826175900.3693844-1-avkrasnov@salutedevices.com (mailing list archive)
Headers show
Series vsock: handle writes to shutdowned socket | expand

Message

Arseniy Krasnov Aug. 26, 2023, 5:58 p.m. UTC
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=b38460bc463c54e0c15ff3b37e81f7e2059bb9bb

Link to v1:
https://lore.kernel.org/netdev/20230801141727.481156-1-AVKrasnov@sberdevices.ru/

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(+)

Comments

Stefano Garzarella Aug. 31, 2023, 3:23 p.m. UTC | #1
Hi Arseniy,

On Sat, Aug 26, 2023 at 08:58:58PM +0300, Arseniy Krasnov 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).
>
>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=b38460bc463c54e0c15ff3b37e81f7e2059bb9bb
>
>Link to v1:
>https://lore.kernel.org/netdev/20230801141727.481156-1-AVKrasnov@sberdevices.ru/
>
>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

Thanks for this series, I fully reviewed it, LGTM!

Please send it targeting net-next when it reopens.

Stefano
Arseniy Krasnov Aug. 31, 2023, 5:04 p.m. UTC | #2
On 31.08.2023 18:23, Stefano Garzarella wrote:
> Hi Arseniy,
> 
> On Sat, Aug 26, 2023 at 08:58:58PM +0300, Arseniy Krasnov 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).
>>
>> 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=b38460bc463c54e0c15ff3b37e81f7e2059bb9bb
>>
>> Link to v1:
>> https://lore.kernel.org/netdev/20230801141727.481156-1-AVKrasnov@sberdevices.ru/
>>
>> 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
> 
> Thanks for this series, I fully reviewed it, LGTM!
> 
> Please send it targeting net-next when it reopens.

Hi Stefano,

Ok and thanks for review!

Thanks, Arseniy

> 
> Stefano
>