Skip to content
Snippets Groups Projects
Commit e6db4754 authored by Peilin Ye's avatar Peilin Ye Committed by Yongqiang Liu
Browse files

vsock: Fix memory leak in vsock_connect()

stable inclusion
from stable-v4.19.256
commit 2fc2a7767f661e6083f69588718cdf6f07cb9330
category: bugfix
bugzilla: 187891, https://gitee.com/src-openeuler/kernel/issues/I5WYLL
CVE: CVE-2022-3629

--------------------------------

commit 7e97cfed9929eaabc41829c395eb0d1350fccb9d upstream.

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;

  2. Later, the 2nd, blocking request gets interrupted by a signal after
     a few jiffies while waiting for the connection to be established.
     Socket state is back to SS_UNCONNECTED, but @connect_work is still
     pending, and will expire after 100 jiffies.

  3. Now, the 3rd, non-blocking request tries to schedule @connect_work
     again.  Since @connect_work is already scheduled,
     schedule_delayed...
parent 62daba85
No related branches found
No related tags found
No related merge requests found
...@@ -1213,7 +1213,14 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr, ...@@ -1213,7 +1213,14 @@ static int vsock_stream_connect(struct socket *sock, struct sockaddr *addr,
* timeout fires. * timeout fires.
*/ */
sock_hold(sk); 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. */ /* Skip ahead to preserve error code set above. */
goto out_wait; goto out_wait;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment