Jelajahi Sumber

2005-01-27 Sebastien Pouliot <[email protected]>
* Overlapped.cs: Added check for ControlPolicy and ControlEvidence for
Unsafe pack. Added MonoTODO for missing security stack propagation.
* Thread.cs: Add security checks for ControlThread.
* ThreadPool.cs: Added declarative security checks.


svn path=/trunk/mcs/; revision=39656

Sebastien Pouliot 21 tahun lalu
induk
melakukan
83fb9ee0dc

+ 6 - 0
mcs/class/corlib/System.Threading/ChangeLog

@@ -1,3 +1,9 @@
+2005-01-27  Sebastien Pouliot  <[email protected]>
+
+	* Overlapped.cs: Added check for ControlPolicy and ControlEvidence for
+	Unsafe pack. Added MonoTODO for missing security stack propagation.
+	* Thread.cs: Add security checks for ControlThread.
+	* ThreadPool.cs: Added declarative security checks.
 
 Thu Jan 13 18:15:32 CET 2005 Paolo Molaro <[email protected]>
 

+ 4 - 0
mcs/class/corlib/System.Threading/Overlapped.cs

@@ -33,6 +33,7 @@
 //
 
 using System.Runtime.InteropServices;
+using System.Security.Permissions;
 
 namespace System.Threading
 {
@@ -78,6 +79,7 @@ namespace System.Threading
 		}
 
 		[CLSCompliant(false)]
+		[MonoTODO ("Security - we need to propagate the call stack")]
 		unsafe public NativeOverlapped *Pack (IOCompletionCallback iocb)
 		{
 			NativeOverlapped *result = (NativeOverlapped *) Marshal.AllocHGlobal (Marshal.SizeOf (typeof (NativeOverlapped)));
@@ -88,8 +90,10 @@ namespace System.Threading
 		}
 		
 		[CLSCompliant(false)]
+		[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
 		unsafe public NativeOverlapped *UnsafePack (IOCompletionCallback iocb)
 		{
+			// no need to propagate the call stack in the unsafe version
 			return Pack (iocb);
 		}
 

+ 20 - 8
mcs/class/corlib/System.Threading/Thread.cs

@@ -100,6 +100,7 @@ namespace System.Threading
 		private CompressedStack _stack;
 		
 		public static Context CurrentContext {
+			[SecurityPermission (SecurityAction.LinkDemand, Infrastructure=true)]
 			get {
 				return(AppDomain.InternalGetContext ());
 			}
@@ -118,7 +119,7 @@ namespace System.Threading
 				}
 				return p;
 			}
-			[SecurityPermission (SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlPolicy)]
+			[SecurityPermission (SecurityAction.Demand, ControlPrincipal = true)]
 			set {
 				CurrentThread._principal = value;
 			}
@@ -251,9 +252,10 @@ namespace System.Threading
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		private extern static void ResetAbort_internal();
 
-		public static void ResetAbort()
+		[SecurityPermission (SecurityAction.Demand, ControlThread=true)]
+		public static void ResetAbort ()
 		{
-			ResetAbort_internal();
+			ResetAbort_internal ();
 		}
 		
 
@@ -401,6 +403,7 @@ namespace System.Threading
 				return culture;
 			}
 			
