]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
map_anon: define a macro if it is possible for noinherit to fail.
authorNick Mathewson <nickm@torproject.org>
Wed, 6 Mar 2019 16:03:26 +0000 (11:03 -0500)
committerNick Mathewson <nickm@torproject.org>
Thu, 4 Apr 2019 16:56:52 +0000 (12:56 -0400)
src/lib/malloc/map_anon.h
src/test/test_util.c

index edd750082126965c2e9be8cb5a405b60dd1c2441..89fb9da0f054e26a32677a19d59be2b5aa1b647c 100644 (file)
  * the child process. */
 #define INHERIT_ZERO 2
 
+/* Here we define the NOINHERIT_CAN_FAIL macro if and only if
+ * it's possible that ANONMAP_NOINHERIT might yield inheritable memory.
+ */
+#ifdef _WIN32
+/* Windows can't fork, so NOINHERIT is never needed. */
+#elif defined(HAVE_MINHERIT)
+/* minherit() will always have a working MAP_INHERIT_NONE or MAP_INHERIT_ZERO.
+ * NOINHERIT should always work.
+ */
+#elif defined(HAVE_MADVISE)
+/* madvise() sometimes has neither MADV_DONTFORK and MADV_WIPEONFORK.
+ * We need to be ready for the possibility it failed.
+ *
+ * (Linux added DONTFORK in 2.6.16 and WIPEONFORK in 4.14. If we someday
+ * require 2.6.16 or later, we can assume that DONTFORK will work.)
+ */
+#define NOINHERIT_CAN_FAIL
+#else
+#define NOINHERIT_CAN_FAIL
+#endif
+
 void *tor_mmap_anonymous(size_t sz, unsigned flags,
                          unsigned *inherit_result_out);
 void tor_munmap_anonymous(void *mapping, size_t sz);
index 039fc435cec0a6be8465a2e87581a86b74291fe2..f6085fdb90aefc9ea3c7dd07399d007b7e5c6991 100644 (file)
@@ -6224,11 +6224,17 @@ test_util_map_anon_nofork(void *arg)
   int ws;
   waitpid(child, &ws, 0);
 
+#ifndef NOINHERIT_CAN_FAIL
+  /* Only if NOINHERIT_CAN_FAIL should it be possible for us to get
+   * INHERIT_KEEP behavior in this case. */
+  tt_assert(inherit, OP_NE, INHERIT_KEEP);
+#else
   if (inherit == INHERIT_KEEP) {
     /* Call this test "skipped", not "passed", since noinherit wasn't
      * implemented. */
     tt_skip();
   }
+#endif
 
  done:
   tor_munmap_anonymous(ptr, sz);