This application relates generally to data processing and, more particularly, to programmable units for metadata processing.
Today's computer systems are notoriously hard to secure. Conventional processor architectures, for example, allow various behaviors, such as buffer overflows, pointer forging and the like, which violate higher level abstractions. Closing the gap between programming language and hardware may be left to software, where the cost of enforcing airtight abstractions is often deemed too high.
Some recent efforts have demonstrated the value of propagating metadata during execution to enforce policies that catch safety violations and malicious attacks as they occur. These policies can be enforced in software but typically incur high, undesirable overheads, such as in performance and/or costs, that discourage their deployment or other motivate coarse approximations providing less protection. Hardware support for fixed policies may reduce overhead to acceptable levels and prevent a large portion of undesired code violations, such as may be performed by malicious code or malware attacks. For example, Intel recently announced hardware for bounds checking and isolation. While these mitigate many of today's attacks, fully securing systems will require more than memory safety and isolation. Attacks rapidly evolve to exploit any remaining forms of vulnerability.
Thus, there is a need for a flexible security architecture that can be quickly adapted to this ever-changing landscape. It would be desirable to have such an architecture provide support for software-defined metadata processing with minimal overhead. It is desirable that such an architecture is extensible to generally support and enforce any number and type of policies without placing a visible, hard bound on the number of bits allocated to metadata. Metadata may be propagated during execution to enforce policies and catch violation of such policies such as, for example, by malicious code or malware attacks.
In accordance with one aspect of the techniques described herein is a method of processing instructions comprising: receiving, for metadata processing, a current instruction with an associated metadata tag, said metadata processing being performed in a metadata processing domain isolated from a code execution domain including the current instruction; determining, in the metadata processing domain and in accordance with the metadata tag and the current instruction, whether a rule exists in a rule cache for the current instruction, said rule cache including rules on metadata used by said metadata processing to define allowed operations; and responsive to determining no rule exists in the rule cache for the current instruction, performing rule cache miss processing in the metadata processing domain comprising: determining whether execution of the current instruction is allowed; responsive to determining the current instruction is allowed to be executed in the code execution domain, generating a new rule for the current instruction; and responsive to writing to a register, inserting the new rule into the rule cache. First metadata used to select the rule for the current instruction may be stored in a first portion of a plurality of control status registers used by the metadata processing. The first portion of the plurality of control status registers may be used to communicate a plurality of metadata tags for the current instruction to the metadata processing domain. The plurality of metadata tags may be used as data in the metadata processing domain. The register may be a first control status register of a plurality of control status registers used by the metadata processing and a first portion of the plurality of control status registers may be used to communicate a plurality of metadata tags from the metadata processing domain to the rule cache. The plurality of metadata tags may be for the current instruction. The new rule may be inserted into the rule cache responsive to writing a second metadata tag to the first control status register. The second metadata tag may be placed on a result of the current instruction and the result may be any of a destination register or a memory location. The plurality of control status registers may include any one or more of: a bootstrap tag control status register including an initial metadata tag from which all other generated metadata tags are derived; a default tag control status register specifying a default metadata tag; a public untrusted control status register specifying a public untrusted metadata tag used to tag instruction and data classified as public and untrusted; an opgroup value control status register including data written to a table including information on opgroups and care information for different opcodes; an opgroup address control status register specifying a location in the table to which data of the opgroup value control status register is written; and a pumpflush control status register wherein a write to the pumpflush control status register triggers flushing of the rule cache. The plurality of control status registers may include a tag mode control status register denoting a current mode of metadata processing. The tag mode control status register may indicate when metadata processing is disengaged whereby rules of one or more defined policies are not enforced by metadata processing. The tag mode control status register may be set to one of a defined set of allowed states to denote the current mode of metadata processing, the allowed states including: an off state, a state whereby metadata processing writes a default tag on all results, and a state indicating that metadata processing is engaged and operational when instructions are executed in the code domain at one or more specified privilege levels. The rule cache miss processing may be performed in a first of the defined set of allowed states where metadata processing is disengaged. The allowed states may include a first state indicating that metadata processing is engaged only when instructions execute in the code domain at a user privilege level; a second state indicating that metadata processing is engaged only when instructions execute in the code domain at a user or supervisor privilege level; a third state indicating that metadata processing is engaged only when instructions execute in the code domain at a user, supervisor, or hypervisor privilege level; and a fourth state indicating that metadata processing is engaged when instructions execute in the code domain at a user, supervisor, hypervisor, or machine privilege level. Whether the metadata processing is engaged or disengaged may be determined in accordance with a current tag mode of the tag mode control status register in combination with a current privilege level of code executing in the code domain. Rules of one or more defined policies may not be enforced when metadata processing is disengaged and wherein the rules may be enforced when metadata processing is engaged. The plurality of control status registers may include an extended opcode control status register including additional opcode bits, if any, for the current instruction. The current instruction may be included in an instruction set having variable length opcodes. Each opcode of the instruction set may optionally include the additional opcode bits. The extended opcode control status register may include the additional opcode bits, if any, for the current instruction. A table may include information that maps an opcode of the instruction set to a corresponding opgroup and bit vector information. The opgroup may denote a group of associated opcodes treated similarly by the metadata processing domain. The bit vector information may denote whether particular inputs and outputs with respect to the metadata processing domain are used in connection with processing the opcode. The table may be indexed using a first portion of opcode bits less than a maximum number of allowable opcode bits. The maximum number may denote an upper bound on a number of bits of an opcode of the instruction set. For each opcode mapped using the table, there may be a result bit vector corresponding to the opcode. The result bit vector may denote what portion, if any, of the additional opcode bits in the extended opcode control status register are used with the opcode. The current instruction may be one of multiple instructions stored in a single word of memory associated with a single metadata tag and the single metadata tag may be associated with the multiple instructions included in the single word. The plurality of control status registers may include a subinstruction control status register indicating which of the multiple instructions stored in the single word is the current instruction. The single metadata tag may be a first pointer to a first memory location including a different metadata tag for each of the multiple instructions in the single word. At least a first metadata tag stored in the first memory location for a first instruction of the multiple instructions may include a second pointer to a second memory location including metadata tag information for the first instruction. The metadata tag information for the first instruction may include a complex structure where the complex structure may comprise at least one scalar data field and at least one pointer field to a third memory location. A first memory location may include multiple bytes of data and a single metadata tag may be associated with the first memory location. The first memory location may be a single word, and a plurality of control status registers used by the metadata processing may include a byte-enable control status register indicating which of the multiple bytes stored in the single word are any of read from, and written to, by the current instruction. The first memory location may be a single word, and a plurality of control status registers used by the metadata processing may include a bit-enable control status register indicating which one or more bits stored in the single word are any of read from, and written to, by the current instruction. The single metadata tag may be a pointer to a second memory location including tags for the multiple bytes of data. The second memory location may include a variable length structure comprising a first field denoting a number of subsequent tag fields of the variable length structure, and the subsequent tag fields may specify tags for the multiple bytes of data. The single metadata tag may be a pointer to a hierarchical structure including tags for the multiple bytes of data.
In accordance with another aspect of techniques herein is a non-transitory computer readable medium comprising code thereon that, when executed, perform a method of processing instructions comprising: receiving, for metadata processing, a current instruction with an associated metadata tag, said metadata processing being performed in a metadata processing domain isolated from a code execution domain including the current instruction; determining, in the metadata processing domain and in accordance with the metadata tag and the current instruction, whether a rule exists in a rule cache for the current instruction, said rule cache including rules on metadata used by said metadata processing to define allowed operations; and responsive to determining no rule exists in the rule cache for the current instruction, performing rule cache miss processing in the metadata processing domain comprising: determining whether execution of the current instruction is allowed; responsive to determining the current instruction is allowed to be executed in the code execution domain, generating a new rule for the current instruction; and responsive to writing to a register, inserting the new rule into the rule cache. In accordance with another aspect of the techniques herein is a system comprising: a processor; and a memory comprising code stored thereon that, when executed by the processor, performs a method of processing instructions comprising:
receiving, for metadata processing, a current instruction with an associated metadata tag, said metadata processing being performed in a metadata processing domain isolated from a code execution domain including the current instruction; determining, in the metadata processing domain and in accordance with the metadata tag and the current instruction, whether a rule exists in a rule cache for the current instruction, said rule cache including rules on metadata used by said metadata processing to define allowed operations; and responsive to determining no rule exists in the rule cache for the current instruction, performing rule cache miss processing in the metadata processing domain comprising: determining whether execution of the current instruction is allowed; responsive to determining the current instruction is allowed to be executed in the code execution domain, generating a new rule for the current instruction; and responsive to writing to a register, inserting the new rule into the rule cache. The processor may be a pipeline processor in a reduced instruction set computing architecture.
The foregoing will be apparent from the following more particular description of example embodiments, as illustrated in the accompanying drawings in which like reference characters refer to the same parts throughout the different views. The drawings are not necessarily to scale, emphasis instead being placed upon illustrating embodiments.
A description of example embodiments follows.
Described in following paragraphs are various embodiments and aspects of a Programmable Unit for Metadata Processing (PUMP) that indivisibly associates a metadata tag with every word in the system's main memory, caches, and registers. To support unbounded metadata, the tag is large enough to indirect to a data structure in memory. On every instruction, the tags of the inputs are used to determine if the operation is allowed, and if so to calculate the tags for the results. In some embodiments, the tag checking and propagation rules are defined in software; however, to minimize performance impact, these rules are cached in a hardware structure, the PUMP rule cache, that operates in parallel with the arithmetic logic unit (ALU) portion of a processor. In some embodiments, a miss handler, such as may be implemented using software and/or hardware, may be used to service cache misses based on the policy currently in effect.
In at least one embodiment using a composition of four different policies, the performance impact of the PUMP may be measured (See
The foregoing are examples of well-known policies that may be used in an embodiment in accordance with techniques herein. For such well known policies whose protection capabilities have been established in the literature, techniques herein may be used to enforce such policies while also reducing the performance impact of enforcing them using the PUMP. Except for NXD+NWC, each of these policies needs to distinguish an essentially unlimited number of unique items; by contrast, solutions with a limited number of metadata bits can, at best, support only grossly simplified approximations.
As illustrated and described elsewhere herein, one embodiment in accordance with techniques herein may utilize a simple, direct implementation of the PUMP which uses pointer-sized (64b or byte) tags to 64b words thereby at least doubling the size and energy usage of all the memories in the system. Rule caches add area and energy on top of this. For this particular embodiment, an area overhead of 190% (See
However, as described in more detail below most policies exhibit spatial and temporal locality for both tags and the rules defined over them. Thus, an embodiment in accordance with techniques herein may significantly reduce the number of unique rules significantly by defining them over a group of similar (or even identical) instructions, reducing compulsory misses and increasing the effective capacity of the rule caches. Off-chip memory traffic can be reduced by exploiting spatial locality in tags. On-chip area and energy overhead can be minimized by using a small number of bits to represent the subset of the pointer-sized tags in use at a time. Runtime costs of composite policy miss handlers can be decreased by providing hardware support for caching component policies. Thus, an embodiment in accordance with techniques herein may include such optimizations to thereby allow the PUMP to achieve lower overheads without compromising its rich policy model.
An embodiment in accordance with techniques herein may enhance memory words and internal processor state with metadata that can be used to encode an arbitrary number of security policies that can be enforced either in isolation or simultaneously. An embodiment in accordance with techniques herein may achieves the foregoing by adding, to a “conventional” processor (e.g. RISC-CPU, GPU, Vector processor, etc.), a metadata processing unit (the PUMP) that works in parallel with the data flow to enforce an arbitrary set of policies; the present disclosure technique specifically makes the metadata unbounded and software programmable, such that the techniques herein may be adapted and applied to a wide range of metadata processing policies. For example, the PUMP may be integrated as a new/separate pipeline stage of a conventional (RISC) processor, or can be integrated as a stand-alone piece of hardware working on parallel with the “host” processor. For the former case, there may be an instruction level simulator, elaborated policies, implementation optimizations and resource estimates, and extensive simulations to characterize the design.
Existing solutions trying to enforce policies at the fine (i.e. instruction) granularity level cannot enforce an arbitrary set of policies. Commonly, only a small number of fixed policies can be enforced at the instruction level. Enforcing policies at a higher granularity level (i.e. thread) cannot prevent certain classes of Return Oriented Programming attacks, thus rendering that type of enforcement limited in its usefulness. In contrast, embodiments in accordance with techniques herein allow the expression of an unlimited number of policies (the only limit is the size address space, as the meta-data is expressed in terms of address pointers that can point to any arbitrary data structures) that may be enforced at the instruction level singly or simultaneously.
It should be noted that various figures described in following paragraphs illustrate various examples, methods, and other example embodiments of various aspects of the techniques described herein. It will be appreciated that, in such figures, the illustrated element boundaries (e.g., boxes, groups of boxes, or other shapes) generally represent one example of the boundaries. One of ordinary skill in the art will appreciate that in some examples one element may be designed as multiple elements or that multiple elements may be designed as one element. In some examples, an element shown as an internal component of another element may be implemented as an external component and vice versa. Furthermore, elements may not be drawn to scale.
Referring to
Various embodiments may implement the PUMP 10 using electronic logic that is a mechanism providing policy enforcement and metadata propagation. An embodiment of the PUMP 10 may be characterized by: (i) an empirical evaluation of the runtime, energy, power ceiling, and area impacts of a simple implementation of the PUMP 10 on a standard set of benchmarks under four diverse policies and their combination; (ii) a set of micro-architectural optimizations; and (iii) measurements of the gains from these optimizations, showing typical runtime overhead under 10%, a power ceiling impact of 10%, and typically energy over-head under 60% by using 110% additional area for on-chip memory structures.
In computing, benchmarking may be characterized as the act of running a computer program, a set of programs, or other operations, in order to assess the relative performance of an object, normally by running a number of standard tests and trials against it. The term ‘benchmark’ used herein refers to benchmarking programs themselves. The types of benchmark programs used throughout this application and the Figures are GemsFDTD, astar, bwaves, bzip2, cactusADM, calculix, deall, gamess, gcc, gobmk, gromacs, h264ref, hmmer, Ibm, leslie3d, libquantum, mcf, mile, namd, omnetpp, perlbench, sjeng, specrand, sphinx3, wrf, zeusmp, and mean. See, for example,
“Logic”, as used herein, includes but is not limited to hardware, firmware, software and/or combinations of each to perform a function(s) or an action(s), and/or to cause a function or action from another logic, method, and/or system. For example, based on a desired application or needs, logic may include a software controlled microprocessor, discrete logic like a processor (e.g., microprocessor), an application specific integrated circuit (ASIC), a programmed logic device, a memory device containing instructions, an electric device having a memory, or the like. Logic may include one or more gates, combinations of gates, or other circuit components. Logic may also be fully embodied as software. Where multiple logics are described, it may be possible to incorporate the multiple logics into one physical logic. Similarly, where a single logic is described, it may be possible to distribute that single logic between multiple physical logics.
In at least one embodiment in accordance with techniques herein, the PUMP 10 may be characterized as an extension to a conventional RISC processor 12. Following paragraphs provide further details of the ISA (instruction set architecture)-level extensions that constitute the PUMP's 10 hardware interface layer, the basic micro-architectural changes, and the accompanying low-level software that may be used in an embodiment in accordance with techniques herein.
In an embodiment in accordance with techniques herein, each word in a PUMP-enriched system may be associated with a pointer-sized tag. These tags are uninterpreted at the hardware level. At the software level, a tag may represent metadata of unbounded size and complexity, as defined by the policy. Simpler policies that need only a few bits of metadata may store the metadata directly in the tag; if more bits are required, then indirection is used to store the metadata as a data structure in memory, with the address of this structure used as the tag. Notably, these pointer-sized tags are one exemplary aspect of the present disclosure and are not to be considered limiting. The basic addressable memory word is indivisibly extended with a tag, making all value slots, including memory, caches, and registers, suitably wider. A program counter (PC) is also tagged. This notion of software-defined metadata and its representation as a pointer-sized tag extends previous tagging approaches, where only a few bits are used for tags and/or they are hardwired to fixed interpretations. Some exemplary taxonomies of tagging schemes are presented in Table 2 which is reproduced in
Metadata tags are not addressable by user programs. Rather, the metadata tags are addressed by policy handlers invoked on rule cache misses as detailed below. All updates to tags are realized through PUMP 10 rules.
Besides unbounded metadata, another feature of an embodiment of the PUMP 10 in accordance with techniques herein is hardware support for single-cycle common-case computation on metadata. These computations are defined in terms of rules of the form opcode: (PC, CI, OP1, OP2, MR)⇔(PCnew, R), which should be read: “If the current opcode is opcode, the current tag on the program counter is PC, the tag on the current instruction is CI, the tags on its input operands (if any) are OP1 and OP2, and the tag on the memory location (in case of load/store) is MR, then the tag on the program counter in the next machine state should be PCnew and the tag on the instructions result (a destination register or a memory location, if any) should be R”. This rule format, allowing two output tags to be computed from up to five input tags, is markedly more flexible than those considered in prior work, which typically compute one output from up to two inputs (see Table 2 in
To resolve the rules in a single cycle in the common case, an embodiment in accordance with techniques herein may use a hardware cache of the most recently used rules. Depending on the instruction and policy, one or more of the input slots in a given rule may be unused. To avoid polluting the cache with rules for all possible values of the unused slots, the rule-cache lookup logic refers to a bit vector containing a “don't-care” (See
Placing the PUMP 10 as a separate stage (between memory stage 20 and writeback stage 22) is motivated by the need to provide the tag on the word read from memory (load), or to be overwritten in memory (store), as an input to the PUMP 10. Since rules are allowed that depend on the existing tag of the memory location that is being written, write operations become read-modify-write operations. The existing tag is read during the Memory stage 20 like a read rule, the read rule is checked in the PUMP 10 stage, and the write is performed during the Commit stage which may also be referred to as writeback stage 22. As with any caching scheme, multiple levels of caches may be used for the PUMP 10. As described in more detail below, an embodiment in accordance with techniques herein may utilize two levels of caches. The extension to multiple levels of caches is readily apparent to one having ordinary skill in the art.
In one non-limiting example, when a last-level miss occurs in the rule cache in the writeback stage 22, it is handled as follows: (i) the current opcode and tags are saved in a (new) set of processor registers used only for this purpose, and (ii) control is transferred to the policy miss handler (described in more detail below), which (iii) decides if the operation is allowed and if so generates an appropriate rule. When the miss handler returns, the hardware (iv) installs this rule into the PUMP 10 rule caches, and (v) re-issues the faulting instruction. To provide isolation between the privileged miss handler and the rest of the system software and user code, a miss-handler operational mode is added to the processor, controlled by a bit in the processor state that is set on a rule cache miss and reset when the miss handler returns. To avoid the need to save and restore registers on every rule cache miss, the integer register file may be expanded with 16 additional registers that are available only to the miss handler. Additionally, the rule inputs and outputs appear as registers while in miss handler mode (cf. register windows), allowing the miss handler (but nothing else) to manipulate the tags as ordinary values. Again, these are all non-limiting examples of the writeback stage 22.
A new miss-handler-return instruction is added to finish installing the rule into the PUMP 10 rule caches and returns to user code. In this particular non-limiting example, this instruction can only be issued when in miss-handler mode. While in miss-handler mode, the rule cache is ignored and the PUMP 10 instead applies a single, hardwired rule: all instructions and data touched by the miss handler must be tagged with a predefined MISSHANDLER tag, and all instruction results are given the same tag. In this way, the PUMP 10 architecture prevents user code from undermining the protection provided by the policy. Alternatively, the PUMP may be used to enforce flexible rules on miss-handler access. Tags are not divisible, addressable, or replaceable by user code; metadata data structures and miss handler code cannot be touched by user code; and user code cannot directly insert rules into the rule cache.
With reference to
Rather than forcing users to choose a single policy, multiple policies are enforced simultaneously and new ones are added later. An exemplary advantage to these “unbounded” tags is that they can enforce any number of policies at the same time. This can be achieved by letting tags be pointers to tuples of tags from several component policies. For example, to combine the NXD+NWC policy with the taint-tracking policy, each tag can be a pointer to a tuple (s, t), where s is a NXD+NWC tag (either DATA or CODE) and t is a taint tag (a pointer to a set of taints). The rule cache lookup is similar, however when a miss occurs, both component policies are evaluated separately: the operation is allowed only if both policies allow it, and the resulting tags are pairs of results from the two component policies. However, in other embodiments, it might be possible to express how the policies are to be combined (not simply as AND between all the constituent components).
With reference to
Most policies will dispatch on the opcode to select the appropriate logic. Some policies, like NXD+NWC, will just check whether the operation is allowed. Others may consult a data structure (e.g., the CFI policy consults the graph of allowed indirect call and return ids). Memory safety checks equality between address color (i.e pointer color) and memory region colors. Taint tracking computes fresh result tags by combining the input tags (Alg. 1). Policies that must access large data structures (CFI) or canonicalize across large aggregates (Taint Tracking, Composite) may make many memory accesses that will miss in the on-chip caches and go to DRAM. On average across all of the benchmarks, servicing misses for NXD+NWC required 30 cycles, Memory Safety required 60 cycles, CFI required 85 cycles, Taint Tracking required 500 cycles, and Composite required 800 cycles.
If the policy miss handler determines that the operation is not allowed, it invokes a suitable security fault handler. What this fault handler does is up to the runtime system and the policy; typically, it would shut down the offending process, but in some cases it might return a suitable “safe value” instead. For incremental deployment with UNIX-style operating systems, assumed policies are applied per process, allowing each process to get a different set of policies. The recitation of being applied per process is non-limiting but rather exemplary and one having skill in the art recognizes this. It also allows us to place the tags, rules, and miss handling support into the address space of the process, avoiding the need for an OS-level context switch. Longer term, perhaps PUMP policies can be used to protect the OS as well.
The following details evaluation methodology for measuring runtime, energy, area, and power overheads and applies it on a simple implementation of the PUMP hardware and software, using 128b words (64b payload and 64b tag) and the modified pipeline processor 12 depicted in
To estimate the physical resource impact of the PUMP, memory costs were primarily focused on, since the memories are the dominant area and energy consumers in a simple RISC processor and in the PUMP hardware extensions. A 32 nm Low Operating Power (LOP) process is considered for the L1 memories (See
A baseline processor (no-PUMP) has separate 64 KB L1 caches for data and instructions and a unified 512 KB L2 cache. Delay-optimized L1 caches and an energy-optimized L2 cache were used. All caches use a writeback discipline. The baseline L1 cache has a latency around 880 ps; it is assumed that it can return a result in one cycle and set its clock to 1 ns, giving a 1 GHz-cycle target—comparable to modern embedded and cell phone processors. The parameters for this processor are presented in Table 3 in
One embodiment of the PUMP rule cache 10 hardware implementation may include two parts: extending all architectural states in stages 14, 16, 20 with tags, and adding PUMP rule caches to the processor 12. Extending each 64b word in the on-chip memories with a 64b tag increases their area and energy per access and worsens their access latency. This is potentially tolerable for the L2 cache, which already has a multi-cycle access latency and is not used every cycle. But adding an extra cycle of latency to access the L1 caches (See
In an embodiment in accordance with techniques herein, the PUMP rule cache 10 utilizes a long match key (5 pointer-sized tags plus an instruction opcode, or 328b) compared to a traditional cache address key (less than the address width), and returns a 128b result. In one embodiment, a fully associative L1 rule cache may be used but would lead to high energy and delay (See Table 3 in
With reference to
The PUMP simulator 28 includes miss-handler code (written in C) to implement each policy, and metadata tags are assigned on the initial memory depending on the policy. The PUMP simulator 28 allows captures the access patterns in the PUMP 10 rule caches and estimates the associated runtime and energy costs, accounting for the longer wait cycles required to access the L2 rule cache. Since the PUMP simulator 28 having miss handler code also runs on the processor, separate simulations for the miss handler on gem5 to capture its dynamic behavior. Since the miss-handler code potentially impacts the data and instruction caches, a merged address trace is created that includes properly interleaved memory accesses from both user and miss-handler code, which is used for the final address-trace simulation to estimate the performance impact of the memory system.
In following paragraphs, the evaluation of the simple PUMP implementation is provided in comparison to the no-PUMP baseline.
As one point of evaluation, it should be noted that the overall area overhead of the PUMP 10 on top of the baseline processor is 190% (See Table 3 in
Another points of evaluation relates to runtime overhead. For all single policies on most benchmarks, the average runtime overhead of even this simple implementation is only 10% (see
Two factors contribute to this overhead: (1) the large number of cycles required to resolve a last-level rule cache miss (since every component miss handler must be consulted), and (2) an explosion in the number of rules, which expands the working set size and increases the rule cache miss rate. In the worst case, the number of unique composite tags could be the product of the unique tags in each component policy. However, the total rules increase by a factor of 3×-5× over the largest single policy, Memory Safety.
Another point of evaluation is energy overhead. Moving more bits, due to wider words, and executing more instructions, due to miss handler code, both contribute to energy overheads, impacting both the single and composite policies (
For many platform designs the worst-case power, or equivalently, energy per cycle, is the limiter. This power ceiling may be driven by the maximum current the platform can draw from a battery or the maximum sustained operating temperature either in a mobile or in a wired device with ambient cooling.
An embodiment incorporating the foregoing implementation described above achieves reasonable performance on most benchmarks, the runtime overhead for the Composite policy on some of them and the energy and power overheads on all policies and benchmarks seem unacceptably high. To address these overheads, a series of targeted microarchitecture optimizations may be introduced and also incorporated into an embodiment in accordance with techniques herein. In Table 4 at
What will now be described are “opgroups” as may be used in an embodiment in accordance with techniques herein. In practical policies, it is common to define similar rules for several opcodes. For example, in the Taint Tracking policy, the rules for the Add and Sub instructions are identical (See Algorithm 1 in
An embodiment in accordance with techniques herein may utilize main memory tag compression that will now be described. Using 64b tags on 64b words doubles the off-chip memory traffic and therefore approximately doubles the associated energy. Typically, though, tags exhibit spatial locality—many adjacent words have the same tag. For example,
However, as depicted in
The compression scheme presented above may be utilized in embodiment in accordance with techniques herein, for example, due to its combination of simplicity and effectiveness at reducing off-chip memory energy. One having skill in the art clearly recognizes that additional alternative clever schemes for fine-grained memory tagging exist—including multi-level tag page tables, variable-grained TLB-like structures, and range caches—and these may also be used to reduce the DRAM footprint in an embodiment in accordance with techniques herein.
What will now be described is how tag translation may be performed in an embodiment in accordance with techniques herein. With reference again to
To obtain the foregoing saving advantage without losing the flexibility of full, pointer-sized tags, different-width tags may be used for different on-chip memory subsystems and translate between these as needed. For example, one might use 12b tags in the L1 memories and 16b tags in the L2 memories.
When a long tag is not in the long-to-short translation table, a new short tag is allocated, potentially reclaiming a previously allocated short tag that is no longer in use. There is a rich design space to explore for determining when a short tag can be reclaimed, including garbage collection and tag-usage counting. For simplicity, short tags are allocated sequentially and flush all caches above a given level (instruction, data, and PUMP) when the short tag space is exhausted, avoiding the need to track when a specific short tag is available for reclamation. Caches may be designed with suitable techniques that making cache flushes inexpensive. For example, in an embodiment in accordance with techniques herein, all caches may be designed with a lightweight gang clear, such as known in the art and described, for example, in K. Mai, R. Ho, E. Alon, D. Liu, Y. Kim, D. Patil, and M. Horowitz. Architecture and Circuit Techniques for a 1.1 GHz 16-kb Reconfigurable Memory in 0.18 um-CMOS.
IEEE J. Solid-State Circuits, 40(1):261-275, January 2005, which is incorporated by reference herein.
In comparison to Table 3 (reproduced in
What will now be described are various techniques that may be used in connection with miss handler acceleration. An embodiment in accordance with techniques herein may combine four policies into a single Composite policy. With reference to
In connection with various aspects of the PUMP microarchitecture such as illustrated in
As also illustrated in
As also included in
Taken together, a 2048-entry UCP cache and a 512-entry CTAG cache reduce the average time spent on each L2 rule cache miss from 800 cycles to 80 cycles.
An embodiment in accordance with techniques herein may also improve performance by prefetching one or more rules which are stored in one or more of the caches including rules. Thus, it is additionally possible to reduce the compulsory miss rate with precompute rules that might be needed in the near future. An exemplary instance has high value for the Memory Safety rules. For example when a new memory tag is allocated, new rules will be needed (initialize (1), add offset to pointer and move (3), scalar load (1), scalar store (2)) for that tag. Consequently, all of these rules may be added to the UCP cache at once. For the single-policy Memory Safety case, the rules may be added directly into the rule caches. This reduces the number of Memory Safety miss-handler invocations by 2×.
In connection with an overall evaluation and with reference to
The magnitude of the benefits vary across benchmarks and policies. Across all benchmarks, the benefit beyond 10b L1 tags is small for the SPEC CPU2006 benchmarks, so 10b are used as the compromise between energy and delay and use a 2048-entry UCP cache and a 512-entry CTAG cache to reduce area overhead while coming close to the minimum energy level within the space of the architecture parameters explored.
Applications with low locality have baseline energy and performance driven by DRAM due to high main memory traffic. The overhead in such benchmarks (e.g., lbm) trends to the DRAM overhead, so reductions in DRAM overhead directly impact runtime and energy overhead. Applications with more locality are faster in the baseline configuration, consume less energy, and suffer less from DRAM overheads; as a result, these benchmarks are more heavily impacted by the reduced L1 capacity and the tag energy in the L1 D/I and rule caches. DRAM optimization has less effect on these applications, but using short tags has a large effect on energy and removes the L1 D/I cache capacity penalty (e.g. h264ref).
The benchmarks with heavy dynamic memory allocation have higher L2 rule cache miss rates due to compulsory misses as newly created tags must be installed in the cache. This drove the high overheads for several benchmarks (GemsFDTD, omnetpp) in the simple implementation. The miss handler optimizations as described herein reduce the common case cost of such misses, and the opgroup optimization reduces the capacity miss rate. For the simple implementation, GemsFDTD took an L2 rule cache miss every 200 instructions and took 800 cycles to service each miss driving a large part of its 780% runtime overhead (See
Overall, these optimizations bring runtime overhead below 10% for all benchmarks except GemsFDTD and omnetpp (See
To illustrate, the performance impact of the PUMP may be measured using a composition of four different policies (See Table 1 at
The micro-architecture optimizations such as described herein may be included in an embodiment in accordance with techniques herein to reduce the impact on power ceiling to 10% (See FIG.-10C), suggesting the optimized PUMP will have little impact on the operating envelope of the platform. DRAM compression reduces the energy overhead for lbm to 20%; since it also slows down by 9%, its power requirement only increases by 10%.
The area overhead of the optimized design is around 110% (e.g., see Table 5 of
One goal of the model and optimizations as described herein is to make it relatively simple for an embodiment to add additional policies that are simultaneously enforced. The Composite policy on the simple PUMP design incurred more than incremental costs for several benchmarks due to the large increase in miss handler runtime, but these are reduced with the miss handler optimizations.
A brief summary of related work is identified in Table 2 reproduced at
In accordance with a policy programming model in accordance with techniques herein, a PUMP policy includes a set of tag values together with a collection of rules that manipulate these tags to implement some desired tag propogation and enforcement mechanism. Rules come in two forms: the software layer (symbolic rules) or hardware layer (concrete rules) of the system.
For example, to illustrate the operation of the PUMP, consider a simple example policy for restricting return points during program execution. The motivation for this policy comes from a class of attacks known as return-oriented programming (ROP), where the attacker identifies a set of “gadgets” in the binary executable of the program under attack and uses these to assemble complex malicious behaviors by constructing appropriate sequences of stack frames, each containing a return address pointing to some gadget; a buffer overflow or other vulnerability is then exploited to overwrite the top of the stack with the desired sequence, causing the snippets to be executed in order. One simple way of limiting ROP attacks is to constrain the targets of return instructions to well-defined return points. This is accomplished by using the PUMP by tagging instructions that are valid return points with a metadata tag target. Each time a return instruction is executed, the metadata tag on the PC is set to check to indicate that a return has just occurred. On the next instruction, the PC tag is check, verify that the tag on the current instruction is target, and signal a security violation if not. By making the metadata richer, it is possible to precisely control which return instructions can return to which return points. By making it yet richer, full CFI checking may be implemented.
From the point of view of the policy designer and the software parts of the PUMP 10, policies may be compactly described using symbolic rules written in a tiny domain-specific language. An exemplary symbolic rule and its program language is described, for example, in an APPENDIX attached hereto, entitled “PROGRAMMING THE PUMP, Hardware-Assisted Micro-Policies for Security”.
Symbolic rules may compactly encode a great variety of metadata tracking mechanisms. At the hardware level, however, a rule is needed for representation that is tuned for efficient interpretation to avoid slowing down the primary computation. To this end, a lower level rule format, called concrete rules, may be introduced. Intuitively, each symbolic rule for a given policy can be expanded into an equivalent set of concrete rules. However, since a single symbolic rule might in general generate an unbounded number of concrete rules, this elaboration is performed lazily, generating concrete rules as needed while the system executes.
For policies with metadata tags (e.g., which are richer than ROP), the translation from symbolic to concrete rules follows the same general lines, but the details become a bit more intricate. For example, the taint-tracking policy takes tags to be pointers to memory data structures, each describing an arbitrarily sized set of taints (representing data sources or system components that may have contributed to a given piece of data). The symbolic rule for the load opgroup says that the taint on the loaded value should be the union of the taints on the instruction itself, the target address for the load, and the memory at that address. The symbolic rule and its program language is incorporated by reference from and is available for public inspection in the paper entitled “PROGRAMMING THE PUMP, Hardware-Assisted Micro-Policies for Security” which was previously identified.
To reduce the number of distinct tags (and, hence, pressure on the rule cache), metadata structures may be internally stored in canonical form and since tags are immutable, sharing is fully exploited (e.g., set elements are given a canonical order so that sets can be compactly represented sharing common prefix subsets). When no longer needed, these structures can be reclaimed (e.g., by garbage collection).
An embodiment may utilize composite policies. Multiple orthogonal policies may be simultaneously enforced by letting tags be pointers to tuples of tags from several component policies. (In general, multiple policies may not be orthogonal) For example, to compose the first return opgroup (ROP) policy with the taint-tracking policy, let each tag be a pointer to a representation of a tuple (r; t), where r is an ROP-tag (a code location identifier) and t is a taint tag (a pointer to a set of taints). The cache lookup process is exactly the same, but when a miss occurs the miss handler extracts the components of the tuple and dispatches to routines that evaluate both sets of symbolic rules. The operation is allowed only if both policies have a rule that applies; in this case the resulting tag is a pointer to a pair containing the results from the two sub-policies.
In connection policy system and protection, the policy system exists as a separate region of memory within each user process. The policy system may include, for example, the code for the miss handler, the policy rules, and the data structures representing the policy's metadata tags. Placing the policy system in the process is minimally invasive with the existing Unix process model and facilitates lightweight switching between the policy system and the user code. The policy system is isolated from user code using mechanisms described next.
Clearly, the protection offered by the PUMP would be useless if the attacker could rewrite metadata tags or change their interpretation. The techniques described herein are designed to prevent such attacks. The kernel, loader, and (for some policies) compiler is trusted. In particular, the compiler is relied on to assign initial tags to words and, where needed, communicate rules to the policy system. The loader will preserve the tags provided by the compiler, and that the path from the compiler to the loader is protected from tampering, e.g., using cryptographic signatures.
An embodiment in accordance with techniques herein may use a standard Unix-style kernel which sets up the initial memory image for each process. (It may be possible to use micro-policies to eliminate some of these assumptions, further reducing the size of the TCB). It is further assumed that, in such embodiments, the rule-cache-miss-handling software is correctly implemented. This is small, hence a good target for formal verification. One concern is to prevent user code running in a process from undermining the protection provided by the process's policy. User code should not be able to (i) manipulate tags directly—all tag changes should be performed in accordance with the policy/policies rules currently in effect; (ii) manipulate the data structures and code used by the miss handler; (iii) directly insert rules in the hardware rule cache.
In connection with addressing, to prevent direct manipulation of tags by user code, the tags attached to every 64b word are not, themselves, separately addressable. In particular, it is not possible to specify an address that corresponds only to a tag or a portion of a tag in order to read or write it. All user accessible instructions operate on (data, tag) pairs as atomic units—the standard ALU operating on the value portion and the PUMP operating on the tag portion.
In connection with the miss handler architecture in an embodiment in accordance with techniques herein, the policy system may only be activated on misses to the PUMP cache. To provide isolation between the policy system and user code, a miss-handler operational mode is added to the processor. The integer register file is expanded with 16 additional registers that are available only to the miss handler, to avoid saving and restoring registers. Note, the use of 16 additional registers is illustrative and in practice may need to expand the integer register file to less/more registers. The PC of the faulting instruction, the rule inputs (opgroup and tags), and the rule outputs appear as registers while in miss handler mode. A miss-handler-return instruction is added, which finishes installing a concrete rule into the cache and returns to user code.
In an embodiment in accordance with techniques herein, the normal behavior of the PUMP 10 is disengaged while the processor 12 is in miss-handler mode. Instead, a single hardwired rule is applied: all instructions and data touched by the miss handler must be tagged with a predefined miss-handler tag that is distinct from the tags used by any policy. This ensures isolation between miss handler code and data and the user code in the same address space. User code cannot touch or execute policy system data or code, and the miss handler cannot accidentally touch user data and code. The miss-handler-return instruction can only be issued in miss-handler mode, preventing user code from inserting any rules into the PUMP.
While previous work has used clever schemes to compactly represent or approximate safety and security policies, this is often a compromise on the intended policy, and it may trade complexity for compactness. As described herein, it is possible to include richer metadata that captures the needs of the security policies both more completely and more naturally with little or no additional runtime overhead. Rather than imposing a fixed bound on the metadata representation and policy complexity, the PUMP 10 provides a graceful degradation in performance. This allows policies to use more data where needed without impacting the common case performance and size. It further allows the incremental refinement and performance tuning of policies, since even complex policies can easily be represented and executed.
With evidence mounting for the value of metadata-based policy enforcement, the present disclosure defines an architecture for software-defined metadata processing and identifies accelerators to remove most of the runtime overhead. An architecture is introduced and described herein with no bounds (i.e., free from any bound) on the number of metadata bits or the number of policies simultaneously supported along with four microarchitecture optimizations (opgroups, tag compression, tag translation, and miss handler acceleration) that achieve performance comparable to dedicated, hardware metadata propagation solutions. The software defined metadata policy model and its acceleration will be applicable to a large range of policies beyond those illustrated here, including sound information-flow control, fine-grained access control, integrity, synchronization, race detection, debugging, application-specific policies, and controlled generation and execution of dynamic code.
Some non-limiting advantages of the various aspects and embodiments described herein provide (i) a programming model and supporting interface model for compactly and precisely describing policies supported by this architecture; (ii) detailed examples of policy encoding and composition using four diverse classes of well-studied policies; and (iii) quantification of the requirements, complexity, and performance for these policies.
The programming model of an embodiment as described herein may encode a host of other policies. Information-flow control is richer than the simple taint tracking models here, but tracking implicit flows can be supported either with RIFLE-style binary translation or by using the PC tag along with some support from the compiler. Micro-policies can support lightweight access control and compartmentalization. Tags can be used to distinguish unforgeable resources. Unique, generated tokens can act as keys for sealing and endorsing data, which in turn can be used for strong abstraction—guaranteeing that data is only created and destructured by authorized code components. Micropolicy rules can enforce data invariants such as immutability and linearity. Micro-policies can support parallelism as out-of-band metadata for synchronization primitives such as full/empty bits for data or futures or as state to detect race conditions on locks. A system architect can apply specific micro-policies to existing code without auditing or rewriting every line.
The PUMP 10 design as described herein offers an attractive combination of flexibility and performance, supporting a diverse collection of low-level, fine-grained security policies with single policy performance comparable to dedicated mechanisms in many cases while supporting richer and composite policies with mostly graceful performance degradation as rule complexity grows. Further, the mechanisms provided by the PUMP may be used to protect its own software structures. An embodiment in accordance with techniques herein may replace the special miss-handler operational mode by implementing a “compartmentalization” micro-policy using the PUMP 10 and using this to protect the miss-handler code. Finally, as described herein, orthogonal sets of policies may be combined, where the protections provided by each one are completely independent of the others. But policies often interact: for example, an information-flow policy may need to place tags on fresh regions being allocated by a memory safety policy. Policy composition requires analysis in connection with both in expression and in efficient hardware support.
What will now be described is a further example illustrating implementation of a memory safety policy in an embodiment in accordance with techniques herein that identifies all temporal and spatial violations in heap-allocated memory. In at least one embodiment, for each new allocation processing may be performed to make up a fresh color-id, c, and write c as the tag on each memory location in the newly created memory block (e.g., such as via memset). The pointer to the new block is also tagged c. Later, when processing is performed to dereference a pointer, processing may include checking that the pointer's tag is the same as the tag on the memory cell to which the pointer references or points. When a block is freed, the tags on all cells of the block may be modified to a constant F representing free memory. The heap may be initially tagged F. A special tag, ⊥, may be used for non-pointers. Thus, generally, an embodiment may write a tag t for a memory location that is either a color c or ⊥.
Because memory cells may contain pointers, in general each word in memory may be associated with two tags. In such an embodiment, the tag on each memory cell be a pointer to a pair (c, t), where c is the id of the memory block in which this cell was allocated and t is the tag on the word stored in the cell. An embodiment may use domain-specific language based on the rule function described elsewhere herein for specifying a policy in terms of symbolic rules. The rules for load and store take care of packing and unpacking these pairs, along with checking that each memory access is valid (i.e., the accessed cell is within the block pointed to by this pointer):
The checking performed in the foregoing and other rules shows up as conditions under which the symbolic rule is valid (e.g., c2=c3 above in the store rule). The “-” symbol indicates the don't care fields in the rule.
Address arithmetic operations preserve the pointer tag:
To maintain the invariant that tags on pointers can only originate from allocation, operations that create data from scratch (e.g., loading constants) set its tag to 1.
In an embodiment implementing the memory safety policy, operations such as malloc and free may be accordingly modified, for example, to tag memory regions using the tagged instructions and ephemeral rules (e.g., which may be deleted from the cache once they are used). In connection with malloc, processing may generate a fresh tag for the pointer to a new region via an ephemeral rule. For example, the rule for move may be an ephemeral rule such as:
The arrow with the superscript of 1 (e.g., →1) may denote an ephemeral rule. The newly tagged pointer may then be used to write a zero to every work in the allocated region using a special store rule:
In such an embodiment using the memory safety policy, opgroups may be used to describe the rule set as follows:
The symbolic rules used above for policy specification may be written using variables, allowing a few symbolic rules to describe the policy over an unbounded universe of distinct values. The concrete rules stored in the rule cache, however, refer to specific, concrete tag values. For example, if 23 and 24 are valid memory block colors, an embodiment may use concrete rules with concrete instances of symbolic Rule (3) above in the PUMP rule cache for c=23 and c=24. Assuming, for example, an embodiment encodes ⊥ as 0 and marks don't care fields as 0, the concrete rules are for symbolic rule (3) above are:
Consistent with discussion elsewhere herein, in at least one embodiment, the miss handler may obtain the concrete input tags and execute code compiled from the symbolic rules to produce the associated concrete output tags in order to insert rules into the PUMP rule cache. When the symbolic rule identifies a violation, control transfers to an error handler and no new concrete rules are inserted into the PUMP rule cache.
What will now be described is an embodiment in accordance with techniques herein based on the RISC-V architecture further extended with metadata tags and the PUMP to support software defined metadata processing (SDMP) consistent with discussion herein. RISC-V may be characterized as an open source implementation of reduced instruction set computing (RISC) instruction set architecture (ISA). In such an embodiment, metadata tags are placed on both instructions and data for each word. In the RISC-V architecture, words are 64 bits. The RISC-V architecture provides different word size variants—RV64 with a word size of 64 bits and RV32 with a word size of 32 bits. The width or size of the registers and user address space may vary with the word size. Tag size or width may be independent of word size or width but may more typically be the same in an embodiment. As known in the art, the RISC-V architecture has 32 bit instructions and thus an embodiment supporting and operating using the 64 bit word size may store 2 instructions in a single tagged word. The foregoing and other aspects of the RISC-V architecture are discussed elsewhere herein in connection with use of different techniques and features in connection with extending the RISC-V architecture for use with metadata tags, the PUMP and SDMP.
The RISC-V architecture includes user-level instructions as described, for example, in “The RISC-V Instruction Set Manual Vol. I, User-Level ISA, Version 2.0”, May 6, 2014, Waterman, Andrew, et. al., (also referred to as the “RISC-V user level ISA”) which is incorporated by reference herein, and is publically available, for example, at the RISCV.ORG website, and through the University of California at Berkeley as Technical Report UCB/EECS-2014-54. The RISC-V architecture also incorporates a privileged architecture including privileged instructions and additional functionality needed for running operating systems, attached external devices, and the like, as described, for example, in “The RISC-V Instruction Set Manual Volume II: Privileged Architecture, Version 1.7”, May 9, 2015, also referred to as the “RISC-V privileged ISA”) which is incorporated by reference herein, and is publically available, for example, at the RISCV.ORG website, and through the University of California at Berkeley as Technical Report UCB/EECS-2015-49.
An embodiment of the RISC-V architecture may have four RISC-V privilege levels as follows: level 0 for user/application (U) privilege level, level 1 for supervisor (S) privilege level, level 2 for hypervisor (H) privilege level, and level 3 for machine (M) privilege level. In the foregoing, RISC-V privilege levels may be ranked, highest to lowest, from 0 to 3 where level 0 denotes the highest or greatest level of privilege and level 3 denotes the lowest or minimum privilege level. Such privilege levels may be used to provide protection between different components and attempts to execute code that perform operations not permitted by the current privilege level or mode will cause an exception to be raised such as traps into an underlying execution environment. Machine level has the highest privileges and is the only mandatory privilege level for a RISC-V hardware platform. Code run in machine-mode (M-mode) is inherently trusted, as it has low-level access to the machine implementation. User-mode (U-mode) and supervisor-mode (S-mode) are intended for conventional application and operating system usage respectively, while hypervisor-mode (H-mode) is intended to support virtual machine monitors. Each privilege level has a core set of privileged ISA extensions with optional extensions and variants. It should be noted that an implementation of the RISC-V architecture must support at least the M-mode and most implementations support at least U-mode and M-mode. S-mode may be added to provide further isolation between code of supervisor-level operating system and other more privileged code executing in M-mode. User or application code may typically execute in U-mode until a trap (e.g., supervisor call, page fault) or interrupt occurs forcing a transfer of control to a trap handler which runs at one of the supported higher privilege modes or levels (e.g., H, S or M mode). Code of the trap handler is then executed and control may then be returned to the original user code or application which caused the trap. Such execution of the user code or application may resume at or after the original trapped instruction in U-mode that triggered the trap handler invocation. Various combinations of supported modes in a RISC-V implementation may include only: the single M mode, two modes—M and U, three modes—M, S and U, or all four modes M, H, S, U. In at least one embodiment described herein, all 4 of the foregoing privilege levels may be supported. At a minimum, an embodiment in accordance with techniques herein may support M AND U modes.
The RISC-V architecture has control status registers (CSRs) that may be atomically read and modified by one or more associated privilege levels. Generally, a CSR may be accessible at a first of the four privilege levels and any other of the four privilege levels higher than the first. For example, assume a program is executing in U-mode (level 3) and a trap, such as a rule cache miss, occurs whereby control is transferred to a trap handler, such as the rule cache miss handler code, running at a higher privilege or mode (e.g., any of levels 0-2). Upon the occurrence of the trap, information may be placed in CSRs accessible to the trap handler executing in M-mode, for example, that are not otherwise accessible to any other code executing at a lower privilege level (e.g., not accessible to code in H, S or U mode). In at least one embodiment, the rule cache miss handler may run at a privilege level above the level of PUMP protection (e.g., may run in H-mode, S-mode, or M-mode). In such an embodiment, as described elsewhere herein, the tag definitions and policies may be global across an operating system (e.g., per virtual machine) at the rule cache miss handler level whereby the same tag definitions and policies may be applied across all executing code. In at least one embodiment, per application or process policies may be supported where such policies are installed globally and the PC (program counter identifying the current instruction) and/or code may be tagged to distinguish process or application-specific rules. In an embodiment where virtual machines (VMs) do not share memory, policies may be defined at a per-VM basis.
Consistent with discussion elsewhere herein, the PUMP may be characterized as a rule cache for SDMP. There may be a mapping between a set of tags on the instruction and instruction inputs and tags for the result of the operation. Tag processing is independent and parallel from the normal operations of the instruction. In at least one embodiment, the PUMP runs in parallel with the normal RISC-V operations, supplying the tags for the results of the operation. Since the PUMP is a cache, rule cache misses occur the first time the PUMP receives a particular instruction, and thus a particular corresponding set of PUMP inputs (e.g., compulsory) or when the PUMP was unable to retain a rule in cache (e.g., capacity of cache exceeded therefore the rule was evicted from the rule cache, or perhaps conflict). Rule cache misses cause a miss trap that is then handled by code of a miss handler system (e.g., rule cache miss handler). Inputs may be communicated to the miss handler through PUMP CSRs and rule insertion may be provided back to the PUMP also through CSRs. This is discussed in more detail below. A first embodiment is discussed elsewhere herein where there are 5 PUMP input tags. As a variation, an embodiment may include a different number of tags and other PUMP inputs. The particular number of PUMP tag inputs may vary with the instruction set and operands. For example, the following may be included as PUMP inputs in one embodiment based on the RISC-V architecture:
1. Opgrp—denotes particular opgroup include a current instruction. Generally, an opgroup is an abstraction of a group of instructions and is discussed elsewhere herein.
3. Cltag—tag on the instruction
4. OP1tag—tag on RS1 input to instruction
5. OP2tag—tag on RS2 input to instruction (or tag on CSR when a CSR instruction)
6. OP3tag—tag on RS3 input to instruction
7. Mtag—tag on memory input to instruction or memory target of an instruction
8. funct12 (funct7)—extended opcode bits that occur in some instructions as described elsewhere herein.
9. subinstr—when there are multiple instruction packed in a word, this input identifies which instruction in the word is the current instruction being operated upon by the PUMP.
The following may be included as PUMP outputs in one embodiment based on the RISC-V architecture:
1. Rtag—tag on result: destination register, memory, or CSR
2. newPCtag—tag on the PC after this operation (e.g., sometimes referred to herein as PCnew tag).
Information may be communicated, for example, from user code executing in U-mode at the time of the trap occurrence to a trap handler, such as the rule cache miss handler, executing in M-mode via CSRs. In a similar manner, information may be communicated between the trap handler in M-mode when resuming program execution in U-mode via CSRs where information in the CSRs may be placed in corresponding registers accessible in U-mode. In this manner, there may be mapping between the CSRs at one privilege level and registers at other privilege levels. For example, in an embodiment in accordance with techniques herein, a CSR may be defined that is accessible to the M-mode handler and PUMP where a particular instruction operand tag is written to the CSR upon the occurrence of a trap to communicate the tag to the PUMP and rule cache miss handler as an input. In a similar manner, the CSR may be used to communicate information from the trap handler and/or PUMP (operating at a privilege level higher than U-mode) to other code executing in U-mode such as when resuming program execution after a rule cache miss (e.g., where rule cache miss occurs when a matching rule is not found in the PUMP rule cache for a current instruction). For example, a CSR may be used to output or propagate PUMP output tags for PCnew and RD. Additionally, CSRs may be defined where different actions may occur responsive to writing to a particular CSR. For example, the rule cache miss handler code may write/insert a new rule into the rule cache of the PUMP by writing to a particular CSR. The particular CSRs defined may vary with embodiment.
Referring to
Rows 901a-c identify CSRs having special tag values used for tagging code and/or instructions by the PUMP. In at least one embodiment, the sboottag CSR defined by entry 901a may include a first initial or starting tag value used in a system. The foregoing starting tag value may be referred to as a bootstrap tag value. In one aspect, the bootstrap tag value may be characterized as a “seed” from which all other tags may be derived or based on. Thus, the bootstrap tag may be used in one embodiment as a starting point for generating all other tags. In a manner similar to initial loading of a starting location of bootstrap code in the operating system, hardware may be used to initialize the CSR 901a to the particular predefined tag value used as the bootstrap tag. Once the bootstrap tag has been read as part of booting a system in accordance with techniques herein, the sboottag CSR may be cleared. For example, a privileged portion of operating system code may include instructions which invoke rules performing initial tag propagation using the bootstrap tag value. Use of the bootstrap tag and tag generation and propagation are further described elsewhere herein. Row 901b identifies a CSR containing the tag value used for tagging data from a public untrusted source as described elsewhere herein. For Row 901c identifies a CSR containing a default tag value that may be used as a default tag value when tagging data and/or instructions.
Rows 901d and e, respectively, denote the address and data for writing to the opgroup/care table (e.g., also referred to elsewhere herein as a mapping or translation table including opgroups and care/don't care bits for opcodes). Writing to the CSR denoted by row 901e triggers a write to the opgroup/care table. Row 901f identifies a CSR that may be written to in order to flush the PUMP rule cache. Rows 901g-901m identify CSRs providing tag inputs for a current instruction to the PUMP and rule cache miss handler. Rows 901j-m each denote a different operand tag for an operand of the current instruction being processed causing the rule cache miss whereby an instruction may include up to 4 such operands (with 3 of the 4 operands being registers (CSRs 901j-1) and a 4th operand being a memory location with a tag stored in the CSR denoted by row 901m). Row 901n identifies a CSR holding the extended opcode bits when the opcode of the current instruction uses the extended func12 field as described elsewhere herein. Row 9010 identifies a CSR indicating which subinstruction in a word is the current instruction being referenced. As discussed elsewhere herein, a single tagged word may be 64 bits and each instruction may be 32 bits whereby two instructions may be included in a single tagged word. The CSR denoted by row 9010 identifies which of the two instructions is being processed by the PUMP. Rows 901p-q identify CSRs including PUMP output tags, respectively, of the new PC (e.g., new PC tag for the next instruction) and the RD (destination register, address for result of the current instruction). Writing to the CSR denoted by 901q causes a write of the rule (e.g., matching a current instruction that triggered a PUMP rule cache miss) into the PUMP rule cache. Row 901r identifies a tagmode for PUMP operation. Tagmodes are described in more detail elsewhere herein.
In at least one embodiment, the one or more tables (e.g. opgroup/care table) used to store opgroups and care/don't care bits may be populated by writing to CSR sopgrpvalue denoted by 901e where the contents of the foregoing CSR 901e is written to the address stored in the sopgrpaddr CSR denoted by 901d. A rule may be written or installed into the PUMP rule cache responsive to writing to the srtag CSR define by entry 901q. The rule written is the rule specifying tag values matching the opcode (or more specifically the opgroup for the opcode) and tag values for the current instruction as input to the PUMP via PUMP CSRs (e.g., based on PUMP CSR inputs 901g-o).
To allow tagging and tag protection on CSR operations, the dataflow allows CSR tags to be inputs to, and outputs from the PUMP. In accordance with the RISC-V architecture, there are read and write instructions, respectively, to read from, and write to, CSRs. In connection with a CSR instruction with the PUMP, the R2tag input to the PUMP is the current CSR tag. The CSR read/write instructions (e.g., csrrc, csrrci, csrrs, csrrsi, csrrw, csrrwi) write two outputs: (1) RD, and (2) the CSR referenced by the instruction. In this case, the PUMP output R tag (or RD tag of the destination) specifies the CSR tag output by the PUMP and copying the CSRtag directly to the register destination tag:
In connection with privilege denoted by column 904, CSR mtagmode, defined by row 901r, is accessible for read/write by code executing at the machine or M-mode level. The remaining CSRs defined by rows 901a-q are accessible for read/write by code executing at least at the supervisor or S-mode level. Thus, the privileges indicated in column 904 for the various CSRs denote a minimum RISC-V privilege level of executing code in order for the code to access the particular CSR. An embodiment may assign different RISC-V privilege levels with CSRs used in an embodiment than as illustrated in the example 900.
An embodiment in accordance with techniques herein may define multiple tag modes affecting tag propagation performed by the PUMP. The current tag mode is identified by the value at a current in point in time stored in the CSR mtagmode as defined by row 901r. In at least one embodiment, tag mode may be used in combination with the RISC-V defined privileges (e.g., M, H, S and U modes described above) to define a CSR protection model used in connection with the PUMP.
In order to allow the rule cache miss handler placement to be configurable, a protection model may be utilized that further extends the RISC-V privileges. Rather than defining PUMP CSR access entirely by privilege level, CSR access may be further defined relative to the current tag mode in combination with the RISC-V privilege levels. Thus, in at least one embodiment in accordance with techniques herein, whether executing code is allowed to access a CSR may depend on the minimum RISC-V privilege level of the CSR, the current tag mode and the current RISC-V privilege level of the executing code. Tag modes are discussed below in more detail.
Referring to
In connection with rows 911c-f, denoted are different tag modes that may be specified for engaging or disengaging the PUMP for code executing at different RISC-V privilege levels. When the PUMP is engaged, the PUMP may be characterized as active, enabled and providing protection when code is executed whereby the rules of its policies are enforced during code execution. In contrast, when the PUMP is disengaged, the PUMP may be characterized as inactive, disabled and not providing protection when code is executed whereby rules of its policies are not enforced during code execution. When the PUMP is disengaged, tags may be propagated using one or more default tag propagation rules rather than have tags propagated based on evaluation of a rule with tag values matching those of the current instruction. Whether the PUMP is engaged or disengaged may vary with the particular assumed level of trust and desired level of protection attributed to code that executes at different RISC-V privilege levels.
In connection with tag modes 911c-f, all PUMP CSRs of the example 900, except for the mtagmode CSR denoted by 901r, may be accessible only when the PUMP is disengaged. That is, PUMP CSRs of the example 900, except for the mtagmode CSR denoted by 901r, are only accessible to code executing at a current RISC-V operating privilege or mode that is more privileged than the highest ranked PUMP privilege denoted by the tag mode (e.g., highest ranked privilege denoted by 911c is U mode, highest ranked privilege denoted by 911d is S mode, highest ranked privilege denoted by 911e is H mode, and highest ranked privilege denoted by 911f is M mode).
When tag mode is 100 as denoted by 911c, the PUMP is disengaged and not operational when the RISC-V privilege level denotes a higher or more elevated privilege level than U-mode. Thus, tag mode 911c indicates that the PUMP and its rules providing protection are only engaged and enforced when code executes at U-mode thereby indicating that code executing at a privilege level higher than U-mode (e.g., at S, M, or H mode) is trusted. When tag mode is 100 as denoted by 911c and the RISC-V protection level of executing code is S, M, or H mode, the PUMP is disengaged and its CSRs are accessible to code that executes only in the S, M or H mode (e.g., CSRs are not accessible to code executing in U-mode).
When tag mode is 101 as denoted by 911d, the PUMP is disengaged and not operational when the RISC-V privilege level denotes a higher or more elevated privilege level than S-mode. Thus, tag mode 911d indicates that the PUMP and its rules providing protection are only engaged and enforced when code executes at S-mode and U-mode thereby indicating that code executing at a privilege level higher than S-mode (e.g., at M or H mode) is trusted. When tag mode is 101 as denoted by 911d and the RISC-V protection level of executing code is M or H mode, the PUMP is disengaged and its CSRs are accessible to code that executes only in the M or H mode (e.g., CSRs are not accessible to code executing in S or U mode).
When tag mode is 110 as denoted by 911e, the PUMP is disengaged and not operational when the RISC-V privilege level denotes a higher or more elevated privilege level than H-mode. Thus, tag mode 911e indicates that the PUMP and its rules providing protection are only engaged and enforced when code executes at H-mode, S-mode and U-mode thereby indicating that code executing at a privilege level higher than H-mode (e.g., at M mode) is trusted. When the tag mode is 110 as denoted by 911e and the RISC-V protection level of executing code is M mode, the PUMP is disengaged and its CSRs are accessible to code that executes only in the M mode (e.g., CSRs are not accessible to code executing in U, H or S mode).
When tag mode is 111 as denoted by 911f, the PUMP is always engaged and operational for all the RISC-V privilege levels of M, H, S and U. Thus, tag mode 911f indicates that the PUMP and its rules providing protection are engaged and enforced when code executes at any of M-mode, H-mode, S-mode and U-mode thereby indicating that no code is inherently trusted. With tag mode=111 as denoted by 911f, the PUMP is never disengaged and its CSRs are not accessible to any executing code.
In connection with tag modes denoted by rows 911c-f, when the current RISC-V privilege level of executing code is higher than the highest engaged PUMP level denoted by tag mode, the PUMP may be disengaged and tags may be propagated using one or more default tag propagation rules.
When the tag mode has an encoding of 000 as denoted by row 911a (indicating the PUMP is off) or when the tag mode has an encoding of 010 as denoted by row 911b (indicating write default mode), all CSRs of table 900 may only be accessible by code executing in M mode.
Thus, in at least one embodiment in accordance with techniques herein, whether executing code is allowed to access a CSR may depend on the minimum RISC-V privilege level of the CSR (such as specified in column 904 of table 900), the current tag mode, and the current RISC-V privilege level of the executing code. For example, in the RISC-V architecture without considering tag mode, code executing at U-mode is not allowed to access any of the CSRs defined in 900 due to the minimum privilege levels denoted by 904 for all such CSRs. However, without considering tag mode, code executing with a privilege of at least H-mode is allowed access to all CSRs of 900 except for 901r and code executing in M mode is allowed to access all CSRs of 900. Now consider determining CSR access for CSRs of 900 in accordance with the minimum RISC-V privilege of 904 and tag mode. For example, consider code portion A executing at H-level. Code portion A is allowed to access CSRs 901a-q (of table 900) when the tag mode is 100 as denoted by 911c or when the tag mode is 101 as denoted by 911d. Code portion B executing in S mode, however, may not be allowed access to CSRs 901a-q since it does not have the minimum privilege level specified by the defined CSR privilege level in 904 for such CSRs. Thus, for example, code portion A may be the cache miss handler in one embodiment executing at H-level using CSRs as defined in table 900. As a second example, assume the minimum RISC-V privilege defined for CSRs 901a-q is SRW (denoting S mode as the minimum privilege level to access such CSRs). Code portion A executing in H mode is allowed to access CSRs 901a-q when the tag mode is 100 as in 911c and when the tag mode is 101 as in 911d, and code portion B executing in S mode is allowed to access CSRs 901a-q when the tag mode is 100 as in 911c. Thus, code portion A or B may be code of the cache miss handler.
In at least one embodiment, the off tag mode of 911a may be current tag mode when the PUMP is off such as during appropriate parts of the boot up process. The default tag tag mode of 911b may be the current tag mode when initializing memory locations to have the same default tag (e.g., as denoted by CSR 901c). Generally, although 4 privilege modes are specified in the RISC-V architecture, an embodiment may alternatively use a different number of privilege modes where a first privilege level denotes a user mode or unprivileged mode and a second privilege level denotes an elevated or privileged mode of execution (e.g., similar to kernel mode in a UNIX based operating system). In such an embodiment, the PUMP may be engaged and enforcing policy rules when executing code in user or unprivileged mode and the PUMP may be disengaged (e.g., PUMP protection off or not enforcing rules) when executing code in the second elevated privilege mode. In this manner, an embodiment may disengage the PUMP when executing trusted or elevated privilege code such as a miss handler to store a new rule in the PUMP rule cache.
As noted above, an embodiment may use default propagation rules to determine PUMP outputs new PC tag and R tag, for example, when the PUMP is disengaged and/or when the rule specifies don't care for the PUMP outputs new PC tag and R tag (e.g., such don't care values may be indicated by the care vector for a particular opcode of the current instruction). In one embodiment, the following may denote logic embodied in default propagation rules used.
In at least one embodiment of techniques herein based on the RISC-V architecture, a new PUMP miss trap may be defined for a rule cache miss occurrence. The PUMP miss trap may have a lower priority than virtual memory fault or illegal instructions.
n at least one embodiment in accordance with techniques herein using the RISC-V architecture, strict separation and isolation between data and metadata may be maintained where there is separation and isolation between tag metadata processing and normal instruction processing. Thus, separate execution domains between metadata rule processing and normal or typical program instruction execution may be maintained. Metadata processing performed using the PUMP for tags associated with instructions and data of executing code may be performed. A PUMP rule cache miss results in a trap causing transfer of control to a rule cache miss handler that generates or retrieves a rule matching the current instruction and stores the rule in the PUMP rule cache. Information may be communicated between the above-noted execution domains using CSRs. When switching from the instruction execution domain of an executing program to the metadata rule processing domain (such as when the rule cache miss handler is triggered via rule cache miss trap), tags and other information relevant to the instruction (causing the trap) may be provided as inputs to the PUMP and also the miss handler using CSRs. In a similar manner, when transferring control from the metadata rule processing domain to the instruction execution domain of an executing program (such as when returning from the rule cache miss handler after handling a rule cache miss trap), PUMP outputs may be communicated using CSRs where the contents of the CSRs are then stored in corresponding mapped registers in the instruction execution domain. Consistent with discussion herein, an instruction which does not map to a rule (e.g., no matching rule for the instruction is located in the cache and the cache miss handler determines that no such matching rule exists for the current instruction) indicates that the rule is not allowed to execute whereby a trap or other event is triggered. For example, the processor may stop execution of the current program code.
In this manner, there may be strict separation between the foregoing domains and associated data paths even though the same RISC-V processor and memory may be used in both domains. Using techniques herein, no instructions of executing code are allowed to read or write metadata tags or rules. All metadata transformations including tagging instructions and data may be done through the PUMP. Similarly, rule insertion into the PUMP cache may be performed only by the rule cache miss handler of the metadata subsystem. In connection with processing performed by the metadata subsystem or processing system, the metadata tags of the executing code are placed in PUMP CSRs and become the “data” input to, and operated upon, by the metadata system (e.g., pointers are into metadata memory space). The metadata subsystem reads the PUMP inputs via the PUMP input CSRs for processing in accordance with rules. If the instruction is allowed to proceed via the rules, the PUMP writes tag results (e.g., such as for PC new and R tag) to defined PUMP output CSRs. Rule insertion into the rule cache may be triggered responsive to writing to a particular CSR (e.g., such as the srtag CSR in 901q). In this manner, all tag updates are done through rules in the PUMP and controlled by the metadata subsystem. Only the metadata subsystem can insert rules into the PUMP cache via the cache miss handler invoked upon occurrence of a rule cache miss. Additionally, in at least one embodiment as described herein using the RISC-V architecture, the foregoing separation between metadata processing and normal instruction processing may be maintained without adding any new instructions beyond those in the “RISC-V user level ISA” and the “RISC-V privileged ISA”. Consistent with discussion elsewhere herein, an embodiment in accordance with techniques herein may maintain strict separation and isolation between data and metadata whereby there is separation between metadata processing based on tags and normal instruction processing. In at least one embodiment, such separation may be maintained by having a separate physical metadata processing subsystem with a separate processor and a separate memory. Thus, a first processor and a first memory may be used when processing instructions of an executing program and a second processor and a second memory may be included in the metadata processing subsystem for use with performing metadata processing such as when executing code of the rule cache miss handler.
Referring to
Metadata processing subsystem 1004 is a processor (also referred to as the metadata processor) that includes components used in connection with metadata rule processing using tags of a current instruction and associated data provided as inputs to the PUMP 1003. The PUMP 1003 may be as described elsewhere herein and includes a rule cache. For example, in at least one embodiment, the PUMP 1003 may include the components illustrated in
The example 1000 illustrates an alternative embodiment having a separate metadata processing subsystem 1004 rather than performing metadata processing on the same subsystem as used for normal program execution as described elsewhere herein. For example, rather than have a separate metadata processor or subsystem 1004, an embodiment may include only the PUMP 1003 and subsystem 1002. In such an embodiment with a single processor, CSRs may be used as described herein to communicate information between the metadata processing and normal processing mode executing a user program to thereby provide isolation and separation. In such an embodiment with a single processor rather than a separate metadata processor, code of the miss handler may be stored in the single memory in a manner so that it is protected. For example, without a separate metadata processor or subsystem, the code of the miss handler may be protected using tags as described elsewhere herein to limit access, may be mapped to a portion of memory that is not addressable by user code, and the like.
What will now be described are further details regarding PUMP I/O (input/output). It should be noted that PUMP I/O described below applies to embodiments of the PUMP which may use the same processor or subsystem as for normal code execution as well as those which may use separate processors or subsystems such as in the example 1000. Furthermore, the PUMP I/O described below may be used with an embodiment based on the RISC-V architecture and may be generalized for use with other processor architectures.
Referring to
First, consider the PUMP I/O associated with normal PUMP verification processing. PUMP inputs 1012 may include tags, such as the PC tag, the CI tag, instruction operand tags (e.g., OP1 tag, OP2 tag or CSR tag (for CSR-based instructions in RISC-V), OP3 tag, M Tag (for a memory location tag for memory instructions. Note that Mtag may also be referred to herein as the MR tag for a memory instruction), opcode information (e.g., op group denoted by Opgrp input, funct12 (funct7) input for RISC-V for extended opcodes, subinstr input providing an indicator of which instruction is the current instruction in an instruction word including multiple instructions such as in examples 200 and 220) and care input bits. The Opgrp may be the opgroup for the current instruction where Opgrp may be an output of a prior stage (e.g., stage 3 or stage 4) as described elsewhere herein. Funct 12 (funct 7) PUMP input may be the additional opcode bits, if any, for those RISC-V opcodes using additional bits of the instruction word (e.g., example 400). PUMP outputs 1014 may include Rtag (e.g., tag for the instruction result register or destination memory location), PC new tag (denoting the propagated tag placed on the PC used for the next instruction), and an indicator 1014a denoting whether there has been a PUMP rule cache miss resulting in a trap to the miss handler in stage 6.
The care bits 1012a may denote which PUMP inputs 1012 and which PUMP outputs 1014 are cared/not care about (e.g., ignored) for a particular instruction. Care bits regarding PUMP inputs may include a care bit for funct12 and a second care bit for funct7. As described elsewhere herein, both of the foregoing care bits denote whether the particular opcode of the current instruction includes any bits for the extended 12 opcode bit portion for a RISC-V instruction (e.g. 404a of the example 400). If both funct12 and funct7 care bits are “don't care”, then all 12 bits of the extended 12 opcode bit portion are masked out. If funct7 indicates “care”, then all the bottom 5 bits of the extended 12 opcode bit portion are masked out. If funct12 indicates “care”, then there is no masking of the extended 12 opcode bit portion.
Now consider the PUMP I/O associated with controlling rule insertion into the PUMP rule cache. PUMP inputs 1016 may be used in combination with inputs 1012 in connection with the PUMP cache rule insertion. PUMP inputs 1016 may include Opldata (an output from the metadata processor or subsystem), the instruction (from stage 6), and the tag mode (an output from the metadata processor or subsystem) and privilege (priv denoting the RISC-V privilege). The tag mode and priv inputs of 1016 are used by the metadata processor or subsystem to determine whether code, such as the miss handler or other code, executing in the metadata processor has sufficient privilege to access the CSRs described below and elsewhere herein providing the various inputs to the metadata processor (e.g., such as inputs 1012). Rdata 1018 is an input to the metadata processor or subsystem for use in stage 6 (e.g., cache miss handler processing input). It should be noted that Opldata, R data, and other items of the example 1010 are described in more detail in following paragraphs and figures.
Thus generally, in the example 1010, element 1012 denotes inputs to the PUMP and metadata processor from the processor executing user code (e.g. non-metadata processor or subsystem such as 1002), element 1014 denotes outputs generated by the metadata processor, element 1016 denotes outputs generated by the metadata processor input to the PUMP, and element 1018 denotes an input to the metadata processor.
Referring to
A second flow of I/O is illustrated in 1020 by inputs and outputs in the horizontal direction from left (inputs 1026) to right (output 1028). The second flow of I/O in 1020 is illustrative of processing performed in connection with controlling the selection of PUMP output Rdata 1028 which is input to the metadata processor or stage 6. The inputs 1026 are as described above in connection with 1016. The output 1028 is as described above in connection with 1018.
Referring to
Referring to
Element 1049 denotes how the Boolean engaged is determined as a function of current RISC-V privilege and the current tagmode. Element 1049 includes a logical expression using standard notation known in the art whereby “A==B” denotes if a logical test for equality between A and B, “A && B” denotes a logical AND operation of A and B, and “A∥B” denotes a logical inclusive OR operation between A and B.
Element 1041a and 1045a denote inputs to 1043a which are outputs from the rule cache lookup 1036. PC tag 1041b is the PC tag included in the PUMP inputs 1012. Other inputs 1041b generally denote multiple other inputs that may be possibly selected as the final R tag 1047 output by the PUMP. For example, in one embodiment, other inputs 1041b may include M tag, PC tag, CI tag, OP1 tag, OP2 tag, OP3 tag, and possibly others depending on the instruction. The particular R tag output 1047 may vary with the particular RISC-V instruction/opcode.
The following may summarize particular values for R tag 1047 and PC new tag 1043 generated as PUMP output values in one embodiment. It should be noted that following indicates particular R tag output values for different RISC-V instructions. Thus, the particular R tag values output as the final PUMP R tag value may vary with the instructions that utilize such PUMP outputs in connection with subsequent metadata processing.
1. PCtag does not change when output care bit is off for PC new tag
2. Rtag is Op1tag for CSRRW operations
3. Rtag is Op2tag (CSRtag) for CSRR?I, CSRRS, CSRRC operations
4. Rtag is PCtag for JAL and JALR instructions
5. Rtag is PCtag for AUIPC instruction
6. Rtag is Cltag for LUI instruction
7. Rtag is Op1tag for non-memory, non-CSR, non-JAL®/AUIPC/LUI operations when output care bit is off (indicates care for Rtag).
8. Rtag is Op2tag for memory write operations when output care bit is off
9. Rtag is Mtag for memory load operations when output care bit is off
Referring to
It should be noted that element 1052 of the example 1050 does not include all of the inputs of 1012. For example, funct12 (funct7) and subinstr inputs of 1012 are not illustrated in the example 1050 for purposes of simplicity. However, one of ordinary skill in the art appreciates that the inputs funct12 (funct7) and subinstr from 1012 may also be included in 1052. More generally, the inputs 1052 may be adapted for the particular inputs to metadata rule processing that may be used in an embodiment.
When the PUMP is performing processing for an instruction for normal PUMP verification (e.g., verify whether current instruction is allowed using policy rules), the inputs 1052 may simply pass through as the outputs 1054. The outputs 1054 in this case flow through to the PUMP as inputs such as inputs to components of
Upon the occurrence of a rule cache miss, as a first step, the current values from 1052 for the current instruction are loaded into registers G1-G7 of 1056. Thus, G1-G7 includes a snapshot of the opcode and tag values for the current instruction that caused the rule cache miss and such values may now be used in connection with subsequent processing by the cache miss handler reading out the one or more desired values of G1-G7 as needed for such processing.
Thus, in a second step, the cache miss handler executes, reads as inputs values from G1-G7 and generates the new rule for the current instruction. Multiplexer M16 may be used to control selection of the various possible inputs from G1-G7 where the selected output from M10 is denoted as R data 1053 for processing by the cache miss handler (e.g. which may execute on either the same processor as when executing program code or may otherwise executed on a separate metadata processor such as in the example 1000). Given the inputs G1-G7 for the current instruction causing the rules cache miss, the cache miss handler performs processing to determine the new rule to be inserted into the cache. The cache miss handler generates outputs R tag and PC new tag for the new rule just determined, writes the Rtag to the Rtag CSR G8, and writes the PC new tag to the PC new CSR G9. In the example 1050, Opldata 1051 denotes the outputs generated by the metadata processor such as the outputs Rtag and PC new tag for the new rule where such outputs are then stored in CSRs G8 and G9 as described.
At this time, the values in CSRs G1-G9 are the tag values for the new rule just generated by the cache miss handler and may be inserted/written to the rule cache as the new rule in a third step. In at least one embodiment using techniques herein with the RISC-V architecture, writing to the R tag CSR denoted by G8 triggers writing of the new rule (e.g., contents of CSRs G1-G9) to the rule cache. In connection with rule insertion, CSRs G1-G7 are provided as output 1052 and CSRs G8 and G9 are provided as output 1055 to the PUMP for storing into the rule cache. More specifically, in one embodiment, the outputs 1052 and 1055 may be provided to the components of
In the simple case, an embodiment may insert one new rule to satisfy the current rule miss by writing the contents of CSRs G1-G9 for the new rule to the PUMP rule cache as just described (e.g., via outputs 1052 and 1055). In such an embodiment, the multiplexers M1-M7 are not needed since Opldata 1051 output by the metadata rule processor executing the cache miss handler only generates R tag and PC new tag for the new rule. However, an embodiment may also allow for rule prefetching or inserting multiple rules into the rule cache. For example, upon the occurrence of a rule cache miss, the cache miss handler may determine multiple rules to be written to/inserted into the rule cache rather than just a single new rule for the current instruction. In this case, the Opldata 1051 may include additional new values for the opcode, PCtag, Cltag, Op1tag, Op2tag, Op3tag and Mtag (written to CSRs G1-G7) as well as new values for the Rtag and PC new tag (as written to CSRs G8 and G9). In such a case, multiplexers M1-M7 may be used to select the foregoing new values from Opldata 1051 as inputs, respectively, for CSRs G1-G7.
Generally, Opldata 1051 denotes output from the metadata processor to the PUMP and R data 1053 denotes output from the PUMP to the metadata processor. Also, element 1052 denotes inputs to the PUMP from the processor executing user code (e.g., as part of normal instruction processing) where values for element 1054 are equal to those as in 1052 when performing normal PUMP verification (e.g., verify whether current instruction is allowed using policy rules).
Referring to
In connection with non-memory operations, the Mtag is not needed as an input to the PUMP stage and the PUMP may continue performing processing without it. In the case of a memory operation instruction, the PUMP stalls until the Mtag has been retrieved from memory. Alternatively, an embodiment may perform Mtag prediction as described elsewhere herein. Consistent with discussion elsewhere herein, the PC new tag needs to provided back to the stage 1 such as illustrated and described in connection with
As described herein, an embodiment may associate a single tag with each word. In at least one embodiment, the word size associated with each tag may be 64 bits. The contents of the tagged word may contain, for example, an instruction or data. In such an embodiment, the size of a single instruction. However, an embodiment may also support instructions which are a different size other than 64 bits. For example, an embodiment may be based on the RISC-V architecture which, as described in more detail elsewhere herein, is an open source instruction set architecture (ISA) based on established reduced instruction set computing (RISC) principles. An embodiment using the RISC-V architecture may include instructions of multiple different sizes such as, for example, 32 bit instructions as well as 64 bit instructions. In such a case, an embodiment in accordance with techniques herein may associate a single tag with a single 64 bit word where the single word may therefore include one 64 bit instruction or two 32 bit instructions.
Referring to
Thus what will now be described are techniques that may be used in an embodiment in connection with multiple subinstructions in the same instruction word whereby a different tag may be used in connection with each of the multiple subinstructions.
Referring to
In an embodiment having multiple subinstructions within the same instruction word 205, an additional input may be provided to the PUMP indicating which of the subinstructions included in the instruction word 205 is being executed at a point in time. For example, where there are 2 subinstructions 204b-c in the instruction word 205, the additional input to the PUMP may be 0 or 1 indicating, respectively, whether subinstruction 1 204b or subinstruction2 204c is being executed at a particular point in time. In at least one embodiment consistent with discussion elsewhere herein based on the RISC-V architecture, a CSR (such as the ssubinstr CSR described elsewhere herein) may be defined which records or stores the additional input (denoting which subinstruction is being executed) to the PUMP. In at least one embodiment, the PUMP may normally receive the foregoing additional input from the data path (e.g., from the code execution domain) without use of a CSR. However, on a rule miss, the foregoing additional input may be recorded in a CSR so that the metadata processing domain in which the rule miss handler is executing may obtain the foregoing additional input (e.g., the CSR value for the foregoing additional input is provided to the PUMP on a rule insertion).
To further illustrate, an embodiment may include subinstructions which provide for transfer of control between two locations in a program. Examples of such subinstructions may be those that provide for jumping, branching, returning or more generally transferring control from a source location in the code to a target (e.g., sink or destination) location in the code. In connection with CFI or control flow integrity described elsewhere herein, it may be desirable to have the PUMP implement rules of a CFI policy to limit or control transfers between locations to only those supported by the program. For example, consider a case where a transfer of control is made from a source location in code having tag T1 to a target location in code having tag T2. Information used by the PUMP in enforcing the CFI policy may be a list of valid source locations which are allowed to transfer control to T2. In an embodiment of the CFI policy, two rules may be used to provide two checks of two instructions or opcodes when transferring control from the source to the target location. Consider a pseudo-code representation of the transfer or call as illustrated in the example 230 of
In at least one embodiment, the check of the second rule may be performed by determining whether the marked tag of the PC (as set by the first rule) identifying the source location 232 (e.g., which denotes the source location address X1) identifies a valid source location from which control may be transferred to target location 234. In such an embodiment, the second rule may be supplied with a defined list denoting all valid source locations which are allowed to transfer control to the target location 234. In at least one embodiment, the defined list may identify valid source locations, for example, by their addresses such as X1 noted above.
Referring to
The example 240 illustrates structures in one embodiment where the two subinstructions 204b-c are target locations. The subinstruction tag 242a points 243a to a location of a structure 245 including a source id field 245a and an allowed source set field 245b. The source id field 245a may be null in the case where the subinstruction 204b is not a source location, such as the case here with subinstructions 204b is a target location. The source set field 245b may be a pointer to a location including a list structure 247 identifying one or more valid source locations which are allowed to transfer control to the particular target location including subinstruction 204b. In at least one embodiment, the list structure 247 may include a first element denoting a size or number of valid source locations. Thus size 247a of “n” (n being an integer greater than 0) denotes the number of source locations denoted by elements 247b-n in the list 247. Each of elements 247b-n may identify a different valid source location which can transfer control to the target location including subinstruction 204b. In at least one embodiment, each of the allowed sources 247b-n may be a scalar or non-pointer that is, for example, the address of one of the valid source locations.
In the example 240, elements 243b, 246 and 248 used with subinstruction 2 204c are respectively similar to elements 243a, 245 and 247 as used with subinstruction 1 204b. Generally, in such an embodiment using the structures of 240, any item that does not exist may be assigned a null or zero value. If the instruction word 205 includes a pair of subinstructions 204b-c that are neither source nor destination locations, the tag 202b may be null (e.g., or otherwise identify a non-pointer or other pointer that does not point to a structure 242). If one of the subinstructions 204b-c is neither a source nor a target location of a transfer, its associated tag in 242 is null. For example, if subinstruction 204b is neither a source nor a target location but subinstruction 204 is a target, then 242a may be null and 242b may be as illustrated in the example 240. If a subinstruction 204b-c is not a source location, its source id is null (e.g., since 204b-204c in the example 240 are target locations, both 245a and 236a are null). If a subinstruction 204b-c is not a target location, its allowed source set field pointer is null. For example, if subinstruction 204b identified a source location rather than a target location, source id 245a would identify the address of the source location instruction and 245b would be null.
To further illustrate, reference is made to
It should be noted that the addresses of the source locations such as in entries 256b-d, and more generally, in any allowed source of the allowed source set (e.g., any of 248b-n of 248 of the example 240) may be a byte level address granularity.
In a manner similar to that just described for multiple instructions (also referred to as subinstructions) included in a single tagged word, an embodiment may allow access to data portions which are less than a single tagged word of data. For example, an embodiment may include instructions which access data at the byte level and it may be desirable to provide byte level tagging so that each byte may have its own associated tag in manner similar to providing a different tag for each of the multiple subinstructions included in a single tagged word. In following examples, reference is made to providing byte level tagging where each of 8 bytes included in a 64 bit word may have its own associated tag. However, more generally, techniques herein may be used to provide for sub-word tagging for any number of multiple data items included in a single tagged word. In such cases, the tag associated with the tagged data word may be a pointer to a structure identifying the byte level tags for the bytes of the tagged data word.
Referring to
Referring to
It should be noted that the particular level of data access granularity may vary with the particular architecture and instruction set in an embodiment. The foregoing may be used to provide byte level tagging in an embodiment which allows byte level data access. As a variation, an embodiment may support data access at a different level of granularity and techniques herein may be readily extended to any subword tagging level of granularity.
Similarly, the examples 260 and 267 illustrate one example of a data structure that may be used to hold the byte level or other sub word data tagging. As a variation, an embodiment may use a tree or other hierarchical structure to specify byte level tags for bytes of a single tagged data word. The tree or other hierarchical structure representing the byte level tags may be similar the hierarchical structure described herein with for storing word-level tags, for example, in connection with elements 100, 120, 130 and 140, respectively of
To further illustrate, an embodiment may use a tree structure to represent byte level tags as in the example 270 of
The example 270 illustrates a tree structure where there are no homogeneous byte level tags and each of the bytes B1-B8 of 265 has a different tag value. In a manner consistent with discussion elsewhere herein (e.g., with elements 100, 120, 130 and 140, respectively of
In an embodiment providing byte level tagging, or more generally subword tagging, within the same data word 265, an additional input may be provided to the PUMP indicating which one or more byte level tags (corresponding to which one or more of the bytes included in the word 265) are being referenced. For example, with byte level tagging where there are 8 bytes B1-B8 in a single tagged data word 265, the additional input to the PUMP may be a bitmask of 8 bits where each of the 8 bits is associated with a different one of the bytes B1-B8 and denotes whether to use the byte level tag for the particular byte of the word 265. As a variation, an embodiment may denote the one or more bytes by specifying a byte range, such as starting byte and length or size (e.g., bytes B4-B8 by specifying starting byte B4 and denoting a size or length of 5). In at least one embodiment consistent with discussion elsewhere herein based on the RISC-V architecture, a CSR may be defined which records or stores the additional input denoting which one or more byte level tags for the one or more bytes B1-B8 are to be used by the PUMP. The additional input may be, for example, the bitmask or other suitable representation identifying the particular byte level tags used by the PUMP. In at least one embodiment, the PUMP may normally receive the foregoing additional input denoting which one or more bytes are to be used as an input from the data path (e.g., from the code execution domain) without use of a CSR. However, on a rule miss, the foregoing additional input may be recorded in a CSR so that the metadata processing domain in which the rule miss handler is executing may obtain the foregoing additional input (e.g., the CSR value for the foregoing additional input is provided to the PUMP on a rule insertion).
As discussed elsewhere herein, at the policy level many instructions may be treated in a similar manner. For example, add and subtract instruction operation codes or opcodes may typically treat their metadata the same whereby both opcodes may behave similarly at the rule level for a particular policy by considering the same tag inputs to the PUMP and the same tag outputs propagated by the PUMP. In such a case, add and subtraction opcodes may be grouped together in a single operation group or “opgroup” so that the same set of rules may be used for all opcodes in that particular opgroup. How opcodes are grouped together is policy dependent and thus may vary with policy. In one embodiment, a translation or mapping table may be used which maps a particular opcode to its associated opgroup on a per policy level. In other words, a different mapping table may be created for each policy (or specified group of multiple policies having the same opcode to opgroup mappings) since the mappings may vary per policy.
For a particular opcode, the translation or mapping table may determine the opgroup as noted above and may also determine additional information for the particular opcode. Such additional information may include the care/don't care bit vectors as also discussed elsewhere herein which may indicate which PUMP inputs and PUMP outputs (e.g., input tags and propagated output tags) are, respectively, actually used as inputs for rule processing and propagated as a relevant output of rule processing for a particular opcode. The don't care bit vectors may be determined with respect to any PUMP input and output in an embodiment. In one embodiment, the don't care bit vector may indicate which input tags and output tags are relevant and may also indicate which particular opcode bits are actually used for a particular opcode. This is described below in more detail with respect to the RISC-V architecture and instruction formats but may also be more generally used in connection with other suitable instruction formats of different architectures. The forgoing translation or mapping table including opgroups and care/don't care bits for particular opcodes (e.g., element 422 of example 420 discussed below) may also be referred to as the opgroup/care table elsewhere herein.
RISC-V has multiple different instruction formats each using a different set of instructions bits for the opcode. Referring to the example 400 of
Illustrated in
In such an embodiment, the remaining 12 opcode bits of funct 12 404a of an instruction may be provided as an input to the PUMP where appropriate portions of 404a are masked for the particular opcode. Information regarding which particular bits of funct12 404a should/should not be masked for a particular opcode may be included in the care/don't care bit vector information output from the mapping table 422 lookup for the opcode. In at least one embodiment based on the RISC-V architecture, the care/don't care bit vector information may indicate one of the following with respect to the 12 opcode bits of funct 12 404a for an opcode:
1. all 12 bits may be masked since no bits of 404a are used;
2. 7 of the 12 bits, as denoted by 402a, are used where the bottom most 5 bits of 404a (e.g., bits 20-25) are masked out; or
3. all 12 bits of 404a are used and therefore there is no masking of an bits of 404a.
Also, in such an embodiment, the 12 opcode bits of funct12 404a may be recorded or stored in a CSR, such as sfunct12 CSR described elsewhere herein, provided as a PUMP input in connection with performing rule insertion into the PUMP. In at least one embodiment, the PUMP may normally receive the foregoing opcode bits from the data path (e.g., from the code execution domain) without use of a CSR. However, on a rule miss, the foregoing may be recorded in a CSR so that the metadata processing domain in which the rule miss handler is executing may obtain the foregoing as an input (e.g., the CSR value is provided as an input to the PUMP on a rule insertion).
In at least one embodiment in accordance with techniques herein, multiple user processes may execute using a virtual memory environment where physical pages are mapped into a user process address space. Techniques herein may be utilized to allow sharing of physical pages of memory among multiple user processes where the same set of one more physical pages that may be simultaneously mapped into multiple user process address spaces. In at least one embodiment, tags used by such processes for which the sharing is allowable may be characterized as global having the same value and meaning or interpretation across user process address spaces.
Referring to
Similarly, physical pages of memory 432 may be mapped into virtual address space 436 where the contents of the mapped physical page may be accessed by P2 using the mapped virtual addresses of such mapped physical pages. For example, physical page A 432a may be mapped into a subrange X2 of P2's virtual address space. Process P2 may, for example, read a data item or instruction from a location in page A 432a by referencing a particular virtual address in the subrange X2.
The tags 431 may denote the tags on the memory locations of page A 432 where such tags may be used by the PUMP in connection with rule processing as described herein. Since page A 432 is shared by both P1 and P2 via the mapping as illustrated, the same set of tags 431 are also used by the PUMP in connection with executing instructions of both P1 and P2. In such an embodiment, the tags 431 may be characterized as global tags shared by both P1 and P2. Additionally, in at least one embodiment, the global tags 431 shared by multiple processes P1 and P2 are interpreted in a similar manner such as using the same rules and policies. For example, a first tag having a value of 100 may be associated with a first memory location in 432a. The first tag may denote a value representing a coloring of the first memory location used in connection with rules of policy which determine whether it is allowable for a particular executing instruction to perform an operation referencing the first memory location, or its contents. The first tag may be interpreted as the same color by the rules in connection with instruction execution of both P1 and P2. For example, the tag value of 100 needs to be interpreted as the same color by the rules in connection with both P1 and P2. Furthermore, the same set or instance of policies and rules may be used by the PUMP for both P1 and P2.
In such an embodiment which uses global tags on shared memory as described above, it may be desirable to also allow for further differentiating or allowing different access, authority or operations on a per process basis. For example, assume that page A 432a includes data shared by both P1 and P2. However, it may be desirable to allow different operations or access with respect to the shared data of 432a on a per process basis even though global tags are used to tag the shared page A 432a. For example, process P1 may have write access to page 432a and process P2 may have read-only access to page 432a. However 432a may be a shared memory page tagged with global tags. In such an embodiment with global tags on the shared page, the same policy and set of rules may be used in connection P1 and P2 where different read and write access capabilities for each process may be differentiated using different tag values on the PC. For example, process P1 may be include a first instruction which performs a write to a memory location in 432a and the current PC tag has a value of X. Rules of an access policy may perform the following logic:
In such a case, the PC tag has a value of X which is interpreted by the rules to allow write access for process P1 and thus P1 is allowed to execute the first instruction. Process P2 may be executing a second instruction which performs also performs a write to a memory location in 432a and the current PC tag has a value of Y. In such a case, the PC tag has a value of Y which is interpreted by the rules to not allow write access and rather allow read-only access for process P2 and thus P2 is not allowed to execute the second instruction.
Thus, in at least one embodiment, the PC tag may be used to encode privilege, access or authority that may differ per process whereby the particular allowed privilege, access or authority may be represented by different PC tag values.
An embodiment may specify a particular PC tag value to be used for each process in any suitable manner. For example, privileged code may execute as part of operating system startup or initialization which initially specifies a PC tag value to be used for a particular process. As a variation, an embodiment may perform a mapping operation as part of mapping the shared page A 432a into a process address space. The rules applied by the operating system when performing the mapping may propagate or produce a particular PC tag as an output that denotes a desired access, privilege or authority based on the particular process.
In this manner, the same set of rules may be used with shared pages having global tags where the rules encode the logic for the difference in access, authority or privilege based on the PC tag. It should be noted that the PC tag may also be a pointer to a memory location whereby the pointer tag points to a structure including different tag values for different policies in a manner as described herein in connection with other tags. In this manner, the same set of PC tag values may be used to denote different capabilities for a process that may vary with policy. For example, the PC tag value of X as described above with P1 may have a first use as described above with a memory safety policy or data access policy for shared regions. The same PC tag value of X may have a second use and meaning imparted by rules of a second different policy, such as control flow integrity (CFI).
Aspects of the CFI policy are described herein that may be used in connection with restricting control transfers based on a static definition of allowable calls, jumps, return points, and the like. However, an additional aspect or dimension that may be included in a CFI policy relates to enforcement of dynamic or runtime call information thereby further refining the conditions under which a control transfer that is a return may be made. To further illustrate, reference is made to the example 500 of
A static CFI policy may, for example, allow all potential control flows between any two transfer points without further restricting control flows or transfers based on the current runtime stack or call chain reflecting the dynamic runtime control flow aspects. For example, For example, if foo 502 can call bar 504 as illustrated in 500, there is a statically allowed control flow from bar back to address X2 of the instruction after the call of bar at X1 in foo. However, if foo has not been invoked, or has only, so far, invoked another call to something that should return before the bar call, it should not be possible to exercise the return link to return to X2. As another example with the runtime execution as illustrated in the example 500, it should not be possible for a call to Bar 504 through 501a to return to Foo 502 at Y2 through 501d.
What will now be described are techniques that may be used in connection with extending rules of a CFI policy to enforce a dynamic CFI return policy controlling return flow path control. For the dynamic CFI return policy to ensure that a return to a particular return location such as X2 is valid only when made subsequent to a particular call or invocation, such as the call to bar at X1, the dynamic CFI return policy may store information, such as in one or more tags, when the call is made in order to rule out an invalid return. As known in the art, when a call is made, such as using a JAL (jump and link) instruction of the RISC-V instruction set, a return address is saved in a return address register, RA. The RISC-V instruction set also includes a JALR (jump and link register) instruction which is an example of a return instruction. In one aspect, the saved return address in RA register from a JAL may be characterized as a “capability” to return to that point. In at least one embodiment, the JAL instruction may be tagged with a tag that causes a rule to push a suitable tag capability onto the resulting return address. For example, with RA as the return address register, a rule may place a tag on the RA register which indicates that the RA register includes a valid or suitable return address and, at a later point, the address of the RA register may be used as a return point to which control may be transferred. In other words, the tag on the RA register gives permission for the address in RA to be used as a return address which is loaded into the PC to execute the return transfer of control. When loading the PC with the address of RA, the RA tag may also be stored as the PC tag by rules of the CFI policy.
To further illustrate techniques that may be used to limit control flow on returns, an embodiment may code tag each return point (e.g., X2, Y2) with a dynamic-CFI-tag, such as expect-A. Also, code tag each JAL instruction (or call instruction) causing a rule evaluated for the JAL instruction to tag the return address in the RA register (where the return address is calculated by the JAL) with the appropriate dynamic—CFI-return-to-A tag. For each return, such as each JALR instruction that uses the RA register tagged with the dynamic-CFI-return-to-A tag, a PUMP rule propagates the tag (dynamic-CFI-return-to-A tag) onto the PC as may be performed in connection with other static CFI policy rules. The rules of the CFI policy may embody logic that checks the RA register used for the return instruction. If the RA register used for the return is not tagged with dynamic-CFI-return-to-A tag, then it is known that the RA register does not include a valid return address allowed for use with the JALR instruction. At the return point (e.g., X2 and Y2), rules may embody logic whereby when the expect-A code tag is encountered (e.g., as the tag on the instruction at X2), check that the PC is tagged with dynamic—CFI-return-to-A, and clear the CFI-return-to-A tag from the PC.
As a consequence of the above, code is prevented from returning to just any return address. Furthermore, if the return address is copied to another location, such as another register, the rules can prevent the copied value from retaining the return authorization capability; this prevents code form making copies of the return address in registers that can be used to perform multiple returns for the same call. As another consequence of the above, if a valid return address (properly tagged) on the stack is overwritten with a new address (not properly taged) and then an attempt is made to return to the new address, the return is prevented.
An embodiment may also include rules in order to prevent or further limit the ability to use the dynamic-CFI-return-to-A tag more than once. As a first implementation, an embodiment may use rules that restrict where the return address (as stored in the RA register tagged with the dynamic-CFI-return-to-A tag) may be written or copied. For example, an embodiment may use rules that only allow the return address of the appropriately tagged RA register to write the return address to the stack in properly code-tagged function code. As a second alternative implementation, an embodiment may include rules that use PC state (e.g., PC tag) and atomic memory operations to make the return address linear (e.g., follow or occur subsequent to a call). For example, performing a call sets the PC tag to denote a valid-return-address. Rules may only allow a return if the PC tag is set to valid-return-address. Additional rules may be used that, when writing a return address to memory, sets the PC tag to no-return-address. Rules may be used that, when copying the return address to a target register, may set the PC tag to no-return-address, and the target register is not tagged as a valid-return address. Rules may be used that, when an arithmetic operation is performed using a return address from an RA register, the result is not tagged as a valid return address. Rules may be used that only allow recovering a return address from memory with an atomic swap operation with a non-return-address (e.g., where the PC tag is set to valid-return-address).
An embodiment may further define rules to provide a stack protection policy. In one aspect, the stack protection policy may, in part, be viewed as an extension of one or more other policies, such as memory safety where the rules may use tags of both instructions and data for policy enforcement. It should be note that in following discussion and elsewhere herein, terms such as routine and procedure may be used interchangeably and more generally refer to a callable unit of code that, when invoked, results in creation of a new stack frame on the call stack. Other names that may also be used for a callable unit of code may include function, subroutine, subprogram, method, and the like.
Referring to
Information stored in a stack frame (such as 522, 524, 526) for a runtime call instance or invocation may include, for example, return addresses, data used by that call instance for registers, variables or data items, and the like. Elements 522a and 524a may denote return addresses, respectively, included in frame 522 for foo and frame 524 for G1. One common attack, such as may be performed by malicious code, may be to modify return addresses such as 522a and 524a stored on the stack 520. Using the techniques such as described elsewhere herein for the dynamic CFI return policy (e.g., described in connection with
As described below in more detail, different levels of stack protection may be provided. In one aspect, stack protection may be determined based on static procedure (also referred to as the static authority protection model described elsewhere herein) or may be determined based on both procedure and also invocation instance of the particular procedure (also referred to as the instance authority protection model described elsewhere herein). With the static authority protection model, rules of the stack protection policy may provide stack protection based on the particular procedure or routine that creates the frame. For example, rather than the stack including only a single frame for a single instance of foo as in 520, there may be multiple invocation instances of foo including in the current call chain at a point in time and thus multiple call stack frames in the stack for routine foo (e.g., such as based on recursive calls to foo). Based on the static routine or procedure, any instance of foo may be able to modify or access information in any call stack frame for an instance of foo. For example, foo instance 1 may have call stack frame 1 and foo instance 2 may have call stack frame 2. Based on static routine or procedure for stack protection, code of foo instance 1 may be able to access stack frames 1 and 2 and code of foo instance 2 may also be able to access stack frames 1 and 2. In such an embodiment, call stack frames for all instances of the same procedure or routine foo may be colored with the same tag. For example, frame 1 for foo instance 1 and frame 2 for foo instance 2 may be both be colored with tag T1 so that rules of memory safety policy will allow the above-noted stack frame access across different instances of the same routine or procedure.
As further finer granularity of stack protection, an embodiment may use rules of the stack protection policy that further limit access of the stack based on static routine or procedure as well as the particular runtime instance of the routine or procedure (e.g., the instance authority protection model). For example, foo instance 1 may have call stack frame 1 and foo instance 2 may have call stack frame 2 as noted above. Based on static routine or procedure and also invocation instance for stack protection, code of foo instance 1 may be able to access stack frame 1 but not stack frame 2, and code of foo instance 2 may be able to access stack frame 2 but not stack frame 1. In such an embodiment, call stack frames for each invocation instance of a procedure or routine may be colored with a different tag. For example, frame 1 for foo instance 1 may be colored with tag T1 and frame 2 for foo instance 2 may be colored with tag T2 so that rules of a memory safety policy will allow the above-noted stack frame access based on each particular invocation and routine or procedure.
An embodiment may further provide a finer level of granularity for different regions or portions of the stack for a single procedure call instance such as by coloring different objects or data items in a stack frame each with a different color (also referred to as the object protection model described elsewhere herein). As described elsewhere herein, the stack frame may include storage for data items or objects used in a particular invocation of a routine or procedure where each such data item or object may be tagged with a different color. For example, referring to
As yet a further variation, an embodiment may define different trust regions or boundaries for sets of code (e.g., routines, procedures, etc.) and provide different levels of protection. For example, not all routines invoked may have the same level of trust. For example, a developer may have a first set of routines he/she has written and have a high level of trust that the operations performed by code of the first set does not contain any malicious code. However, the first set of routines may make calls into a library that was provided by a third party or obtained from the internet. The library may be untrusted. Thus, an embodiment may vary the level of protection based on the different bodies of code and the particular data items used by each. For example, with reference to example 550 of
Whether a particular routine, library or body or code has a particular level of trust may be determined based on analysis using one or more criteria and inputs. For example, based on runtime analysis and usage of code of a library, a level of trust may be determined. For example, if the library makes calls to yet other unknown or untrusted external or third party libraries, then the level of trust may be relatively low. A level of trust for a body of code may be used on the source or location from which the code was obtained. For example, use of code from a library obtained from the internet may be considered untrusted. In contrast, code developed by a particular developer which does not invoke any untrusted code may have a high level of trust.
The foregoing and other aspects of stack frames and stack protection are described in more detail below.
In connection with stack frames and with reference again to the example 530, a compiler may create a new stack pointer by adding an integer (the size of the frame) to the existing stack pointer. The old stack pointer may be pushed onto the stack (into the frame) and then recovered by reading it back from the stack. The addition to the stack pointer may represent the total size of a frame that includes many independent objects such as described above in 531 for the data items 540a-c. The stack needs space for these 3 data items 540a-c and the compiler is able to determine the total space needed for the data items 540a-c. In standard usage, the compiler accesses storage 532, 534 and 536, respectively, for these data items 540a-c by computing their addresses off of the stack pointer (or frame pointer that is created from the stack pointer). Thus, the compiler, runtime, and calling conventions in an embodiment may create and use pointers to different regions of the stack call frames by doing simple pointer arithmetic.
The static authority protection model indicates authority over objects belongs to the static code block, such as routine or procedure that creates the frame. Thus, as discussed elsewhere herein, procedure foo that creates a frame has authority to create pointers to things in that frame. In the simplest case, the same authority would allow foo to access any of the frames it creates, even if they were earlier or later on the stack. Static authority means tags (e.g., colors for memory cells, colored pointers, code tags (e.g., also referred to as instruction tags or tags on instructions) that create colored pointers) may be pre-allocated at load time. Instance authority protection provides authority based on the depth of the function invocation on the stack. Object protection indicates protection at the level of objects allocated on the stack, not just stack frames. Thus, object protection allows for detection and prevention of overflow from one object (e.g., array, buffer) within a frame into another object on the same frame, which is something not achieved using simple stack frame granularity PUMP rules with the static authority protection model or the instance protection model. Object protection can be applied to both the static authority protection model and the instance protection model. As a variation of object protection, an embodiment may also employ hierarchical object protection for hierarchical objects, such as a structure that includes multiple different data items subobjects, such as an integer, and an array. In at least one embodiment with hierarchical objects where a first object includes one or more levels each of one or more subobjects, a first tag may be generated for the first object and then additional subobject tags may be generated based on the first tag. Each subobject tag may be used to tag a different subobject. The subobject tag may be a value denoting the particular position of the subobject in the hierarchy. For example, tag T1 may be generated for use with a structure including 2 arrays as subobjects 2 and 3. A different subobject tags for each the 2 arrays may be generated from T1 and used to tag the 2 array subobjects.
What will now be described is processing that may be performed in connection with stack memory for different stack operations in an embodiment in accordance with techniques herein. At startup, the stack memory may have all memory cells marked or tagged using a free-stack frame tag. Consistent with other discussion and techniques herein, such tagging may be performed by invoking the PUMP rules. It should be noted that the initial tagging of stack memory cells to the free-stack frame tag may not be performed for the entire stack at once, but may rather be performed incrementally in the kernel page fault handlers that expand the stack.
In connection with allocating a new stack frame such as by the compiler, a new frame tag may be created for the newly allocation frame. A pointer to the new frame may be tagged with the new frame tag. For example, an embodiment may tag an instruction (e.g., such as an add instruction performing pointer arithmetic (by adding to the stack pointer)) that creates a new frame pointer where the tag on the instruction triggers the policy rule to create the new frame tag. Using rules and tag propagation, a special tag may be created for and used to tag the stack pointer. Subsequently, for each frame pointer, a unique frame pointer tag may be derived from the stack pointer special tag, and the frame pointer may be tagged with its unique frame pointer tag. In such an embodiment, the frame pointer tag may be created from a tagged copy (e.g., an add or 0) of the stack pointer.
When a new stack frame is allocated such as for a new invocation of a routine or procedure, memory cells of the newly allocated stack frame may be tagged or colored using, for example, a first technique referred to as strict object initialization or a second technique may be referred to as lazy object coloring.
With the first technique of strict object initialization, free stack frame cells of the newly allocated frame are all initially colored or tagged to the intended one or more colors such as based on the static objects of the frame. Such initial coloring may be performed as part of initialization processing of a newly allocated frame prior to subsequently using the frame, for example, to store information for the associated invocation. An embodiment may add code that triggers rules to perform the coloring or tagging of the free stack frame cells to the intended one or more colors such as based on the static objects of the frame. Code tags on instructions may be used to authorize and define associated memory cell coloring. Subsequent stores or reads of colored memory cells of the frame may be allowed or not based on the frame memory cell color such as in accordance with memory safety policy rules (e.g., for a memory cell tagged with color C1, a rule allows a memory operation to access the colored memory cell contents using a pointer having a tag also of the same color C1 but may not allow the memory operation if the pointer is of a different color C2). Additionally, a code tag on an instruction may provide authority to perform the memory operation within a procedure.
With the second technique of lazy object coloring, there is no initial coloring of all stack objects as with the strict object initialization technique. Rather, with lazy object coloring, a store to a stack memory location tagged as free stack frame results in triggering a rule that allows the store and also changes the color of the memory location based on the writer. A read to a stack memory location tagged as free stack frame is an uninitialized memory read and may be allowed/not allowed depending on whether the policy allows/disallows uninitialized memory reads. With lazy object coloring, no initial block of code is executed that invokes rules to completely initially tag all memory cells of a frame upon creation. Rather, memory cells are tagged by rules invoked in connection with store operations.
In at least one embodiment, whether to use strict object initialization or lazy object coloring may depend on a desired level of protection and an occurrence of untenable vulnerabilities.
Code within a routine or procedure that directly accesses data from the stack/frame pointer is code tagged to allow it do so. In connection with lazy object coloring, storing to a memory cell results in coloring the memory cell based on the writer as noted above. For example, with reference back to the example 530, a store instruction of routine foo having frame 531 may write a value to a memory location in array 532. In accordance with a current stack protection policy in effect, in order for a store instruction to write to a location in array 532 of the call frame for foo, the store instruction may be required to have a tag of Red1. A first rule of the policy may be triggered to perform this check for a store instruction. Thus, an embodiment may have a compiler generate a code sequence that triggers the first rule to tag the store instruction with Red1. (e.g., As a variation to the foregoing, the tag on a memory cell, such as Red1, may be related to but not the same as the tag on the instruction store or other instruction. For example, the “Red1code” CI tag may indicate that the instruction having this tag can access Red1 tagged memory cells and may create Red1 tagged memory cells). When the store instruction is the current instruction, the foregoing first rule may be triggered which checks the instruction tag to ensure it is Red1. As an output, the rule may tag the memory location in array 532 with the Red1 tag.
Code within a procedure that creates a pointer to a particular object is tagged to taint or set the pointer for that object. The pointer may be for the procedure's own use in subsequent instructions and/or may be passed to another procedure as an argument.
Storing register values to a frame or restoring register values from a frame may be based on the frame authority. The memory location(s) of the stack frame storing the register values may be treated as a unique object in the stack frame. Instruction tagging provides authority for such tagged store and load instructions. With lazy-object-coloring, the store instruction tagged with the authority to store data to a memory cell also provides the authority to tag the memory cell based on the writer (e.g., procedure including the store instruction).
Procedure arguments passed on the stack may be marked with a tag that allows both the caller and callee to access. Note that return addresses may be specially tagged (e.g., the dynamic CFI return policy described elsewhere herein such as in connection with
In connection with a return or other operation resulting in removing a frame from the stack (e.g., such as due to completion of a called routine), tagged code may clear the frame. The tags on such code provides the authority to change any frame object tags associated with this frame to the free-stack-frame-cell tag.
Code of a program executed in an embodiment of a computer system in accordance with techniques herein may include code that performs exception handling. As known in the art, exception handling is processing performed responsive to an exception denoting an occurrence of an anomalous or exceptional condition requiring special processing performed by the exception handler. Thus, when an exception occurs at a first point in a program, the normal flow of program execution may be interrupted so that control is transferred to an exception handler. Prior to transferring control to the handler, the current state of execution may be saved in a predetermined location. If program execution may be resumed after the exception has been processed by the handler, execution of the program may resume (e.g., control may then be transferred back following the first point in the program). For example, a divide by zero operation may result in an exception that is continuable where the program execution may resume after the exception is handled by the handler. In connection with implementing an exception handler, an embodiment may use library routines such as setjump and longjump. For example, setjump and longjump may be standard C library routines, respectively, setjmp and longjmp, defined as follows:
Setjmp saves the program's calling environment in the environment buffer specified by the env argument for later use by longjmp. If the return is from a direct invocation, setjmp returns 0. If the return is from a call to longjmp, setjmp returns a nonzero value.
Thus, setjmp may be used to save a current state of a program. The state of a program depends on, for example, the contents of memory (i.e. the code, globals, heap, and stack), and the contents of its registers. The contents of the registers includes the stack pointer, frame pointer and program counter. Setjmp saves the current state of the program so that longmp may restore the program state and thus return the state of the program execution to what it was when setjmp was called. In other words, longjmp( ) doesn't return. Rather, when longjmp is invoked, execution returns or resume to the particular point denoted by the previously saved program state (as saved by setjmp). Thus, longjmp( ) may be used to transfer control from a signal handler back to a saved execution point in a program without using standard calling or return conventions.
For example, reference is made to
In connection with a stack protection policy, it may be desirable to clear the stack prior to resuming execution to the point X1 previously saved by settmp. For example, based on the above call chain main-first-second, 3 stack frames may exist in the call stack and processing may be performed to clear stack memory associated with invocations in the call chain between the longjmp call and setjmp call. In particular, code of longjmp may include code that clears stack frames for first 563 and second 564 in this example. What will now be described are techniques that may be used in connection with performing such stack clearing in accordance with a stack protection policy.
In connection with a stack protection policy when performing a setjmp that saves program state to stack memory, an embodiment may tag the current stack pointer memory cell with a distinguished tag component so that, in connection with a subsequent longjmp, rules may check that the stack hasn't changed since the setjmp. Data may be saved to the setjmp data structure, jmpbuf, denoting the current program state. The saved data may include the stack pointer, program counter, a first pointer (tagged as being a pointer that is allowed to point to a memory location tagged with the distinguished tag component (e.g. point to the current stack pointer memory cell), and a second pointer (tagged as longjmp-clearing-authority-pointer to provide authority to perform longjmp processing). In at least one embodiment, the longjmp-clearing-authority-pointer may only provide authority to clear tags associated with frames in the set of procedures that could be recursively called from this procedure.
In connection with a stack protection policy when performing a longjmp, code may check that the current stack pointer denotes a deeper stack position than the saved stack pointer of the set jump structure (e.g., setjmp data structure, jmpbuf). A rule may be triggered that checks that the memory cell of the set jump structure containing the saved stack pointer (as saved by setjmp) has a tag that is compatible with the tagged first pointer (of the set jump structure). Code may be executed that clears all stack memory locations between the current stack pointer and the saved stack pointer (as previously saved by set jump in the set jump structure). Such code may be perform the clearing using the second pointer noted above that is tagged as the longjmp-clearing-authority-pointer providing the stack clearing authority (e.g., second pointer used to point to stack locations cleared). Rules may be triggered by the code performing the clearing where the rules check that the second pointer is tagged as longjmp-clearing-authority-pointer. Instructions in longjmp are uniquely tagged so that invoked rules allow the uniquely tagged instructions to use of a pointer tagged as longjmp-clearing-authority-pointer. Other code that is not in longjmp cannot use a pointer tagged as longjmp-clearing-authority-pointer (e.g., the other code is not tagged to allow use of longjmp-clearing-authority-pointer).
In at least one embodiment, tagging of instructions may be performed by having the compiler generate an instruction sequence that invokes rules to perform desired instruction tagging and/or memory location tagging. For example, for stack memory location tagging, the compiler may generate an instruction sequence with store instructions that trigger rules to initialize or reset the tag of a stack location. For tagging instructions, the compiler may generate an instruction sequence with store instructions that trigger rules to tag an instruction where the tag for the instruction may be based on the color associated with a tagged memory location accessed by the instruction. In connection with a return from a call having an associated stack frame, code may be added that clears the frame from the stack. When strict object initialization is employed and a new frame created in response to a call, code may be added that appropriately tags or colors objects of the new frame.
What will now be described with reference to
To further illustrate and consistent with discussion elsewhere herein, code, such as prolog code executed when a call is made, writes return addresses and registers to the stack. The prolog code may invoke rules that tag the stack locations with special tags to limit what code can modify or generally access the stack locations. For example, prolog code may perform memory writes/stores to store return addresses, registers, and the like, in a memory cell of a stack frame. Such write/store instructions of the prolog code may invoke a rule that tags a memory cell of the stack frame with a special tag STACK FRAME TAG to mark the memory location as special and limit what code can modify the memory cell. The write/store instructions of the prolog code may also be tagged with PROLOG STACK TAG to limit the instructions that can perform this tagging. The following is an example of logic enforced by the rule invoked by the write/store instructions of the prolog code that tags a memory cell of the stack frame with a special tag STACK FRAME TAG to mark the memory location as special and limit what code can modify the memory cell:
In the foregoing rule logic, output tag refers to the tag placed on the stack location.
In a similar manner, other code, such as epilogue code invoked with performing a return, may be allowed to clear the stack, or portion thereof. The epilogue code may be tagged with the special tag of EPILOG STACK TAG (e.g., CI tag) and may be given authority through access of a pointer tagged with the special tag STACK FRAME TAG. The epilogue code may perform the foregoing stack clearing using write/store operations using the pointer specially tagged with STACK FRAME TAG. To further limit performing stack clearing, the epilogue code may be tagged as noted above. In such an embodiment, the write/store instructions may invoke a rule implementing the following logic to enforce the policy where stack clearing may only be performed by epilogue code using the specially tagged pointer (tagged with STACK FRAME TAG):
Code that is intended to restore return addresses and registers from the stack may be given authority to read these specially tagged memory cells of the stack. Such authority may be given, for example, by any of: tagging the code (CI tag) to denote the code is allowed to access the specially tagged memory cells of the stack, tagging the PC to indicate the code has the authority, or tagging a pointer used by the code where the pointer points to the specially tagged memory cells and the tag on the pointer denotes the access authority. For example, a read/load instruction may be given authority to read the stack memory cells tagged with STACK FRAME TAG. In one embodiment, the read/load instruction may be given authority by allowing only read/load instructions using the specially tagged pointer (tagged with STACK FRAME TAG) to read from a stack memory location. Rule logic allowing only read/load instructions using the specially tagged pointer (tagged with STACK FRAME POINTER) to read from the specially tagged stack memory location (tagged with STACK FRAME TAG) may be:
As a variation to the foregoing, the read/load instruction may be given authority by tagging a pointer used by the read/load instructions with the special tag STACK FRAME TAG.
Rule logic allowing only read/load instructions using the specially tagged instructions (tagged with STACK FRAME INSTRUCTION) to read from a stack memory location may be:
Examples of mechanisms are described below and elsewhere in more detail.
Element 572a identifies an undesired runtime behavior of a called routine (callee) that never returns to the calling routine (caller). To prevent this behavior, an action taken may be to have a timeout associated with each call where a maximum amount of time may be allowed to complete the invoked routine. After the maximum amount of time elapses, runtime execution of the invoked routine is terminated. Mechanisms to implement the timeout may include having the invoked routine of the third party code be made from a separate thread that enforces the timeout, or directly limiting the amount of time of the called routine using a time or instruction limited call.
Element 572b identifies an undesired runtime behavior of resource exhaustion where the called routine may use up an available resource, such as memory. To prevent this behavior, an action taken may be to limit resource made available to the called routine. Mechanisms to implement the timeout may include having the invoked routine of the third party code be made from a separate thread that enforces the maximum resource limits, or directly limiting the amount of resource of the called routine using a special instruction limited call.
Element 572c identifies an undesired runtime behavior of the invoked routine exercising unexpected authority such as by making an expected call to yet another routine. To prevent this behavior, an action taken may be to limit the authority of the called routine to the minimum privilege allowable. Mechanisms to implement this may include tagging the PC with the authority and control capabilities of the callee or called routine and limiting the portion of the file system or other resources accessible to the called routine, and limiting the allowable system calls the invoked routine can make.
Element 572d identifies an undesired runtime behavior of the called routine reading items left in registers by other routines subsequently called by the called routine (e.g., mycode calls P1 in the library and P1 further calls routine evil and P1 may read data left in registers by evil). To prevent this behavior, an action may be taken to clear the non-input and non-return registers. Mechanisms to implement this may include performing explicit register clearing, coloring portions of the stack including the non-return and non-input registers so that they cannot be read by the called routine, and having a separate process invoke the called routine.
Element 572e identifies an undesired runtime behavior of the called routine reading items left on the stack by other routines subsequently called by the called routine (e.g., mycode calls P1 in the library and P1 further calls routine evil and P1 may read data left on stack by evil). To prevent this behavior, an action may be taken to make the called stack inaccessible (e.g., stack region used by the further invoked other routines such as evil are inaccessible to the first called routine such as P1). Mechanisms to implement this may include using separate stacks (e.g., for the first called routine P1 and the further invoked routine evil), capabilities (e.g., tag PC or use specially tagged pointer allowed to access particular stack regions to limit ability or authority of code allowed to read stack areas), coloring (e.g., tag data areas of stack to limit what code can access), and having a separate process invoke the called routine.
Element 572f identifies an undesired runtime behavior of the called routine writing over items in the stack prefix (e.g., overwriting the return address area identifying the return address). The stack prefix may be an area of stack that includes information needed to return to some prior caller. To prevent this behavior, an action taken to make the stack prefix inaccessible or unwritable to the called routine. Mechanisms to implement this may include having the called routine and the user code invoking the called routine use separate stacks, using capabilities (e.g., allow access through specially tagged code or code provided authority through PC tag or specially tagged pointer), using coloring (e.g., tagging the data items of the stack prefix with special tags so that called routine is not allowed to access), and having a separate process invoke the called routine.
Element 572g identifies an undesired runtime behavior of the called routine read data in the stack prefix. To prevent this behavior, an action taken to make the stack prefix inaccessible to the called routine using mechanisms similar to those described with 572f.
Element 572h identifies an undesired runtime behavior of the called routine redirecting control flow in the stack prefix such as by overwriting the pointer to the return address where the pointer is stored in the stack prefix. To prevent this behavior, action may be taken to protect the return address stored in the stack prefix. In one aspect, element 572h identifies a particular instance of 572h and thus the mechanisms of 572h are similar to those of 572f. Mechanisms to implement this may include having the called routine and the user code invoking the called routine use separate stacks, using capabilities (e.g., allow access through specially tagged code or code is provided authority through PC tag or specially tagged return pointer that is tagged by access authority), using coloring (e.g., tagging the memory location of the stack prefix including the return address with a special tags so that called routine is not allowed to access), and having a separate process invoke the called routine.
Element 581a identifies an undesired runtime behavior of executing code writing over unintended items in the current frame of the executing routine. To prevent this behavior, an action taken may be to maintain object integrity. Mechanisms to implement this may include using capabilities by object (e.g., allow access through capability provided with specially tagged code or code provided authority through PC tag or specially tagged return pointer that is tagged by access authority), or color by object (e.g., tagging the memory locations of an object).
Element 581b identifies an undesired runtime behavior of reading items in the current frame of the executing routine. To prevent this behavior, an action taken may be to maintain object integrity. Mechanisms to implement this may include using capabilities by object (e.g., allow access through capability provided with specially tagged code or code provided authority through PC tag or specially tagged return pointer that is tagged by access authority), or color by object (e.g., tagging the memory locations of an object with object specific tag).
Element 581c identifies an undesired runtime behavior of executing code (having current frame) writing over unintended items in the predecessor frame (e.g., of other routine that invoked the executing code). To prevent this behavior, an action taken may be to isolate or separate tack frames. Mechanisms to implement this may include using capabilities by frame (e.g., allow access through capability provided with specially tagged code or code provided authority through PC tag or specially tagged return pointer that is tagged by access authority), or color by frame (e.g., tagging the memory locations of frame with frame-specific tag).
Element 581d identifies an undesired runtime behavior of executing code (having current frame) reading items in the predecessor frame (e.g., of other routine that invoked the executing code). To prevent this behavior, an action taken may be to isolate or separate tack frames. Mechanisms to implement this may include using capabilities by frame or color by frame as described with element 581c.
Element 581e identifies an undesired runtime behavior of executing code (having current frame) reading items left of the stack by another routine invoked by the currently executing code. The preventive action is to make the called stack of the invoked routine inaccessible to the currently executing code. Mechanisms to implement this may include using a separate process, a separate stack, capabilities and coloring in a manner similar to as described in connection with 572g.
Element 581f identifies an undesired runtime behavior of executing code (having current frame) modifying the return pointer (e.g., location in stack including return address in routine that invoked executing code). The preventive action is to protect the return pointer or location in the stack including the return address. Mechanisms to implement this may include using capabilities and coloring in a manner similar to as described in connection with 572g.
An embodiment in accordance with techniques herein may use the PUMP rule metadata processing system as part of another hybrid system to learn and validate new set of rules. For example, the PUMP rule metadata processing system may be used to learn (e.g., through logging) allowed control flow and thus determine rules and allowed valid control transfers for an executing program. The rules and allowed valid control transfers may be then be used as the rules and set of valid control transfers of a CFI policy enforced for the program that was executed.
To further illustrate learning rules and control transfers for the program's CFI policy, a first training or learning phase may be performed. In this first phase, the program is executed with all control points (e.g., branch or transfer source and targets) tagged and a training version of a CFI policy where there are no rules for control transfer instructions. Thus, each time there is a control transfer, such as a branch or jump instruction, there is a PUMP rule cache miss causing transfer of control to the cache miss handler of the PUMP rule metadata system. The cache miss handler may perform processing to log information regarding the control transfer. The information logged may include, for example, the source location of the transfer and the target location of the transfer. Other information may also include, for example, the calling procedure or routine from which the transfer is made (e.g., and includes the source location) and the called procedure or routine to which control is transferred (e.g., and includes the target location). More specifically, in the learning or training phase, the first time a particular transfer of control occurs, the cache miss handler computes a new rule of the learned set of rules for that particular transfer of control from a source to a target. Subsequent runtime transfers of control from the same source to the same target use this computed rule. In this manner, if the program is presumed bug-free and a non-attack program (not malicious code) and all control paths are exercised during a program run, the logged set of control transfers, as indicated by the learned rule set at the end of program execution, represents as all valid or allowable control transfers for this particular program. Thus, the learned set of rules may denote an initial or first set of rules for the CFI policy for the program.
Processing may be performed to validate the learned set of rules denoting the CFI policy for the program. The validation may include ensuring that none of these rules allow invalid control transfers. The validation of the learned set of rules may be performed in any suitable manner. For example, an embodiment may run an analysis tool that validates each rule. The tool may, for example, examine the binary or object code, symbol table and original source code, and the like, to validate that each rule corresponds to an allowed transfer. To further illustrate, validation may examine the binary code that has all control points (e.g., branch or transfer source and targets) tagged. In this manner, the tagged binary or source code denotes the valid set of all potential source and target locations thereby providing a valid set of potential source and targets that can actually be used in a runtime transfer of control. Any runtime transfer of control logged should only occur from a source to a target where each of the source and target are included in the valid set. For example, the tagged binary or source code may include locations A1, A2 A3 and A4. Any logged transfer of control should include a source that is A1, A2, A3 or A4, and a target that is A1, A2, A3 or A4. If a logged runtime control transfer denoted by a first rule is from A1 to B7, the first rule may be invalidated since B7 should not be a target of a control transfer (e.g., B7 is not included in the set of statically determined possible control points tagged consistent of A1, A2 A3 and A4). In one aspect, the learned set of rules may be characterized as a candidate set of rules which may be further reduced via rule removal as a result of validation processing.
All rules of the initial or learned set of rules for the CFI policy for the program that have been validated may then be used as a validated set of rules included in a CFI policy that is then enforced for the program.
Referring to
Thus, for foregoing first program execution in 602 may be used to determine a set of valid control transfers for the program. However, it may not be reasonable to assume that this single program execution exercises all control paths whereby the control transfers identified in 608 as valid may denote less than all possible valid control transfers. In this case, processing may be performed as described above in connection with 610 using the validated set of CFI policy rules. During runtime, if a control transfer is encountered causing a rule cache miss (e.g., indicating an unforeseen control transfer not having a rule in 608), additional checking may be performed at runtime, for example, to validate the control transfer such as described above (e.g., using the set of possible control points tagged in binary code or annotated in a source program). If the control transfer is determined as invalid, a fault or exception may be triggered.
As an alternative, if a control transfer is encountered causing a rule cache miss thereby denoting an unexpected runtime control transfer, the cache miss handler may record the unexpected transfer rule for later validation and also allow the unexpected transfer of control to proceed with additional or different policies in effect. For example, for an unvalidated control transfer, the transfer may be considered untrusted so policies may be modified to reflect a higher level of protection due to the untrusted nature of the unvalidated control transfer. For example, the unexpected transfer may transfer control to a library routine. The library routine may be executed using policies reflecting a higher level of protection and less trust than those in effect prior to the unexpected transfer. For validated control transfers, a first stack protection policy may be in effect at a first point in time prior to the unexpected transfer of control and a second stack protection policy in effect after the unexpected transfer of control. The first stack protection policy may enforce static procedure authority. The first protection policy may not include any coloring at the object level as described elsewhere herein with the object protection model. After the unexpected control transfer, the second stack protection policy in effect may provide for stack protection in accordance with the object protection model described elsewhere herein with strict object coloring. Thus, code executed once the unexpected control transfer is encountered may utilize the more restrictive second stack protection policy providing a tighter finer level of granularity of stack protection. Additionally, the program execution may continue with a reduced level of priority once the unexpected transfer of control occurs.
Referring to
Referring to flowchart 620, at step 622 a program may be executed using a set of validated rules. At step 624 during program execution, a runtime transfer of control is performed. At step 626, it is determined whether there is a rule cache miss thereby indicating that the transfer is unexpected. In particular, if there is a rule in the second set of validated rules for the runtime transfer of control, then the transfer of control is expected where step 626 evaluates to no and processing continues with step 628 where the control transfer is performed and the program continues execution.
If step 626 evaluates to yes (e.g, cache miss indicating an unexpected transfer of control), processing continues with step 632 where runtime validation processing is performed for the unexpected control transfer. In particular, the miss handler may perform processing that attempts to validate the unexpected transfer. Examples of rule validation processing may include determining whether the runtime source and target locations are included in a set of potential control transfer points as described above that may be determined using tagged binary code, the original source program and symbol table, and the like. At step 634, it is determined whether the validation processing of step 632 determined the unexpected transfer of control is valid. If step 634 evaluates to yes, processing continues with step 636 where the new rule is added to the second set used as the CFI policy for the program and processing of the program continues. If step 634 evaluates to no, program execution may be terminated, for example, by causing a trap.
Referring to flowchart 631, steps 622, 624, 628 and 628 are as described above in connection with flowchart 620. If step 626 evaluates to yes, control proceeds to step 639 where the unexpected transfer of control may be recorded (e.g., candidate rule for unexpected transfer of control recorded) for later validation. In step 639, the program is allowed to continue execution even when the transfer of control is unexpected. However, in step 639, program execution continues, for example, using a set of one or more restrictive policies, reduced execution priority, and the like, such as noted above.
The processing described above of such as described above may be similarly performed in connection with other policies such as taint tracking. For example, for taint tracking, a first learning or training phase may be performed to learn rules of a policy via program execution by having the cache miss handler “log” each cache miss. As described herein, taint tracking may include tagging data based on the code that produces or accesses it (e.g., such as using the CI as described elsewhere herein.) One reason to taint data based on code or source is to make sure that programs are properly contained and do not perform unwanted or improper data accesses. For example, rules may be used to assure that data tainted by the JPEG decoder never flows into the password database, or that credit card data, social security number or other personal information is only accessed by a particular set of one or more restricted applications. With determining a taint tracking policy, processing may be performed for a learning or training phase with no taint tracking rules run on test data that causes a cache handler miss the first time it sees a particular flow of data (e.g., which routines of a program access what data, what user input is written to what database, and the like) and records the rule. In a manner similar to that as described above for the CFI policy, at the end of a test run of the first learning phase, there is a set of learned rules to apply to protect the program during operation. Validation processing of the learned set of rules may be also be performed using a tool or other suitable means as noted above for the CFI learned set of rules. Such validation processing for taint tracking may include ensuring that each data flow or access is proper.
Also, in a manner similar to that as described in connection with flowcharts 620 and 631, the validated set of rules may be used with the PUMP system where a cache miss handler handles processing for any data access that does not have a corresponding rule in the validated set. Similar to processing of flowchart 620, the cache miss handler may then also perform runtime validation processing (e.g., similar to step 632) to determine whether a candidate rule for the data access or data flow is valid and allow program execution to continue (e.g., similar to steps 634, 636) or not (e.g., similar to step 638). Alternatively, similar to processing of flowchart 631, the cache miss handler may record a candidate rule for the unexpected data access or data flow that may be validated offline (e.g., not during runtime) and continue program execution using, for example, more restrictive policies, reduced priority, and the like (e.g., similar to step 639).
The examples above describe a generally binary learning process. An embodiment in accordance with techniques herein may further support use of statistics in making a decision about whether or not to allow an event (e.g., control transfer or data access). In at least one embodiment, a counter may be added to each rule to count the number of uses of each rule during program execution. When the rule is evicted from the PUMP cache, processing may add the accumulated rule usage into a global, software count that may be used to provide additional statistics regarding rule usage. The count may also be used to allow something to occur a limited number of times. For example, in connection with taint tracking rules tracking the flow of data from a source to a target, a limited threshold amount of data may be allowed for unexpected data flows between a source and target (e.g., X amount of data read from a particular database by a particular program). Once that threshold amount has been transferred, no additional data may be transferred between the source and target until the corresponding candidate rule has been successfully validated. With the limited use case with the threshold amount, the PUMP system (e.g., miss handler) may allow an instruction lacking a rule to occur some limited number of times. Aggregation or counting as applied to the threshold may be done in different ways. For example, consider unexpected control transfers. Non-aggregated, the cache miss handler may not allow the same unexpected control transfer without a validated rule to occur more than 5 times. Aggregated, such as across all unexpected control transfers for a program, the program may be allowed to make a maximum number of 100 unexpected control transfers. This may be useful for example, for cases where it is acceptable for a single instance of an unexpected transfer of control or unexpected data access to occur. For example, a single query to examine data from a particular source may be allowed. However, if above a threshold number of queries are performed to the data source (e.g., particular database), the program should be flagged or stopped.
The more general statistics case may be used for learning the range of normal behavior. For example, a program may be executed in a learning phase to determine a relative usage of the different rules of a policy (e.g., ratio of usage of each rule). For example, relative usage of each rule invoked for a runtime control transfer may be recorded. Ideally, such execution may be performed for the program using many different data sets to learn what may be considered average or normal program behavior. Rule learning and validation may then result in a set of rules for the validated control transfers (as described above) and additionally a ratio indicating a relative usage of each validated rule. Both the validated rules and associated usage ratios may be used during subsequent processing as the enforced policy rules. During subsequent program execution when the policy is enforced, the PUMP system may check if current rule usage is out of line with the expected ratio. An embodiment may include, for example, a range or maximum expected usage for the rule where control transfers invoking the rule more than the maximum may be flagged. For example, the program invoking the particular control transfer rule more than the maximum may be flagged for further inspection or analysis. Using this mechanism, program runtime behavior can be monitored similar to the way network behavior is monitored to generate firewall rules. Statistical learning algorithms can be used to capture rule usage, and perhaps other standard runtime characteristics like main-memory traffic and cache miss rates, to learn normal case versus attack behavior. In embodiment applying the limited-use threshold as described above, if a program exhibits other runtime behavior that is anomalous or otherwise may be considered untrusted, the use limits may be greatly reduced or otherwise set to zero. Alternatively, if a program exhibits normal runtime behavior or otherwise may be considered trusted, the use limits may be set much higher or increased in comparison the untrusted scenario.
The techniques above may be used to determine a set of valid rules of a policy, such as valid control transfers reflected in rules of a CFI policy, without having a compiler output any additional information. Thus, an embodiment in accordance with techniques herein may have two version of each policy—one used for the learning phase and another used for subsequent enforcement. The learning phase may be used as an automated diagnostic mode to discover allowable data accesses or flows for taint tracking, discover control transfers for a CFI policy, and the like.
What will now be described are examples of architectures that may be used in embodiments in accordance with techniques herein using a RISC-V processor. Additionally, described below are techniques that may be used in connection with performing processor-based mediated data transfers between untagged and tagged data sources used by the processor. Such techniques provide for tagging external untrusted data that may be brought into the system for use by the processor and also removing tags from tagged data used within the system to generate untagged data for use outside of the system.
Referring to
The example 700 illustrates a separate tagged fabric 710 and untagged fabric with the processor 702 used for moving data between the two. Add tag 714a takes as an input untagged data and tags it with a tag indicating that the data is public (can be used outside the system described herein) and untrusted (since the source may be unknown or otherwise not from a known trusted source). In at least one embodiment, the untagged data of untagged memory 716 may be received by 714a. The received untagged data from 716 may be encrypted whereby add tag 714a simply adds an untrusted tag to the received encrypted data. The received data may be encrypted using asymmetric cryptography, such as public key cryptography using a public-private key pair, or other suitable encryption technique known in the art. The received data may be stored in an encrypted form. As known in the art, for a public-private key pair of an owner, the private key is known only to the owner but the public key is made public and used by others. A third party may encrypt information sent to the owner using the owner's public key. The owner may then decrypt the received encrypted information using its private key (not shared with anyone else). In a similar manner, the owner may encrypt information using his private key where the encrypted information is sent to a third party that decrypts the encrypted information using the owner's public key.
Validate drop tag 714b may receive tagged encrypted data and remove the tag thereby resulting in untagged encrypted data that is being exported to the untagged memory 716. Such untagged encrypted data stored in memory 716 may be used, for example, on another system and processor not using tags and associated metadata rule processing as performing using the PUMP described herein.
In at least one embodiment, the untagged data received at 714a may be encrypted, as noted above, and also signed to provide integrity of the data. Furthermore, signatures may be used in validating the received data item to ensure authentication and data integrity (e.g., has not been modified since sent by the original sender that signed, ensure data was sent by the sender signing the data). For example, an owner may hash a message to produce a hash value or “digest,” and then encrypt the digest with the owner's private key to produce a digital signature. The owner may send the message and signature to a third party. The third party may validate the received data using the signature. First, the third party may decrypt the message using the owner's public key. The signature may be verified by computing the hash or digest of the decrypted message, decrypting the signature with the owner's/signer's public key to obtain an expected digest or hash, and comparing the computed digest with the decrypted expected digest or hash. Matching digests confirms the message has not been modified since it was signed by the owner.
In operation, an instruction, such as a load instruction, may reference data stored in the untagged memory 716 which is then transferring into the data cache 706 for use in instruction execution. For such a load instruction, the data may be transferred from 716 over 715 for processing by 714a which outputs the tagged data (tagged as untrusted and public). The tagged data output by 714a is stored in the L1 data cache 706 for processing. In a similar manner, a store instruction may store data from the data cache 706 to a location in untagged memory 716. For such a store instruction, the data may be transferred from 706 over 710 to validate drop tag 714b which outputs the untagged data. The untagged data output by 71ba is then transmitted over 715 for storage in 716.
Code may be executed on the processor 702 to import the untagged data from 716 into the system for storage, for example, on DRAM 712c. The following may be denote logic of the code that imports the untagged data:
1. the tagged data output by add tag 714a may be stored in untrusted buffer (tagged as public, untrusted).
2. decrypt the tagged data stored in untrusted buffer and store in decode buffer. Thus decode buffer includes decrypted data that is tagged as public, untrusted.
3. perform validation processing to ensure that the decode buffer includes valid uncompromised data. Such validation processing may use digital signatures as described elsewhere herein and known in the art.
4. if the decode buffer includes validate data, a second portion of trusted code may be executed to convert the data of decode buffer tagged as public, untrusted, to data that is tagged as trusted. The trusted code portion may include one or more instructions that, when executed, invoke rules to retag the data of decode buffer as trusted, public. The retagged data now tagged as trusted, public may be stored in a trusted buffer located in external DRAM 712c.
The trusted code may include a memory instruction tagged with a special instruction tag giving it the authority to, when executed, invoke a rule that retags a referenced memory location. For example, the trusted code may include a specially tagged store instruction that stores the data tagged as public, untrusted (untrusted buffer) in a destination memory location (trusted buffer) with a new tag of public, trusted. The foregoing store instruction of trust may be specially tagged, for example, by a loader.
The following may be denote logic of the trust code that retags data from public, untrusted, to public trusted:
temp=*untrusted buffer [i];
trusted buffer [i]=temp;
where N is the length of the untrusted buffer and temp is a temporary buffer used for the retagging performed. The first instruction, temp=*untrusted buffer [i], may result in a load instruction that loads a first element of untrusted buffer from untagged memory 716 into temp. The second instruction, trusted buffer [i]=temp, may be a store instruction that stores the data tagged in temp as public, untrusted to trusted buffer [i] with a new tag of public, trusted. Thus, the second instruction is the instruction that is specially tagged as noted above to have authority to perform the data retagging from untrusted to trusted.
In a similar manner, when tagged data of 712c is being exported or stored in untagged memory 716 (or any untagged memory source 701), code is executed by the processor 702 that encrypts the data item and generates a signature where the encrypted data item and signature may be sent to 714b where the tag is removed before transmission over 715 for storing in 716.
As a variation to the example 700, the memories 716 and 712c may be unified and also the interconnect fabric 710 and 715 may be unified. In such an embodiment, the address range that the untagged memory source 701 is allowed to access may be limited. For example, reference is made to the example 720 of
An embodiment needing to run unported I/O processing code may be executed on a dedicated I/O processor on the untrusted side of components. For example, reference is made to the example 730 of
As described elsewhere herein in more detail, a separate I/O PUMP may be used as another alternative to mediate between the untagged data sources (e.g., 701, 716) and tagged memory 712c used by the processor 702.
Referring to
In a simplest case, the hardware of intern 742 and extern 744 may host a single public-private key set where the signing and cryptography are also performed using the single key set. The key set may be encoded in hardware used by 742 and 744. In a further variation, the hardware of intern 742 and extern 744 may host multiple public-private key sets where the signing and cryptography are also performed using one of the multiple key sets (each set including a different public-private key pair). The multiple key sets may be encoded in hardware used by 742 and 744. Clear data included with the incoming untagged data tells the intern unit 742 which set of keys to use. Thus, intern 742 may perform a lookup in a hardware data store (e.g., associative memory) including the multiple key sets to select the desired key set. Each of the multiple key sets may be associated with a different tag so the particular key set indicated by the clear data also indicates the particular tag that the tagged data will include. In this manner, the tag of the tagged data item output by 742 denotes that the data item is public and trusted and also that the data item is encrypted/decrypted using a particular one of the multiple key sets. In the embodiment with multiple key sets, extern 744 may examine the tag to determine which particular one of the multiple key sets is used in connection with encrypting and signing a data item. Thus, the intern unit 742 processing provides an isolated hardware component that verifies received untagged data and performs tagging thereby avoiding the need to have a portion of code, such as the trust code portion noted above, with the capability to tag data.
With reference back to
Referring to
As illustrated in the example 800, additional outputs of the PUMP 802 in stage 5 include R tag 805a and PC new tag 805b. When using a predicted MR tag, a rule for the predicted MR tag may be determined where the rule specifies an associated tag for R tag. When operating in prediction mode, the predicted MR tag 805c is an additional input to stage 6 808 of the pipeline. Element 808 may denote the commit or writeback stage as described elsewhere herein (e.g.,
In stage 6 808, additional processing 808b may be performed when the PUMP 802 operates in prediction mode. Element 808b indicates that a check may be performed in stage 6 808 which compares the predicted MR tag to the action MR tag obtained from memory for the operand of the instruction. In other words, 808b evaluates whether the PUMP 802 correctly predicted the MR tag value by determining whether the predicted MR tag matches the MR tag obtained from memory. If the predicted MR tag does not match MR tag as obtained from memory, then an incorrect rule was triggered and used by PUMP 802 in determining R tag 805a with the incorrect predicted MR tag. The correct rule must now be selected (in accordance with the actual MR tag) and used in determining a revised R tag. Thus, if the predicted MR tag does not match MR tag, a rule cache miss is determined and cache miss handling is performed. Consistent with description elsewhere herein, cache miss handling may include processing to select and evaluate the correct rule using MR tag.
Load/read and store/write instructions are examples of instructions in an embodiment that may include a memory location as an operand benefiting from use of a predicted MR tag. Other inputs 804 to the PUMP include a set of other or remaining input tags besides MR tag 804a. For example, one embodiment as illustrated in connection with
For example, consider a memory safety policy with typical load and store operations. A load operation may load data from a source memory location using a pointer where a first rule indicates that the tag or color on the source memory location should match the tag or color of the pointer. A store operation may store data to a target memory location using a pointer where a second rule indicates that the tag or color on the target memory location should match the tag or color of the pointer. For a load instruction, the first rule may be the only rule having tag values matching the 4 input tags for PC tag CI tag, OP1 tag and OP2 tag of the load instruction. The MR tag of the first rule may be used as the predicted MR tag 805c. Additionally, the R tag of the first rule may be determined using the set of 4 input tags and the predicted MR tag. In a similar manner, for a store instruction, the second rule may be the only rule having tag values matching the 4 input tags for PC tag CI tag, OP1 tag and OP2 tag of the store instruction. The MR tag of the second rule may be used as the predicted MR tag 805c. Additionally, the R tag of the second rule may be determined using the set of 4 input tags and the predicted MR tag.
In other instances, the set of rules of the policy having tags matching the input tags for PC tag CI tag, OP1 tag and OP2 tag of an instruction may include multiple matching rules with each matching rule identifying a different allowable or candidate MR tag that may be used as the predicted MR tag 805c. An embodiment may use any suitable technique to select one of the multiple allowable MR tags to use as the predicted MR tag. For example, an embodiment may select the MR tag of the set of allowable MR tags that is the most common or likely to occur. The MR tag that is most likely to occur may be based on previous observations or rule profiling. As an alternative, an embodiment may set the predicted MR tag to be the previous or most recent MR tag. In the worst case, if the predicted MR tag does not match the actual MR tag once received, cache miss handling may be performed as described herein to determine the correct rule using the actual MR tag along with the other inputs tags of the instruction.
In at least one embodiment, a class of rules for memory operations may be created which are used when the PUMP operates in prediction mode. The class of rules may be referred to as a class of “predict memory tag” rules. For the “predict memory tag” rules, the MR tag 804a is not used as an input to the PUMP 802 and is thus not used in connection with various lookups performed by the PUMP. For example, the care/don't care bit vector for the “predict memory tag” rules may treat the MR tag as a don't care. Additionally, the “predict memory tag” rules may omit the MR tag as an input and rather specify predicted MR tag as an output. As described above, if there are multiple matching normal rules matching a particular set of input tags for PC tag, CI tag, OP1 tag and OP2 tag, the single “predict memory tag” rule corresponding to the set of matching rules may specify a predicted MR tag as an output that is the most common or expected MR tag. In one embodiment, the single “predict memory tag” rule corresponding to the set of matching rules may specify, as the predicted MR tag, the last or previous MR tag that was received by the PUMP 802.
Policy logic may decide whether to insert or use “predict memory tag” rules or not. An embodiment may keep 2 versions of each policy where a first version includes policy “predict memory tag” rules for use when operating in prediction mode and a second version includes normal or non-prediction policy rules for use when operating in normal processing mode or non-prediction mode. If the check performed in 808b of stage 6 fails for a given instruction when using a “predict memory tag” rule, the cache miss handling may perform processing to determine a matching rule for the instruction using the normal rule set (e.g., second version of rules described above).
In an embodiment using a RISC-V processor and architecture, the prediction mode selector 804b may have a corresponding PUMP CSR. Use of CSRs in an embodiment using the RISC-V architecture is described elsewhere herein in more detail.
Referring to
At step 842, a determination is made as to whether prediction mode is on/enabled thereby denoting that the PUMP is operating in prediction mode using “predict memory tag” rules. If step 842 evaluates to no, control proceeds to step 846 where the PUMP operates in normal or non-prediction mode using normal rules. If step 842 evaluates to yes, control proceeds to step 844 where a determination is made as to whether the current instruction is a memory input operation instruction. If step 842 evaluates to no, control proceeds to step 846. If step 844 evaluates to yes, control proceeds to step 848 where the PUMP operates in prediction mode using “predicted memory tag” rules. In step 848, a matching “predicted memory tag” rule for the instruction may be determined. In step 852, the R tag for the current instruction may be determined using the matching “predicted memory tag” rule from step 848. At step 854, a determination is made as to whether the predicted MR tag matches the actual MR tag. If step 854 evaluates to no, control proceeds to step 856 to perform rule cache miss processing by invoking the rule miss handler. If step 856 evaluates to yes, control proceeds to step 858 where the R Tag, as determined with the rule including the predicted MR tag, is used as the R tag PUMP output.
As a variation from the of the example 800, reference is made to
Stage 6 (808) is revised to take PUMP outputs Rtag 805a and PCnewtag 805b from MR tag prediction PUMP 822 and outputs Rtag 805d and PCnew tag 805e from PUMP 802. Additionally, in stage 6, selection is made between Rtags 805a and 805d and also selection is made between PCnew tags 805c and 805e based on whether or not the predicted MR tag matches the actual MR tag (e.g., as denoted by 808a). If there is a match between the predicted MRtag and the actual MRtag (e.g., 808a evaluates to 1 or true), the tags (e.g., Rtag 805a and PCnew tag 805b) from the predicted PUMP 822 are used and the tags (e.g., Rtag 805d and PCnew tag 805e) from the non-predicted PUMP 802 are discarded. If there is a mismatch between the predicted MRtag and the actual MRtag (e.g., 808a evaluates to 0 or false), the tags 805a-c from the predicted PUMP 822 are discarded and the tags 805d-e from the non-predicted PUMP 802 are used. The non-predicted PUMP 802 provides its output outputs 805d-e a cycle later than the outputs 805a-c of predicted PUMP 822, so when PUMP outputs from stage 5 regarding PCnewtag and MRtag are needed as inputs to stage 6 for processing, this introduces a stall into stage 6 waiting on the foregoing stage 6 inputs. The non-predicted PUMP 802 may also experience a PUMP rule cache miss when it is selected, in which case, this is handled like a typical rule cache miss as described elsewhere within this disclosure.
Referring to the stage 6 808, elements 850 and 852 represent multiplexers. Element 808a may denote a selector used to select an input from each of 850 and 852 based on the logical result of whether MRtag predicted matches MRtag. If the foregoing two tag values match, Rtag 805a is selected as the input into 850 provided as the selected Rtag 850a denoting the in final Rtag output of stage 6; otherwise if the foregoing two tag values do not match, Rtag 805d is selected as the input into 850 provided as the selected Rtag 850a. Additionally, if the foregoing two tag values match, PCnew tag 805b is selected as the input into 852 provided as the selected PCnew tag 852a denoting the in final PCnew tag output of stage 6; otherwise if the foregoing two tag values do not match, PCnew tag 805e is selected as the input into 852 provided as the selected PCnew tag 852a.
What will now be described are techniques using coloring allocated memory that may be used in an embodiment in accordance with techniques herein.
A user program, such as one coded in the C programming language, may include calls to routines used in connection with memory allocation and deallocation. For example, malloc and free are routines in the C standard library and may be linked into an executable of a user program. Thus, malloc and free execute as routines in the user process address space along with other user code that may invoke malloc and free. Malloc is invoked for dynamic memory allocation to allocate a block of memory used by executing code. In at least one embodiment, malloc may have an input specified on the invocation denoting the size of the memory block to be allocated whereby malloc returns a pointer to the allocated memory block. A program accesses the allocated memory block using the pointer returned by malloc. In at least one embodiment, free is invoked to free or deallocate memory previously allocated with malloc. When a memory block allocated using malloc is no longer needed, the pointer (as returned by malloc) may be passed to free as an input argument whereby free deallocates the memory (located as the address denoted by the pointer) so that it may be used for other purposes. User code executing on a processor in an embodiment in accordance with techniques herein may perform such calls to malloc and free or other routines or functions similarly performing memory allocation and deallocation. Routines such as malloc and free that perform dynamic memory allocation may utilize memory management metadata regarding the allocated memory. In following paragraphs, such metadata used for memory management may be referred to as malloc metadata and is distinct and in addition to tag-based metadata described herein including tags and other metadata pointed to by pointer tags (e.g., where tag-based metadata that is inaccessible to executing user code and is processed by the metadata processor or subsystem such as described in connection with the example 1000 and elsewhere herein). Malloc metadata may include, for example, information about the allocated memory block such as the size of an allocated memory block, and a pointer to the malloc metadata portion for a subsequently allocated memory block.
Referring to
After an allocated block of memory, such as 1102b, is no longer needed by the executing code, the code may perform a call to free to free the memory block 1102b so that such memory block 1102b is deallocated and may be used for other purposes. Pointer P1 may be returned when making such a call to free. In a similar manner, when memory blocks 1104b-c are no longer needed, calls to free may be made specifying, respectively, pointers P2 and P3.
Through a pointer such as P1 returned by malloc to executing user code, the user code may inadvertently or intentionally access the malloc metadata since the address of the memory portion 1102a holding the malloc metadata is mapped into the executing code's address space. For example, the user code may assign another pointer P4 an address in memory portion 1102a (e.g., P4=P1-2) and then read or write to the memory location identified by the pointer P4. Thus, the user code may, for example, overwrite the malloc metadata stored in 1102a and read malloc metadata stored in 1102a. In this manner, performing a write to the memory location at the address identified by P4 may corrupt the malloc metadata portion 1102a. More generally, the foregoing may be performed by user code in connection with any of the malloc metadata portions 1102a, 1104a and 1106a.
In connection with a call to free, user code may specify a pointer that does correspond to the starting address of an allocated memory block previously allocated using malloc. For example, the user code may perform a call to free specifying the foregoing pointer P4 as an argument rather than P1, P2 or P3. Assume, for example, malloc allocates an X byte block (e.g., X being a non-zero integer) for each malloc metadata portion 1102a-c in connection with a call to malloc. The routine free may perform processing under the assumption that memory locations from the first address (P4-X) to the second address (P4-1) denote, respectively, starting and ending address spanning a malloc metadata portion such as 1102a. In this case, processing performed by free may be using a corrupted malloc metadata portion 1102a resulting in, for example, unexpected runtime performance and/or dynamic memory management errors.
An embodiment may use techniques described herein to protect the malloc metadata portions 1102a, 1104a and 1106a to avoid corruption through overwrites performed by other executing code, such as the user code. Such techniques may include tagging code and/or data with particular colors or tags and enforcing rules to allow only desired access and operations such as described elsewhere herein.
With reference to
Element 1111 may denote tags specified for corresponding memory locations 1113. Elements 1112a, 1114a and 1116a respectively denote tags for malloc metadata portions 1102a, 1104a and 1106a. Elements 1112b, 1114b and 1116b respectively denote tags for memory blocks 1102b, 1104b and 1106b allocated by malloc for user by user code via calls made to malloc as described above.
Elements 1112a, 1114a and 1116a denote that each memory location, respectively in 1102a, 1104a and 1106a is tagged as red. Elements 1112b, 1114b and 1116b denote that each memory location, respectively in 1102b, 1104b and 1106b is tagged as blue.
Generally, an embodiment may use instruction tagging, colored pointers, or a combination of the foregoing, in connection with triggering rules that color the memory blocks of 1113 with tags denoted by 1111, and also enforce a memory safety policy whereby only malloc and free are able to access malloc metadata areas 1102a, 1104a and 1106a and user code cannot.
In a first embodiment, code of malloc and free may be tagged (e.g., instruction tagging) such as by a loader, with a special instruction tag (e.g., CI tag). Both malloc and free may be tagged with the same unique or special instruction tag (e.g., malloc and free code tagged with the same CI tag of tmem) or may each be tagged with their own unique or special instruction tag (e.g., malloc code tagged with tmalloc and free code tagged with tfree). Code of malloc may include store instructions that, when executed, trigger rules that perform coloring such as in the example 1110. Code of free may include store instructions that, when executed, trigger rules that reinitialize or deallocate a malloc metadata portion (e.g., 1102a, 1104a and 1106a) or a previously malloced memory block (e.g., 1102b, 1104b and 1106b) such as by retagging each memory cell of the block or malloc metadata portion with an F tag representing free memory. Also, in the first embodiment, the memory safety policy may include rules triggered by execution of particular instructions, such as the load and store instructions, whereby the rules only allow instructions tagged with the special instruction tag(s) noted above to 1) access malloc metadata portions 1102a, 1104a and 1106a and 2) perform the memory block coloring as in the example 1110. Such rules may generally check the CI tag to ensure that each instruction coloring or accessing a memory cell in any of 1102a, 1104a and 1106a has the special instruction tag denoting malloc or free.
In a second embodiment, rather than use special instruction tags, an embodiment may use colored pointers with rules of the memory safety policy triggered by execution of particular instructions, such as the load and store instructions. The loader may tag pointers of malloc and free that reference malloc metadata portions 1102a, 1104a and 1106a with the color red. Code of malloc may include store instructions that, when executed, trigger rules that perform coloring such as in the example 1110. Code of free may include store instructions that, when executed, trigger rules that reinitialize or deallocate a malloc metadata portion (e.g., 1102a, 1104a and 1106a) or a previously malloced memory block (e.g., 1102b, 1104b and 1106b) such as by retagging a memory cell with a tag F representing free memory. The memory safety policy may include rules triggered by execution of particular instructions, such as the load and store instructions, whereby the rules only allow access to malloc metadata portions 1102a, 1104a and 1106a with instructions referencing a memory cell using a red colored pointer. Such rules may generally check the MR tag to ensure that the memory instruction accessing a memory cell in any of 1102a, 1104a and 1106a uses a pointer with a first color that matches a second color of the memory cell.
In a third embodiment, both special instruction tags and colored pointers as described above may be utilized in combination. Following is an example of instructions and rules that may be used in such a third embodiment. Consistent with other discussion herein, following examples use rules based on 5 input tags to metadata processing for PC (program counter), CI (current instruction), OP1 (operand 1 of the current instruction), OP2, operand 2 of the current instruction), MR (memory location, if any, referenced in the current instruction), and two propagated or generated tags for PCnew (new PC tag for next PC for next instruction) and R(tag for result of current instruction; used to tag destination register or memory location into which the result of the current instruction is stored). Additionally, “-” denotes a don't care for a tag. In such an embodiment, the loader may tag instructions of malloc with the special tag tmalloc and may tag instruction of free with the special tag tfree. Colored pointers may be created using triggered rules noted below.
In connection with malloc, metadata rule processing triggered by executing the code portion of malloc may generate a tag for the pointer to a newly allocated memory block such as 1102b via a first rule invoked as a result of a store instruction in the code portion of malloc. For example, malloc C code may be “P1=next free” where next free is a pointer to the next free memory location in 1113 and the store instruction may be “move R1, R2”, where register R1 is the source register that contains the address next free and register R2 is the destination register that is the pointer P1. Register R1 may be OP1 (having OP1 tag) and register R2 may be the result or destination register (having R tag propagated or generated as a result of a fired rule). The code portion of malloc may include instructions, such as the foregoing move instruction, also tagged with a special tag, tmalloc, denoting the instruction is included in malloc code. In at least one embodiment, the loader may tag instructions of malloc with the special code tag, tmalloc. The first rule may tag pointer P1 to the allocated memory block 1102b with the tag blue. The first rule triggered as a result of the above move instruction in malloc may be:
The above rule only fires when the CI tag is tmalloc and thus for tagged move instruction in malloc. Assuming that the pointer used by malloc is P1, the above my rule 1A tags P1 stored in register R2 with the tag or color blue to denote it is a pointer to a blue memory location (e.g., memory location tagged with blue tag).
The pointer P1 tagged with blue may then be used with another second store instruction of malloc to write a 0 or some other initial value to each word in the allocated memory block 1102b. For example “*P1=0” may be included in malloc C code resulting in “Store R3, (R2)” where R3 is a source register operand OP1 containing zero (0), and R2 is the OP2 register that contains the address P1. In this store instruction, “(R2)” is operand MR and also denotes a memory location that is the target or destination of the store instruction. Additionally, the above store instruction in malloc may also be tagged tmalloc and may result in triggering a second special store rule as follows:
The above store rule 2A only fires when CI tag is tmalloc, the pointer or address in R2 (denoting P1) is tagged as blue, and when the memory location MR pointed to by P1 has an F tag. The foregoing memory location *P1 is assumed tagged with “F” prior to coloring the memory location blue. In this example, F denotes a free memory location. The resulting MR tag for the memory location denotes a blue tag for the memory location.
Thus, malloc may include code that results in triggering the above-noted second rule for each memory location of a memory block being allocated.
Malloc may also include code that triggers additional rules described below (e.g. that are similar to move (my) rule 1A and store rule 2A above) for use in initializing malloc metadata portions 1102a, 1104a, and 1106a. For example, malloc C code may be “(P1-2)=MD area” where MD area is a pointer into the malloc metadata area 1102a and the move instruction may be “move R7, R8”, where register R7 is the source register that contains the address “P1-2” and register R8 is the destination register that is the pointer MD area. The rule triggered by the above move instruction may be:
Malloc may also include code that triggers store rule 2B noted below (that is similar to the store 2A rule above) to tag each memory location of a malloc metadata portion such as to store tags 1112a, 1114a, 1116a, respectively for malloc metadata portions 1102a, 1104a and 1106a. For example assume size is an integer denoting the size of the malloced memory block 1102b and that “*(P1-2)=size” is included in malloc C code resulting in “Store R6, (R7)” where R6 is a source register operand OP1 containing the size value), and R7 is the OP2 register that contains the address P1. In this store instruction, “(R7-2)” is operand MR and also denotes a memory location in MR 1102a that is the target or destination of the store instruction. The store rule 2B may be:
which performs the store if the store instruction is tagged tmalloc, if the R7 register containing address P1 is tagged red, and if the MR operand is tagged as F. It should be noted that an embodiment may also include store rule 2D (store 2D) noted above that is a variation of store 2B rule noted above whereby store 2D rule may be used in cases where updating the metadata value is desired.
At a later point in time, free may include code, such as “*P=0” that results in triggering store rule 3 noted below to retag a memory location of a previously malloced memory block (e.g., memory block allocated for user code use), such as when freeing or deallocating blue colored block 1102b. The loader may color or tag instructions of free with tfree. The routine free may include the C code statement “*P=0” that results in “Store R4, (R1)” where R4 is source register operand OP1 containing zero, R1 is the OP2 register containing the address of the memory location to be initialized, and “(R1)” denotes a memory operand MR with R1 containing the address to the memory location. The store rule 3 may be:
Thus, free may include code that results in triggering the above-noted third rule for each memory location of a memory block being deallocated, where the memory block was previously allocated using malloc for use by user code (e.g., used for storing data other than malloc metadata). Store rule 3 checks to ensure that the CI tag=t free and that both the memory location and pointer thereto have the same color, blue.
It should be noted that the MR tag of “blue” may generally be any color previously used by malloc to color an allocated user memory block.
Code of free may also include code that triggers move (my) rule 1C and store rule 4 described below in connection with retagging each memory location of a malloc metadata portion such as 1112a. Code of free may include code that triggers move (my) rule 1C noted below which is similar to move (my) rule 1B above. Move (my) rule 1C may be:
Store rule 4 below (that is similar to the store rule 3 above) may be triggered to retag each memory location of a malloc metadata portion such as retag 1112a, 1114a, 1116a, respectively for metadata portions 1102a, 1104a and 1106a. The store rule 4 may be:
In a fourth embodiment, PC tagging may be used to provide malloc and free to provide malloc and free with sufficient privilege, access or authority to read data from and write data to malloc metadata portions 1102a, 1104a and 1106a and also exclude other code from accessing the foregoing metadata portions. PC tagging is described elsewhere herein, for example, in connection with the example 430 with providing different privilege, access or authority on a per process basis using different PC tag values. In a similar manner, a special or unique PC tag value may be used to provide malloc and free with authority to perform load and store operations with respect to malloc metadata portions 1102a, 1104a and 1106a. To further illustrate, malloc may include instructions tagged with tmalloc (e.g. CI tag=tmalloc when instruction is executed). Malloc may also include code that, when executed, triggers application of a rule that propagates or produce a particular PC tag as an output denoting a privilege or authority to access malloc metadata portions 1102a, 1104a and 1106a. Malloc may include a first instruction INS1 such as:
In a similar manner, free may include instructions that invoke rules to generate or propagate a PCnew tag value to provide free with access to 1102a. The rules applied may propagate or produce a particular PC tag as an output that denotes a desired access, privilege or authority based on the particular process whereby the particular allowed privilege, access or authority may be represented by different PC tag values.
It should be noted that the foregoing illustrates a single color of blue for all malloced memory blocks and a single color of red for all malloc metadata portions. More generally, as described elsewhere herein, malloc may be provided with the authority to generate an unbounded number of new colors as may be needed for coloring different portions of heap memory. As discussed elsewhere herein, for example, malloc may be given and initial predetermined set of one or more colors or tags and may generate subsequently needed tags from the initial predetermined set. For example, malloc's initial predetermined set may include yellow or Y and red or R. For an executing process, malloc may generate a fresh Y-based tag (e.g., Y1, Y2, Y3, . . . ) for each call to malloc to allocate a new memory block used by user code (e.g., other than for malloc metadata storage). Thus, a different Y-based tag may be used to color each malloced memory block 1102b, 1104b and 1106b (e.g., 1102b colored with Y1, 1104b colored with Y2, 1106b colored with Y3). Malloc may generate a fresh R-based tag (e.g., R1, R2, R3, . . . ) for each different malloc metadata portion created for each call to malloc. Thus, R-based tags may be used to color malloc metadata portions 1102a, 1104a, 1106a each with a different R-based tag (e.g., 1102a colored with R1, 1104a colored with R2, 1106a colored with R3). The current or last R-based tag and the current or last Y-based tag used by malloc may be stored as state information via rules triggered when executing malloc instructions. For example, malloc may include an instruction which triggers a rule that stores the last Y-based tag, Y9, as the tag of a first memory location. Y9 may be generated as the Rtag. A subsequent instruction may again reference the same first memory location tagged with the saved last Y-based tag, Y9, where the subsequent instruction triggers a rule that 1) generates a new tag, Y10, based on the last Y-based tag, Y9, and 2) saves the tag Y10 as the tag on the first memory location. Y10 may be generated as the Rtag. The rule triggered by the subsequent instruction may indicate to determine Rtag, for example, as MRtag+1, where MRtag is Y9 for the subsequent instruction.
What will now be described are techniques that may be used as an optimization in connection with metadata processing using hardware accelerated miss handling. Generally, some policies used in embodiment herein may cause frequent rule cache misses and the cache miss handlers for such policies may take many cycles to run. In some policies, the relationships between various rule inputs may be rather simple in terms of logically determining a result or outcome and may therefore be hardwired and resolved quickly with dedicated hardware.
As a result, such policies implemented using hardware (HW) rule cache miss handler may be resolved in a much shorter amount of time than others not using such hardware acceleration. In such an embodiment, policy components, such as the cache miss handler for one or more selected policies, may be implemented with dedicated hardware. Thus, an embodiment in accordance with techniques herein may use such hardware-supported policies alone, or in combination with, software-defined policy components using a software rule cache miss handler.
As one example, consider a memory safety policy that uses memory safety coloring. In connection with a memory safety policy such as described elsewhere herein, memory cells and pointers may be colored whereby rules invoked in connection with both load and store operations may only allow a memory reference where a pointer color matches that of the memory cell. For example, rules triggered for a load instruction may be used to enforce a policy where the pointer color (e.g., of a register tag where the register is an operand such as OP1) is equal to a memory-cell color (e.g., memory location tag such as Mtag). The memory safety policy may challenge capacity by filling the PUMP rule cache with many different concrete rules that simply capture this equal color relationship for many colors, increasing the capacity miss rate. In some embodiments as described herein without preloading the rule cache, compulsory rule cache misses are required to insert every one of these rules. Since memory safety policy rules may be commonly triggered in connection with executing user code, memory safety policy rules may be supported using HW rule cache miss handler rather than a software rule cache miss handler.
In such an embodiment, the HW rule cache miss handler may generate or calculate a new rule inserted into cache upon the occurrence of a rule cache miss. For example, the miss handler for memory safety may be implemented using hardware as a HW rule cache miss handler that, for load instructions, compares OP1tag to the Mtag If OP1tag equals Mtag, the HW rule cache miss handler may generate a new rule with Rtag assigned Mtag. For example, if the pointer PTR is red and the memory cell pointed to by PTR is red, the instruction invoking the rule is allowed and the resulting tag Rtag should be red. To generate the foregoing as a new rule to be inserted in the rule cache, the HW cache miss handler may first compare OP1tag to Mtag. If they are not equal, there has been a rule violation and the instruction is not allowed (e.g., cause processor to stop execution). If the HW rule cache miss handler determines OP1tag is equal to Mtag, the HW rule cache miss handler may generate as outputs of hardware the new rule including opcode=load, OP1tag=red, Mtag=red, and Rtag=red (all other tag inputs and outputs of the rule may be don't cares), where the generated rule may then be inserted into the rule cache.
Referring to
Element 1303 illustrates the HW rule cache miss handler 1304 that may be used in an embodiment in accordance with techniques herein rather than the software rule cache miss handler. In such an embodiment, the HW rule cache miss handler 1304 may be implemented using dedicated hardware including, for example, gate-level logic and other hardware components. In such an embodiment, the HW miss handler 1304 may take the same inputs 1302a as the PUMP rule cache 1302 and may generate, using its hardware, the same outputs 1302b that would be output the PUMP rule cache. Subsequently, a new rule may be formed by combining the opcode, input tags and output tags as noted above. The new rule may then be stored in the PUMP rule cache (e.g.
In at least one embodiment, the HW rule cache miss handler for the memory safety policy may be implemented as described above in hardware (e.g., using gate level logic) that, to load a rule into cache, may simply copy the memory-cell tag from the Mtag to the Rtag and immediately perform the PUMP rule insertion. Note in this simple case, there is no need to dereference memory and perform any data structure operations in memory.
Additionally, in at least one embodiment, memory safety may implement the memory cell's tag as a pair of tags: (1) memory-cell color tag, (2) pointer-color tag on pointer in the memory cell. Memory-safety acceleration may include dedicated caches to perform the combination of the Mtag and OP2tag into the new Rtag on a store, and to perform the extraction of the pointer-tag from an Mtag pair to place onto the Rtag for a load. Misses to these caches may use simpler, dedicated software handlers. While the foregoing is described for a single (non-composite) policy such as memory safety, the same general technique may be applied to a component of a composite policy on the UCP.
An embodiment may also perform hardware acceleration using HW rule cache miss handler for a limited common subset of rules such as those that are expected to be commonly referenced. For example, in memory safety, the rules for load/store and propagation during arithmetic are the most standard and stylized. Other, uncommon rules exist for initially coloring memory regions and reclaiming memory regions on free. Such uncommon rules may result in using the typical rule miss handler as described herein rather than being implemented with hardware support.
In at least one embodiment, a HW rule cache miss handler may directly implement a mapping function as gate-level logic. For example, such gate level logic may map an input tag to an output tag for rule such as mapping Mtag to Rtag for store instruction rules of the memory safety policy. As another example, a HW rule cache miss handler for a CFI (control flow integrity) policy may use gate level logic to make the tag of the control flow target or destination be a pointer to the set of allowed callers (e.g., source locations or addresses allowed to transfer control to the tagged particular control flow target or destination), allowing the CFI HW rule cache miss handler to read through the set for a match. As yet another example, a stack protection policy may encode the stack-frame-code tag and the associated stack-frame-memory-cell tag in a manner that allows hardware derived one from the other (e.g. they could differ by only a few bits, and this could be arranged even if the tags were pointers by allocating the stack-frame-code tag pointer and the stack-frame-memory-cell tag pointer together); consequently, a HW rule cache miss handler enforcing a stack protection policy would be able to determine the tag to create (in case of creating a tag from the stack pointer), or demand on the memory reference (in the case of a read or write) within such code.
As a variation from using HW rule cache miss handlers to calculate or determine a new rule which is then inserted into the PUMP rule cache, an embodiment may actually hardwire the logic of one or more rules of a policy where such rules are completely embodied and enforced in hardware and therefore not stored in the PUMP rule cache. For example, rather use a HW rule cache miss handler and PUMP rule cache for a policy, an embodiment may use hardware to enforce and encode the rules of the policy (e.g., rules of policy embodied in hardware such as gate level logic and circuits). In such an embodiment using both the PUMP rule cache and HW specified rules, a rule lookup may be performed of both the PUMP rule cache and also the HW specified rules. In this case, a miss handler (e.g., either a HW rule cache miss handler or a software miss handler) may be invoked to determine/calculate a new rule responsive to not finding a rule for the particular inputs in either the PUMP rule cache or the HW specified rules.
Composite policies present additional challenges and opportunities. Consistent with discussion elsewhere herein, a composite policy includes multiple policies simultaneously enforced for an instruction. The challenge is that the composite policies need resolution of several different policy components. The opportunity is that the entire sequence of resolution for the composite policy may be hardware supported using HW rule cache miss handlers for all the different policy components of the composite policy with the data cache, UCP caches (per UCP cache per policy component in the composite policy), and CTAG cache. From prior experience, a common challenge is where newly allocated memory (e.g., using malloc), hence new memory color tags, causes compulsory rule cache misses. In these cases, the memory safety policy component needs new rules, but the other components may likely already have their rules in the UCP caches. With hardware acceleration through HW rule cache miss handlers for the top-level composite policy and for the memory-safety color matching, memory rule resolution may be performed with a small finite state machine running in hardware and consulting the caches (e.g., data cache, UCP caches and CTAG cache) rather than requiring hundreds-to-thousands of cycles to resolve the rules running software-based miss handler code.
In at least one embodiment, the UCP caches may be decomposed by component policy and all resolved in parallel to produce the composite set of tag results to then be fed back into the CTAG cache. If all the policies may be resolved either by their UCP cache or by a simple hardware rule like the one for memory safety, the total time for lookup for the UCP caches would be that of a single policy rather than being proportional to the number of policies. This works perfectly if the number of component policies is fixed and matched to the hardware provided. Nonetheless, a slight variant simply distributes the component policies across the fixed, available number of UCP caches, so that the number of sequential UCP cache resolutions is only the ratio of the number of component tags to physical UCP caches.
Referring to
Additionally, although not illustrated in the example 1310, an embodiment may use the UCP caches and CTAG cache in combination with the HW rule cache miss handlers 1314a-c in an embodiment in accordance with techniques herein. As described elsewhere herein (e.g., in connection with
As an alternative to having HW rule cache miss handlers for all 3 policies of the composite policy as in the example 1310, an embodiment may selectively choose to implement HW rule cache miss handlers for one or more, but less than all, such policies comprising the composite policy. In such an embodiment, a portion of the rule cache miss handlers may be implemented in hardware and the remaining portion of the rule cache miss handlers of the composite policy may be implemented in software as described elsewhere herein.
It should be noted that some policies as described herein may allocate new tags such as, for example, in connection with a memory safety policy. In at least one embodiment, the HW rule cache miss handler for a policy such as memory safety that may allocate new tags may be provided with a FIFO-based cache of new tag values that the HW-based handler may use (e.g., cache of tags that may be used as the newly allocated tag values generated. If the tag allocated is a pointer denoting an address, then the cache includes addresses or pointers rather than the tag values). In this manner, the HW rule cache miss handler may perform allocation simply by reading the top entry from the FIFO-based cache. Periodically, software handlers may be executed the metadata processing domain to refill the FIFO-based cache with new tags available for allocation.
Embodiments are described herein where there is complete and strict isolation between the metadata processing domain and the “normal” code processing of the user code or execution domain. As a variation, an embodiment may take a more relaxed approach and expand the foregoing strict isolation model which still does not allow modification or writing of information by the user code or execution domain to the metadata processing domain but may allow information/values to be returned by the metadata domain to the user code or execution domain.
What will now be described are techniques that may be included in at least one embodiment which may utilize the foregoing more relaxed approach whereby the metadata processing domain returns a value that may be used or referenced by code executing in the normal code processing or execution domain (e.g., metadata processing returns a value that is an input to the normal or user code execution domain). For example, as described elsewhere herein, an embodiment may use malloc and free routines where such routines have their code tagged with instruction tags providing them with unique capabilities needed so that code of malloc and free, when executed, trigger rules which allow malloc and free the ability to perform their processing accessing malloc metadata, generating new color tags, tagging user data areas with such new color tags, and the like. The foregoing provides such privileges or abilities uniquely assigned to malloc and free at the exclusion of other code, such as user code. Now consider such an embodiment where malloc and free perform their processing and code tagging is utilized to specially tag malloc and free code by the loader with a special code tag(s) uniquely identifying such code as belonging to malloc and free with special execution privileges. In such an embodiment, it may be the case that user code making a call to free, for example provides a pointer PTR1 which has been corrupted or otherwise does not point to the beginning of the previously allocated storage area which is now being deallocated. PTR1 may be presumed, by free, to point to the first location of the user data area previously allocated by malloc. Free may assume a predetermined structure to the user data area and associated memory locations of the memory heap such as described in connection with
What will now be described are techniques that may be used in an embodiment to have the PUMP return a value to the code execution domain.
With reference to the example 1200 of
In such a case where PTR1 provided by the user code on the free invocation does not point to the expected location P1 and whereby PTR2 denotes the presumed beginning of malloc metadata used by free, code of free may incorrectly access data stored in memory block 1102b using such data as its malloc metadata which causes a violation, interrupt or trap (e.g., may be due to a rule violation detected by the PUMP, or other code execution error condition during execution of free). Thus, the execution of code executing in the user process space or domain may be aborted due to the foregoing violation during execution of the routine free as invoked in the call to free using PTR1 from user code. Rather than have routine free cause the foregoing abort of user code, it may be desirable to allow code of free to query the PUMP, or more generally, the metadata processing to return a value. The returned value may be, for example, a Boolean denoting whether the color associated with PTR2 (as will be used by code of free to access malloc metadata) actually points to a valid or expected malloc metadata area. Using such a returned PUMP or metadata processing value allows free to perform different conditional processing based on the whether the color associated with the memory location at address PTR2 denotes a valid malloc metadata color, such as red. Routine free may perform some recovery or other action if PTR2 identifies an invalid malloc metadata area as determined through the color of PTR2. Such action may be more desirable than having the user code aborted due to a rule violation, trap, interrupt or other execution error.
In at least one embodiment using the RISC-V instruction set, to implement returning a metadata processing value, a new instruction, gmd (get-metadata-info), may be added to the RISC-V instruction set such as:
Thus, R2 and R3 may be registers that are input or source operands, and R1 may be the register containing the result or output. In this particular example, R3tag may be red denoting the color of a valid malloc metadata area and R2tag may be blue. The rule invoked by the new instruction may output a return value as a Boolean in this example denoting whether R2tag=R3tag where the foregoing Boolean result may be the return value output by metadata rule processing (e.g., PUMP output) stored in register R1 accessible to free included in the address space of user executing code. It should be noted that R1 may be tagged with Rtag as the result tag consistent with discussion elsewhere herein.
The following describes logical processing that may be performed by code of free using a C-like pseudo code description with PTR1, PTR2, and OFF1 as described above:
In the above logical processing, IS RED may check to see if PTR2 is the color RED.
The recovery processing performed by code of the above-noted else block may, for example, try to locate the beginning of a valid malloc metadata area by searching backward or forward from PTR2. Code of the above-noted else block may allow termination of user code in a more defined an expected manner such as with a runtime error message/condition denoting the invalidly colored pointer PTR2.
The new instruction Get metadata info R1, R2, R3 may be included in instructions generated, for example, as a result of compilation and linking code of a free routine written in C to perform the above-noted logical processing. An embodiment may want to control or restrict what particular code portions may be allowed to execute this new instruction. PUMP rules may be used to mediate or restrict when this new instruction is allowed to be executed by what routine. For example, code of free or malloc may be allowed to execute the new Get metadata info instruction but not user code. Any suitable technique, some of which are described herein, may be used to provide the routine free with the needed privilege or authority to execute the new instruction returning a PUMP value. For example, code of free may be tagged with a special instruction tag denoting that free is allowed to execute the new instruction. For example, a loader may tag the new instruction appearing in free code with a special tag NI. Rules may be used to mediate or restrict what code may be allowed to invoke the new instruction to those having an instruction tag (CI tag) of NI.
Referring to
Referring to
More generally, the foregoing use of a new instruction may be used in an embodiment in accordance with techniques herein to return a value that is any suitable and desirable value that may be used by code specially tagged (e.g., with NI) to denote those occurrences of the new instruction that are allowable via invoked metadata processing rule(s).
Alternate embodiments may avoid adding a new instruction. This can be done by code-tagging an existing instruction to control this behavior and setting the care-bit to select the value output in this case. Another alternative may add a value-output-care-bit that is also an output of the PUMP so that the rule can determine the cases in which the value output should flow to the RD value result. This second case allows the opcode to behave normally when not tagged, and only exhibit this special behavior when given the appropriate code tag.
What will now be described are techniques that may be used to guarantee that a particular sequence of instructions is performed atomically as a single unit or complete sequence in a specified order from the first instruction to the last instruction of the sequence. Additionally, such techniques guarantee that there is no transfer of control into the sequence of instructions other than to the first instruction of the sequence and that there is no transfer or exit out of the sequence other than through the last specified instruction of the sequence. For example, consider the simple instruction sequence of
In the example 1400, shown is a sequence of 2 instructions 1402 and 1404. The first instruction 1402 reads or loads contents from a memory location (where the address of the memory location is stored in R2) to R1. The second instruction writes or stores a zero (0) to the same memory location (the memory location having the address stored in R2). Such an instruction sequence may provide for ensuring that a value read from a memory location (having the address specified in R2) is used only once whereby the old value is erased or zeroed out from the memory location immediately after the value is read from the memory location. Thus, the zeroing out of the memory location is performed by the second instruction 1404 of the sequence and is required to be performed as the next instruction in the sequence after the first instruction 1402 that reads the value from the memory location.
In at least one embodiment in accordance with techniques herein using a RISC architecture, rules may be used to enforce the foregoing linearity of a data item and atomicity of the instruction sequence of 1400. In such an embodiment, the PC tag (PC new tag) may be updated to communicate the state of the sequence of the next expected instruction in the sequence. In at least one embodiment, one solution is to tag the instruction 1402 with a CI tag denoting it as a linear read instruction. Additionally, (R2), denoting the memory location having the address stored in R2, may be typed and tagged as a linear variable with a unique metadata id X1 (e.g., X1 uniquely identifies this linear variable from all other linear variables). A first rule may be triggered as a result of the first instruction 1402. The first rule may indicate that only instructions tagged as linear reads are allowed to read from linear variables. Additionally, the resulting PCnew tag may be clear-linear-variable-X1-next to denote that the next instruction executed needs to clear the linear variable X1. A second rule may be triggered as a result of executing the second instruction 1404 where the value of the operand, zero (written to the memory location), is tagged with a special EMPTY tag denoting the special value used to initialize or clear the memory location. Additionally, the memory location is required to be the linear variable X1 denoting the particular tagged linear variable from the immediately preceding instruction 1402. If the second instruction following 1402 does anything other than write an EMPTY value to linear variable X1, a trap is caused. Thus the second rule enforces the desired sequentially and atomicity of the sequence of instructions in 1400.
More specifically, assume the first instruction 1402 is a load instruction that loads into R1 the contents from the memory location having the address stored in R2. The load instruction may be as follows:
Additionally, assume the second instruction 1404 is a move instruction that move zero (0) into the memory location having the address stored in R2. The move instruction may be as follows:
Following conventions noted elsewhere herein a rule may be defined as an opcode, input tags—PCtag, Cltag, OPltag, OP2tag, Mtag—and output tags—PCnewtag, Rtag. Based on the foregoing rule conventions, for the first load instruction, OP1 is R1, OP2 is R2 and (R2) is the memory location tagged as Mtag. The first rule triggered by the first load instruction may be:
Based on the foregoing rule conventions, for the second store instruction, OP1 is 0, OP2 is R2 and (R2) is the memory location tagged as Mtag. The second rule triggered by the second move instruction may be:
This example shows how tags and rules can be used to guarantee the indivisibility of a particular instruction sequence. One skilled in the art can readily see that this general technique can be applied in many other scenarios where it is desirable to enforce that data may only be accessed in a particular way as part of a specific sequence of instructions. One skilled in the art can also readily see that this technique can be adopted for any case where strict enforcement of an instruction sequence is required. As noted above, the general technique involves tagging the new PC (e.g., PCnew tag) from instruction N in the sequence with a special tag that is checked as the PC tag in a rule triggered by the next expected instruction N+1 in the glued sequence.
What will now be described are techniques that may be performed as part of booting or starting up a system in an embodiment in accordance with techniques herein based on the RISC-V architecture. Following paragraphs may refer to various CSRs described elsewhere herein such as in connection with the example 900 where such CSRs may be used in connection with the metadata processing domain.
As described elsewhere herein, a bootstrap tag may be hardwired or a value stored in a particular ROM location. As part of booting the system, a segment of bootstrapping code may be executed that generally performs initialization including initializing different CSRs, memory and the like. As part of initializing, such processing also initially tags memory locations with a default tag value derived from an initial bootstrap tag. In at least one embodiment, a CSR such as the boottag CSR (e.g., sboottag CSR as in the example 900) may be initialized with a special bootstrap tag used as the initial “seed” tag from which all other tags in the system are derived. Different code entities, such as a loader, may have their instructions specially tagged (e.g., CI tags set to special instruction tag) to thereby designate the loader as having particular privileges or authority to perform tasks that other code not having the special instruction tag is not allowed to do. The foregoing may be enforced using rules triggered by code of the loader that examine the CI tag to ensure it is the special tag in order to have the triggered rule perform a desired tagging operation. Thus, for example, the special CI tag used to tag instructions of the loader may be generated or derived from the bootstrap tag as a result of special rules triggered by executing code as part of the startup process. Generally, once some portion of code or stored instructions are tagged, rules may be triggered by execution of such tagged code to generate more desired tags and also place such generated tags on code and data. The foregoing and other aspects are described in more detail below.
At startup or booting of the system, the tag mode such as stored in the tagmode CSR (e.g., 901r of the example 900) may initially be off (e.g., 911a of the example 910). A bootstrap ROM program may be executed that first directly sets the default tag CSR (e.g., 901c of the example 900) to a special default tag value. Subsequently, the bootstrap program may set the tagmode CSR to a mode whereby the metadata processing domain writes the default tag as stored in the default tag CSR on all results. In other words, while in defaulttag tag mode (e.g., 911b of the example 900), the PUMP output Rtag is always the default tag value.
Subsequently, after memory locations have been initialized and tagged with the default tag, processing may be performed to generate an initial set of tags that will be used to further generate or derive all other subsequent tags (e.g., the initial set may be further used to derive one or more other generations of tags in an unbounded manner). Such processing may include executing an instruction sequence or code segment that triggers rules to generate the initial set of tags. In this case, the tag mode may be set to an appropriate tag mode level that engages the PUMP during execution of the code segment. For example with reference to the example 910 if boot code is executing in hypervisor mode, the tag mode may be set to either×110 as denoted by 911e or ×111 as denoted by 911f to engage the PUMP during execution of the code segment whereby rules are triggered and enforced as a result of the code segment instructions.
It should be noted that prior to executing the above-noted code segment, processing may be performed to verify or validate the code segment. For example, in at least one embodiment, the above-noted code segment may be stored in an encrypted form where, prior to executing, the code segment is decrypted and verified or validated (e.g., such as using a digital signature) to ensure the code segment has not been tampered with or modified.
To further illustrate, the bootstrap program may include in the above-noted code segment 4 instructions executed while the PUMP is engaged to thereby generate an initial set of tags:
1. R1←read boottag CSR
In instruction 1 above, R1 is a general-purpose register. Instruction 1 reads the boottag CSR, transferring both the value stored in the boottag CSR and the tag stored in the boottag CSR onto R1. The boottag CSR was either set to hold a particular tag during processor reset or by privileged mode write of the CSR, including its tag. The read from the boottag CSR may also clear the boottag CSR so that it is not available to be retrieved after this initial retrieval during boot.
In each of the add instructions forming instructions 2-4 of the above of the form “Add Rn←Ry+1” wherein Rn denotes the target or result register to store the results of the Add, and wherein Ry also denotes a register a source operand. Instruction 2 of the foregoing code segment may trigger a second rule that generates a second tag from the first tag and places the second tag on the memory location pointed to by R2. Instruction 3 of the foregoing code segment may trigger a third rule that further generates a third tag from the second tag and places the third tag on the memory location pointed to by R3. Instruction 4 of the foregoing code segment may trigger a fourth rule that further generates a fourth tag from the third tag and places the fourth tag on the memory location pointed to R4. In this manner the foregoing code segment may be used to generate an initial set of 4 tags stored as tag values on registers. The foregoing general technique may be further extended in a similar manner to generate any desired number of tags of the initial set.
Generally, in generating an initial set of tags in at least one embodiment, the particular number of tags in the initial set may be a predefined number. Each of the special tags may be generated as a result of a different unique rule triggered when executing an instruction. Each instruction, such as in the code segment above, may result in a cache miss and thereby result in execution of the cache miss handler to calculate the Rtag as part of the rule outputs for the particular instruction, where Rtag is one of the tags of the initial set. In a manner similar to the instructions of the code segment above, a different code sequence may be executed at different points in time to further generate other tags using one of the tags of the initial set. Thus, each tag in the initial set may denote a tag generator used to further generate another sequence of tags. In the foregoing example, the Add instruction may be used in generating a next tag generator that may be used to generate another entire sequence of tags. As discussed below, a tag generator of the initial set (which is itself a further tag generator used as a starting point to generate another sequence) may be distinguished from a regular or non-generating tag which cannot be further used as a generator to generate another sequence of tags. Thus, particular instructions such as ADD may be used to trigger rules and miss handling to generate a set or sequence of tag generators. This may be contrasted with another instruction, such as MOVE, which may trigger rules and miss handling to generate a non-generating tag in a sequence. In connection with code such as malloc, an ADD instruction may be similarly used to generate a new application tag color generator used to generate a sequence of different colors for a first application (e.g., new application tag color generator may be APP1 used to generate a sequence of different colors RED-APP1, BLUE-APP1, GREEN-APP1, etc for the particular application). A tagged ADD instruction may then be used to obtain the next tag in the particular applications specific sequence, such as one of RED-APP1-gen, BLUE-APP1-gen, or GREEN-APP1-gen. Then a tagged MOVE instruction may be used to generate the actual colors, RED-APP1, BLUE-APP1, or GREAN-APP1 from RED-APP1-gen, BLUE-APP1-gen, or GREEN-APP1-gen, respectively, (where RED-APP1, BLUE APP1, GREEN-APP1 cannot be used to further generate additional tag sequences).
The code segment of the bootstrap program that is executed while the PUMP is engaged may also include additional code that, when executed, triggers rules to tag kernel code/instructions and additionally tag other code modules or entities with any desired special instruction tags to enable such specially tagged code to have desired privileges or capabilities. For example, the code segment may include instructions that trigger rules to tag the loader code, and code of routines malloc and free with special instruction tags extending privileges or authority to such code to perform privileged tagging operations. The special code tags may be generated from the initial set of tags in a manner similar to that as noted above using a predetermined code sequence/set of instructions that triggers rules to generate further desired tags and also appropriately tag additional code and/or data with the generated tags.
In at least one embodiment, additional measures or techniques may be taken in connection with portions of the above-noted code segment. For example, the above noted 4 instructions used to generate the initial set of tags may be included in a first instruction sequence using rules of a “glue” policy to enforce sequentiality and atomicity such as described elsewhere herein (e.g., example 1400).
After the code segment noted above has been executed to generate the initial set of tags and further specially tag kernel code and any other desired instructions, control may be transferred to additional boot code. In at least one embodiment based on the RISC-V architecture, the additional boot code may be executed at a hypervisor privilege level. Such additional boot code may, for example, include instructions triggering loading of an initial set of rules into the PUMP. Once booting has been completed, the PUMP tag mode as denoted by the tagmode CSR may be set to suitable level to engage the PUMP in connection with user code such as executes at the user privilege level (e.g., set tag mode as in 911c of the example 910 to denote PUMP is engaged and operations in U (user) mode or privilege level only).
Referring to
What will now be described in more detail is how to generate tags from the bootstrap tag. The tag generation processing commencing with the bootstrap tag may also be referred to as a tag tree or tree of life. More generally, the tag generation process forms a hierarchical structure as illustrated in the example 1620 of
The example 1620 illustrates the boottag 1621 as the root of the tag generation process. Element 1621a-d may denote the initial set of tags such as generated as described above. In this example, the initial set of tags 1621a-d may include an initial OS special instruction tag 1621a used to further generate a sequence 1622 of an unbounded number of special instruction tags which may then be applied 1623 to tag instructions of different code portions or modules 1624. From the initial OS special instruction tag 1621a, additional tags 1622 may be generated for the different modules to be tagged. For example, a first OS special instruction tag1 1622a may be generated for malloc which is applied 1623a to malloc code whereby instructions of malloc are tagged 1624a with the special instruction tag 1 1622a. In this manner, malloc code may be tagged with a special instruction tag identifying malloc as a tag generator (e.g, denoting that malloc code has privileges to further generator other new tags and further use the newly generated tags to tag other memory cells).
In this example regarding malloc, 1621b may be the initial malloc tag used to further generate malloc tag generator application tags 1626, one per user application since an instance of malloc is included in each user application. We want to give each such malloc instance in each user application the privilege to generate different colored tags as included in 1625.
Generally, the example 1620 illustrates an initial set of tags 1621a-d for Special Instruction tags 1621a, Malloc 1621b, CFI 1621c, and Taint 1621d. Thus, each of the tags 1621a-d in the vertical display of tags in the first row (other than boottag 1621) denotes a different initial tag used for a generating an unbounded tag sequence. For example, the value 1621a is used in further deriving or generating an unbounded number of special instruction tags 1622. The value 1621b is used in further deriving or generating an unbounded number of values 1626. Each instance of 1626 may be further used as a generator of another unbounded sequence of tags for each application. For example, 1626a denotes a generator value used to further generate another unbounded sequence 1629 of different colors used for a single application appl. In a similar manner, each different generator value of 1626 may be used to further generate an unbounded number of colors for each application.
The value 1621c may be used as a generator in further generating an unbounded number of values 1627. Element 1627 is similar to 1626 in that each occurrence of CFI tag generator n for a particular application or app N denotes a privilege or ability to further generate another unbounded sequence. For example, 1627a denotes a generator value used to further generate another unbounded sequence 1630 of different colors used for a single application appl. In a similar manner, each different generator value of 1627 may be used to further generate an unbounded number of colors for each application.
The value 1621d may be used as a generator in further generating an unbounded number of values 1628. Element 1628 is similar to 1626 and 1627 in that each occurrence of a tag generator n for a particular application or app N denotes a privilege or ability to further generate another unbounded sequence. For example, 1628a denotes a generator value used to further generate another unbounded sequence 1631 of different colors used for a single application appl. In a similar manner, each different generator value of 1628 may be used to further generate an unbounded number of colors for each application.
As illustrated sequences or subtrees for CFI and Taint originating, respectively, from 1621c-d are similar to the Malloc subtree originating from 1621b. In the example 1620, nxtTag or TlnxtTag is used to denote a next element in a generated unbounded sequence, and getTag to extract a next tag from a sequence member. Generally, getTag may be used to denote extracting a tag to use which is, itself, not a tag generator. If the usable tag is going to be given to a particular code portion to use, we don't to want to also give the code portion the ability to generate tags. For example, we want to give each application a Malloc Tag Generator for that application (e.g. ApplColorTagX), but do not want to give the application the ability to generate the Malloc Tag Generator for other applications. So, getTag changes the type from generator to instance. The distinction between nxtTag and TlnxtTag is that nxtTag is usable without a “tagged instruction”, but TlnxtTag is one that is only usable by a suitably tagged instruction.
The Malloc Application Tag sequence 1626 allows the operating system or loader to generate Color Tag generators for each application. For example, element 1626a denotes an application specific color tag generator value used to generate tags of the application color sequence 1629. Within an application, the AppYColorTag sequence 1629 allows malloc to generate an Authority for each color. That color authority can be used to: color the cells for allocated memory, color a pointer for the allocation and free cells of that color (e.g., when free is invoked). The use of colors such as with malloc and free are described elsewhere herein.
In this manner, different tags may be reserved for different uses. From initially tagged kernel instructions as noted above, kernel code may be executed that further tags other code portions with different capabilities or authority. For example, kernel code of the operating system may further tag other code entities, such as a loader, with special privileges such as granting the loader the ability to further tag other code and data, generate additional tag generators, and the like. The loader when loading a user program including malloc may further tag malloc code with special instruction tag(s) denoting it as malloc code giving it the capability to further generate other tags used to color different memory regions. A particular instruction tag placed on code of the loader thus provides the loader with one set of privileges. Placement of a second different instruction tag on malloc code provides malloc code with another different set of privileges. Generally, when performing tag generation of a sequence a current tag in the sequence is saved as state information which is referenced and used in connection with generating a next tag in the sequence. As described herein, such state information regarding the current tag in the sequence may be saved and used in the metadata processing domain. The current tag, or more generally metadata processing state information, may be saved and restored as a result of rule processing and cache miss processing. The current tag in a sequence, such as the last color allocated for use for a particular application, may be saved as a current state of the sequence as a tag on a specified memory location. When a new next color for the application needs to be allocated, code of malloc may trigger rules which retrieve the last allocated color for the application and use the last allocated color to determine the next color in the application-specific color sequence. Generally, generating a unique sequence of tags may include executing instructions that trigger rules that perform the following:
1. storing/saving sequence state in a tag portion of an atom (e.g., register, memory location);
2. executing an instruction that triggers a rule which generates the next tag of the sequence using the saved/stored sequence state; and
3. storing/saving the next tag of the sequence (generated from 2) in the tag portion of an atom where the next tag is now the updated current state of the sequence.
With reference back to the example 1620, the loader may allocate for each application using malloc a particular one of the malloc tag generator application tags of 1626. The loader may, for example, execute code triggering a rule which generates the next malloc tag generator tag, such as 1626a, and then stores this tag as state information via tagging a memory location. Subsequently, on a first call to malloc by the application, code of malloc may execute that triggers a rule which then retrieves the saved malloc tag generator tag, uses the saved tag to generate the first color for the application, and then updates the saved state information to store the first color as the last or most recent color generated for the application. On a second call to malloc by the application, code of malloc may execute that triggers a rule which then retrieves the previously saved first color, uses the saved first color to generate a second color for the application, and then updates the saved state information to now store the second color as the last or most recent color generated for the application. In a similar manner, other subsequent calls to malloc may be trigger other rules to allocate additional colors based on the saved state information (e.g., most recently allocated color) for the application.
What will now be described are aspects of a direct memory access (DMA) architecture that may be included in an embodiment in accordance with technique herein. Generally, described in following paragraphs is use of an I/O PUMP to mediate DMAs issued from a source, such as an untrusted device connected to a first interconnect fabric that uses untagged data, to access data stored in memory of a second interconnect fabric that uses tagged data.
Referring to
In at least one embodiment, the I/O PUMP 1502 may be an instantiation of the PUMP as described herein (e.g.,
The I/O PUMP 1502 is a rule cache for SDMP. The I/O PUMP provides a mapping between a set of tags involved in a DMA operation and the result of the operation. In at least one embodiment, the 110 PUMP runs independent of the processor 702. Since the I/O PUMP 1502 is a cache, it will take misses when it has never seen a set of inputs before (compulsory) or when it was unable to hold onto a rule (capacity, or perhaps conflict). This results in a rule cache miss with respect to the I/O PUMP in a manner similar to rule cache misses as described herein for the PUMP. Misses with respect to the 110 PUMP rule cache 1502 raise an interrupt that is then handled by in software by a rule cache miss handler system—the same one that services processor 702 miss traps. On a rule miss with respect to the 110 PUMP 1502, inputs are communicated to the Miss Handler (such as executed on code of the processor 702 in the metadata processing domain) through I/OPUMP CSRs described below (e.g., example 1520), and rule insertion is provided back to the I/O PUMP through CSRs. I/OPUMP misses cause the I/O PUMP to be disable until serviced by the processor 702. In at least one embodiment, the disabled state of the I/O PUMP means all DMA transfers mediated by the I/O PUMP are stalled until the 110 PUMP miss is serviced.
Consistent with discussion elsewhere herein with the PUMP, I/O PUMP inputs include an opgroup (opgrp), tags for the DMA instruction and its operands (e.g. PCtag, CI tag, OP1 tag, OP2 tag, Mtag (also referred to sometimes herein as the MRtag). I/O PUMP outputs may include the Rtag and PCnew tag (tag for the PC of the next instruction) as described herein. In connection with the 110 PUMP, such inputs and outputs may have further meaning and values as described below in one embodiment.
Following are I/O PUMP inputs in one embodiment:
1. Opgrp—there are current two: load and store
2. PCtag—state of the DMA 10 device (analog to the PCtag for code)
3. Cltag—tag identifying the DMA 10 device (analogous to instruction tags on a designated region of code)
4. OP1tag—assume always “public, untrusted” (not physically represented in IOPUMP cache, but used for rules)
5. OP2tag—same as OP1tag
6. Mtag—tag on memory input to DMA operation
7. byteenable—which bytes are being read/written?
Following are I/O PUMP outputs in one embodiment:
8. Rtag—tag on memory result for a store
10. PCnew tag—state of the DMA I/O device after this operation
With the I/O PUMP, there may be no programmable opgroup mapping table (e.g., example 420). Rather, an opgroup used by the I/O PUMP to look up a rule may be a fixed opcode denoting a single opgroup for DMA load and DMA store operations. In at least one embodiment, there is no care masking for the I/O PUMP.
When there is a rule cache miss in connection with the PUMP as described herein such as in
Referring to
In at least one embodiment, if bit 0 of the status CSR is 1, it means the I/O PUMP is disabled and if the bit 0 otherwise has a value of 0, it means the I/O PUMP is disabled. PUMP I/O misses disable the pump. Bit 1 of the status CSR indicates whether the PUMP has faulted and is waiting for service (e.g., Bit1=1 implies I/O PUMP faults/cache miss and waiting for service). Bit 2 of the status CSR indicates whether an I/O PUMP rule miss is currently being resolved by a rule cache miss handler and, if the transaction id matches, will provide the inserted results directly to the pending miss operation. All the foregoing bits of the status CSR are reset (e.g., bit 0=enabled, bit 1=no fault, bit 2=no pending miss) by a commit operation (successful or unsuccessful). Writing to the status CSR may also be performed to reset the foregoing bits, for example, as needed on startup to initially enable the I/O PUMP. Reset of the status CSR for an unsuccessful write allows the DMA device to retry the operation and retrigger the fault.
Load/store memory operations by the processor 702 to the I/O PUMP CSRs should be tagged with the iopump CI tag. Policy rules should be in place to restrict operations to instructions having the iopump CI tag. Individual I/O PUMP CSRs do not have tags.
Each device 1504a-c on the untagged or untrusted fabric 715 may be configured with its own tag that is presented as a device tag when the processor performs loads or stores to the device (e.g., see 1534b where the device tag is stored in the device register file described below and specified as the CI tag when the particular device performs a DMA load or store). This allows fine-grained control over which code and authorities can access which devices directly. The same tag is presented on all loads and stores to the device, and the tag does not change based on load and store operations. The particular device tag associated with, and identifying, each device 1504a-c may be stored in a device register file. A particular device tag specified for a device 1504a-c may only be changed by modifying the device register file. The device register file may denote, for each device 1504a-c, a unique target device id (used to identify the device on the untagged or untrusted fabric 715) and a target-device specific tag for the unique target device id. In at least one embodiment, the device register file may itself be accessed as a device on the untrusted fabric 715 with its own device tag. To bootstrap the use of the device register file, the device tag register file's own tag (stored in the device register file) may be written to the file during startup before the PUMP is enabled. For example, the device tag register file's own tag may be written to the file as part of boot processing while the PUMP is off (e.g., tagmode denoting by 911a of the example 910). The CI tag of an instruction may identify the target id of the DMA target device performing a load or store instruction where the CI tag may be used in rules triggered by such load and store operations to restrict (e.g., allow or not allow) a particular load or store operation by the specified DMA device. Additionally, if a particular DMA device performs load and/or store operations which are not allowed, a state associated with the particular DMA device may be modified to disabled so that further requests (e.g., DMA loads and stores) are ignored.
As noted above, a DMA device that initiates or is a source of DMA requests or instructions may have an associated status indicated by the PCtag of the DMA device. In particular, a unique PCtag may be used to denote a disabled status with respect to DMA operations being allowed from a DMA device (identified by the CI tag). Disabled initiators have their DMA requests rejected at the start of the DMA or Trustbridge pipeline described below (e.g., examples 1530 and 1540).
It should be noted that an embodiment may have a single I/O PUMP mediating all DMA traffic, an I/O PUMP per DMA engine, or multiple I/O PUMPs that mediates DMA trafffic for multiple DMA engines. Illustrated in the example 1510 is a single I/O PUMP for a single DMA engine (e.g., single memory 712c). Use of a single I/O PUMP as in the example 1500 may become a bottleneck and thus an embodiment may choose to have multiple I/O PUMPs mediate I/O traffic. In such an embodiment where there are multiple I/O PUMPs, each may be enabled or disabled independently so that even though a first portion of one or more of the multiple I/O PUMPs may be disabled (due to an I/O PUMP miss), the remaining second portion of the multiple I/O PUMPs may be enabled and continue to service DMA requests.
In at least one embodiment, different DMA devices acting as initiators or sources of the DMA operations may each be allowed to access only specified portions of memory 712c. Different portions of memory 712c accessible via DMAs may each be tagged with a distinct tag. For example, device 1504a may have access to a first range of addresses of memory 712c and device 1504b may have access to a different second range of addresses of memory 712c. Memory locations of 712c corresponding the first range may be tagged with a first tag and memory locations of 712c corresponding to the second range may be tagged with a second tag. In this manner, rules may be used to enforce or restrict access of device 1504a to memory locations in the first range and enforce or restrict access of device 1504b to memory location in the second range. As a variation, different tags may be associated with a type of allowed access (e.g., read only, write only read and write). In a similar manner, in an embodiment having multiple DMA engines accessing the same memory 712c, different portions of the single memory 712c accessible exclusively to each of the DMA engines may be uniquely tagged whereby rules enforce or restrict access of each DMA engine to its specified address range of memory locations.
Referring to
Element 1537 denotes values provided as inputs to load (or retrieve) the I/O PUMP CSRs as described in the example 1520. Additionally device state information for the different DMA device initiators may be stored in the untrusted fabric device register file 1534b including the PCtag (e.g., state of the DMA device such as whether requests from this DMA device are disabled) and Cltag (e.g., DMA device unique identifier) for the DMA device initiator (e.g., such as 1504a-c on the untrusted fabric 715). The entry in the device register file 1534b for a particular DMA device performing a DMA load or store may provide the CI tag and PCtag values for the current DMA load or store. Element 1535a may denote the channel used for devices on the untrusted fabric 1536 to make mediated DMA processing requests of 1534. Element 1535b may denote the channel used for returning the results of mediated DMA requests of 1534 to the untrusted fabric 1536.
Elements 1531a-b denote channels for forwarding DMA requests from the untrusted fabric 1536 (via the DMA mediation processing of 1534) to the trusted fabric 1532. In particular, channel 1531a is a channel for forwarding initial tag read (unvalidated) DMA requests to the trusted fabric 1532 and channel 1531b is a second channel for forwarding the final write of data with tags updated. Use of the two channels may become more apparent given further discussion of the DMA or trustbridge pipeline described below in connection with the example 1540. Element 1531c denotes a channel from the trusted fabric 1531c to the untrusted fabric via the DMA mediation processing 1534.
In one embodiment, element 1534 may represent a DMA processing pipeline as illustrated in the example 1540 of
Element 1542 may denote the rules that pass along a request from the untrusted fabric and pass along information (from stage 1 1541a) regarding the I/O request for the I/O PUMP 1545 (in stage 3 1541c) while the memory fetch is performed in stage 2 1541b. Elements 1544 may denote the rules that gather up tag responses from the trusted fabric, formulate the actual rule input to the I/O PUMP, and propagate information from stage 1541b to the writeback stage 1541d to be merged with the output of the I/O PUMP.
As a variation to the foregoing embodiment, reference is made back to the example 1500. In at least one embodiment, rather than have rules stored in an I/O PUMP cache as described above, the I/O PUMP may be implemented as a hardwired I/O PUMP where the rules may be implemented using dedicated hardware such as logic gates wired to embody a fixed set of I/O PUMP load and store DMA rules.
As further variation, the I/O PUMP may alternatively be defined in yet another embodiment as a cache that is programmable as described in connection with the example 1500 with the difference that the I/O PUMP as a rule cache has a finite capacity and is filled with a fixed set of rules that are all stored in the I/O PUMP cache. In this latter embodiment, the I/O PUMP may be populated with the complete set of all DMA rules so that there is never a rule cache miss for the I/O PUMP. Thus, there is never a need to service an I/O PUMP rule cache miss.
What will now be described are techniques that may be used in connection with initializing, setting or resetting tags such as may be associated with memory locations. Consistent with description elsewhere herein, a tag used in connection with such techniques may denote a non-pointer tag (where the non-pointer tag is the actual tag value for the associated memory location) or a pointer tag (where the pointer tag is a pointer or address of another memory location including the actual tag value or values). For example, a pointer tag associated with a memory location may be used in connection with composite tags where the pointer identifies an address in memory including multiple tag values such as for a plurality of composite policies implemented in parallel. As described elsewhere herein, example composite policies that may be supported in parallel include a memory safety policy and a control flow integrity (CFI) policy described elsewhere herein.
Processing performed in connection with memory safety and stack policies, for example, may include setting or initializing a large number of tags associated with memory locations to a particular value. For example, when allocating a region of memory such as may be associated with a particular color, each tag associated with a memory location in the region needs to be initialized to have the particular color value. As another example, when reclaiming a region of memory such as when freeing the memory region, all memory locations of the freed or unallocated region may be initialized to a particular tag value denoting the memory locations as free or unallocated.
Processing performed to initialize or reset tags of all memory locations in a region may consume an unacceptable amount of time and becomes particularly unacceptable as the size of memory region to be tagged increases. Thus, described in following paragraphs are techniques that provide for efficiently initializing or setting tags (e.g., tagging) of memory locations. In at least one embodiment, tag initialization or setting may be performed, for example, in connection with allocation a region of memory or freeing a region of memory. Such techniques described herein are scalable for use with large memory regions. Although such techniques are illustrated below in connection with tags of memory location, more generally, such techniques may be used in connection with initializing, setting or resetting values each associated with a data item or entity.
In at least one embodiment, the tags and associated memory locations of a region of memory may be represented in a hierarchical structure or arrangement where the leaves of the hierarchy denote the tags for the memory locations. For purposes of illustration, following discussion makes reference to a tree as the hierarchical structure. However, more generally, any suitable hierarchical structure may be used to represent an address space associated with a region of memory locations.
In an extreme case, in one embodiment, the leaves of the tree or hierarchical structure may represent individual words in memory and hold the tags. However, if an entire subtree is homogeneously tagged with the same tag value, techniques herein may simply store the tag value at that particular node and associated level in the tree without further representing any descendant nodes of the subtree. In this case, the tag value of the node specifies a tag value for multiple memory locations of a particular region (e.g., such as a range of consecutive or contiguous memory addresses). In this manner, storage may be saved in storing tag values if there are large homogenously tagged regions. In a worst case scenario where there is no homogeneous tag value (e.g., no two memory locations having consecutive addresses have the same tag value), the leaves of the tree each represent a tag value for a single memory location, such as a single word in the region.
With such a hierarchical structure such as a tree as described in following paragraphs, processing may be performed to retag or initialize a power-of-two memory region by simply rewriting one node in the tree. For a non-power-of-two region, processing may be performed to partition the region into a minimum set of power-of-two regions (e.g., at most 2*log 2 (region size) such regions in the minimum set). When a tag of a particular word or memory location is needed (e.g., read the tag for an associated memory location), processing may be performed to determine the tag using the tree. In at least one embodiment described below, a hierarchy of cache memories may be utilized for the different levels of the tree. The tag value may be provided by the cache associated with the highest level in the tree having a cache hit with respect to the desired memory location (e.g., perform a cache lookup for the tag value for the address of the desired memory location). In connection with processing performed to write or modify a tag value associated with a memory location, processing may include performing a single write to mark a subtree, or multiple writes (e.g., 2*log 2 (region size) log writes). Such multiple writes may be performed, for example, responsive to modifying or setting the tag of a first memory location included in a first memory region that is homogenously tagged prior to such modifying or setting the tag value. In this case, setting or modifying the tag value causes the first memory region to no longer be homogenously tagged and the hierarchical structure denoting the tag values for the first memory region is accordingly updated to further decompose a subtree denoting tag values for the first memory region.
Referring to
The example 100 illustrates a binary tree representation of tag values for 8 memory locations having addresses 0 through 7, inclusively. The tree in this example may include up to 4 levels of nodes, depending on which of the 8 memory locations, if any, are homogeneously tagged using a same subtree of the structure 100. In this example, the entire memory region of 8 memory locations may be partitioned repeatedly into power of two smaller memory regions where each such partitioning of smaller memory regions corresponds to a different level of nodes in the tree. For example, level 1 104 includes node A1 corresponding to the entire address space 0 through 7 which is partitioned into two smaller regions each represented by a node (nodes B1 and B2) at level 2 106. Level 2 106 includes node B1 associated with addresses 0-3 and node B2 associated with addresses 4-7.
Each of the nodes B1 and B2 at level 2 106 may be further partitioned into two smaller regions each represented by a node at level 3 108. Node B1 and its associated address range 0-3 is partitioned into two regions represented by nodes C1 and C2, where C1 is associated with address range 0-1 and C2 is associated with address range 2-3. Similarly, node B2 and its associated address range 4-7 is partitioned into two regions represented by nodes C3 and C4, where C3 is associated with address range 4-5 and C4 is associated with address range 6-7.
Each of the nodes C1-C4 at level 3 108 may be further partitioned into two smaller regions each represented by a node at level 4 110. In this example, nodes at level 4 each represent a tag value for a single word or memory location. Node C1 and its associated address range 0-1 is partitioned into two regions represented by nodes D1 and D2, where D1 is associated with address 0 and D2 is associated with address 1. Node C2 and its associated address range 2-3 is partitioned into two regions represented by nodes D3 and D4, where D3 is associated with address 2 and D4 is associated with address 3. Node C3 and its associated address range 4-5 is partitioned into two regions represented by nodes D5 and D6, where D5 is associated with address 4 and D6 is associated with address 5. Node C4 and its associated address range 6-7 is partitioned into two regions represented by nodes D7 and D8, where D7 is associated with address 6 and D8 is associated with address 7.
All the nodes A1, B1-B2, C1-C4 and D1-D8 may represent the maximum number of possible nodes that may exist in the hierarchical representation of tag values for the region of 8 memory locations. However, as described in more detail below, the particular nodes included in the tree denoting the tag values stored in the memory locations 0-7 may vary depending on the particular tag values and homogenous and non-homogeneous tag regions represented at various points in time. Levels of the hierarchy may be ranked from a highest level corresponding to the root or level 1 104 node to the lowest level corresponding to the bottom most level 4 110.
In connection with techniques herein with a first example, reference is made to 120 of
In a second example, reference is made to 130 of
At a first point in time, the tag hierarchy may be as described in connection with the example 120 with only the single node 122 since all tags have the same tag value. At a subsequent second point in time, tag values for addresses 0-3 may be modified to be the same first tag value T1 and addresses 4-7 may be modified to be the same second tag value T2. As a result of the foregoing tag modifications, two addition nodes B1 and B2 as described above in the example 130 may be added to the hierarchy. Assume now at a subsequent third point in time tag values for addresses 0-3 remain the same as in the example 130. However, tag values for addresses 4-7 may be modified as described below in connection with
In a third example, reference is made to 140 of
The foregoing illustrations of 120, 130 and 140 may denote the hierarchical representation of tag values for the memory region for addresses or memory locations 0-7 at different points in time as tag values associated with the memory locations may change over time. In a manner similar to adding nodes to the hierarchy as described above, nodes may be removed from the hierarchy as needed as subtrees of existing nodes are modified to all have the same tag value (e.g., if descendants of a node all have the same tag value then all descendant nodes may be removed from the hierarchy and the node may be used as the sole node of a subtree to denote the single homogeneous tag value of the node and its descendants).
In at least one embodiment, when a first node at a level in the tree specifies a value for one or more memory locations associated with the first node, there is no need to further represent descendant nodes of the first node (e.g. no need to further represent nodes of the subtree beyond the first node). To further illustrate, reference is made to the first example noted above in 120 of
In a worst case scenario assuming there are no homogeneously tagged memory locations in the memory region having addresses 0-7, the entire hierarchical structure of nodes of
Referring back to
In at least one embodiment in accordance with techniques herein, a series of tag cache memories may be used where the number of tag caches may correspond to the number of levels in the hierarchy of nodes denoting tag values. Continuing with the example discussed above and with reference back to 100 of
In connection with the example embodiment described herein with an 8 bit address space, the top or highest 5 bits 152a of the address of a memory location may be used by level 1 cache 152 to lookup whether the cache 152 includes any level 1 node for the address of the memory location. The top or highest 6 bits 154a of the address of the memory location may be used by level 2 cache 154 to lookup whether the cache 154 includes any level 2 node for the address of the memory location. The top or highest 7 bits 156a of the address of a memory location may be used by level 3 cache 156 to lookup whether the cache 156 includes any level 3 node for the address of the memory location. The 8 bits 154a of the address of the memory location may be used by the level 4 cache 158 to lookup whether the cache 158 includes any level 4 node for the address of the memory location.
For a particular address, each of the caches associated with a level other than the bottom most level, may return:
1). the tag value for the particular address (denoting that this is a homogeneous tag value at that level for multiple addresses);
2). an indicator that the cache does not specify a tag value for the particular address and a cache at a lower level in the hierarchy needs to be consulted to obtain the tag value for the particular address (this particular level does not specify a homogeneous tag value for the particular address); or
3). null or a second indicator denoting that there is no cache location in that particular level cache including node or tag information corresponding to the particular address. The second indicator also denotes that no cache at a lower non-bottom level cache includes a node or tag information for the address. This is discussed below in more detail.
Consistent with discussion above, the indicator returned in item 2) above may be the “NO TAG” indicator associated with a node such as illustrated in examples 120, 130 and 140. For example, with reference to the illustration 130 of
For contents of a memory location stored in an L1 (level 1) data cache, cached information may include the current tag value and also the level in the tag cache hierarchy where the tag value is defined. Referring again to the example above for the memory location 5 using the hierarchy 130 of
In an embodiment in accordance with techniques herein, processing may be performed by the PUMP to resolve or determine a tag value for a particular memory location having a particular address. When performing processing to obtain a tag value and contents for a particular memory location, there may be a data cache hit whereby the memory location contents and its tag are stored in the data cache. Upon the occurrence of a data cache hit for a memory location, processing may be performed to consult the stored level of the tag cache hierarchy which defines the tag value for this memory location to make sure the first cached tag value obtained from the tag caching level matches the second tag value of the memory location as stored in the data cache. If the two do not match, this indicates that the second cached tag value as stored in the data cache is stale, out of date and has been modified. In this case if the second cached tag value stored in the data cache for the memory location and the first tag value as obtained from the tag cache for the memory location do not match, processing may be performed including updating the second cached tag value as stored in the data cache for the memory location (e.g., to match that as stored in the tag cache hierarchy). In at least one embodiment, for a memory location having its data and thus its tag cached in the data cache, information may be tracked in the data cache for the memory location's tag including the level of the tag cache hierarchy where the tag is defined. The foregoing storing of the level in the cache tag hierarchy may be an optimization whereby the stored level may be used to readily access the tag value from the tag hierarchy (e.g., rather than having to consult all tag level caches or otherwise search the hierarchy of existing nodes such as in a search from the root or top of hierarchy downward toward the leaf nodes). Thus, upon the occurrence of a data cache hit and where the tag value stored in the data cache for a memory location does not match the tag value stored in the tag hierarchy for the memory location, processing may include updating the tag value as stored in the data cache and additionally updating the hierarchy level information stored in the data cache as to where the memory location's tag is defined in the tag hierarchy. Subsequently, processing performed by the PUMP for resolving or determining the tag value for the memory location may be restarted.
Upon the occurrence of a data cache miss for a memory location (e.g., where the memory location contents and tag are not found in the data cache), processing may be performed to perform a tag cache lookup for the tag value in levels of the tag cache (e.g., other than the bottom most tag cache level) in parallel. For example, a lookup for the tag value for the memory location may be performed by consulting the 4 caches 152, 154, 156 and 158, respectively, for levels 1, 2, 3 and 4 of the tag caches in parallel. As discussed above, the tag value returned by the highest level of the tag caches 152, 154, 156 and 158 is used as the tag value for the memory location. Additionally, it should be noted that in a properly represented tag value hierarchy, only a single one of 152, 154,156 and 158 may return a tag value for the memory location. In at least one embodiment, the caches 152, 154, 156 and 158 may be indexed to allow for parallel access.
An embodiment may also not perform a parallel lookup or search for a particular memory location's tag with respect to all 4 tag caches 152, 154, 156 and 158. As a variation an embodiment may traverse the tag caches of the hierarchy from the root node level (level 1) downward toward the leaf nodes (e.g., level 4). For a tag cache miss at a level N, the tree or hierarchy may be traversed inserting nodes into the different levels of tag caches for the particular memory access. In connection with a level cache miss for a parallel search of the tag caches, an embodiment may choose to only insert nodes into the level caches when there is a tag. So as some level cache provides a tag, it is not required that all other level caches have a NO TAG entry.
As discussed elsewhere herein, a tag of a memory location may be modified. In response to modifying a tag of a memory location, processing may be performed to accordingly update the hierarchy specifying a tag value for the memory location. Such updating may include invalidating any one or more levels of the hierarchy which are no longer homogeneous. Additionally, processing may be performed to accordingly update the levels of caches such as illustrated in the example 150 of
When performing an operation to set or initialize a tag of a memory location, such processing may include the PUMP checking for the validity of performing the desired operation. For example, consider the case with retagging all memory locations in the memory region with a new tag. Processing may include obtaining the current tag values of all memory locations in the region and checking via PUMP processing for validity of the retag. The processing may include clearing the tags of the memory locations in the region, if allowed, and then updating the tag values for the memory locations in the region, if allowed. Consistent with discussion above, updating, modifying, or setting tags of a memory region may include accordingly modifying the hierarchy and associated nodes to reflect the tag values for different memory locations in the memory region (e.g., decomposing portions of the region which are homogeneous prior to the modification and non-homogeneous after the modification whereby there may be additional children or descendant nodes added to reflect the tag value modification(s)).
In at least one embodiment, the hierarchical representation of tag values for a memory region may be a tree. For example, the tree may be a binary tree where each node has either 0, 1 or 2 children. As a variation, the hierarchical representation may be a tree but not a binary tree. For example, each node in the tree may be allowed to have any suitable number of child nodes up to a specified maximum. The hierarchical representation may include any suitable number of levels, nodes at each level, children per parent node, and the like. As known in the art, there is a tradeoff between various parameters of the hierarchical representation such as depth or number of levels and nodes at each level/number of children per parent node). For example, the larger the number of nodes at each level, the fewer the number of levels and thus the shorter amount of time/levels to be consulted when determining a tag value for a memory location. However, in such a case, more writes need be performed to clear a region.
What will now be described are techniques that may be performed, such as by rules triggered as a result of loader code, in connection with a CFI policy in an embodiment in accordance with techniques herein. To enforce the CFI policy using metadata processing rules accessing tag information, information regarding allowable control flow needs to be communicated to the metadata processing domain. To this end, an embodiment in accordance with techniques herein may use an approach described in following paragraphs. Generally, a transfer of control is made from a branch source to a target or destination. In connection with allowable control flow, for a particular control flow target or destination, a set of sources that are allowed to transfer control to the particular control flow target or destination may be identified. The set of sources for each possible control flow target may be communicated to the metadata processing domain, such as stored metadata tag information, which may then be used by rules of the CFI policy in connection with CFI policy enforcement during runtime execution of user code (e.g., code executing in the code execution domain or non-metadata processing domain).
The processing performed may include uniquely tagging each source and then tagging each target with the set of allowable sources (e.g., address of the sources) permitted to transfer control to that particular target. For example, reference is made to
In at least one embodiment consistent with description elsewhere herein, execution of kernel code may trigger rules that tag code of the loader with special instruction tags enabling the tagged instructions of the loader, when executed, to trigger rules that generate a sequence of source tags (each tag of the sequence being unique) used to tag the sources (e.g., generate source tags D7, C3 and E8). For example, reference is made to
Element 1723 may be the following instruction included in loader code that triggers a rule that generates or allocated the new CFI source tag:
where the ADD instruction (e.g., such as ADDI in the RISC-V instruction set) has been tagged by the kernel code with the special CI tag of CFI-alloc-tag marking this instruction as an allowable tag generator instruction. In at least one embodiment a different sequence of source tags may be generated by the loader for each application in connection with a CFI policy (e.g., in the example 1620, the loader may use a different sequence of CFI tags 1630 as the unique sequence of CFI source tags for an application where the sequence of CFI tags may be generated from a particular one of the CFI tag generator App-n tags of 1627). The CFI-alloc-tag is the CI tag placed on the loader ADD instruction above denoting that the ADD instruction is allowed to allocate or generate a next tag in the application specific CFI sequence. CFI-alloc-tag may be one of the special instruction types of 1624 as described in connection with the example 1620. The ADD instruction above indicates that the tag on R1 holds the state of the CFI sequence where the state may be the last tag of the sequence previously generated. Execution of the above ADD instruction triggers a rule that generates the next new tag in the CFI sequence and updates the tag on R1 to now be the newly generated tag. Using rule conventions as described elsewhere herein, the following ADD rule may denote the rule triggered by the above ADD instruction:
which ensures that the CI tag for the ADDI instruction is CFI-alloc-tag. In this ADD rule, t1 denotes the previous tag in the sequence (saved as the current state of the CFI tag sequence for the application) which is used to generate the next tag, t1next, in the sequence, where t1next is then stored as the tag for RD (the destination or result register). The foregoing tag, t1next, in the CFI sequence may be used as the unique CFI source tag placed on a source point.
Element 1724 may be an instruction of the loader code, such as a ST (store) instruction below, used to trigger a rule that tags a source location with the unique CFI source tag:
where R3 is a pointer to the control flow source location in the user program code (e.g., 1704a in the example 1700) being tagged, and the tag on R1 is the unique CFI source tag to be placed on the source location. The above ST instruction may also be tagged with a special CI tag, such as CI-LDR, denoting the ST instruction is included in loader code triggering rule ST below:
where CI tag=CI-LDR, t1 is the CFI source tag currently stored as the tag on R1, and codetag is an instruction tag on the source location at address R3 (e.g., ensuring that the source location is currently tagged as code). As a result, the destination (R3) is tagged with t1, the unique CFI source tag.
Element 1725 may be an instruction of the loader code, such as an ADD instruction below, used to trigger a rule that adds the address of the source (e.g., currently pointed to by R3, where R3 contains the address of the source) to an accumulated set of CFI source tags denoting allowable source locations that can transfer control to the target:
where the tag on R2 points to a memory location denoting the accumulated set of allowable source locations. The above ADD instruction may be tagged with a special CFI UNION instruction tag denoting that this ADD instruction is performing a union operation of CFI sources and the union is stored as a tag on R2. The following rule for ADD may be fired as a result of the above ADD instruction:
which checks to ensure that the CI tag is CFI UNION, tset is a target set, and tsrc is a source tag. It produces a new CFI set, tunion, that represents the addition of tsrc to tset.
Element 1726 may be an instruction of the loader code, such as a ST instruction below, used to trigger a rule that tags the target with the union or accumulated list of allowable source locations that can transfer control to the target:
R17 may be a register containing the address of the target location, and R2 may be, as noted above, a register tagged with the current accumulated set union of allowable source locations (e.g., tag on R2 denotes the set of allowable source locations for the target location whose address is contained in R17). The above ST instruction may be tagged with a special instruction tag CFI MARK TARGET denoting the instruction as a special one that is allowed to tag a control transfer target location (e.g., this STORE instruction 1726 of the loader code may have been tagged by kernel code in a manner similar to other code tags on load code instructions that trigger rules to perform processing of 1720). The following ST rule may be triggered as a result of the above STORE instruction for 1726:
which triggers when CI tag is CFI MARK TARGET and the target (pointed to by R17, wherein R17 includes the target address) is tagged with codetag indicating an instruction, and places the tset annotation onto the target.
Different tag structures or layouts that may be defined for use with sources, targets and the set of allowable source locations are described elsewhere herein as well as any other suitable structure definition (e.g., see examples 240, 250, 260, 267, 270 and 280 describing tag layouts for use with tagged source and target locations that may be used more generally with any instruction as well as in connection with multiple instructions per tagged word).
Thus, the processing steps described above as in the example 1720 may be performed by having code of the loader properly tagged so that when such loader code is executed, rules are fired which cause the steps of the example 1720 to be performed by the metadata processing domain in an embodiment in accordance with techniques herein. It should be noted that the foregoing sequence of instructions and fired rules as a result of the instructions are merely one examples of instructions and rules that may be used in an embodiment using techniques herein. For example, an embodiment may include a different instruction other than an ADD in loader code that triggers a rule performing processing as described above (e.g., element 1725).
In the foregoing description, certain terms have been used for brevity, clearness, and understanding. No unnecessary limitations are to be implied therefrom beyond the requirement of the prior art because such terms are used for descriptive purposes and are intended to be broadly construed. Moreover, the description and illustration of the preferred embodiment of the present disclosure are an example and the present disclosure is not limited to the exact details shown or described.
Various aspects of techniques described herein may be performed by executing code which is stored on any one or more different forms of computer-readable media. Computer-readable media may include different forms of volatile (e.g., RAM) and non-volatile (e.g., ROM, flash memory, magnetic or optical disks, or tape) storage which may be removable or non-removable.
While the invention has been disclosed in connection with various embodiments shown and described in detail, their modifications and improvements thereon will become readily apparent to those skilled in the art. Accordingly, the spirit and scope of the present invention should be limited only by the following claims.
While example embodiments have been particularly shown and described, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the scope of the embodiments encompassed by the appended claims.
This application is a continuation of U.S. application Ser. No. 16/256,640, filed Jan. 24, 2019, which is a continuation of U.S. application Ser. No. 15/168,689, filed May 31, 2016, now U.S. Pat. No. 10,235,176, granted Mar. 19, 2019, which claims priority to U.S. Provisional Application Ser. No. 62/268,639 filed on Dec. 17, 2015, and U.S. Provisional Application Ser. No. 62/270,187 filed on Dec. 21, 2015. The entire teachings of the above applications are incorporated herein by reference.
Number | Date | Country | |
---|---|---|---|
62268639 | Dec 2015 | US | |
62270187 | Dec 2015 | US |
Number | Date | Country | |
---|---|---|---|
Parent | 16256640 | Jan 2019 | US |
Child | 17452271 | US | |
Parent | 15168689 | May 2016 | US |
Child | 16256640 | US |