summaryrefslogtreecommitdiff
path: root/gnome-keyring-40.0-ssh-agent-avoid-deadlock.patch
blob: 93d3d564bce51517b5e06cde6a7ce041d8b1898c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
From dd92a85fb44ff68e075c348176d042448745fac8 Mon Sep 17 00:00:00 2001
From: Steven Luo <s_luo@berkeley.edu>
Date: Mon, 5 Feb 2024 10:22:02 -0800
Subject: [PATCH 1/2] ssh-agent: avoid deadlock when agent process dies before
 we connect to it

gkd_ssh_agent_process_connect() waits for the ssh-agent process to
become ready to accept input by entering the main loop while holding
self->lock.  However, if the ssh-agent process dies before becoming
ready, the main loop will call on_child_watch(), which needs to take
self->lock, causing a deadlock.  Fix this by releasing the lock before
entering the main loop.

This should prevent a busyloop that's been reported multiple times [1]
[2] from lasting forever.

[1] https://bugzilla.gnome.org/show_bug.cgi?id=794848
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1841855 (migrated to
https://issues.redhat.com/browse/RHEL-9302)
---
 daemon/ssh-agent/gkd-ssh-agent-process.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/daemon/ssh-agent/gkd-ssh-agent-process.c b/daemon/ssh-agent/gkd-ssh-agent-process.c
index d3bb3a7ed..cbf10ffb2 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-process.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-process.c
@@ -228,8 +228,11 @@ gkd_ssh_agent_process_connect (GkdSshAgentProcess *self,
 
 	if (started && !self->ready) {
 		source = g_timeout_add_seconds (5, on_timeout, &timedout);
-		while (!self->ready && !timedout)
+		while (!self->ready && !timedout) {
+			g_mutex_unlock (&self->lock);
 			g_main_context_iteration (NULL, FALSE);
+			g_mutex_lock (&self->lock);
+		}
 		g_source_remove (source);
 	}
 
-- 
GitLab


From 03ca2228205bfaa7510116142f9beaaf2a682042 Mon Sep 17 00:00:00 2001
From: Steven Luo <s_luo@berkeley.edu>
Date: Mon, 5 Feb 2024 10:29:56 -0800
Subject: [PATCH 2/2] ssh-agent: stop waiting for agent to become ready if it's
 dead

If the ssh-agent process we launch dies before it becomes ready to take
input, self->pid will be set to 0 by on_child_watch().  If that happens,
there's no point in continuing to wait for the process to become ready.
This should avoid an unnecessary five-second wait in cases like [1] or
[2].

[1] https://bugzilla.gnome.org/show_bug.cgi?id=794848
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1841855 (migrated to
https://issues.redhat.com/browse/RHEL-9302)
---
 daemon/ssh-agent/gkd-ssh-agent-process.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/daemon/ssh-agent/gkd-ssh-agent-process.c b/daemon/ssh-agent/gkd-ssh-agent-process.c
index cbf10ffb2..82e5559fb 100644
--- a/daemon/ssh-agent/gkd-ssh-agent-process.c
+++ b/daemon/ssh-agent/gkd-ssh-agent-process.c
@@ -226,9 +226,9 @@ gkd_ssh_agent_process_connect (GkdSshAgentProcess *self,
 		started = TRUE;
 	}
 
-	if (started && !self->ready) {
+	if (started && self->pid && !self->ready) {
 		source = g_timeout_add_seconds (5, on_timeout, &timedout);
-		while (!self->ready && !timedout) {
+		while (self->pid && !self->ready && !timedout) {
 			g_mutex_unlock (&self->lock);
 			g_main_context_iteration (NULL, FALSE);
 			g_mutex_lock (&self->lock);
-- 
GitLab