Message ID | fd0dc1aa3a78df22d64de59333e1d47ee60ed3e8.1659981325.git.peilin.ye@bytedance.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 7e97cfed9929eaabc41829c395eb0d1350fccb9d |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net,v3,1/2] vsock: Fix memory leak in vsock_connect() | expand |
Hello: This series was applied to netdev/net.git (master) by David S. Miller <davem@davemloft.net>: On Mon, 8 Aug 2022 11:04:47 -0700 you wrote: > From: Peilin Ye <peilin.ye@bytedance.com> > > An O_NONBLOCK vsock_connect() request may try to reschedule > @connect_work. Imagine the following sequence of vsock_connect() > requests: > > 1. The 1st, non-blocking request schedules @connect_work, which will > expire after 200 jiffies. Socket state is now SS_CONNECTING; > > [...] Here is the summary with links: - [net,v3,1/2] vsock: Fix memory leak in vsock_connect() https://git.kernel.org/netdev/net/c/7e97cfed9929 - [net,v3,2/2] vsock: Set socket state back to SS_UNCONNECTED in vsock_connect_timeout() https://git.kernel.org/netdev/net/c/a3e7b29e3085 You are awesome, thank you!
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c index f04abf662ec6..4d68681f5abe 100644 --- a/net/vmw_vsock/af_vsock.c +++ b/net/vmw_vsock/af_vsock.c @@ -1391,7 +1391,14 @@ static int vsock_connect(struct socket *sock, struct sockaddr *addr, * timeout fires. */ sock_hold(sk); - schedule_delayed_work(&vsk->connect_work, timeout); + + /* If the timeout function is already scheduled, + * reschedule it, then ungrab the socket refcount to + * keep it balanced. + */ + if (mod_delayed_work(system_wq, &vsk->connect_work, + timeout)) + sock_put(sk); /* Skip ahead to preserve error code set above. */ goto out_wait;