System and method for dynamic optimizations using security assertions

Information

  • Patent Application
  • 20080028461
  • Publication Number
    20080028461
  • Date Filed
    July 26, 2006
    19 years ago
  • Date Published
    January 31, 2008
    18 years ago
Abstract
The invention relates to a system and method for efficient security runtime. If the same security demand for permissions occurs twice during the same code path (i.e. execution stack) the latter can be automatically turned (optimized) into a security assertion based on the former demand. A security runtime can determine which assertions to establish in a call stack, using declarative security information kept in an assembly metadata and based on execution history to know what has already been demanded for a specific stack frame. If the method being called has been allowed to execute before then a demand may be replaced with an assertion for the same permissions within the call stack. If that frame was executed then it means the security demand was successfully evaluated. Furthermore, if the permission evaluation result is known to be static (e.g., its result will not change) it can be determined that another check on the same permissions is not required higher on the stack, so this demand can safely be replaced by an assertion, which can effectively speed up the code execution without sacrificing security.
Description

DETAILED DESCRIPTION OF DRAWINGS


FIG. 1 is a block diagram of a code call stack according to prior art.



FIG. 2 is a high-level block diagram according to one embodiment of the invention.



FIG. 3 is block diagram for a code call stack according to one embodiment of the invention.



FIG. 4 is a flow chart for a method according to one embodiment of the invention.





DETAILED DESCRIPTION

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 FIG. 2, a system is provided that includes at least one computer terminal 200 (e.g., client terminal) having a processor, a memory, a display and at least one input mechanism (e.g., keyboard or other input mechanism) (not shown). The computer terminal 200 may be connected or connectable to other computer terminals via wired, wireless, and/or a combination of wired and wireless connections and/or to servers via wired, wireless, and/or a combination of wired and wireless connections. Application sources 230 and assembly sources 240 may communicate over a communications connection to the computer 200. The computer 200 may be linked to network 250 using other conventional network communication means. The network 250 may also be one or more various network types including, but not limited to, LAN, WAN, or Internet.


As shown in FIG. 2 the computer system 200 may include one or more applications (201, 202, 203) for execution on computer 200. Execution may be carried out using Common Language Runtime (CLR) module 210, where Code Access Security (CAS 211) may be employed to make security decisions during execution. The dynamic security optimizer module 213 may be used to transform security demands into assertions during runtime, if they are judged safe to promote. Secure recourses (221, 223, 225) stored at computer 200 may include code libraries, assemblies, and/or other resources. Metadata associated with the resources can include declarative security information for accessing other resources. Declarative security information may include static attributes kept in the assembly metadata, which identifies security information that can be used in the optimization process.


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.



FIG. 3 is a visual representation of some of the decisions made during runtime. By way of example, a resource, exemplified as Assembly A, may execute a function (Method A) which calls a function (Method B) of another resource (Assembly B) and the called function (Method B) may call another function (Method C) of another resource (Assembly C), and so on.


During runtime a resource may demand a specified permission (Permission1) from the calling code. For example, with respect to FIG. 3, Assembly C may demand that the method calling it, Method B of Assembly B (including its callers, Method A of Assembly A) have the specified permission. To prevent unsecured access from an indirect source (e.g., Assembly A), each of the methods and assembly transitions up to the “bottom of the stack” (Assembly A) are verified for the same permission (Permission1). Any calls into Method C will provoke a stack walk to verify the requested permission(s) are allowed for each caller.


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. FIG. 4 is a flow diagram of the runtime security for permission demands. By way of example, during runtime a demand for PermissionA may be made (similar to demand for Permission1 illustrated in FIG. 3) to the CAS 211. In step 403, PermissionA is evaluated for all called code in the execution stack. This is similar to stack walk #1 illustrated in FIG. 3. A determination may be made at step 405 as to whether the stack walk completed without throwing a security exception. If not, the process ends with a security exception (step 407). If the stack walk successfully completes without a security exception then the permission may be checked to determine whether it is a declarative permission (e.g., coming from the assembly metadata). If not, runtime may proceed as normal and the demand for permission is carried out in a conventional manner in step 415. If, however, the permission is declarative, another determination may be made as to whether the permission is static in step 411. If not static, runtime may proceed as normal in step 415. If the permission is static, then the original demand from step 401 (demand for PermissionA) may be promoted into an assertion in step 413 for future evaluation. Thus, if the demand for PermissionA is made again, in the same execution stack, it will automatically be executed as an assertion. This promotion (from a demand to an assert) will effectively shortcut any further stack-walk, initiated from further up in the stack, for the same permissions. In performing such an optimization, performance may be increased without making a sacrifice in security.


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.

Claims
  • 1. A computer-implemented method of dynamically optimizing runtime execution of computer code object on a computer by applying stack manipulation techniques, comprising: performing a stack walk for evaluating whether a requested permission is allowed for the plurality of sequential stack frames of a call stack; if the requested permission is not allowed for at least one of the sequential stack frames in the call stack, then creating a security exception;if the requested permission is allowed for the plurality of sequential stack frames in the call stack, then evaluating security elements associated with the requested permission and each stack frame of the call stack for determining whether the permission can be optimized; if yes, then automatically promoting a future request for the same permission into a permission assertion;if not, then continuing with the execution.
  • 2. The method of claim 1, wherein the security elements include syntax, past results with in a current call stack, or permission type.
  • 3. The method of claim 1, wherein the determining step includes determining whether the requested permission is a declarative permission and determining whether the requested permission is a static permission.
  • 4. The method of claim 3, wherein the step of automatically promoting a future request is based on whether the requested permission is both a declarative permission and a static permission.
  • 5. The method of claim 1, wherein the computer executes using ECMA-335 virtual machine.
  • 6. The method of claim 1, wherein the computer code object is received at computer from an application source server over the network.
  • 7. The method of claim 1, wherein the computer code object is an application program.
  • 8. The method of claim 1, wherein runtime execution of computer code object is carried out using common language runtime.
  • 9. The method of claim 1, wherein secure resources may be accessed on the computer.
  • 10. The method of claim 1, wherein the secure resources are programmed with permission attributes within metadata of the resource.
  • 11. A computer system of dynamically optimizing runtime execution of computer code object on a computer using stack manipulation techniques, comprising: a code access security module performing a stack walk for evaluating whether a requested permission is allowed for the plurality of sequential stack frames of a call stack; if the requested permission is not allowed for at least one of the sequential stack frames in the call stack, then creating a security exception;if the requested permission is allowed for the plurality of sequential stack frames in the call stack, then evaluating security elements associated with the requested permission and each stack frame of the call stack for determining whether the permission can be optimized; if yes, then automatically promoting a future request for the same permission into a permission assertion;if not then continuing to execute the runtime execution.
  • 12. The system of claim 11, wherein the security elements include syntax, past results with in a current call stack, or permission type.
  • 13. The system of claim 11, wherein the code access security modules includes determining whether the requested permission is a declarative permission and determining whether the requested permission is a static permission.
  • 14. The system of claim 13, wherein automatically promoting a future request is based on whether the requested permission is both a declarative permission and a static permission.
  • 15. The system of claim 11, wherein the computer executes using Ecma-335 virtual machine.
  • 16. The system of claim 11, wherein the computer code object is received at computer from an application source server over the network.
  • 17. The system of claim 11, wherein the computer code object is an application program.
  • 18. The system of claim 11, wherein runtime execution of computer code object is carried out using common language runtime.
  • 19. The system of claim 11, wherein secure resources may be accessed on the computer.
  • 20. The system of claim 11, wherein the secure resources are programmed with permission attributes within metadata of the resource.