+			[SecurityPermission (SecurityAction.Demand, ControlThread=true)]
 			set {
 				in_currentculture = true;
 
@@ -578,17 +581,23 @@ namespace System.Threading
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		private extern void Abort_internal (object stateInfo);
 
-		public void Abort() {
+		[SecurityPermission (SecurityAction.Demand, ControlThread=true)]
+		public void Abort () 
+		{
 			Abort_internal (null);
 		}
 
-		public void Abort(object stateInfo) {
-			Abort_internal(stateInfo);
+		[SecurityPermission (SecurityAction.Demand, ControlThread=true)]
+		public void Abort (object stateInfo) 
+		{
+			Abort_internal (stateInfo);
 		}
 		
 
 		[MonoTODO]
-		public void Interrupt() {
+		[SecurityPermission (SecurityAction.Demand, ControlThread=true)]
+		public void Interrupt ()
+		{
 		}
 
 		// The current thread joins with 'this'. Set ms to 0 to block
@@ -642,6 +651,7 @@ namespace System.Threading
 #if NET_2_0
 		[Obsolete ("")]
 #endif
+		[SecurityPermission (SecurityAction.Demand, ControlThread=true)]
 		public void Resume () 
 		{
 			if ((state & ThreadState.Unstarted) != 0 || !IsAlive || 
@@ -695,7 +705,9 @@ namespace System.Threading
 #if NET_2_0
 		[Obsolete ("")]
 #endif
-		public void Suspend() {
+		[SecurityPermission (SecurityAction.Demand, ControlThread=true)]
+		public void Suspend ()
+		{
 			if((state & ThreadState.Unstarted) != 0 || !IsAlive) {
 				throw new ThreadStateException("Thread has not been started, or is dead");
 			}

+ 9 - 6
mcs/class/corlib/System.Threading/ThreadPool.cs

@@ -7,11 +7,7 @@
 //   Maurer Dietmar ([email protected])
 //
 // (C) Ximian, Inc.  http://www.ximian.com
-// Copyright (C) 2004 Novell (http://www.novell.com)
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -33,10 +29,10 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-using System;
 using System.Collections;
 using System.Globalization;
 using System.Runtime.CompilerServices;
+using System.Security.Permissions;
 
 namespace System.Threading {
 
@@ -50,6 +46,7 @@ namespace System.Threading {
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		static extern bool BindHandleInternal (IntPtr osHandle);
 
+		[SecurityPermission (SecurityAction.Demand, UnmanagedCode=true)]
 		public static bool BindHandle (IntPtr osHandle)
 		{
 			return BindHandleInternal (osHandle);
@@ -65,6 +62,7 @@ namespace System.Threading {
 		public static extern void GetMinThreads (out int workerThreads, out int completionPortThreads);
 			
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
+		[SecurityPermission (SecurityAction.Demand, ControlThread=true)]
 		public static extern bool SetMinThreads (int workerThreads, int completionPortThreads);
 			
 		public static bool QueueUserWorkItem (WaitCallback callback)
@@ -135,6 +133,7 @@ namespace System.Threading {
 							    (long) millisecondsTimeOutInterval, executeOnlyOnce);
 		}
 
+		[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
 		public static bool UnsafeQueueUserWorkItem (WaitCallback callback, object state)
 		{
 			IAsyncResult ar = callback.BeginInvoke (state, null, null);
@@ -144,6 +143,7 @@ namespace System.Threading {
 		}
 		
 		[MonoTODO]
+		[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
 		public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject,
 			WaitOrTimerCallback callBack, object state, int millisecondsTimeOutInterval,
 			bool executeOnlyOnce) 
@@ -152,6 +152,7 @@ namespace System.Threading {
 		}
 		
 		[MonoTODO]
+		[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
 		public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject,
 			WaitOrTimerCallback callBack, object state, long millisecondsTimeOutInterval,
 			bool executeOnlyOnce) 
@@ -160,6 +161,7 @@ namespace System.Threading {
 		}
 
 		[MonoTODO]
+		[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
 		public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject,
 			WaitOrTimerCallback callBack, object state, TimeSpan timeout,
 			bool executeOnlyOnce) 
@@ -169,6 +171,7 @@ namespace System.Threading {
 
 		[MonoTODO]
 		[CLSCompliant (false)]
+		[SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
 		public static RegisteredWaitHandle UnsafeRegisterWaitForSingleObject (WaitHandle waitObject,
 			WaitOrTimerCallback callBack, object state, uint millisecondsTimeOutInterval,
 			bool executeOnlyOnce)