[gnome-remote-desktop] session-rdp: Protect close_session_idle_id with a mutex



commit d2b7af908b06d0a2383e0469efa8b48fa03acc2d
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Thu Oct 14 16:06:14 2021 +0200

    session-rdp: Protect close_session_idle_id with a mutex
    
    maybe_queue_close_session_idle() can be called from three different
    threads:
    
    1. The main thread (e.g. when the remote desktop session is stopped
       from the g-s system menu).
    2. The socket thread (most common case) (e.g. when the user closes the
       RDP client)
    3. The RDPGFX thread inside FreeRDP (e.g. when the RDP client uses the
       CapsAdvertise PDU without providing any capability sets.
    
    To avoid race conditions, when queueing the idle source to stop the
    remote desktop session, add a mutex around close_session_idle_id, when
    creating the idle source.

 src/grd-session-rdp.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/src/grd-session-rdp.c b/src/grd-session-rdp.c
index 6ec76c9..8435ab2 100644
--- a/src/grd-session-rdp.c
+++ b/src/grd-session-rdp.c
@@ -147,6 +147,7 @@ struct _GrdSessionRdp
 
   GSource *pending_encode_source;
 
+  GMutex close_session_mutex;
   unsigned int close_session_idle_id;
 
   GrdRdpPipeWireStream *pipewire_stream;
@@ -565,11 +566,16 @@ grd_session_rdp_hide_pointer (GrdSessionRdp *session_rdp)
 static void
 maybe_queue_close_session_idle (GrdSessionRdp *session_rdp)
 {
+  g_mutex_lock (&session_rdp->close_session_mutex);
   if (session_rdp->close_session_idle_id)
-    return;
+    {
+      g_mutex_unlock (&session_rdp->close_session_mutex);
+      return;
+    }
 
   session_rdp->close_session_idle_id =
     g_idle_add (close_session_idle, session_rdp);
+  g_mutex_unlock (&session_rdp->close_session_mutex);
 
   SetEvent (session_rdp->stop_event);
 }
@@ -2211,6 +2217,7 @@ grd_session_rdp_init (GrdSessionRdp *session_rdp)
   g_cond_init (&session_rdp->pending_jobs_cond);
   g_mutex_init (&session_rdp->pending_jobs_mutex);
   g_mutex_init (&session_rdp->rdp_flags_mutex);
+  g_mutex_init (&session_rdp->close_session_mutex);
 
   session_rdp->rdp_event_queue = grd_rdp_event_queue_new (session_rdp);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]