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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
See discussion starting at
http://lists.gnu.org/archive/html/bug-hurd/2010-07/msg00010.html
for the whole story. This is unfortunately not a complete patch, but mitigates
the symptom.
diff --git a/auth/auth.c b/auth/auth.c
index 2afeaf7..11db0f8 100644
--- a/auth/auth.c
+++ b/auth/auth.c
@@ -251,11 +251,22 @@ S_auth_makeauth (struct authhandle *auth,
/* Transaction handling. */
-/* A pending transaction. */
-struct pending
+/* Since the user is responsible for freeing the rendezvous port, it has to
+ * wait for the server to have finished transmitting uids.
+ *
+ * The server thus waits for the user to give it uids (unless it was already
+ * there), transmits them and provides the passthrough port.
+ *
+ * The user gives the uids and waits for the passthrough port from the server.
+ *
+ * If the user is early, it has to tell the server it arrived.
+ */
+
+/* A pending user. */
+struct pending_user
{
- hurd_ihash_locp_t locp; /* Position in one of the ihash tables. */
- struct condition wakeup; /* The waiter is blocked on this condition. */
+ hurd_ihash_locp_t locp; /* Position in the pending_users ihash table. */
+ struct condition wakeup; /* The reader is blocked on this condition. */
/* The user's auth handle. */
struct authhandle *user;
@@ -264,11 +275,18 @@ struct pending
mach_port_t passthrough;
};
+/* A pending server. */
+struct pending_server
+ {
+ hurd_ihash_locp_t locp; /* Position in the pending_servers ihash table. */
+ struct condition wakeup; /* The server is blocked on this condition. */
+ };
+
/* Table of pending transactions keyed on RENDEZVOUS. */
struct hurd_ihash pending_users
- = HURD_IHASH_INITIALIZER (offsetof (struct pending, locp));
+ = HURD_IHASH_INITIALIZER (offsetof (struct pending_user, locp));
struct hurd_ihash pending_servers
- = HURD_IHASH_INITIALIZER (offsetof (struct pending, locp));
+ = HURD_IHASH_INITIALIZER (offsetof (struct pending_server, locp));
struct mutex pending_lock = MUTEX_INITIALIZER;
/* Implement auth_user_authenticate as described in <hurd/auth.defs>. */
@@ -280,7 +298,9 @@ S_auth_user_authenticate (struct authhandle *userauth,
mach_port_t *newport,
mach_msg_type_name_t *newporttype)
{
- struct pending *s;
+ struct pending_server *s;
+ struct pending_user u;
+ error_t err;
if (! userauth)
return EOPNOTSUPP;
@@ -288,65 +308,54 @@ S_auth_user_authenticate (struct authhandle *userauth,
if (rendezvous == MACH_PORT_DEAD) /* Port died in transit. */
return EINVAL;
+ u.user = userauth;
+ condition_init (&u.wakeup);
+
mutex_lock (&pending_lock);
- /* Look for this port in the server list. */
- s = hurd_ihash_find (&pending_servers, rendezvous);
- if (s)
- {
- /* Found it! Extract the port. */
- *newport = s->passthrough;
- *newporttype = MACH_MSG_TYPE_MOVE_SEND;
+ err = hurd_ihash_add (&pending_users, rendezvous, &u);
+ if (err) {
+ mutex_unlock (&pending_lock);
+ return err;
+ }
- /* Remove it from the pending list. */
- hurd_ihash_locp_remove (&pending_servers, s->locp);
+ /* Give the server the auth port.
+ We need to add a ref in case the port dies. */
+ ports_port_ref (userauth);
- /* Give the server the auth port and wake the RPC up.
- We need to add a ref in case the port dies. */
- s->user = userauth;
- ports_port_ref (userauth);
+ /* Look for this rendezvous in the server list. */
+ s = hurd_ihash_find (&pending_servers, rendezvous);
+ if (s) {
+ /* Found it! */
- condition_signal (&s->wakeup);
- mutex_unlock (&pending_lock);
+ /* Remove it from the pending list. */
+ hurd_ihash_locp_remove (&pending_servers, s->locp);
- mach_port_deallocate (mach_task_self (), rendezvous);
- return 0;
- }
- else
+ /* Tell it we eventually arrived. */
+ condition_signal (&s->wakeup);
+ }
+
+ ports_interrupt_self_on_port_death (userauth, rendezvous);
+ /* Wait for server answer. */
+ if (hurd_condition_wait (&u.wakeup, &pending_lock) &&
+ hurd_ihash_find (&pending_users, rendezvous))
+ /* We were interrupted; remove our record. */
{
- /* No pending server RPC for this port.
- Create a pending user RPC record. */
- struct pending u;
- error_t err;
+ hurd_ihash_locp_remove (&pending_users, u.locp);
+ err = EINTR;
+ }
- err = hurd_ihash_add (&pending_users, rendezvous, &u);
- if (! err)
- {
- /* Store the user auth port and wait for the server RPC to wake
- us up. */
- u.user = userauth;
- condition_init (&u.wakeup);
- ports_interrupt_self_on_port_death (userauth, rendezvous);
- if (hurd_condition_wait (&u.wakeup, &pending_lock)
- && hurd_ihash_find (&pending_users, rendezvous))
- /* We were interrupted; remove our record. */
- {
- hurd_ihash_locp_remove (&pending_users, u.locp);
- err = EINTR;
- }
- }
- /* The server side has already removed U from the ihash table. */
- mutex_unlock (&pending_lock);
+ mutex_unlock (&pending_lock);
- if (! err)
- {
- /* The server RPC has set the port and signalled U.wakeup. */
- *newport = u.passthrough;
- *newporttype = MACH_MSG_TYPE_MOVE_SEND;
- mach_port_deallocate (mach_task_self (), rendezvous);
- }
- return err;
+ if (! err)
+ {
+ /* Extract the port. */
+ *newport = u.passthrough;
+ *newporttype = MACH_MSG_TYPE_MOVE_SEND;
+ mach_port_deallocate (mach_task_self (), rendezvous);
}
+
+ return err;
}
/* Implement auth_server_authenticate as described in <hurd/auth.defs>. */
@@ -366,7 +375,7 @@ S_auth_server_authenticate (struct authhandle *serverauth,
uid_t **agids,
size_t *nagids)
{
- struct pending *u;
+ struct pending_user *u;
struct authhandle *user;
error_t err;
@@ -378,66 +387,69 @@ S_auth_server_authenticate (struct authhandle *serverauth,
mutex_lock (&pending_lock);
- /* Look for this port in the user list. */
+ /* Look for this rendezvous in the user list. */
u = hurd_ihash_find (&pending_users, rendezvous);
- if (u)
+ if (! u)
{
- /* Remove it from the pending list. */
- hurd_ihash_locp_remove (&pending_users, u->locp);
-
- /* Found it! We must add a ref because the one held by the
- user RPC might die as soon as we unlock pending_lock. */
- user = u->user;
- ports_port_ref (user);
-
- /* Give the user the new port and wake the RPC up. */
- u->passthrough = newport;
-
- condition_signal (&u->wakeup);
- mutex_unlock (&pending_lock);
- }
- else
- {
- /* No pending user RPC for this port.
- Create a pending server RPC record. */
- struct pending s;
-
+ /* User not here yet, have to wait for it. */
+ struct pending_server s;
+ condition_init (&s.wakeup);
err = hurd_ihash_add (&pending_servers, rendezvous, &s);
if (! err)
- {
- /* Store the new port and wait for the user RPC to wake us up. */
- s.passthrough = newport;
- condition_init (&s.wakeup);
+ {
ports_interrupt_self_on_port_death (serverauth, rendezvous);
- if (hurd_condition_wait (&s.wakeup, &pending_lock)
- && hurd_ihash_find (&pending_servers, rendezvous))
+ if (hurd_condition_wait (&s.wakeup, &pending_lock) &&
+ hurd_ihash_find (&pending_servers, rendezvous))
/* We were interrupted; remove our record. */
{
hurd_ihash_locp_remove (&pending_servers, s.locp);
err = EINTR;
}
- }
- /* The user side has already removed S from the ihash table. */
+ else
+ {
+ u = hurd_ihash_find (&pending_users, rendezvous);
+ if (! u)
+ /* User still not here, odd! */
+ err = EINTR;
+ }
+ }
+ }
+
+ if (u)
+ {
+ error_t err2;
+
+ /* Remove it from the pending list. */
+ hurd_ihash_locp_remove (&pending_users, u->locp);
+
+ /* Found it! */
+ user = u->user;
+
mutex_unlock (&pending_lock);
- if (err)
- return err;
+ /* Tell third party. */
+ err2 = auth_server_authenticate_reply (reply, reply_type, 0,
+ user->euids.ids, user->euids.num,
+ user->auids.ids, user->auids.num,
+ user->egids.ids, user->egids.num,
+ user->agids.ids, user->agids.num);
+
+ if (err2)
+ mach_port_deallocate (mach_task_self (), reply);
+
+ mutex_lock (&pending_lock);
+
+ /* Give the user the new port and wake the RPC up. */
+ u->passthrough = newport;
- /* The user RPC has set the port (with a ref) and signalled S.wakeup. */
- user = s.user;
+ condition_signal (&u->wakeup);
}
- /* Extract the ids. We must use a separate reply stub so
- we can deref the user auth handle after the reply uses its
- contents. */
- err = auth_server_authenticate_reply (reply, reply_type, 0,
- user->euids.ids, user->euids.num,
- user->auids.ids, user->auids.num,
- user->egids.ids, user->egids.num,
- user->agids.ids, user->agids.num);
+ mutex_unlock (&pending_lock);
if (err)
- mach_port_deallocate (mach_task_self (), reply);
+ return err;
+
ports_port_deref (user);
mach_port_deallocate (mach_task_self (), rendezvous);
return MIG_NO_REPLY;
|