Skip to content

Commit 6b4bac6

Browse files
committed
mountd: protect the client list with a mutex
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
1 parent 2a9d04a commit 6b4bac6

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

servers/nfsd/mountd.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626

2727
#include <arpa/inet.h>
28-
#include <errno.h>
2928
#include <fcntl.h>
3029
#include <poll.h>
30+
#include <pthread.h>
3131
#include <stdlib.h>
3232
#include <string.h>
3333
#include <sys/stat.h>
@@ -196,7 +196,9 @@ static int mount3_mnt_proc(struct rpc_context *rpc, struct rpc_msg *call, void *
196196
goto out;
197197
}
198198

199+
pthread_mutex_lock(&mountd->clients_mutex);
199200
LIST_ADD(&mountd->clients, client, next);
201+
pthread_mutex_unlock(&mountd->clients_mutex);
200202
client = NULL;
201203
res.fhs_status = MNT3_OK;
202204
res.mountres3_u.mountinfo.fhandle.fhandle3_len = e->fh.data.data_len;
@@ -226,7 +228,9 @@ static int mount3_umnt_proc(struct rpc_context *rpc, struct rpc_msg *call, void
226228

227229
for (c = mountd->clients; c; c = c->next) {
228230
if (!strcmp(c->client, addr) && !strcmp(c->path, *args)) {
231+
pthread_mutex_lock(&mountd->clients_mutex);
229232
LIST_REMOVE(&mountd->clients, c, next);
233+
pthread_mutex_unlock(&mountd->clients_mutex);
230234
talloc_free(c);
231235
return rpc_send_reply(rpc, call, NULL, (zdrproc_t)zdr_void, 0);
232236
}
@@ -246,13 +250,16 @@ static int mount3_umntall_proc(struct rpc_context *rpc, struct rpc_msg *call, vo
246250
return rpc_send_reply(rpc, call, NULL, (zdrproc_t)zdr_void, 0);
247251
}
248252

253+
pthread_mutex_lock(&mountd->clients_mutex);
249254
for (c = mountd->clients; c; c = c->next) {
250255
LIST_REMOVE(&mountd->clients, c, next);
251256
if (!strcmp(c->client, addr)) {
252257
talloc_free(c);
258+
continue;
253259
}
254260
LIST_ADD(&nl, c, next);
255261
}
262+
pthread_mutex_unlock(&mountd->clients_mutex);
256263
mountd->clients = nl;
257264
return rpc_send_reply(rpc, call, NULL, (zdrproc_t)zdr_void, 0);
258265
}
@@ -286,7 +293,13 @@ static int mount3_dump_proc(struct rpc_context *rpc, struct rpc_msg *call, void
286293
talloc_free(tmp_ctx);
287294
return rc;
288295
}
289-
296+
297+
static int mountd_destructor(struct mountd_state *mountd)
298+
{
299+
pthread_mutex_destroy(&mountd->clients_mutex);
300+
return 0;
301+
}
302+
290303
struct mountd_state *mountd_init(TALLOC_CTX *ctx, struct tevent_context *tevent)
291304
{
292305
struct mountd_state *mountd;
@@ -317,13 +330,14 @@ struct mountd_state *mountd_init(TALLOC_CTX *ctx, struct tevent_context *tevent)
317330
printf("Failed to talloc mountd\n");
318331
goto err;
319332
}
333+
talloc_set_destructor(mountd, mountd_destructor);
320334
for (i = 0; i < sizeof(mount3_pt) / sizeof(mount3_pt[0]); i++) {
321335
mount3_pt[i].opaque = mountd;
322336
}
323-
mountd->rpc = NULL;
324337
mountd->tevent = tevent;
325338
mountd->exports = NULL;
326339
mountd->clients = NULL;
340+
pthread_mutex_init(&mountd->clients_mutex, NULL);
327341

328342
servers = libnfs_create_server(mountd, tevent, 0, "libnfs mountd",
329343
TRANSPORT_UDP | TRANSPORT_UDP6 |

servers/nfsd/mountd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ struct mountd_client {
4242

4343
struct mountd_state {
4444
struct tevent_context *tevent;
45-
struct rpc_context *rpc;
4645
struct mountd_export *exports;
4746
struct mountd_client *clients;
47+
pthread_mutex_t clients_mutex;
4848
};
4949

5050
struct mountd_state *mountd_init(TALLOC_CTX *ctx, struct tevent_context *tevent);

0 commit comments

Comments
 (0)