talloc: Test that talloc magic differs between processes. talloc-2.1.4
authorAdrian Cochrane <adrianc@catalyst.net.nz>
Fri, 4 Sep 2015 00:59:57 +0000 (12:59 +1200)
committerJeremy Allison <jra@samba.org>
Fri, 9 Oct 2015 21:15:06 +0000 (23:15 +0200)
Signed-off-by: Adrian Cochrane <adrianc@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Autobuild-User(master): Jeremy Allison <jra@samba.org>
Autobuild-Date(master): Fri Oct  9 23:15:06 CEST 2015 on sn-devel-104

lib/talloc/test_magic_differs.sh [new file with mode: 0755]
lib/talloc/test_magic_differs_helper.c [new file with mode: 0644]
lib/talloc/wscript

diff --git a/lib/talloc/test_magic_differs.sh b/lib/talloc/test_magic_differs.sh
new file mode 100755 (executable)
index 0000000..0f765f0
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/sh
+# This test ensures that two different talloc processes do not use the same
+# magic value to lessen the opportunity for transferrable attacks.
+
+echo "test: magic differs"
+
+if [
+       "`./talloc_test_magic_differs_helper`" != "`./talloc_test_magic_differs_helper`"
+]; then
+       echo "failure: magic remained the same between executions"
+       exit 1
+fi
+
+echo "success: magic differs"
diff --git a/lib/talloc/test_magic_differs_helper.c b/lib/talloc/test_magic_differs_helper.c
new file mode 100644 (file)
index 0000000..6798827
--- /dev/null
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include "talloc.h"
+
+/*
+ * This program is called by a testing shell script in order to ensure that
+ * if the library is loaded into different processes it uses different magic
+ * values in order to thwart security attacks.
+ */
+int main(int argc, char *argv[]) {
+       printf("%i\n", talloc_test_get_magic());
+       return 0;
+}
index 19294d9b9b41ceef4cdfe341482b070b2cdffe24..9cedbbf807026f18d0a07afa3d5ef1a003d2e58e 100644 (file)
@@ -100,6 +100,10 @@ def build(bld):
                          testsuite_deps,
                          install=False)
 
+        bld.SAMBA_BINARY('talloc_test_magic_differs_helper',
+                         'test_magic_differs_helper.c',
+                         'talloc', install=False)
+
     else:
         private_library = True
 
@@ -154,9 +158,14 @@ def test(ctx):
     cmd = os.path.join(Utils.g_module.blddir, 'talloc_testsuite')
     ret = samba_utils.RUN_COMMAND(cmd)
     print("testsuite returned %d" % ret)
+    magic_cmd = os.path.join(srcdir, 'lib', 'talloc',
+                             'test_magic_differs.sh')
+
+    magic_ret = samba_utils.RUN_COMMAND(magic_cmd)
+    print("magic differs test returned %d" % magic_ret)
     pyret = samba_utils.RUN_PYTHON_TESTS(['test_pytalloc.py'])
     print("python testsuite returned %d" % pyret)
-    sys.exit(ret or pyret)
+    sys.exit(ret or magic_ret or pyret)
 
 def dist():
     '''makes a tarball for distribution'''