summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2014-12-12 17:57:22 +0100
committerMichal Schmidt <mschmidt@redhat.com>2014-12-13 00:46:16 +0100
commitfad5a6c66e73d3df20846906121d52159e1f6bf4 (patch)
tree205cd89c4ee6a9185cbff630afe1dd3238056940 /src
parentfc86aa0ed204922dcafa85353cb10e1aa7d91a76 (diff)
journal: add debug mode for mmap-cache (--enable-debug=mmap-cache)
This is useful for exposing unsafe access to mmapped objects after the context that they were mapped in was already moved. For example: journal_file_move_to_object(f1, OBJECT_DATA, p1, &o1); journal_file_move_to_object(f2, OBJECT_DATA, p2, &o2); t = o1->object.type; /* this usually works, but is unsafe */
Diffstat (limited to 'src')
-rw-r--r--src/journal/mmap-cache.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c
index b7db6f1da5..c57c1623c5 100644
--- a/src/journal/mmap-cache.c
+++ b/src/journal/mmap-cache.c
@@ -83,7 +83,13 @@ struct MMapCache {
};
#define WINDOWS_MIN 64
-#define WINDOW_SIZE (8ULL*1024ULL*1024ULL)
+
+#ifdef ENABLE_DEBUG_MMAP_CACHE
+/* Tiny windows increase mmap activity and the chance of exposing unsafe use. */
+# define WINDOW_SIZE (page_size())
+#else
+# define WINDOW_SIZE (8ULL*1024ULL*1024ULL)
+#endif
MMapCache* mmap_cache_new(void) {
MMapCache *m;
@@ -187,11 +193,17 @@ static void context_detach_window(Context *c) {
if (!w->contexts && w->keep_always == 0) {
/* Not used anymore? */
+#ifdef ENABLE_DEBUG_MMAP_CACHE
+ /* Unmap unused windows immediately to expose use-after-unmap
+ * by SIGSEGV. */
+ window_free(w);
+#else
LIST_PREPEND(unused, c->cache->unused, w);
if (!c->cache->last_unused)
c->cache->last_unused = w;
w->in_unused = true;
+#endif
}
}