Fix taint-checking on OpenBSD
authorJeremy Harris <jgh146exb@wizmail.org>
Mon, 29 Jul 2019 14:48:05 +0000 (15:48 +0100)
committerJeremy Harris <jgh146exb@wizmail.org>
Mon, 29 Jul 2019 14:48:05 +0000 (15:48 +0100)
src/OS/Makefile-OpenBSD
src/src/functions.h
src/src/mytypes.h
src/src/readconf.c
src/src/store.c
src/src/transports/smtp.c
src/src/verify.c

index 5a894789cc3192f11cf586b8aa494abbe498c70c..2b37a737391aa8bf9f283bfdb1bbec633e3e475e 100644 (file)
@@ -5,6 +5,7 @@ CHGRP_COMMAND=/usr/sbin/chgrp
 CHMOD_COMMAND=/bin/chmod
 
 CFLAGS=-O2 -Wall -Wno-parentheses -Wno-self-assign -Wno-logical-op-parentheses
+CFLAGS += -DTAINT_CHECK_SLOW
 
 LIBS=-lm
 
index 0602789597788209395d5d53a7b548429ce6d88b..6347b231fc6b55fba7d6bc2fede150e7a00b94b2 100644 (file)
@@ -285,6 +285,7 @@ extern int     ip_unixsocket(const uschar *, uschar **);
 extern int     ip_streamsocket(const uschar *, uschar **, int);
 
 extern int     ipv6_nmtoa(int *, uschar *);
+extern BOOL    is_tainted_fn(const void *);
 
 extern uschar *local_part_quote(uschar *);
 extern int     log_create(uschar *);
index a68dc281714903c62d1ba29c3b3b2e1a420c69fd..f7551336c5e7c7ba3de101a75aa43074e6e8c167 100644 (file)
@@ -136,6 +136,10 @@ is_tainted(const void * p)
 {
 #if defined(COMPILE_UTILITY) || defined(MACRO_PREDEF)
 return FALSE;
+
+#elif defined(TAINT_CHECK_SLOW)
+return is_tainted_fn(p);
+
 #else
 extern void * tainted_base, * tainted_top;
 return p >= tainted_base && p < tainted_top;
index 6ed2ea409dad3cb86546f1ff5b37cbb2725f4ba2..d13d051420cd0161c149bd38c6b061a7995f73cf 100644 (file)
@@ -3326,19 +3326,19 @@ if (f.trusted_config && Ustrcmp(filename, US"/dev/null"))
 
     log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Exim configuration file %s has the "
       "wrong owner, group, or mode", big_buffer);
-  }
 
-/* Do a dummy store-allocation of a size related to the (toplevel) file size.
-This assumes we will need this much storage to handle all the allocations
-during startup; it won't help when .include is being used.  When it does, it
-will cut down on the number of store blocks (and malloc calls, and sbrk
-syscalls).  It also assume we're on the relevant pool. */
+  /* Do a dummy store-allocation of a size related to the (toplevel) file size.
+  This assumes we will need this much storage to handle all the allocations
+  during startup; it won't help when .include is being used.  When it does, it
+  will cut down on the number of store blocks (and malloc calls, and sbrk
+  syscalls).  It also assume we're on the relevant pool. */
 
-if (statbuf.st_size > 8192)
-  {
-  rmark r = store_mark();
-  void * dummy = store_get((int)statbuf.st_size, FALSE);
-  store_reset(r);
+  if (statbuf.st_size > 8192)
+    {
+    rmark r = store_mark();
+    void * dummy = store_get((int)statbuf.st_size, FALSE);
+    store_reset(r);
+    }
   }
 
 /* Process the main configuration settings. They all begin with a lower case
index b7cf4cdee3798503f6d60ec7d564ceaa338c5097..045f27f8e1218bf7ece27244ebe622f740333535 100644 (file)
@@ -159,6 +159,35 @@ static void   internal_store_free(void *, const char *, int linenumber);
 
 /******************************************************************************/
 
+/* Slower version check, for use when platform intermixes malloc and mmap area
+addresses. */
+
+BOOL
+is_tainted_fn(const void * p)
+{
+storeblock * b;
+int pool;
+
+for (pool = 0; pool < nelem(chainbase); pool++)
+  if ((b = current_block[pool]))
+    {
+    char * bc = CS b + ALIGNED_SIZEOF_STOREBLOCK;
+    if (CS p >= bc && CS p <= bc + b->length) goto hit;
+    }
+
+for (pool = 0; pool < nelem(chainbase); pool++)
+  for (b = chainbase[pool]; b; b = b->next)
+    {
+    char * bc = CS b + ALIGNED_SIZEOF_STOREBLOCK;
+    if (CS p >= bc && CS p <= bc + b->length) goto hit;
+    }
+return FALSE;
+
+hit:
+return pool >= POOL_TAINT_BASE;
+}
+
+
 void
 die_tainted(const uschar * msg, const uschar * func, int line)
 {
index 617a55a1691d9ada34cacecf925c72d29d1db487..03243f3fc7dd35258db4ef6ee323262a2a8eea7e 100644 (file)
@@ -8,6 +8,10 @@
 #include "../exim.h"
 #include "smtp.h"
 
+#if defined(SUPPORT_DANE) && defined(DISABLE_TLS)
+# error TLS is required for DANE
+#endif
+
 
 /* Options specific to the smtp transport. This transport also supports LMTP
 over TCP/IP. The options must be in alphabetic order (note that "_" comes
index a1276068b0ab3de5279474db34a3006d36c01585..4422b4ad109bed885ca8063ab25c4db237f289b9 100644 (file)
@@ -2349,7 +2349,7 @@ for (header_line * h = header_list; h; h = h->next)
     if ((*s < 33) || (*s > 126))
       {
       *msgptr = string_sprintf("Invalid character in header \"%.*s\" found",
-                            colon - h->text, h->text);
+                            (int)(colon - h->text), h->text);
       return FAIL;
       }
   }