 vsock: Ignore signal/timeout on connect() if already established · gregkh/linux@ab6b19f · GitHub Skip to content Navigation Menu Toggle navigation Sign in Appearance settings Platform AI CODE CREATION GitHub Copilot Write better code with AI GitHub Spark Build and deploy intelligent apps GitHub Models Manage and compare prompts MCP Registry New Integrate external tools DEVELOPER WORKFLOWS Actions Automate any workflow Codespaces Instant dev environments Issues Plan and track work Code Review Manage code changes APPLICATION SECURITY GitHub Advanced Security Find and fix vulnerabilities Code security Secure your code as you build Secret protection  EXPLORE Why GitHub Documentation Blog Changelog Marketplace View all features Solutions BY COMPANY SIZE Enterprises Small and medium teams Startups Nonprofits BY USE CASE App Modernization DevSecOps DevOps CI/CD View all use cases BY INDUSTRY Healthcare Financial services Manufacturing Government View all industries View all solutions Resources EXPLORE BY TOPIC AI Software Development DevOps Security View all topics EXPLORE BY TYPE Customer stories Events &amp; webinars Ebooks &amp; reports Business insights GitHub Skills SUPPORT &amp; SERVICES Documentation Customer support Community forum Trust center Partners View all resources Open Source COMMUNITY GitHub Sponsors Fund open source developers PROGRAMS Security Lab Maintainer Community Accelerator GitHub Stars Archive Program REPOSITORIES Topics Trending Collections Enterprise ENTERPRISE SOLUTIONS Enterprise platform AI-powered developer platform AVAILABLE ADD-ONS GitHub Advanced Security Enterprise-grade security features Copilot for Business Enterprise-grade AI features Premium Support Enterprise-grade 24/7 support Pricing Search or jump to... Search code, repositories, users, issues, pull requests... --> Search Clear Search syntax tips Provide feedback --> We read every piece of feedback, and take your input very seriously.  Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly --> Name Query To see all available qualifiers, see our documentation . Cancel Create saved search Sign in Sign up Appearance settings Resetting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} gregkh / linux Public Notifications You must be signed in to change notification settings Fork 676 Star 636 Code Actions Security and quality 0 Insights Additional navigation options Code Actions Security and quality Insights Commit ab6b19f Browse files Browse files mmhal authored and gregkh committed vsock: Ignore signal/timeout on connect() if already established [ Upstream commit 002541e ] During connect(), acting on a signal/timeout by disconnecting an already established socket leads to several issues: 1. connect() invoking vsock_transport_cancel_pkt() -&gt; virtio_transport_purge_skbs() may race with sendmsg() invoking virtio_transport_get_credit(). This results in a permanently elevated `vvs-&gt;bytes_unsent`. Which, in turn, confuses the SOCK_LINGER handling. 2. connect() resetting a connected socket's state may race with socket being placed in a sockmap. A disconnected socket remaining in a sockmap breaks sockmap's assumptions. And gives rise to WARNs. 3. connect() transitioning SS_CONNECTED -&gt; SS_UNCONNECTED allows for a transport change/drop after TCP_ESTABLISHED. Which poses a problem for any simultaneous sendmsg() or connect() and may result in a use-after-free/null-ptr-deref. Do not disconnect socket on signal/timeout. Keep the logic for unconnected sockets: they don't linger, can't be placed in a sockmap, are rejected by sendmsg(). [1]: https://lore.kernel.org/netdev/e07fd95c-9a38-4eea-9638-133e38c2ec9b@rbox.co/ [2]: https://lore.kernel.org/netdev/20250317-vsock-trans-signal-race-v4-0-fc8837f3f1d4@rbox.co/ [3]: https://lore.kernel.org/netdev/60f1b7db-3099-4f6a-875e-af9f6ef194f6@rbox.co/ Fixes: d021c34 ("VSOCK: Introduce VM Sockets") Signed-off-by: Michal Luczaj &lt;mhal@rbox.co&gt; Reviewed-by: Stefano Garzarella &lt;sgarzare@redhat.com&gt; Link: https://patch.msgid.link/20251119-vsock-interrupted-connect-v2-1-70734cf1233f@rbox.co Signed-off-by: Jakub Kicinski &lt;kuba@kernel.org&gt; Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt; 1 parent 66c3a3e commit ab6b19f Copy full SHA for ab6b19f 1 file changed + 31 - 9 Lines changed: 31 additions &amp; 9 deletions File tree Expand file tree Collapse file tree Open diff view settings Filter options net/vmw_vsock af_vsock.c Expand file tree Collapse file tree Open diff view settings Collapse file ‎ net/vmw_vsock/af_vsock.c ‎ Copy file name to clipboard Expand all lines: net/vmw_vsock/af_vsock.c + 31 - 9 Lines changed: 31 additions &amp; 9 deletions Original file line number Diff line number Diff line change @@ -1666,18 +1666,40 @@ static int vsock_connect(struct socket *sock, struct sockaddr *addr, 1666 1666 timeout = schedule_timeout ( timeout ); 1667 1667 lock_sock ( sk ); 1668 1668 1669 - if ( signal_pending ( current )) { 1670 - err = sock_intr_errno ( timeout ); 1671 - sk -&gt; sk_state = sk -&gt; sk_state == TCP_ESTABLISHED ? TCP_CLOSING : TCP_CLOSE ; 1672 - sock -&gt; state = SS_UNCONNECTED ; 1673 - vsock_transport_cancel_pkt ( vsk ); 1674 - vsock_remove_connected ( vsk ); 1675 - goto out_wait ; 1676 - } else if (( sk -&gt; sk_state != TCP_ESTABLISHED ) &amp;&amp; ( timeout == 0 )) { 1677 - err = - ETIMEDOUT ; 1669 + /* Connection established. Whatever happens to socket once we 1670 + * release it, that&#39;s not connect()&#39;s concern. No need to go 1671 + * into signal and timeout handling. Call it a day. 1672 + * 1673 + * Note that allowing to &quot;reset&quot; an already established socket 1674 + * here is racy and insecure. 1675 + */ 1676 + if ( sk -&gt; sk_state == TCP_ESTABLISHED ) 1677 + break ; 1678 + 1679 + /* If connection was _not_ established and a signal/timeout came 1680 + * to be, we want the socket&#39;s state reset. User space may want 1681 + * to retry. 1682 + * 1683 + * sk_state != TCP_ESTABLISHED implies that socket is not on 1684 + * vsock_connected_table. We keep the binding and the transport 1685 + * assigned. 1686 + */ 1687 + if ( signal_pending ( current ) || timeout == 0 ) { 1688 + err = timeout == 0 ? - ETIMEDOUT : sock_intr_errno ( timeout ); 1689 + 1690 + /* Listener might have already responded with 1691 + * VIRTIO_VSOCK_OP_RESPONSE. Its handling expects our 1692 + * sk_state == TCP_SYN_SENT, which hereby we break. 1693 + * In such case VIRTIO_VSOCK_OP_RST will follow. 1694 + */ 1678 1695 sk -&gt; sk_state = TCP_CLOSE ; 1679 1696 sock -&gt; state = SS_UNCONNECTED ; 1697 + 1698 + /* Try to cancel VIRTIO_VSOCK_OP_REQUEST skb sent out by 1699 + * transport-&gt;connect(). 1700 + */ 1680 1701 vsock_transport_cancel_pkt ( vsk ); 1702 + 1681 1703 goto out_wait ; 1682 1704 } 1683 1705 0 commit comments Comments 0 ( 0 ) Footer &copy; 2026 GitHub,&nbsp;Inc. Footer navigation Terms Privacy Security Status Community Docs Contact Manage cookies Do not share my personal information You can’t perform that action at this time. 