On 11/15/26 05:01, [email protected] wrote:

> [Severity: Low]
> Do vhost_vsock_reset_orphans() and vmci_transport_handle_detach() really
> reach connect() through the sk_err path described here?

The other (also fixed) path is signal/timeout, unrelated to sk_err.

> vhost_vsock_reset_orphans() in drivers/vhost/vsock.c writes:
> 
>       sk->sk_state = SS_UNCONNECTED;
>       sk->sk_err = ECONNRESET;
> 
> SS_UNCONNECTED is 1, which is the same value as TCP_ESTABLISHED. When
> vsock_connect() takes the lock again, this check runs first:

The sk_state assignment is wrong and it's getting fixed:
https://lore.kernel.org/netdev/[email protected]/

> [Severity: Low]
> Should the changelog also describe the same-transport case? This patch
> seems to close that one too.

It generally closes the issue of unexpected socket state transition.

> [Severity: Medium]
> Does the rest of vsock_connect() need to recognize SS_CONNECTED now?
> 
> With this patch the failure paths can run on a socket whose
> sock->state is SS_CONNECTED. The wait loop and the signal/timeout
> branch still only treat TCP_ESTABLISHED and TCP_CLOSING as success:
> 
>       while (sk->sk_state != TCP_ESTABLISHED &&
>              sk->sk_state != TCP_CLOSING && sk->sk_err == 0) {
> 
> Suppose the handshake completes while connect() sleeps, and the
> socket is then moved to TCP_CLOSE with sk_err == 0. The loop keeps
> sleeping. vmci_transport_handle_detach() does that for an established
> socket, since it only sets sk_err in TCP_SYN_SENT. With virtio,
> virtio_vsock_reset_sock() sets ECONNRESET, but another thread can
> clear it with getsockopt(SO_ERROR) before connect() takes the lock
> again. connect() then waits for the whole connect_timeout, or until a
> signal arrives, and ends up in this branch.
> 
> Here vsock_connect_close() now leaves the socket SS_CONNECTED, yet
> vsock_transport_cancel_pkt() is still called right after it. For
> virtio this reaches virtio_transport_purge_skbs(), which drops every
> skb queued for this vsk, not only the OP_REQUEST mentioned in the
> comment.
> 
> If a concurrent sendmsg() queued OP_RW skbs while the socket was
> TCP_ESTABLISHED, virtio_transport_get_credit() already added them to
> vvs->bytes_unsent. Purging them without
> virtio_transport_consume_skb_sent() seems to leave bytes_unsent
> non-zero for good. SIOCOUTQ then reports stale data, and
> vsock_linger() waits out the full SO_LINGER time on close().
> 
> The caller also gets -ETIMEDOUT or -EINTR for a socket that now
> reports SS_CONNECTED. If the error is -ERESTARTSYS, the restarted
> connect() fails with -EISCONN.
> 
> The long wait and the vsock_transport_cancel_pkt() call predate this
> patch. But this patch is what decides that such a socket stays
> SS_CONNECTED, so the rest of vsock_connect() should probably agree
> with it. Should the loop also stop when sock->state is no longer
> SS_CONNECTING? And should an already connected socket skip
> vsock_transport_cancel_pkt() and return sock_error() (or 0) instead?

This patch is about keeping a bricked socket - safely bricked.

> [Severity: Low]
> Can this leave a socket that never connected stuck in SS_DISCONNECTING?
> 
> Consider a blocking connect() racing with shutdown():
> 
> Thread A                          Thread B
> vsock_connect()
>   sock->state = SS_CONNECTING
>   release_sock(sk)
>   schedule_timeout()
>                                   vsock_shutdown()
>                                     sock->state = SS_DISCONNECTING;
>   lock_sock(sk)
>   timeout, signal or sk_err
>   vsock_connect_close()
>     sk_state = TCP_CLOSE
>     sock->state stays SS_DISCONNECTING
> 
> After this, every later connect() fails here:
> 
>       case SS_DISCONNECTING:
>               err = -EINVAL;
>               goto out;

IOW, after shutdown() races connect(), socket cannot be used to re-connect
(or become a listener). I'm not sure if that's an issue.


Reply via email to