Author: spouliot
Date: 2005-04-21 11:03:59 -0400 (Thu, 21 Apr 2005)
New Revision: 43405

Added:
   trunk/mono/mono/tests/cas/threads/
   trunk/mono/mono/tests/cas/threads/ChangeLog
   trunk/mono/mono/tests/cas/threads/Makefile
   trunk/mono/mono/tests/cas/threads/README
   trunk/mono/mono/tests/cas/threads/thread1.cs
   trunk/mono/mono/tests/cas/threads/thread2.cs
   trunk/mono/mono/tests/cas/threads/thread3.cs
   trunk/mono/mono/tests/cas/threads/timer1.cs
   trunk/mono/mono/tests/cas/threads/timer2.cs
Log:
2005-04-21  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * ChangeLog: New. Track changes in the tests.
        * Makefile: New. Build and execute tests.
        * README: Informations about the tests.
        * thread1.cs: New. Deny unmanaged code before creating the thread 
        object.
        * thread2.cs: New. Deny unmanaged code after creating the thread 
        object but before calling Start.
        * thread3.cs: New. Deny unmanaged code after creating the thread 
        object and calling Start.
        * timer1.cs: New. Use System.Threading.Timer (Thread.Start) to test 
        stack propagation.
        * timer2.cs: New. Use System.Timers.Timer (ThreadPool.
        QueueUserWorkItem) to test stack propagation.


Added: trunk/mono/mono/tests/cas/threads/ChangeLog
===================================================================
--- trunk/mono/mono/tests/cas/threads/ChangeLog 2005-04-21 14:17:03 UTC (rev 
43404)
+++ trunk/mono/mono/tests/cas/threads/ChangeLog 2005-04-21 15:03:59 UTC (rev 
43405)
@@ -0,0 +1,15 @@
+2005-04-21  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * ChangeLog: New. Track changes in the tests.
+       * Makefile: New. Build and execute tests.
+       * README: Informations about the tests.
+       * thread1.cs: New. Deny unmanaged code before creating the thread 
+       object.
+       * thread2.cs: New. Deny unmanaged code after creating the thread 
+       object but before calling Start.
+       * thread3.cs: New. Deny unmanaged code after creating the thread 
+       object and calling Start.
+       * timer1.cs: New. Use System.Threading.Timer (Thread.Start) to test 
+       stack propagation.
+       * timer2.cs: New. Use System.Timers.Timer (ThreadPool.
+       QueueUserWorkItem) to test stack propagation.

Added: trunk/mono/mono/tests/cas/threads/Makefile
===================================================================
--- trunk/mono/mono/tests/cas/threads/Makefile  2005-04-21 14:17:03 UTC (rev 
43404)
+++ trunk/mono/mono/tests/cas/threads/Makefile  2005-04-21 15:03:59 UTC (rev 
43405)
@@ -0,0 +1,65 @@
+RUNTIME = mono --debug --security
+CSCOMPILE = mcs -debug
+PROFILE = net_1_1
+
+all:   thread1.exe thread2.exe thread3.exe \
+       timer1.exe timer2.exe
+
+aot:   thread1.exe.so thread2.exe.so thread3.exe.so \
+       timer1.exe.so timer2.exe.so
+
+FULLTRUST_TEST_FILES = thread1 thread2 thread3 \
+       timer1 timer2
+
+UNHANDLED_TEST_FILES = 
+
+run: all
+       @for i in $(FULLTRUST_TEST_FILES); do   \
+               $(RUNTIME) $$i.exe x;   \
+       done;
+       @for i in $(INTERNET_TEST_FILES); do    \
+               MONO_CAS_ZONE=Internet $(RUNTIME) $$i.exe;      \
+       done;
+
+test: all
+       @failed=0; \
+       passed=0; \
+       for i in $(FULLTRUST_TEST_FILES); do    \
+               $(RUNTIME) $$i.exe > /dev/null; \
+               if [ "$$?" = "0" ]; then        \
+                       echo -e "fulltrust-$$i\tpass";  \
+                       passed=`expr $${passed} + 1`; \
+               else    \
+                       echo -e "fulltrust-$$i\tFAIL ($$?)";    \
+                       failed=`expr $${failed} + 1`; \
+                       failed_tests="$${failed_tests} fulltrust-$$i"; \
+               fi;     \
+       done;   \
+       for i in $(UNHANDLED_TEST_FILES); do    \
+               $(RUNTIME) $$i.exe > /dev/null; \
+               if [ "$$?" = "0" ]; then        \
+                       echo -e "unhandled-$$i\tFAIL ($$?)";    \
+                       failed=`expr $${failed} + 1`; \
+                       failed_tests="$${failed_tests} unhandled-$$i"; \
+               else    \
+                       echo -e "unhandled-$$i\tpass";  \
+                       passed=`expr $${passed} + 1`; \
+               fi;     \
+       done;   \
+       echo -e "\n$${passed} test(s) passed. $${failed} test(s) failed."; \
+       if [ "$${failed}" != "0" ]; then        \
+               echo -e "Failed tests are:";    \
+               for i in $${failed_tests};      \
+                       do echo -e "\t$${i}";   \
+               done;   \
+               exit 1; \
+       fi
+
+clean:
+       rm -f *.exe* *.dll* *.snk
+
+%.exe: %.cs
+       $(CSCOMPILE) $^ /out:$@
+
+%.exe.so: %.exe
+       $(RUNTIME) --aot $^

