The present invention is a computer programming system and method for implementing dynamic optimization for safely replacing previous successful permission demands with security assertions.
ECMA-335 is an international standard that defines a Common Language Infrastructure (CLI) in which applications written in multiple high-level languages can be executed in different system environments without the need to rewrite those applications to take into consideration the unique characteristics of those environments. Unfortunately, malicious applications running un-trusted code (e.g., downloaded applications from the Internet) can present potential risks to local secured computer resources. Code Access Security (CAS) is a well known security mechanism, implemented on computers with an ECMA-335 virtual machine (VM), to limit what managed code can do and access on the computer. In CAS permissions are granted, or refused, based on code evidences and security policies. Resources (e.g., assemblies) can specify requested permissions by using declarative security, which uses attributes to place security information into the metadata of the resource. At runtime if the code attempts to access any resource which requires permissions as specified by declarative security, a demand is issued to determine whether the code calling the resource and all other codes that have been called up that point (call stack) satisfies the requested permissions. If so, access to the resource is allowed, otherwise a security exception is thrown. CAS enforces this by doing “stack walks” where every method on the call stack (e.g., the chain of code being executed) is evaluated for the demanded permission. Although time consuming, this prevents luring attacks by less trusted code that can sit between a trusted application (bottom of the stack) and the code accessing the resource (top of the stack).
A call stack is divided up into contiguous pieces called stack frames, or frames for short; each frame is the data associated with one call to one function, also known as “method”. When a demand for permission is executed CAS starts a stack walk for every frame in the execution stack, starting with the current caller method. Each stack frame, as well as assembly and application domain transitions, are evaluated to see if they satisfy the condition required by the permission.
Executing stack walks is a heavyweight process, but it does ensure that every caller (e.g., method call) has access to a resource before executing the code. However in some cases, like iterations or recursion, having multiple stack walks for the same set of permissions and the same call stalk (e.g. iterations), or a superset of the stack (e.g. recursion), does not augment security but greatly impacts application performance.
For such conditions, CAS includes a mechanism called an assertion, which allows the reduction of permissions checks up to a point in the stack walk where permissions do not need to be verified. For example, if a frame in a call stack asserts a permission to read files, then this permission is not checked for the frames above the frame that made the assertion. It can be safely assumed that the asserted permission has been determined to be allowed for all the above frames. Assertions, even if indirectly, are time savers because they reduce the number of stack frames to process. Using asserts for non-security purposes like performance optimizations, however, can be potentially harmful because they reduce the number of security checks done at runtime. Assertions require careful and manual auditing and any error (e.g. demand for permissions not executed) can lead to security vulnerabilities in applications.
Problems of the present implementations are that most stack walks are invisible or unknown to the programmer; hence any performance problem is hard to diagnose. Using manual assertions is difficult and potentially harmful (if misused) making this mechanism a dangerous one to solve performance issues. As such, there is a need for safe performance optimizations that does not have the drawbacks of current implementations.
Various aspects of the invention overcome at least some of these and other drawbacks of known systems. According to one embodiment of the invention, a system and method is provided for performing dynamic security optimization during application runtime for evaluating security demands for permissions and, when possible, promoting the demands into security assertions on the same permissions. This is possible by determining whether the permissions are static permissions (e.g., its results, under the same conditions, do not change) and were they were first successfully executed in the same stack. If these conditions are fulfilled, the demand may be safely replaced with an assertion in the stack frame.
The present invention employs dynamic optimizations using previously evaluated and successful demands and replaces them, when conditions are met, with security assertions. Assertions added dynamically during execution, for known safe parts, allows a gain in performance (e.g. iterations and recursion) without any of the previously cited problems.
These and other objects, features and advantages of the invention will be apparent through the detailed description of the embodiments and the drawings attached hereto. It is also to be understood that both the foregoing general description and the following detailed description are exemplary and not restrictive of the scope of the invention.
The present invention employs dynamic optimizations using past evaluated and successful permission demands within a current runtime call stack, and replaces them with security assertions (for the same set of permissions). Dynamic optimization may be applied to CAS demands in order to safely increase performance without sacrificing security. Adding assertions dynamically during execution, for known safe parts, allows a gain in performance (e.g. iterations and recursion) without any of the previously cited problems.
The permission demand (herein referred to as “demand”) may be turned into an assertion if the demand has been successfully executed (e.g. in a previous stack-walk, higher in the runtime call stack) in the current call stack. Other considerations include determining if the permission was made using declarative syntax and if the permission is known to be static (e.g., that it will always resolve to the same result). If a demand for a permission fulfilling all of these criteria is encountered, then a stack walk can be avoided, interrupted or, at least, shortened. Replacing a demand with an assertion, under the right conditions, saves both execution resources (e.g. memory) and time during execution. Furthermore the optimization does not require any source code change or programmer awareness.
The invention may be used at a computer on a network or any other computer or device with an ECMA-335 Virtual Machine (VM). According to one embodiment of the invention, shown in
As shown in
The present invention allows ECMA-335 VM supporting Code Access Security (CAS) to dynamically optimize some of the declarative security demands by turning them into assertions. Depending on the call stack depth (e.g., number of frames in a call stack) and the usage (e.g. iterations and recursion) this optimization can yield a performance increase while still ensuring the same level of security as the original implementation.
Application code (201, 202, 203) on a computer may originate from various sources that are either: secure, un-secure, or semi-secure. Application code may be downloaded to a computer via the network connection with the application source 230. Other sources may be included (e.g., hard disk, CD, drive storage).
Application runtime may be initiated by remote or local user of the computer 200 or automatically initiated locally or from a remote location without user intervention. CLR module 210 can be used during execution of an application. During runtime, code may have the potential to perform many functions as programmed. These functions may include calling code from various secure resources (221, 223, 225). The shared resources may be programmed with permission attributes using declarative security within the metadata of the resource. The declarative security attributes may be read (e.g., by the CLR module 210) during runtime access to resources. The attributes may define the minimal permissions needed by code calling the resource during runtime. The demand for permissions may be dynamically evaluated based on the various factors including, characteristics of the code (e.g., origin, name, location, size, etc) and/or the call stack.
During runtime a resource may demand a specified permission (Permission1) from the calling code. For example, with respect to
As execution continues, the same demand for Permission1 may be made at later during runtime (Method F in Assembly F). At such time, another stack walk (stack walk #2) is started. However, the second stack walk, as illustrated, is performed until a point in the stack walk where the same permission was previously made. In the illustrated example, the second stack walk would stop at Method C of Assembly C where the permission would be asserted.
From the dynamic security optimizer 213 point of view, dynamic optimization may be applied at the time of the demand.
Aspects that may be considered when determining whether to promote a security demand into an assertion may include, but are not limited to, whether the permission demand was previously successfully executed; whether the permission was made using the declarative syntax (e.g., present in assembly metadata); and/or whether the permission is known to have a static result. Other consideration may be determined.
In the foregoing specification, the invention has been described with reference to specific embodiments thereof. Various modifications and changes may be made thereto without departing from the broader spirit and scope of the invention. The specification and drawings are, accordingly, to be regarded in an illustrative rather than a restrictive sense.
| Number | Name | Date | Kind |
|---|---|---|---|
| 5452457 | Alpert et al. | Sep 1995 | A |
| 6071316 | Goossen et al. | Jun 2000 | A |
| 6230312 | Hunt | May 2001 | B1 |
| 6282701 | Wygodny et al. | Aug 2001 | B1 |
| 6308275 | Vaswani et al. | Oct 2001 | B1 |
| 6560774 | Gordon et al. | May 2003 | B1 |
| 6615264 | Stoltz et al. | Sep 2003 | B1 |
| 6802054 | Faraj | Oct 2004 | B2 |
| 6871284 | Cooper et al. | Mar 2005 | B2 |
| 6971091 | Arnold et al. | Nov 2005 | B1 |
| 7069554 | Stammers et al. | Jun 2006 | B1 |
| 7487221 | Araki | Feb 2009 | B2 |
| 7512965 | Amdur et al. | Mar 2009 | B1 |
| 7552472 | Baffes et al. | Jun 2009 | B2 |
| 7620940 | Goldsmith et al. | Nov 2009 | B2 |
| 20020042897 | Klein et al. | Apr 2002 | A1 |
| 20020069200 | Cooper et al. | Jun 2002 | A1 |
| 20020198675 | Underseth et al. | Dec 2002 | A1 |
| 20030041267 | Fee et al. | Feb 2003 | A1 |
| 20030065942 | Lineman et al. | Apr 2003 | A1 |
| 20030110192 | Valente et al. | Jun 2003 | A1 |
| 20030115484 | Moriconi et al. | Jun 2003 | A1 |
| 20030177355 | Elgressy et al. | Sep 2003 | A1 |
| 20030196114 | Brew et al. | Oct 2003 | A1 |
| 20030225822 | Olson et al. | Dec 2003 | A1 |
| 20040103323 | Dominic | May 2004 | A1 |
| 20040250112 | Valente et al. | Dec 2004 | A1 |
| 20050071668 | Yoon et al. | Mar 2005 | A1 |
| 20050172126 | Lange et al. | Aug 2005 | A1 |
| 20050240999 | Rubin et al. | Oct 2005 | A1 |
| 20050262517 | French | Nov 2005 | A1 |
| 20060064737 | Wallace | Mar 2006 | A1 |
| 20060117299 | Goldsmith et al. | Jun 2006 | A1 |
| 20060143396 | Cabot | Jun 2006 | A1 |
| 20060150021 | Traskov et al. | Jul 2006 | A1 |
| 20060235655 | Qing et al. | Oct 2006 | A1 |
| Number | Date | Country | |
|---|---|---|---|
| 20080028461 A1 | Jan 2008 | US |