Author: spouliot
Date: 2005-03-10 20:17:37 -0500 (Thu, 10 Mar 2005)
New Revision: 41672
Added:
trunk/mono/mono/tests/cas/demand/
trunk/mono/mono/tests/cas/demand/ChangeLog
trunk/mono/mono/tests/cas/demand/Makefile
trunk/mono/mono/tests/cas/demand/README
trunk/mono/mono/tests/cas/demand/pinvoke1.cs
trunk/mono/mono/tests/cas/demand/pinvoke2.cs
trunk/mono/mono/tests/cas/demand/pinvoke3.cs
trunk/mono/mono/tests/cas/demand/sucs1.cs
trunk/mono/mono/tests/cas/demand/sucs2.cs
trunk/mono/mono/tests/cas/demand/sucs3.cs
trunk/mono/mono/tests/cas/demand/sucs4.cs
Log:
2005-03-10 Sebastien Pouliot <[EMAIL PROTECTED]>
* pinvoke1-3.cs: New. Tests that P/Invoking unmanaged methods provoke
a stack walk (Demand) for SecurityPermissionFlag.UnmanagedCode.
* sucs1-4.cs: New. Tests that [SuppressUnmanagedCodeSecurity] removes
the stack walk when present on either the p/invoked definition or on
it's class.
* Makefile: New. Build/execute new tests.
* README: New. Instruction and details about the tests.
Added: trunk/mono/mono/tests/cas/demand/ChangeLog
===================================================================
--- trunk/mono/mono/tests/cas/demand/ChangeLog 2005-03-10 23:30:03 UTC (rev
41671)
+++ trunk/mono/mono/tests/cas/demand/ChangeLog 2005-03-11 01:17:37 UTC (rev
41672)
@@ -0,0 +1,9 @@
+2005-03-10 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * pinvoke1-3.cs: New. Tests that P/Invoking unmanaged methods provoke
+ a stack walk (Demand) for SecurityPermissionFlag.UnmanagedCode.
+ * sucs1-4.cs: New. Tests that [SuppressUnmanagedCodeSecurity] removes
+ the stack walk when present on either the p/invoked definition or on
+ it's class.
+ * Makefile: New. Build/execute new tests.
+ * README: New. Instruction and details about the tests.
Added: trunk/mono/mono/tests/cas/demand/Makefile
===================================================================
--- trunk/mono/mono/tests/cas/demand/Makefile 2005-03-10 23:30:03 UTC (rev
41671)
+++ trunk/mono/mono/tests/cas/demand/Makefile 2005-03-11 01:17:37 UTC (rev
41672)
@@ -0,0 +1,65 @@
+RUNTIME = mono --debug --security
+CSCOMPILE = mcs --debug
+PROFILE = net_1_1
+
+all: pinvoke1.exe pinvoke2.exe pinvoke3.exe \
+ sucs1.exe sucs2.exe sucs3.exe sucs4.exe
+
+aot: pinvoke1.exe.so pinvoke2.exe.so pinvoke3.exe.so \
+ sucs1.exe.so sucs2.exe.so sucs3.exe.so sucs4.exe.so
+
+FULLTRUST_TEST_FILES = pinvoke1 pinvoke2 pinvoke3 \
+ sucs1 sucs2 sucs3 sucs4
+
+UNHANDLED_TEST_FILES =
+
+run: all
+ @for i in $(FULLTRUST_TEST_FILES); do \
+ $(RUNTIME) $$i.exe; \
+ 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/demand/README
===================================================================
--- trunk/mono/mono/tests/cas/demand/README 2005-03-10 23:30:03 UTC (rev
41671)
+++ trunk/mono/mono/tests/cas/demand/README 2005-03-11 01:17:37 UTC (rev
41672)
@@ -0,0 +1,29 @@
+* Demand
+
+** P/Invoke
+
+pinvoke1.cs Successful p/invoke
+pinvoke2.cs p/invoke denied (Deny) at class level
+pinvoke3.cs p/invoke denied (Deny) at method level
+
+Notes
+- We do not try to refuse UnmanagedCode (RequestRefused) at assembly level
+ because this would fail at the LinkDemand level (which is tested elsewhere)
+- With Mono runtime the native function getuid is called in libc
+- With MS runtime the native function GetTickCount is called in kernel32.dll
+
+
+** [SuppressUnmanagedCodeSecurity] a.k.a. SUCS
+
+Test the automatic demand generated for P/Invoking when
+[SuppressUnmanagedCodeSecurity] is being used to suppress it.
+
+sucs1.cs Call native code without any [SUCS] attribute (fails).
+sucs2.cs Call native code with a [SUCS] attribute at class level.
+sucs3.cs Call native code with a [SUCS] attribute at method level.
+sucs4.cs Call native code with [SUCS] attributes at both class and
+ method level.
+
+Notes
+- With Mono runtime the native function getuid is called in libc
+- With MS runtime the native function GetTickCount is called in kernel32.dll
Added: trunk/mono/mono/tests/cas/demand/pinvoke1.cs
===================================================================
--- trunk/mono/mono/tests/cas/demand/pinvoke1.cs 2005-03-10 23:30:03 UTC
(rev 41671)
+++ trunk/mono/mono/tests/cas/demand/pinvoke1.cs 2005-03-11 01:17:37 UTC
(rev 41672)
@@ -0,0 +1,43 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Security;
+
+public class Program {
+
+ // for Mono
+ [DllImport ("libc", SetLastError=true)]
+ public static extern uint getuid ();
+
+ // for Microsoft
+ [DllImport ("kernel32.dll", SetLastError=true)]
+ public static extern uint GetTickCount ();
+
+ static bool RunningOnMono ()
+ {
+ bool mono = (Type.GetType ("Mono.Math.BigInteger") != null);
+ Console.WriteLine ("Running on {0} runtime...", mono ? "Mono" :
"Microsoft");
+ return mono;
+ }
+
+ static int Test ()
+ {
+ try {
+ uint u = (RunningOnMono ()) ? getuid () : GetTickCount
();
+ Console.WriteLine ("*0* P/Invoke: {0}", u);
+ return 0;
+ }
+ catch (SecurityException se) {
+ Console.WriteLine ("*1* Unexpected
SecurityException\n{0}", se);
+ return 1;
+ }
+ catch (Exception e) {
+ Console.WriteLine ("*2* Unexpected exception\n{0}", e);
+ return 2;
+ }
+ }
+
+ static int Main ()
+ {
+ return Test ();
+ }
+}
Added: trunk/mono/mono/tests/cas/demand/pinvoke2.cs
===================================================================
--- trunk/mono/mono/tests/cas/demand/pinvoke2.cs 2005-03-10 23:30:03 UTC
(rev 41671)
+++ trunk/mono/mono/tests/cas/demand/pinvoke2.cs 2005-03-11 01:17:37 UTC
(rev 41672)
@@ -0,0 +1,46 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Security.Permissions;
+
+[SecurityPermission (SecurityAction.Deny, UnmanagedCode=true)]
+public class Program {
+
+ // for Mono
+ [DllImport ("libc", SetLastError=true)]
+ public static extern uint getuid ();
+
+ // for Microsoft
+ [DllImport ("kernel32.dll", SetLastError=true)]
+ public static extern uint GetTickCount ();
+
+ static bool RunningOnMono ()
+ {
+ bool mono = (Type.GetType ("Mono.Math.BigInteger") != null);
+ Console.WriteLine ("Running on {0} runtime...", mono ? "Mono" :
"Microsoft");
+ return mono;
+ }
+
+ static int Test ()
+ {
+ try {
+ uint u = (RunningOnMono ()) ? getuid () : GetTickCount
();
+ Console.WriteLine ("*1* P/Invoke: {0}", u);
+ return 1;
+ }
+ catch (SecurityException se) {
+ Console.WriteLine ("*0* Expected
SecurityException\n{0}", se);
+ return 0;
+ }
+ catch (Exception e) {
+ Console.WriteLine ("*2* Unexpected exception\n{0}", e);
+ return 2;
+ }
+ }
+
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode=true)]
+ static int Main ()
+ {
+ return Test ();
+ }
+}
Added: trunk/mono/mono/tests/cas/demand/pinvoke3.cs
===================================================================
--- trunk/mono/mono/tests/cas/demand/pinvoke3.cs 2005-03-10 23:30:03 UTC
(rev 41671)
+++ trunk/mono/mono/tests/cas/demand/pinvoke3.cs 2005-03-11 01:17:37 UTC
(rev 41672)
@@ -0,0 +1,45 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Security.Permissions;
+
+public class Program {
+
+ // for Mono
+ [DllImport ("libc", SetLastError=true)]
+ public static extern uint getuid ();
+
+ // for Microsoft
+ [DllImport ("kernel32.dll", SetLastError=true)]
+ public static extern uint GetTickCount ();
+
+ static bool RunningOnMono ()
+ {
+ bool mono = (Type.GetType ("Mono.Math.BigInteger") != null);
+ Console.WriteLine ("Running on {0} runtime...", mono ? "Mono" :
"Microsoft");
+ return mono;
+ }
+
+ static int Test ()
+ {
+ try {
+ uint u = (RunningOnMono ()) ? getuid () : GetTickCount
();
+ Console.WriteLine ("*1* P/Invoke: {0}", u);
+ return 1;
+ }
+ catch (SecurityException se) {
+ Console.WriteLine ("*0* Expected
SecurityException\n{0}", se);
+ return 0;
+ }
+ catch (Exception e) {
+ Console.WriteLine ("*2* Unexpected exception\n{0}", e);
+ return 2;
+ }
+ }
+
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode=true)]
+ static int Main ()
+ {
+ return Test ();
+ }
+}
Added: trunk/mono/mono/tests/cas/demand/sucs1.cs
===================================================================
--- trunk/mono/mono/tests/cas/demand/sucs1.cs 2005-03-10 23:30:03 UTC (rev
41671)
+++ trunk/mono/mono/tests/cas/demand/sucs1.cs 2005-03-11 01:17:37 UTC (rev
41672)
@@ -0,0 +1,45 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Security.Permissions;
+
+public class Program {
+
+ // for Mono
+ [DllImport ("libc", SetLastError=true)]
+ public static extern uint getuid ();
+
+ // for Microsoft
+ [DllImport ("kernel32.dll", SetLastError=true)]
+ public static extern uint GetTickCount ();
+
+ static bool RunningOnMono ()
+ {
+ bool mono = (Type.GetType ("Mono.Math.BigInteger") != null);
+ Console.WriteLine ("Running on {0} runtime...", mono ? "Mono" :
"Microsoft");
+ return mono;
+ }
+
+ static int Test ()
+ {
+ try {
+ uint u = (RunningOnMono ()) ? getuid () : GetTickCount
();
+ Console.WriteLine ("*1* P/Invoke: {0}", u);
+ return 1;
+ }
+ catch (SecurityException se) {
+ Console.WriteLine ("*0* Expected
SecurityException\n{0}", se);
+ return 0;
+ }
+ catch (Exception e) {
+ Console.WriteLine ("*2* Unexpected exception\n{0}", e);
+ return 2;
+ }
+ }
+
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode=true)]
+ static int Main ()
+ {
+ return Test ();
+ }
+}
Added: trunk/mono/mono/tests/cas/demand/sucs2.cs
===================================================================
--- trunk/mono/mono/tests/cas/demand/sucs2.cs 2005-03-10 23:30:03 UTC (rev
41671)
+++ trunk/mono/mono/tests/cas/demand/sucs2.cs 2005-03-11 01:17:37 UTC (rev
41672)
@@ -0,0 +1,46 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Security.Permissions;
+
+[SuppressUnmanagedCodeSecurity]
+public class Program {
+
+ // for Mono
+ [DllImport ("libc", SetLastError=true)]
+ public static extern uint getuid ();
+
+ // for Microsoft
+ [DllImport ("kernel32.dll", SetLastError=true)]
+ public static extern uint GetTickCount ();
+
+ static bool RunningOnMono ()
+ {
+ bool mono = (Type.GetType ("Mono.Math.BigInteger") != null);
+ Console.WriteLine ("Running on {0} runtime...", mono ? "Mono" :
"Microsoft");
+ return mono;
+ }
+
+ static int Test ()
+ {
+ try {
+ uint u = (RunningOnMono ()) ? getuid () : GetTickCount
();
+ Console.WriteLine ("*0* P/Invoke: {0}", u);
+ return 0;
+ }
+ catch (SecurityException se) {
+ Console.WriteLine ("*1* Unexpected
SecurityException\n{0}", se);
+ return 1;
+ }
+ catch (Exception e) {
+ Console.WriteLine ("*2* Unexpected exception\n{0}", e);
+ return 2;
+ }
+ }
+
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode=true)]
+ static int Main ()
+ {
+ return Test ();
+ }
+}
Added: trunk/mono/mono/tests/cas/demand/sucs3.cs
===================================================================
--- trunk/mono/mono/tests/cas/demand/sucs3.cs 2005-03-10 23:30:03 UTC (rev
41671)
+++ trunk/mono/mono/tests/cas/demand/sucs3.cs 2005-03-11 01:17:37 UTC (rev
41672)
@@ -0,0 +1,47 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Security.Permissions;
+
+public class Program {
+
+ // for Mono
+ [DllImport ("libc", SetLastError=true)]
+ [SuppressUnmanagedCodeSecurity]
+ public static extern uint getuid ();
+
+ // for Microsoft
+ [DllImport ("kernel32.dll", SetLastError=true)]
+ [SuppressUnmanagedCodeSecurity]
+ public static extern uint GetTickCount ();
+
+ static bool RunningOnMono ()
+ {
+ bool mono = (Type.GetType ("Mono.Math.BigInteger") != null);
+ Console.WriteLine ("Running on {0} runtime...", mono ? "Mono" :
"Microsoft");
+ return mono;
+ }
+
+ static int Test ()
+ {
+ try {
+ uint u = (RunningOnMono ()) ? getuid () : GetTickCount
();
+ Console.WriteLine ("*0* P/Invoke: {0}", u);
+ return 0;
+ }
+ catch (SecurityException se) {
+ Console.WriteLine ("*1* Unexpected
SecurityException\n{0}", se);
+ return 1;
+ }
+ catch (Exception e) {
+ Console.WriteLine ("*2* Unexpected exception\n{0}", e);
+ return 2;
+ }
+ }
+
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode=true)]
+ static int Main ()
+ {
+ return Test ();
+ }
+}
Added: trunk/mono/mono/tests/cas/demand/sucs4.cs
===================================================================
--- trunk/mono/mono/tests/cas/demand/sucs4.cs 2005-03-10 23:30:03 UTC (rev
41671)
+++ trunk/mono/mono/tests/cas/demand/sucs4.cs 2005-03-11 01:17:37 UTC (rev
41672)
@@ -0,0 +1,48 @@
+using System;
+using System.Runtime.InteropServices;
+using System.Security;
+using System.Security.Permissions;
+
+[SuppressUnmanagedCodeSecurity]
+public class Program {
+
+ // for Mono
+ [DllImport ("libc", SetLastError=true)]
+ [SuppressUnmanagedCodeSecurity]
+ public static extern uint getuid ();
+
+ // for Microsoft
+ [DllImport ("kernel32.dll", SetLastError=true)]
+ [SuppressUnmanagedCodeSecurity]
+ public static extern uint GetTickCount ();
+
+ static bool RunningOnMono ()
+ {
+ bool mono = (Type.GetType ("Mono.Math.BigInteger") != null);
+ Console.WriteLine ("Running on {0} runtime...", mono ? "Mono" :
"Microsoft");
+ return mono;
+ }
+
+ static int Test ()
+ {
+ try {
+ uint u = (RunningOnMono ()) ? getuid () : GetTickCount
();
+ Console.WriteLine ("*0* P/Invoke: {0}", u);
+ return 0;
+ }
+ catch (SecurityException se) {
+ Console.WriteLine ("*1* Unexpected
SecurityException\n{0}", se);
+ return 1;
+ }
+ catch (Exception e) {
+ Console.WriteLine ("*2* Unexpected exception\n{0}", e);
+ return 2;
+ }
+ }
+
+ [SecurityPermission (SecurityAction.Deny, UnmanagedCode=true)]
+ static int Main ()
+ {
+ return Test ();
+ }
+}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches