From 63de4b375cfb02b6039c8acda3a0152132268158 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 21 Nov 2016 20:56:55 +0100 Subject: [PATCH 1/3] tdb: NULL out tdb->mutexes in tdb_mutex_munmap BUG: https://bugzilla.samba.org/show_bug.cgi?id=12455 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison (cherry picked from commit a2843cfd4dca32ccb9e97f20a9119f131db3b9d1) --- lib/tdb/common/mutex.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/tdb/common/mutex.c b/lib/tdb/common/mutex.c index 280dec1..3420d21 100644 --- a/lib/tdb/common/mutex.c +++ b/lib/tdb/common/mutex.c @@ -636,13 +636,20 @@ int tdb_mutex_mmap(struct tdb_context *tdb) int tdb_mutex_munmap(struct tdb_context *tdb) { size_t len; + int ret; len = tdb_mutex_size(tdb); if (len == 0) { return 0; } - return munmap(tdb->mutexes, len); + ret = munmap(tdb->mutexes, len); + if (ret == -1) { + return -1; + } + tdb->mutexes = NULL; + + return 0; } static bool tdb_mutex_locking_cached; -- 2.8.0.rc3.226.g39d4020 From cb407a7adff14cb92fb0c27e74a0e7c9dc327fb4 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 21 Nov 2016 20:58:08 +0100 Subject: [PATCH 2/3] tdb: Only mmap the mutex area if not already mmap'ed BUG: https://bugzilla.samba.org/show_bug.cgi?id=12455 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison (cherry picked from commit 5ce95abf37d5646dd5a6ed9acc018f0ab5d1023c) --- lib/tdb/common/mutex.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/tdb/common/mutex.c b/lib/tdb/common/mutex.c index 3420d21..3df9f5b 100644 --- a/lib/tdb/common/mutex.c +++ b/lib/tdb/common/mutex.c @@ -623,6 +623,10 @@ int tdb_mutex_mmap(struct tdb_context *tdb) return 0; } + if (tdb->mutexes != NULL) { + return 0; + } + ptr = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FILE, tdb->fd, 0); if (ptr == MAP_FAILED) { -- 2.8.0.rc3.226.g39d4020 From 4f58b723ed8b579145aba8148107aba5723e0473 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 21 Nov 2016 21:00:01 +0100 Subject: [PATCH 3/3] tdb: Fix mutexes on FreeBSD susv4 on mmap has the following snippet: > The state of synchronization objects such as mutexes, semaphores, > barriers, and conditional variables placed in shared memory mapped > with MAP_SHARED becomes undefined when the last region in any process > containing the synchronization object is unmapped. This means we can't keep the mutex mmap area unmapped at any point in time. BUG: https://bugzilla.samba.org/show_bug.cgi?id=12455 Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison Autobuild-User(master): Jeremy Allison Autobuild-Date(master): Tue Nov 29 23:59:52 CET 2016 on sn-devel-144 (cherry picked from commit 275d9fc7d943048c5e580e656b6ad85b8fc6cc14) --- lib/tdb/common/mutex.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/tdb/common/mutex.c b/lib/tdb/common/mutex.c index 3df9f5b..cac3916 100644 --- a/lib/tdb/common/mutex.c +++ b/lib/tdb/common/mutex.c @@ -603,12 +603,13 @@ int tdb_mutex_init(struct tdb_context *tdb) fail: pthread_mutexattr_destroy(&ma); fail_munmap: - tdb_mutex_munmap(tdb); if (ret == 0) { return 0; } + tdb_mutex_munmap(tdb); + errno = ret; return -1; } -- 2.8.0.rc3.226.g39d4020