Added: trunk/mono/mono/tests/cas/threads/README
===================================================================
--- trunk/mono/mono/tests/cas/threads/README    2005-04-21 14:17:03 UTC (rev 
43404)
+++ trunk/mono/mono/tests/cas/threads/README    2005-04-21 15:03:59 UTC (rev 
43405)
@@ -0,0 +1,19 @@
+The basic idea of the tests are to try to exit the running process by calling
+Environment.Exit(int). The entry point, Main, denies UnmanagedCode from being
+executed. UnmanagedCode is required to call Environment.Exit(int). Then we try
+to call Environment.Exit(int) from other threads which "should" have inherited
+the restriction from the "main" (i.e. original) thread.
+
+This security stack "inheritance" is called "stack propagation".
+
+
+* thread1.cs   Deny unmanaged code before creating the thread object.
+* thread2.cs   Deny unmanaged code after creating the thread object but 
+               before calling Start.
+* thread3.cs   Deny unmanaged code after creating the thread object and 
+               calling Start. 
+
+* timer1.cs:   Use System.Threading.Timer (Thread.Start) to test stack 
+               propagation.
+* timer2.cs:   Use System.Timers.Timer (ThreadPool.QueueUserWorkItem) to test
+               stack propagation.

Added: trunk/mono/mono/tests/cas/threads/thread1.cs
===================================================================
--- trunk/mono/mono/tests/cas/threads/thread1.cs        2005-04-21 14:17:03 UTC 
(rev 43404)
+++ trunk/mono/mono/tests/cas/threads/thread1.cs        2005-04-21 15:03:59 UTC 
(rev 43405)
@@ -0,0 +1,34 @@
+using System;
+using System.Security;
+using System.Security.Permissions;
+using System.Threading;
+
+class Program {
+
+       static void ThreadProc ()
+       {
+               if (debug)
+                       Console.WriteLine (Environment.StackTrace);
+
+               try {
+                       Environment.Exit (1);
+               }
+               catch (SecurityException se) {
+                       if (debug)
+                               Console.WriteLine ("EXPECTED SecurityException 
{0}", se);
+               }
+       }
+
+       static bool debug;
+
+       // this Deny will prevent Environment.Exit from working
+       [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+       static int Main (string[] args)
+       {
+               debug = (args.Length > 0);
+               Thread t = new Thread (new ThreadStart (ThreadProc));
+               t.Start ();
+               Thread.Sleep (1000);
+               return 0;
+       }
+}

Added: trunk/mono/mono/tests/cas/threads/thread2.cs
===================================================================
--- trunk/mono/mono/tests/cas/threads/thread2.cs        2005-04-21 14:17:03 UTC 
(rev 43404)
+++ trunk/mono/mono/tests/cas/threads/thread2.cs        2005-04-21 15:03:59 UTC 
(rev 43405)
@@ -0,0 +1,39 @@
+using System;
+using System.Security;
+using System.Security.Permissions;
+using System.Threading;
+
+class Program {
+
+       static void ThreadProc ()
+       {
+               if (debug)
+                       Console.WriteLine (Environment.StackTrace);
+
+               try {
+                       Environment.Exit (1);
+               }
+               catch (SecurityException se) {
+                       if (debug)
+                               Console.WriteLine ("EXPECTED SecurityException 
{0}", se);
+               }
+       }
+
+       static bool debug;
+
+       // this Deny will prevent Environment.Exit from working
+       [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+       static void Start (Thread t)
+       {
+               t.Start ();
+       }
+
+       static int Main (string[] args)
+       {
+               debug = (args.Length > 0);
+               Thread t = new Thread (new ThreadStart (ThreadProc));
+               Start (t);
+               Thread.Sleep (1000);
+               return 0;
+       }
+}

Added: trunk/mono/mono/tests/cas/threads/thread3.cs
===================================================================
--- trunk/mono/mono/tests/cas/threads/thread3.cs        2005-04-21 14:17:03 UTC 
(rev 43404)
+++ trunk/mono/mono/tests/cas/threads/thread3.cs        2005-04-21 15:03:59 UTC 
(rev 43405)
@@ -0,0 +1,43 @@
+using System;
+using System.Security;
+using System.Security.Permissions;
+using System.Threading;
+
+class Program {
+
+       static void ThreadProc ()
+       {
+               if (debug)
+                       Console.WriteLine (Environment.StackTrace);
+
+               Thread.Sleep (1000);
+               try {
+                       // this will work
+                       Environment.Exit (0);
+                       Console.WriteLine ("UNEXPECTED execution");
+               }
+               catch (SecurityException se) {
+                       Console.WriteLine ("UNEXPECTED SecurityException {0}", 
se);
+               }
+       }
+
+       static bool debug;
+
+       // this Deny _WONT_ prevent Environment.Exit from working
+       // even if the Deny is executed prior to the call
+       [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+       static int End ()
+       {
+               Thread.Sleep (2000);
+               return 1;
+       }
+
+       static int Main (string[] args)
+       {
+               debug = (args.Length > 0);
+               Thread t = new Thread (new ThreadStart (ThreadProc));
+               t.Start ();
+
+               return End ();
+       }
+}

Added: trunk/mono/mono/tests/cas/threads/timer1.cs
===================================================================
--- trunk/mono/mono/tests/cas/threads/timer1.cs 2005-04-21 14:17:03 UTC (rev 
43404)
+++ trunk/mono/mono/tests/cas/threads/timer1.cs 2005-04-21 15:03:59 UTC (rev 
43405)
@@ -0,0 +1,44 @@
+using System;
+using System.Security;
+using System.Security.Permissions;
+using System.Threading;
+
+class Program {
+
+       static void ShowStackTrace (object o)
+       {
+               if (debug)
+                       Console.WriteLine ("{0}: {1}", counter, 
Environment.StackTrace);
+
+               try {
+                       Environment.Exit (1);
+               }
+               catch (SecurityException se) {
+                       if (debug)
+                               Console.WriteLine ("EXPECTED SecurityException 
{0}", se);
+               }
+
+               if (counter++ > 5) {
+                       t.Dispose ();
+               }
+       }
+
+       static bool debug;
+       static int counter = 0;
+       static Timer t;
+
+       // this Deny will prevent Environment.Exit from working
+       [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+       static int Main (string[] args)
+       {
+               debug = (args.Length > 0);
+
+               ShowStackTrace (null);
+
+               TimerCallback cb = new TimerCallback (ShowStackTrace);
+               t = new Timer (cb, null, 500, 1000);
+
+               Thread.Sleep (5000);
+               return 0;
+       }
+}

Added: trunk/mono/mono/tests/cas/threads/timer2.cs
===================================================================
--- trunk/mono/mono/tests/cas/threads/timer2.cs 2005-04-21 14:17:03 UTC (rev 
43404)
+++ trunk/mono/mono/tests/cas/threads/timer2.cs 2005-04-21 15:03:59 UTC (rev 
43405)
@@ -0,0 +1,55 @@
+using System;
+using System.Security;
+using System.Security.Permissions;
+using System.Timers;
+
+class Program {
+
+       static void ShowStackTrace (object o, ElapsedEventArgs e)
+       {
+               if (debug)
+                       Console.WriteLine ("{0}: {1}", counter, 
Environment.StackTrace);
+
+               try {
+                       Environment.Exit (1);
+               }
+               catch (SecurityException se) {
+                       if (debug)
+                               Console.WriteLine ("EXPECTED SecurityException 
{0}", se);
+               }
+
+               if (counter++ > 5) {
+                       t.AutoReset = false;
+                       t.Enabled = false;
+               }
+       }
+
+       static bool debug;
+       static int counter = 0;
+       static Timer t;
+
+       // this Deny will prevent Environment.Exit from working
+       [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+       static int Main (string[] args)
+       {
+               debug = (args.Length > 0);
+               if (debug) {
+                       SecurityManager.SecurityEnabled = (args [0] != "off");
+               }
+
+               if (SecurityManager.SecurityEnabled) {
+                       Console.WriteLine ("SecurityManager.SecurityEnabled: 
true");
+                       ShowStackTrace (null, null);
+               } else {
+                       Console.WriteLine ("SecurityManager.SecurityEnabled: 
false");
+               }
+
+               t = new Timer (500);
+               t.Elapsed += new ElapsedEventHandler (ShowStackTrace);
+               t.AutoReset = true;
+               t.Enabled = true;
+               
+               System.Threading.Thread.Sleep (5000);
+               return 0;
+       }
+}

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to