US20210011728A1 - Target injection safe method for dynamically inlining branch predictions - Google Patents

Target injection safe method for dynamically inlining branch predictions Download PDF

Info

Publication number
US20210011728A1
US20210011728A1 US16/521,407 US201916521407A US2021011728A1 US 20210011728 A1 US20210011728 A1 US 20210011728A1 US 201916521407 A US201916521407 A US 201916521407A US 2021011728 A1 US2021011728 A1 US 2021011728A1
Authority
US
United States
Prior art keywords
trampoline
code
call
indirect
operating system
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
US16/521,407
Other versions
US10908912B1 (en
Inventor
Nadav Amit
Frederick Joseph Jacobs
Michael Wei
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
VMware LLC
Original Assignee
VMware LLC
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by VMware LLC filed Critical VMware LLC
Priority to US16/521,407 priority Critical patent/US10908912B1/en
Assigned to VMWARE, INC. reassignment VMWARE, INC. ASSIGNMENT OF ASSIGNORS INTEREST (SEE DOCUMENT FOR DETAILS). Assignors: AMIT, NADAV, WEI, MICHAEL, JACOBS, Frederick Joseph
Publication of US20210011728A1 publication Critical patent/US20210011728A1/en
Application granted granted Critical
Publication of US10908912B1 publication Critical patent/US10908912B1/en
Assigned to VMware LLC reassignment VMware LLC CHANGE OF NAME (SEE DOCUMENT FOR DETAILS). Assignors: VMWARE, INC.
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/52Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems during program execution, e.g. stack integrity ; Preventing unwanted data erasure; Buffer overflow
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04MTELEPHONIC COMMUNICATION
    • H04M3/00Automatic or semi-automatic exchanges
    • H04M3/42Systems providing special services or facilities to subscribers
    • H04M3/42221Conversation recording systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • G06F12/08Addressing or allocation; Relocation in hierarchically structured memory systems, e.g. virtual memory systems
    • G06F12/10Address translation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/52Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems during program execution, e.g. stack integrity ; Preventing unwanted data erasure; Buffer overflow
    • G06F21/54Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems during program execution, e.g. stack integrity ; Preventing unwanted data erasure; Buffer overflow by adding security routines or objects to programs
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30003Arrangements for executing specific machine instructions
    • G06F9/3005Arrangements for executing specific machine instructions to perform operations for flow control
    • G06F9/30058Conditional branch instructions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30003Arrangements for executing specific machine instructions
    • G06F9/3005Arrangements for executing specific machine instructions to perform operations for flow control
    • G06F9/30065Loop control instructions; iterative instructions, e.g. LOOP, REPEAT
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/30098Register arrangements
    • G06F9/30101Special purpose registers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/34Addressing or accessing the instruction operand or the result ; Formation of operand address; Addressing modes
    • G06F9/35Indirect addressing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/38Concurrent instruction execution, e.g. pipeline, look ahead
    • G06F9/3802Instruction prefetching
    • G06F9/3804Instruction prefetching for branches, e.g. hedging, branch folding
    • G06F9/3806Instruction prefetching for branches, e.g. hedging, branch folding using address prediction, e.g. return stack, branch history buffer
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/30Arrangements for executing machine instructions, e.g. instruction decode
    • G06F9/38Concurrent instruction execution, e.g. pipeline, look ahead
    • G06F9/3836Instruction issuing, e.g. dynamic instruction scheduling or out of order instruction execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N20/00Machine learning
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04MTELEPHONIC COMMUNICATION
    • H04M3/00Automatic or semi-automatic exchanges
    • H04M3/42Systems providing special services or facilities to subscribers
    • H04M3/42025Calling or Called party identification service
    • H04M3/42034Calling party identification service
    • H04M3/42059Making use of the calling party identifier
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04MTELEPHONIC COMMUNICATION
    • H04M3/00Automatic or semi-automatic exchanges
    • H04M3/42Systems providing special services or facilities to subscribers
    • H04M3/50Centralised arrangements for answering calls; Centralised arrangements for recording messages for absent or busy subscribers ; Centralised arrangements for recording messages
    • H04M3/51Centralised call answering arrangements requiring operator intervention, e.g. call or contact centers for telemarketing
    • H04M3/5175Call or contact centers supervision arrangements
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04MTELEPHONIC COMMUNICATION
    • H04M3/00Automatic or semi-automatic exchanges
    • H04M3/42Systems providing special services or facilities to subscribers
    • H04M3/50Centralised arrangements for answering calls; Centralised arrangements for recording messages for absent or busy subscribers ; Centralised arrangements for recording messages
    • H04M3/51Centralised call answering arrangements requiring operator intervention, e.g. call or contact centers for telemarketing
    • H04M3/5183Call or contact centers with computer-telephony arrangements
    • H04M3/5191Call or contact centers with computer-telephony arrangements interacting with the Internet
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04MTELEPHONIC COMMUNICATION
    • H04M3/00Automatic or semi-automatic exchanges
    • H04M3/42Systems providing special services or facilities to subscribers
    • H04M3/50Centralised arrangements for answering calls; Centralised arrangements for recording messages for absent or busy subscribers ; Centralised arrangements for recording messages
    • H04M3/51Centralised call answering arrangements requiring operator intervention, e.g. call or contact centers for telemarketing
    • H04M3/523Centralised call answering arrangements requiring operator intervention, e.g. call or contact centers for telemarketing with call distribution or queueing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2212/00Indexing scheme relating to accessing, addressing or allocation within memory systems or architectures
    • G06F2212/65Details of virtual memory and virtual address translation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2221/00Indexing scheme relating to security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F2221/03Indexing scheme relating to G06F21/50, monitoring users, programs or devices to maintain the integrity of platforms
    • G06F2221/033Test or assess software
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • G06F9/4484Executing subprograms
    • G06F9/4486Formation of subprogram jump address

Definitions

  • FIG. 1A depicts an example computer system 100 whose CPUs 118 a - n may have these vulnerabilities and FIG. 1B depicts the architecture of CPUs 118 a - n in more detail. Features of the architecture that give rise to the vulnerability are described in reference to FIG. 1B .
  • computer system 100 includes a user space 102 in which one or more user processes 104 a - n run, each with one or more threads 106 a - n , an operating system kernel 108 that may include one or more kernel processes 110 a - n with threads 112 a - n and a set of page tables 114 that map virtual address spaces of the user processes to physical memory.
  • Operating system kernel 108 operates on behalf of the one or more user processes 104 a - n by receiving system calls via a system call interface 111 .
  • Hardware 116 includes one or more CPUs 118 a - n , RAM 124 in which programs and data can be stored and persistent storage 126 such as hard disk drives or solid-state drives.
  • Each CPU 118 a - n includes a cache 128 , 130 , which may include a first level, second level and optionally, a third level cache. Each CPU 118 a - n may also include one or more processing cores 120 a - n , 122 a - n . CPUs 118 a - n are usually superscalar (i.e., multi-issue) and deeply-pipelined.
  • major sections of vulnerable CPUs 118 a - n include a bus unit 152 which is connected to a system bus 150 , a 1st level cache 154 , a 2nd level cache 156 and an optional 3rd level cache 158 , a front end section 160 , an out-of-order execution core 162 , a retirement unit 164 , a set of general-purpose registers 168 , and a branch target buffer (BTB) and branch prediction unit 166 .
  • BTB branch target buffer
  • Front end section 160 includes fetch and decode logic 170 and an execution trace cache 172 .
  • Fetch and decode logic 170 pre-fetches instructions that are likely to be executed, fetches instructions that have not already been prefetched, decodes instructions into micro-operations (micro-ops) and stores the decoded instructions into an execution trace cache 172 .
  • Assisting execution trace cache 172 and fetch and decode logic 170 are BTBs and branch prediction hardware unit 166 . Branch targets are predicted by CPUs 118 a - n based on their linear addresses using the branch target buffers (BTBs).
  • Out-of-order execution core 162 employs dynamic execution, which incorporates three functions, (1) branch prediction, (2) detection of instructions that can be executed out-of-order, and (3) speculative execution of instructions.
  • Speculative execution refers to the CPU's ability to execute instructions that lie beyond a conditional branch or an indirect call that has not been resolved. Executing instructions that lie beyond a conditional branch is helpful to keep the pipeline full and if successful, improves the performance of CPUs 118 a - n.
  • Retirement unit 164 receives results of the executed micro-ops from out-of-order execution core 162 and searches for completed instructions that have no data dependencies or unresolved branch predictions. When found, retirement unit 164 commits the results of these instructions to memory or general-purpose registers 168 in the order in which they were originally issued. Retirement unit 164 also keeps track of branches and sends updated branch target information to the BTBs in unit 166 , which in turn assists fetch/decode logic 170 .
  • the speculative execution of instructions mentioned above has side effects that can reveal private data to attackers if the speculative execution is incorrect, and the processor undoes the speculation.
  • the resulting state of data in 1st level cache 154 constitutes a side channel through which the attacker may be able to extract information about the private data using a timing attack, which attempts to discern the private data based on the timing of certain processing steps. Attacks of this type are called Spectre Variant 2.
  • a code sequence called a ‘retpoline’ is employed in an operating system kernel 108 , such as the Linux® kernel.
  • FIG. 2 depicts a flow of operation for a call to a retpoline.
  • the retpoline code replaces a ‘call %rax’, which is an indirect call to the location that is computed and stored in the %rax register.
  • the retpoline code determines whether the contents of %rax are known (i.e., computed). If not, then a CPU 118 a - n executes a ‘pause’ instruction in step 204 and a ‘lfence’ (load fence) instruction in step 206 .
  • the ‘pause’ instruction is used to release processor resources to a hardware simultaneous multithread (SMT) or to save power if no execution is needed.
  • SMT hardware simultaneous multithread
  • the ‘lfence’ instruction guarantees ordering between two loads and prevents speculative loads from passing the lfence.
  • the retpoline Although the retpoline defends against the Spectre, Variant 2 type attack, the retpoline may still be exposed to an attack, because in some cases, if the RSB is empty, the processor may use the BTB instead.
  • mitigation measures in new hardware or microcode can be employed. However, these mitigation measures only work when operating system kernel 108 runs on the new CPU hardware or microcode. If operating system kernel 108 is moved to older hardware (i.e., hardware or microcode lacking the mitigation measures), the mitigation measures in hardware or microcode are of no use.
  • Another mitigation technique is call promotion in which an indirect call is promoted to a conditional direct call.
  • FIG. 3 depicts a flow of operations for promoting the indirect call.
  • CPU 118 a - n compares the target address to the contents of the %eax register. If the result is zero, as determined in step 304 , CPU 118 a - n calls the target address directly in step 306 . If the result is not zero, as determined in step 304 , CPU 118 a - n performs the indirect call on the %eax register in step 308 .
  • Other limitations include: being allowed only a limited number of target addresses to promote; and being unable to predict accurately the target addresses that should be promoted because likely target addresses are determined at compile time or through the use of a profiling tool that observes an instance of a kernel that may not be representative of a later released or modified kernel.
  • the target addresses learned by a profiling tool requires recompiling operating system kernel 108 to include them. As kernels are distributed in binary form, recompiling operating system kernel 108 is not practical.
  • retpolines and indirect call promotion both defend against Spectre, Variant 2 type attacks, but at a high cost.
  • the retpolines approach comes at a high performance cost because the retpoline prevents speculative execution until the branch target address (i.e., destination branch address) of the indirect call is determined.
  • Call promotion comes at a high performance cost because code size is increased and because promotion occurs without regard to the dynamic behavior of the kernel leading to promotions of infrequently used target addresses.
  • One embodiment provides a method for redirecting an indirect call in an operating system kernel to a direct call.
  • the method includes, while in a learning mode, recording, for each of one or more indirect calls, whose code has been placed with a trampoline code template containing code for a direct call, an entry in a hash table having a plurality of keys and entries, where the recorded entry is a source and destination branch address for an indirect call and a count of a number of occurrences of the source and destination branch address, and the hash table key is a bit-wise combination of the branch source address and the branch destination address.
  • the method further includes, while in an update mode, updating, based on an entry in the hash table, a destination branch address in the direct call code of trampoline code template associated with the indirect call code, and while in a use mode, executing the trampoline code to redirect the indirect call to the updated direct call.
  • FIG. 1A depicts an example system whose CPUs may have these vulnerabilities.
  • FIG. 1B depicts the architecture of the CPUs in more detail.
  • FIG. 2 depicts a flow of operations for a call to a retpoline.
  • FIG. 3 depicts a flow of operations for indirect call promotion.
  • FIG. 4A depicts a flow of operations for inline jump switch (IJS), in an embodiment.
  • FIG. 4B depicts the target(mode) function, in an embodiment.
  • FIG. 5 depicts a flow of operations for an outline jump switch (OJS), in an embodiment.
  • OJS outline jump switch
  • FIG. 6A depicts an example hash table, in an embodiment.
  • FIG. 6B depicts a flow of operations for IJS and OJS switch type learning, in an embodiment.
  • FIG. 7 depicts a flow of operations for IJS and OJS switch type learning policy, in an embodiment.
  • FIG. 8 depicts a flow of operations for an IJS and OJS update, in an embodiment.
  • FIG. 9 depicts a flow of operations for the update function used in FIG. 8 , in an embodiment.
  • FIG. 10A depicts a flow of operations for patching the operating system kernel, in an embodiment.
  • FIG. 10B depicts a flow of operations for phase 1 of patching the operating system kernel, in an embodiment.
  • FIG. 10C depicts a flow of operations for phase 2 of patching the operating system kernel, in an embodiment.
  • FIG. 10D depicts a flow of operations for phase 3 of patching the operating system kernel, in an embodiment.
  • FIG. 10E depicts a flow of operations for checking an interruption while patching the operating system kernel, in an embodiment.
  • FIG. 11 depicts a flow of operations for a plug-in for an operating system compiler, in an embodiment.
  • Jump switches are code fragments, which serve as trampolines for indirect calls, where trampolines are code fragments that redirect the CPU to a different code path.
  • Jump switches are Spectre-aware in that if a jump switch cannot promote an indirect call, then the jump switch falls back to a mitigated indirect call, such as a retpoline or hardware or microcode that provides protection.
  • Embodiments of jump switches include an inline jump switch (IJS) and an outline jump switch (OJS).
  • IJS inline jump switch
  • OJS outline jump switch
  • the IJS is optimized for code size and covers most of the use cases.
  • the OJS is used when the indirect branch has multiple target addresses, thus extending the capabilities of the IJS.
  • FIGS. 4A, 4B and 5 describe a flow of operations for both an inline jump switch (IJS) and an outline jump switch (OJS).
  • IJS inline jump switch
  • OJS outline jump switch
  • FIG. 4A depicts a flow of operations for inline jump switch (IJS), in an embodiment.
  • the IJS is a trampoline that replaces an indirect call.
  • the trampoline includes steps 402 through 408 .
  • the CPU compares a learned target with the contents of the %eax register. If the result is zero, as determined in step 404 , then the CPU performs a call to the learned target in step 406 . If the result is not zero, as determined in step 404 , then in step 408 , the CPU performs a call to a target that depends on a mode of the IJS (target(mode)), which is further described in reference to FIG. 4B .
  • the steps are implemented in x86 assembly language according to Table 1 below.
  • FIG. 4B depicts the target(mode) function, in an embodiment.
  • the mode is matched to one of three possibilities. If the mode is ‘learning’, then in step 454 , the target address points to learning code. If the mode is ‘OJS’, then in step 456 the target address points to an OJS leading to more target addresses. If the mode is ‘fallback’, then in step 458 , the target address points to either a retpoline or a normal indirect call, depending on whether the system is Spectre-vulnerable.
  • the IJS is set to the fallback target by having the target address in steps 456 and 458 set to a retpoline.
  • worker thread 112 a may patch the target addresses depending on the mode the switch is in and what target addresses have been learned by worker thread 112 a.
  • FIG. 5 depicts a flow of operations for an outline jump switch (OJS), in an embodiment.
  • OJS handles the case of multiple target addresses as an extension of the IJS.
  • the multiple target addresses are learned in real-time and provided by worker thread 112 a .
  • the OJS is called by the IJS, when the mode of the IJS is changed to OJS.
  • the OJS is limited to a small number of target addresses, for example, six (6) target addresses.
  • step 502 of FIG. 5 the CPU determines whether a list of learned target addresses is empty or not. If not, then in step 504 , the CPU obtains an item, lta, from the list and executes a comparison in step 506 of the item with the contents of the %eax register. If the results of the comparison are zero, as determined in step 508 , then in step 510 , the CPU jumps to the item, ita. In step 512 , the CPU updates the list. The processor repeats steps 502 to 512 until the list is empty. If the list is originally empty or when the list becomes empty, the CPU executes, in step 514 , a jump to an address of learning code, which is a fallback to the learning code.
  • the steps of FIG. 5 are implemented in x86 code according to Table 2 below.
  • a worker thread 112 a is employed.
  • Worker thread 112 a is a kernel process 110 a that runs periodically. When worker thread 112 a runs, it performs two major functions, learning new target addresses and updating the jump switches, using a hash table.
  • the hash table is described with reference to FIG. 6A .
  • the learning routine is described with reference to FIG. 6B .
  • the learning routine is governed by a policy which is described with reference to FIG. 7 .
  • the switch updating is described with reference to FIGS. 8 and 9 .
  • hash table 620 is a representative one of a plurality of tables, each table being associated with one of the CPU cores 120 a - n , 122 a - n .
  • keys 622 , 624 , 626 are formed by performing a bit-wise combination of the branch source address with the branch target address and then taking the lower 8 bits of the combination. Using the lower 8 bits allows for 256 entries.
  • the bit-wise combination is a bit-wise exclusive-OR.
  • Each entry in hash table 620 includes three items, the branch source address 622 a , 624 a , 626 a , the branch target address 622 b , 624 b , 626 b , and the count 622 c , 624 c , 626 c.
  • FIG. 6B depicts a flow of operations for IJS and OJS learning, in an embodiment. Learning occurs periodically, and when active, a learning flag is set. In one embodiment, learning occurs once every 60 seconds.
  • worker thread 112 a in step 604 computes a key for a hash table 620 (depicted in FIG. 6A ). The key is the lower eight bits of an XOR of the branch source address and the branch destination address.
  • worker thread 112 a computes an entry for hash table 620 corresponding to the key. In one embodiment, the entry is the source instruction pointer (IP), the destination IP and a count of the number of invocations.
  • IP source instruction pointer
  • step 608 worker thread 112 a adds the entry to hash table 620 at the computed key.
  • the learning flag is made false, and worker thread 112 a executes a fallback code function in the IJS in step 610 .
  • the fallback code may be either a retpoline if Spectre-vulnerable hardware is present or a normal indirect call.
  • FIG. 7 depicts a flow of operations for an IJS and OJS learning policy, in an embodiment.
  • worker thread 112 a keeps track of three lists.
  • the first list is a list of jump switches that are in learning mode.
  • the second list is a list of stable jump switches, i.e., those having a single target. Switches in this list need not be disabled for learning because their fallback paths are to the learning routine.
  • the third list is a list of unstable jump switches, which includes switches with an outlined block and those that have too many target addresses and were set not to have an outlined block.
  • step 702 of FIG. 7 if during an epoch (say every 60 seconds) no jump switches were updated, worker thread 112 a selects a sublist of jump switches from the unstable list in step 704 . In step 706 , worker thread 112 a converts the switches in the selected sublist to learning switches, i.e., disabling them and setting their fallback target to the learning routine.
  • FIG. 8 depicts a flow of operations for an IJS and OJS update, in an embodiment.
  • worker thread 112 a receives an epoch or relearning event, where a relearning event is an event triggered by the user such as entering a steady system state after booting the kernel or changing the workload by starting a new process or container.
  • the epoch is one (1) second.
  • worker thread 112 a creates a list of items, each of which is a call total and a source and destination pair over all of the CPU cores 120 a - n , 122 a - n .
  • the list is created by summing calls in the hash table for each CPU core 120 a - n , 122 a - n .
  • worker thread 112 a starts an iterator that runs through each source in the list.
  • worker thread 112 a sorts the list of destinations for each source based on their hits, where a hit is a case in which the jump switch uses the target branch address that is in the hash table.
  • worker thread 112 a starts an iterator that runs through each destination of the current source selected in step 806 . If, as determined in step 812 , the destination has not been promoted, then in step 814 , worker thread 112 a performs an action on the destination.
  • step 816 After iterating through each source and destination in the list, worker thread 112 a in step 816 , clears all of the hash tables. Jump switches that are not in an update mode are in a usable mode, i.e., able to be executed.
  • FIG. 9 depicts a flow of operations for the update function used in FIG. 8 , in an embodiment.
  • Worker thread 112 a executes the update function for each jump switch by performing an action on the jump switch which may involve a set of targets for the switch.
  • the function starts an iterator over the jump switches in the set passed by invoking the function.
  • the function matches the action for the current switch to one of four different actions.
  • the function executes step 906 , updating the IJS with one or more targets if the action is an ‘update’.
  • the function executes step 908 if the action is ‘switch’ and if the IJS is in learning mode, changes the mode to outline mode in step 910 .
  • the function executes step 912 if the mode is ‘add’ by adding or creating one or more targets for the OJS.
  • the function executes step 914 if the action is ‘max’ and the capacity of an IJS is at maximum. If so, then the function, in step 916 , switches the mode of the IJS to fallback mode.
  • FIG. 10A depicts a flow of operations for patching the operating system kernel 108 code, in an embodiment.
  • worker thread 112 a performs steps to ensure that the jump switch is safely updated.
  • the patching uses the text_poke system call in the Linux® operating system, which allows the safe modification of running code.
  • phase 1 step 1002 phase 1 step 1002
  • phase 2 1004 phase 2 1004
  • phase 3 phase 3
  • check(interruption) function determines whether the kernel was preempted with a context switch during the patching.
  • FIG. 10B depicts a flow of operations for phase 1 of patching the operating system kernel, in an embodiment.
  • the worker thread 112 a sets a breakpoint at Line 1 (L 1 ) of the IJS code in Table 1. The breakpoint is set by writing a breakpoint opcode into the first byte of the instruction at L 1 .
  • the worker thread 112 a sets the instruction pointer to the return address on the stack. If the breakpoint is hit, as determined in step 1024 , the CPU jumps to the retpoline code in step 1026 . If the breakpoint is not hit, then in step 1028 the phase 1 function returns.
  • FIG. 10C depicts a flow of operations for phase 2 of patching the operating system kernel, in an embodiment.
  • the worker thread 112 a waits for a quiescent period of time to ensure that no thread runs the instructions in lines 2 - 5 . In an embodiment in which the operating system kernel is the Linux® kernel, this is performed by calling the synchronize_sched function.
  • the worker thread 112 a writes lines 2 - 5 with replacement code.
  • the function returns.
  • FIG. 10D depicts a flow of operations for phase 3 of patching the operating system kernel, in an embodiment.
  • the worker thread 112 a sets a breakpoint at L 1 and in step 1042 sets the instruction pointer to the return address on the stack. If the breakpoint is hit, as determined in step 1044 , the CPU 118 a - n jumps to the retpoline code. If not, then the worker thread 112 a restores the ‘CMP’ opcode in L 1 and returns in step 1050 .
  • FIG. 10E depicts a flow of operations for checking an interruption while patching the operating system kernel, in an embodiment. If, as determined in step 1060 , the operating system kernel 108 performed a context switch, then in step 1062 , the saved instruction pointer (IP) is set to L 1 of the code in Table 1. Setting the IP to L 1 ensures that the code will be executed again when the worker thread 112 a is re-scheduled.
  • IP saved instruction pointer
  • FIG. 11 depicts a flow of operations for a plug-in for an operating system compiler, in an embodiment.
  • the compiler is the GNU compiler when the operating system is the Linux® operating system.
  • the plug-in is built during a kernel build and assists in the operation of worker thread 112 a.
  • step 1106 the plug-in starts an iterator over each indirect call.
  • step 1108 the plug-in replaces each indirect call with a jump switch code template, which contains the basic jump switch code, such as the code in Table 1, but with the jump switch set to execute only fallback code.
  • step 1110 worker thread 112 a writes the instruction pointer (IP) and register used by the call to a new file section of a standard file format, such as an executable and linkable format (ELF) file, used by the compiler.
  • IP instruction pointer
  • ELF executable and linkable format
  • the new section of the ELF file contains information that is read during boot of operating system kernel 108 to compose a list of calls so that worker thread 112 a can easily recognize which register is used in each jump switch.
  • the information also serves as a precaution to prevent worker thread 112 a from patching the wrong code.
  • Worker thread 112 a is integrated into operating system kernel in a manner similar to other periodic tasks which patch code such as static-keys, jump-label and alternatives infrastructure in the Linux® operating system.
  • jump switches are able to dynamically adapt to changing workloads and to take advantage of information only available at runtime.
  • Jump switches are integrated into the operating system kernel, requiring no source code changes to the kernel, and designed for minimal overhead as they only operate to protect indirect calls rather than the entire binary of the operating system kernel.
  • the various embodiments described herein may employ various computer-implemented operations involving data stored in computer systems. For example, these operations may require physical manipulation of physical quantities—usually, though not necessarily, these quantities may take the form of electrical or magnetic signals, where they or representations of them are capable of being stored, transferred, combined, compared, or otherwise manipulated. Further, such manipulations are often referred to in terms, such as producing, identifying, determining, or comparing. Any operations described herein that form part of one or more embodiments of the invention may be useful machine operations.
  • one or more embodiments of the invention also relate to a device or an apparatus for performing these operations.
  • the apparatus may be specially constructed for specific required purposes, or it may be a general purpose computer selectively activated or configured by a computer program stored in the computer.
  • various general purpose machines may be used with computer programs written in accordance with the teachings herein, or it may be more convenient to construct a more specialized apparatus to perform the required operations.
  • One or more embodiments of the present invention may be implemented as one or more computer programs or as one or more computer program modules embodied in one or more computer readable media.
  • the term computer readable medium refers to any data storage device that can store data which can thereafter be input to a computer system—computer readable media may be based on any existing or subsequently developed technology for embodying computer programs in a manner that enables them to be read by a computer.
  • Examples of a computer readable medium include a hard drive, network attached storage (NAS), read-only memory, random-access memory (e.g., a flash memory device), a CD (Compact Discs)—CD-ROM, a CD-R, or a CD-RW, a DVD (Digital Versatile Disc), a magnetic tape, and other optical and non-optical data storage devices.
  • the computer readable medium can also be distributed over a network coupled computer system so that the computer readable code is stored and executed in a distributed fashion.

Abstract

A method for redirecting an indirect call in an operating system kernel to a direct call is disclosed. The direct calls are contained in trampoline code called an inline jump switch (IJS) or an outline jump switch (OJS). The IJS and OJS can operate in either a use mode, redirecting an indirect call to a direct call, a learning and update mode or fallback mode. In the learning and update mode, target addresses in a trampoline code template are learned and updated by a jump switch worker thread that periodically runs as a kernel process. When building the kernel binary, a plug-in is integrated into the kernel. The plug-in replaces call sites with a trampoline code template containing a direct call so that the template can be later updated by the jump switch worker thread.

Description

    CROSS-REFERENCE TO RELATED APPLICATION(S)
  • This application claims the benefit of U.S. Provisional Application No. 62/871,573, filed Jul. 8, 2019, which is incorporated by reference herein.
  • BACKGROUND
  • Modern microprocessors that perform branch predictions have been found to have security vulnerabilities due to their use of speculative execution. FIG. 1A depicts an example computer system 100 whose CPUs 118 a-n may have these vulnerabilities and FIG. 1B depicts the architecture of CPUs 118 a-n in more detail. Features of the architecture that give rise to the vulnerability are described in reference to FIG. 1B.
  • Referring to FIG. 1A, computer system 100 includes a user space 102 in which one or more user processes 104 a-n run, each with one or more threads 106 a-n, an operating system kernel 108 that may include one or more kernel processes 110 a-n with threads 112 a-n and a set of page tables 114 that map virtual address spaces of the user processes to physical memory. Operating system kernel 108 operates on behalf of the one or more user processes 104 a-n by receiving system calls via a system call interface 111. Hardware 116 includes one or more CPUs 118 a-n, RAM 124 in which programs and data can be stored and persistent storage 126 such as hard disk drives or solid-state drives.
  • Each CPU 118 a-n includes a cache 128, 130, which may include a first level, second level and optionally, a third level cache. Each CPU 118 a-n may also include one or more processing cores 120 a-n, 122 a-n. CPUs 118 a-n are usually superscalar (i.e., multi-issue) and deeply-pipelined.
  • Referring to FIG. 1B, major sections of vulnerable CPUs 118 a-n include a bus unit 152 which is connected to a system bus 150, a 1st level cache 154, a 2nd level cache 156 and an optional 3rd level cache 158, a front end section 160, an out-of-order execution core 162, a retirement unit 164, a set of general-purpose registers 168, and a branch target buffer (BTB) and branch prediction unit 166.
  • Front end section 160 includes fetch and decode logic 170 and an execution trace cache 172. Fetch and decode logic 170 pre-fetches instructions that are likely to be executed, fetches instructions that have not already been prefetched, decodes instructions into micro-operations (micro-ops) and stores the decoded instructions into an execution trace cache 172. Assisting execution trace cache 172 and fetch and decode logic 170 are BTBs and branch prediction hardware unit 166. Branch targets are predicted by CPUs 118 a-n based on their linear addresses using the branch target buffers (BTBs).
  • Out-of-order execution core 162 employs dynamic execution, which incorporates three functions, (1) branch prediction, (2) detection of instructions that can be executed out-of-order, and (3) speculative execution of instructions. Speculative execution refers to the CPU's ability to execute instructions that lie beyond a conditional branch or an indirect call that has not been resolved. Executing instructions that lie beyond a conditional branch is helpful to keep the pipeline full and if successful, improves the performance of CPUs 118 a-n.
  • Retirement unit 164 receives results of the executed micro-ops from out-of-order execution core 162 and searches for completed instructions that have no data dependencies or unresolved branch predictions. When found, retirement unit 164 commits the results of these instructions to memory or general-purpose registers 168 in the order in which they were originally issued. Retirement unit 164 also keeps track of branches and sends updated branch target information to the BTBs in unit 166, which in turn assists fetch/decode logic 170.
  • However, the speculative execution of instructions mentioned above has side effects that can reveal private data to attackers if the speculative execution is incorrect, and the processor undoes the speculation. For example, if the pattern of memory accesses performed by such speculative execution depends on private data, the resulting state of data in 1st level cache 154 constitutes a side channel through which the attacker may be able to extract information about the private data using a timing attack, which attempts to discern the private data based on the timing of certain processing steps. Attacks of this type are called Spectre Variant 2.
  • To counter this type of attack, a code sequence called a ‘retpoline’ is employed in an operating system kernel 108, such as the Linux® kernel.
  • FIG. 2 depicts a flow of operation for a call to a retpoline. The retpoline code replaces a ‘call %rax’, which is an indirect call to the location that is computed and stored in the %rax register. In step 202, the retpoline code determines whether the contents of %rax are known (i.e., computed). If not, then a CPU 118 a-n executes a ‘pause’ instruction in step 204 and a ‘lfence’ (load fence) instruction in step 206. The ‘pause’ instruction is used to release processor resources to a hardware simultaneous multithread (SMT) or to save power if no execution is needed. The ‘lfence’ instruction guarantees ordering between two loads and prevents speculative loads from passing the lfence.
  • When the contents of the %rax register become known, then CPU 118 a-n pushes the contents of %rax onto the stack in step 208 and then executes a return in step 210 to the location that the top of the stack points to. Thus, the ‘call %rax’ instruction is converted into a return (‘ret’) instruction to the location specified by %rax. The conversion from an indirect call instruction to a return instruction helps to counter a Spectre, Variant 2 type attack because the return uses a return stack buffer (RSB) instead of the BTB, which is thought to be vulnerable to the attack.
  • Although the retpoline defends against the Spectre, Variant 2 type attack, the retpoline may still be exposed to an attack, because in some cases, if the RSB is empty, the processor may use the BTB instead.
  • Other mitigation measures in new hardware or microcode can be employed. However, these mitigation measures only work when operating system kernel 108 runs on the new CPU hardware or microcode. If operating system kernel 108 is moved to older hardware (i.e., hardware or microcode lacking the mitigation measures), the mitigation measures in hardware or microcode are of no use.
  • Another mitigation technique is call promotion in which an indirect call is promoted to a conditional direct call.
  • FIG. 3 depicts a flow of operations for promoting the indirect call. In step 302, CPU 118 a-n compares the target address to the contents of the %eax register. If the result is zero, as determined in step 304, CPU 118 a-n calls the target address directly in step 306. If the result is not zero, as determined in step 304, CPU 118 a-n performs the indirect call on the %eax register in step 308.
  • While promoting indirect calls reduces the chance that a processor will miss-speculate an indirect call, the promotion is costly because code size is increased and performance is reduced if infrequently used target addresses are promoted. Other limitations include: being allowed only a limited number of target addresses to promote; and being unable to predict accurately the target addresses that should be promoted because likely target addresses are determined at compile time or through the use of a profiling tool that observes an instance of a kernel that may not be representative of a later released or modified kernel. Finally, the target addresses learned by a profiling tool requires recompiling operating system kernel 108 to include them. As kernels are distributed in binary form, recompiling operating system kernel 108 is not practical.
  • Even binary translators or just-in-time (JIT) compilers do not adequately address Spectre Variant 2 type attacks, especially in regard to execution of an operating system kernel.
  • Thus, retpolines and indirect call promotion both defend against Spectre, Variant 2 type attacks, but at a high cost. The retpolines approach comes at a high performance cost because the retpoline prevents speculative execution until the branch target address (i.e., destination branch address) of the indirect call is determined. Call promotion comes at a high performance cost because code size is increased and because promotion occurs without regard to the dynamic behavior of the kernel leading to promotions of infrequently used target addresses.
  • Thus, it is desirable to have a solution to mitigate attacks, such as Spectre, Variant 2 type, of indirect calls but without defeating speculative execution and thus maintaining performance.
  • SUMMARY
  • One embodiment provides a method for redirecting an indirect call in an operating system kernel to a direct call. The method includes, while in a learning mode, recording, for each of one or more indirect calls, whose code has been placed with a trampoline code template containing code for a direct call, an entry in a hash table having a plurality of keys and entries, where the recorded entry is a source and destination branch address for an indirect call and a count of a number of occurrences of the source and destination branch address, and the hash table key is a bit-wise combination of the branch source address and the branch destination address. The method further includes, while in an update mode, updating, based on an entry in the hash table, a destination branch address in the direct call code of trampoline code template associated with the indirect call code, and while in a use mode, executing the trampoline code to redirect the indirect call to the updated direct call.
  • Further embodiments include a computer system configured to carry out one or more aspects of the above method, and a non-transitory computer-readable storage medium containing computer-readable code executable by one or more computer processors to carry out one or more aspects of the above method.
  • BRIEF DESCRIPTION OF THE DRAWINGS
  • FIG. 1A depicts an example system whose CPUs may have these vulnerabilities.
  • FIG. 1B depicts the architecture of the CPUs in more detail.
  • FIG. 2 depicts a flow of operations for a call to a retpoline.
  • FIG. 3 depicts a flow of operations for indirect call promotion.
  • FIG. 4A depicts a flow of operations for inline jump switch (IJS), in an embodiment.
  • FIG. 4B depicts the target(mode) function, in an embodiment.
  • FIG. 5 depicts a flow of operations for an outline jump switch (OJS), in an embodiment.
  • FIG. 6A depicts an example hash table, in an embodiment.
  • FIG. 6B depicts a flow of operations for IJS and OJS switch type learning, in an embodiment.
  • FIG. 7 depicts a flow of operations for IJS and OJS switch type learning policy, in an embodiment.
  • FIG. 8 depicts a flow of operations for an IJS and OJS update, in an embodiment.
  • FIG. 9 depicts a flow of operations for the update function used in FIG. 8, in an embodiment.
  • FIG. 10A depicts a flow of operations for patching the operating system kernel, in an embodiment.
  • FIG. 10B depicts a flow of operations for phase 1 of patching the operating system kernel, in an embodiment.
  • FIG. 10C depicts a flow of operations for phase 2 of patching the operating system kernel, in an embodiment.
  • FIG. 10D depicts a flow of operations for phase 3 of patching the operating system kernel, in an embodiment.
  • FIG. 10E depicts a flow of operations for checking an interruption while patching the operating system kernel, in an embodiment.
  • FIG. 11 depicts a flow of operations for a plug-in for an operating system compiler, in an embodiment.
  • DETAILED DESCRIPTION
  • One or more embodiments described below provide “jump switches,” which avoid the problems with both retpolines and indirect promotion and other mitigation measures. Jump switches are code fragments, which serve as trampolines for indirect calls, where trampolines are code fragments that redirect the CPU to a different code path. Jump switches are Spectre-aware in that if a jump switch cannot promote an indirect call, then the jump switch falls back to a mitigated indirect call, such as a retpoline or hardware or microcode that provides protection.
  • Embodiments of jump switches include an inline jump switch (IJS) and an outline jump switch (OJS). The IJS is optimized for code size and covers most of the use cases. The OJS is used when the indirect branch has multiple target addresses, thus extending the capabilities of the IJS.
  • FIGS. 4A, 4B and 5 describe a flow of operations for both an inline jump switch (IJS) and an outline jump switch (OJS).
  • FIG. 4A depicts a flow of operations for inline jump switch (IJS), in an embodiment. The IJS is a trampoline that replaces an indirect call. The trampoline includes steps 402 through 408. In step 402, the CPU compares a learned target with the contents of the %eax register. If the result is zero, as determined in step 404, then the CPU performs a call to the learned target in step 406. If the result is not zero, as determined in step 404, then in step 408, the CPU performs a call to a target that depends on a mode of the IJS (target(mode)), which is further described in reference to FIG. 4B. In an embodiment, the steps are implemented in x86 assembly language according to Table 1 below.
  • TABLE 1
    Line
    no. Label Code
    1 cmp learnedTarget, %eax
    2 jnz miss
    3 call learnedTarget
    4 jmp done
    5 miss call target(mode)
    6 done

    IJSs are short, upgradable and updatable by a jump switch worker thread 112 a in FIG. 1A (described in relation to FIGS. 6-9) at runtime. The learnedTarget represents a branch target address that the IJS has learned and is promoted to avoid an indirect jump. If a miss occurs (the ‘no’ branch of step 404 in FIG. 4A) then the target address depends on the mode that IJS is in.
  • FIG. 4B depicts the target(mode) function, in an embodiment. In step 452, the mode is matched to one of three possibilities. If the mode is ‘learning’, then in step 454, the target address points to learning code. If the mode is ‘OJS’, then in step 456 the target address points to an OJS leading to more target addresses. If the mode is ‘fallback’, then in step 458, the target address points to either a retpoline or a normal indirect call, depending on whether the system is Spectre-vulnerable.
  • Initially, after compilation, the IJS is set to the fallback target by having the target address in steps 456 and 458 set to a retpoline. At runtime, worker thread 112 a may patch the target addresses depending on the mode the switch is in and what target addresses have been learned by worker thread 112 a.
  • FIG. 5 depicts a flow of operations for an outline jump switch (OJS), in an embodiment. As mentioned above, the OJS handles the case of multiple target addresses as an extension of the IJS. The multiple target addresses are learned in real-time and provided by worker thread 112 a. In an embodiment, the OJS is called by the IJS, when the mode of the IJS is changed to OJS. In an embodiment, the OJS is limited to a small number of target addresses, for example, six (6) target addresses.
  • In step 502 of FIG. 5, the CPU determines whether a list of learned target addresses is empty or not. If not, then in step 504, the CPU obtains an item, lta, from the list and executes a comparison in step 506 of the item with the contents of the %eax register. If the results of the comparison are zero, as determined in step 508, then in step 510, the CPU jumps to the item, ita. In step 512, the CPU updates the list. The processor repeats steps 502 to 512 until the list is empty. If the list is originally empty or when the list becomes empty, the CPU executes, in step 514, a jump to an address of learning code, which is a fallback to the learning code.
  • In one embodiment, the steps of FIG. 5 are implemented in x86 code according to Table 2 below.
  • TABLE 2
    Line
    no. Label Code
    1 cmp $lta0, %eax
    2 jnz relative lta0
    3 cmp $lta1, %eax
    4 jnz relative lta0
    5 . . .
    6 jmp learning relative

    To update the various switches, such as IJS and OJS, with learned target addresses, a worker thread 112 a is employed. Worker thread 112 a is a kernel process 110 a that runs periodically. When worker thread 112 a runs, it performs two major functions, learning new target addresses and updating the jump switches, using a hash table. The hash table is described with reference to FIG. 6A. The learning routine is described with reference to FIG. 6B. The learning routine is governed by a policy which is described with reference to FIG. 7. The switch updating is described with reference to FIGS. 8 and 9.
  • Referring now to FIG. 6A, hash table 620 is a representative one of a plurality of tables, each table being associated with one of the CPU cores 120 a-n, 122 a-n. In hash table 620, keys 622, 624, 626 are formed by performing a bit-wise combination of the branch source address with the branch target address and then taking the lower 8 bits of the combination. Using the lower 8 bits allows for 256 entries. In one embodiment, the bit-wise combination is a bit-wise exclusive-OR. Each entry in hash table 620 includes three items, the branch source address 622 a, 624 a, 626 a, the branch target address 622 b, 624 b, 626 b, and the count 622 c, 624 c, 626 c.
  • FIG. 6B depicts a flow of operations for IJS and OJS learning, in an embodiment. Learning occurs periodically, and when active, a learning flag is set. In one embodiment, learning occurs once every 60 seconds. In the figure, if the learning flag is true as determined in step 602, worker thread 112 a in step 604 computes a key for a hash table 620 (depicted in FIG. 6A). The key is the lower eight bits of an XOR of the branch source address and the branch destination address. In step 606, worker thread 112 a computes an entry for hash table 620 corresponding to the key. In one embodiment, the entry is the source instruction pointer (IP), the destination IP and a count of the number of invocations. In step 608, worker thread 112 a adds the entry to hash table 620 at the computed key. When the learning is completed, the learning flag is made false, and worker thread 112 a executes a fallback code function in the IJS in step 610. The fallback code may be either a retpoline if Spectre-vulnerable hardware is present or a normal indirect call.
  • FIG. 7 depicts a flow of operations for an IJS and OJS learning policy, in an embodiment. To implement the learning policy, worker thread 112 a keeps track of three lists. The first list is a list of jump switches that are in learning mode. The second list is a list of stable jump switches, i.e., those having a single target. Switches in this list need not be disabled for learning because their fallback paths are to the learning routine. The third list is a list of unstable jump switches, which includes switches with an outlined block and those that have too many target addresses and were set not to have an outlined block.
  • In step 702 of FIG. 7, if during an epoch (say every 60 seconds) no jump switches were updated, worker thread 112 a selects a sublist of jump switches from the unstable list in step 704. In step 706, worker thread 112 a converts the switches in the selected sublist to learning switches, i.e., disabling them and setting their fallback target to the learning routine.
  • FIG. 8 depicts a flow of operations for an IJS and OJS update, in an embodiment. In step 802, worker thread 112 a receives an epoch or relearning event, where a relearning event is an event triggered by the user such as entering a steady system state after booting the kernel or changing the workload by starting a new process or container. In one embodiment, the epoch is one (1) second. In step 804, worker thread 112 a creates a list of items, each of which is a call total and a source and destination pair over all of the CPU cores 120 a-n, 122 a-n. The list is created by summing calls in the hash table for each CPU core 120 a-n, 122 a-n. In step 806, worker thread 112 a starts an iterator that runs through each source in the list. In step 808, worker thread 112 a sorts the list of destinations for each source based on their hits, where a hit is a case in which the jump switch uses the target branch address that is in the hash table. In step 810, worker thread 112 a starts an iterator that runs through each destination of the current source selected in step 806. If, as determined in step 812, the destination has not been promoted, then in step 814, worker thread 112 a performs an action on the destination. The actions on the destination are described in more detail in reference to FIG. 9. After iterating through each source and destination in the list, worker thread 112 a in step 816, clears all of the hash tables. Jump switches that are not in an update mode are in a usable mode, i.e., able to be executed.
  • FIG. 9 depicts a flow of operations for the update function used in FIG. 8, in an embodiment. Worker thread 112 a executes the update function for each jump switch by performing an action on the jump switch which may involve a set of targets for the switch. In step 902, the function starts an iterator over the jump switches in the set passed by invoking the function. In step 904, the function matches the action for the current switch to one of four different actions. The function executes step 906, updating the IJS with one or more targets if the action is an ‘update’. The function executes step 908 if the action is ‘switch’ and if the IJS is in learning mode, changes the mode to outline mode in step 910. The function executes step 912 if the mode is ‘add’ by adding or creating one or more targets for the OJS. The function executes step 914 if the action is ‘max’ and the capacity of an IJS is at maximum. If so, then the function, in step 916, switches the mode of the IJS to fallback mode.
  • FIG. 10A depicts a flow of operations for patching the operating system kernel 108 code, in an embodiment. To update a jump switch, worker thread 112 a performs steps to ensure that the jump switch is safely updated. In one embodiment, the patching uses the text_poke system call in the Linux® operating system, which allows the safe modification of running code.
  • The case of updating an IJS jump switch is depicted in FIG. 10A. As shown in the figure the patch is performed in three phases, phase1 step 1002, phase2 1004, and phase3 1006 and a final step 1008, in which check(interruption) function determines whether the kernel was preempted with a context switch during the patching.
  • FIG. 10B depicts a flow of operations for phase 1 of patching the operating system kernel, in an embodiment. In step 1020, the worker thread 112 a sets a breakpoint at Line 1 (L1) of the IJS code in Table 1. The breakpoint is set by writing a breakpoint opcode into the first byte of the instruction at L1. In step 1022, the worker thread 112 a sets the instruction pointer to the return address on the stack. If the breakpoint is hit, as determined in step 1024, the CPU jumps to the retpoline code in step 1026. If the breakpoint is not hit, then in step 1028 the phase 1 function returns.
  • FIG. 10C depicts a flow of operations for phase 2 of patching the operating system kernel, in an embodiment. In step 1030, the worker thread 112 a waits for a quiescent period of time to ensure that no thread runs the instructions in lines 2-5. In an embodiment in which the operating system kernel is the Linux® kernel, this is performed by calling the synchronize_sched function. In step 1032, the worker thread 112 a writes lines 2-5 with replacement code. In step 1034, the function returns.
  • FIG. 10D depicts a flow of operations for phase 3 of patching the operating system kernel, in an embodiment. In step 1040, the worker thread 112 a sets a breakpoint at L1 and in step 1042 sets the instruction pointer to the return address on the stack. If the breakpoint is hit, as determined in step 1044, the CPU 118 a-n jumps to the retpoline code. If not, then the worker thread 112 a restores the ‘CMP’ opcode in L1 and returns in step 1050.
  • FIG. 10E depicts a flow of operations for checking an interruption while patching the operating system kernel, in an embodiment. If, as determined in step 1060, the operating system kernel 108 performed a context switch, then in step 1062, the saved instruction pointer (IP) is set to L1 of the code in Table 1. Setting the IP to L1 ensures that the code will be executed again when the worker thread 112 a is re-scheduled.
  • FIG. 11 depicts a flow of operations for a plug-in for an operating system compiler, in an embodiment. In one embodiment, the compiler is the GNU compiler when the operating system is the Linux® operating system. The plug-in is built during a kernel build and assists in the operation of worker thread 112 a.
  • Referring to FIG. 11, if a compiler build-option flag, CONFIG, is true, as determined in step 1102, then the compiler compiles the operating system to use jump switches according to the following steps. In step 1106, the plug-in starts an iterator over each indirect call. In step 1108, the plug-in replaces each indirect call with a jump switch code template, which contains the basic jump switch code, such as the code in Table 1, but with the jump switch set to execute only fallback code. In step 1110, worker thread 112 a writes the instruction pointer (IP) and register used by the call to a new file section of a standard file format, such as an executable and linkable format (ELF) file, used by the compiler. The new section of the ELF file contains information that is read during boot of operating system kernel 108 to compose a list of calls so that worker thread 112 a can easily recognize which register is used in each jump switch. The information also serves as a precaution to prevent worker thread 112 a from patching the wrong code.
  • Worker thread 112 a is integrated into operating system kernel in a manner similar to other periodic tasks which patch code such as static-keys, jump-label and alternatives infrastructure in the Linux® operating system.
  • Thus, jump switches are able to dynamically adapt to changing workloads and to take advantage of information only available at runtime. Jump switches are integrated into the operating system kernel, requiring no source code changes to the kernel, and designed for minimal overhead as they only operate to protect indirect calls rather than the entire binary of the operating system kernel.
  • The various embodiments described herein may employ various computer-implemented operations involving data stored in computer systems. For example, these operations may require physical manipulation of physical quantities—usually, though not necessarily, these quantities may take the form of electrical or magnetic signals, where they or representations of them are capable of being stored, transferred, combined, compared, or otherwise manipulated. Further, such manipulations are often referred to in terms, such as producing, identifying, determining, or comparing. Any operations described herein that form part of one or more embodiments of the invention may be useful machine operations. In addition, one or more embodiments of the invention also relate to a device or an apparatus for performing these operations. The apparatus may be specially constructed for specific required purposes, or it may be a general purpose computer selectively activated or configured by a computer program stored in the computer. In particular, various general purpose machines may be used with computer programs written in accordance with the teachings herein, or it may be more convenient to construct a more specialized apparatus to perform the required operations.
  • The various embodiments described herein may be practiced with other computer system configurations including hand-held devices, microprocessor systems, microprocessor-based or programmable consumer electronics, minicomputers, mainframe computers, and the like.
  • One or more embodiments of the present invention may be implemented as one or more computer programs or as one or more computer program modules embodied in one or more computer readable media. The term computer readable medium refers to any data storage device that can store data which can thereafter be input to a computer system—computer readable media may be based on any existing or subsequently developed technology for embodying computer programs in a manner that enables them to be read by a computer. Examples of a computer readable medium include a hard drive, network attached storage (NAS), read-only memory, random-access memory (e.g., a flash memory device), a CD (Compact Discs)—CD-ROM, a CD-R, or a CD-RW, a DVD (Digital Versatile Disc), a magnetic tape, and other optical and non-optical data storage devices. The computer readable medium can also be distributed over a network coupled computer system so that the computer readable code is stored and executed in a distributed fashion.
  • Although one or more embodiments of the present invention have been described in some detail for clarity of understanding, it will be apparent that certain changes and modifications may be made within the scope of the claims. Accordingly, the described embodiments are to be considered as illustrative and not restrictive, and the scope of the claims is not to be limited to details given herein, but may be modified within the scope and equivalents of the claims. In the claims, elements and/or steps do not imply any particular order of operation, unless explicitly stated in the claims.
  • Plural instances may be provided for components, operations or structures described herein as a single instance. Finally, boundaries between various components, operations and data stores are somewhat arbitrary, and particular operations are illustrated in the context of specific illustrative configurations. Other allocations of functionality are envisioned and may fall within the scope of the invention(s). In general, structures and functionality presented as separate components in exemplary configurations may be implemented as a combined structure or component. Similarly, structures and functionality presented as a single component may be implemented as separate components. These and other variations, modifications, additions, and improvements may fall within the scope of the appended claim(s).

Claims (20)

What is claimed is:
1. A method of redirecting an indirect call in an operating system kernel to a direct call, the method comprising:
while in a learning mode, recording, for each of one or more indirect calls, whose code has been replaced with a trampoline code template containing code for a direct call, an entry in a hash table having a plurality of keys and entries, wherein the recorded entry includes a source and destination branch address for an indirect call and a count of a number of occurrences of the source and destination branch address, and the hash table key is a bit-wise combination of the branch source address and the branch destination address;
while in an update mode, updating, based on an entry in the hash table, a destination branch address in the direct call code of trampoline code template associated with the indirect call code; and
while in a use mode, executing the trampoline code to redirect the indirect call to the updated direct call.
2. The method of claim 1, wherein the trampoline code template is installed in the operating system kernel at compile time.
3. The method of claim 1, wherein the learning mode is operative in response to an epoch event that occurs once every sixty seconds.
4. The method of claim 1, wherein the update mode is operative in response to an epoch event that occurs once every second.
5. The method of claim 1, wherein the trampoline has fallback code which allows the trampoline to operate as an indirect call.
6. The method of claim 1, wherein the trampoline has fallback code which allows the trampoline to operate as a retpoline, which is a return trampoline that prevents speculative execution until the destination branch address of the indirect call is determined.
7. The method of claim 1, wherein the trampoline has an expansion mode which allows the trampoline to access a list of destination branch addresses as possible branch addresses.
8. The method of claim 1, wherein updating the direct call code in the trampoline code template includes updating the trampoline code template while the operating system kernel is running.
9. A system for redirecting an indirect call in an operating system kernel to a direct call, the system comprising:
memory containing the operating system kernel and one or more user processes in a user space of the kernel;
one or more CPUs coupled to the memory, the one or more CPUs running the operating system kernel and the one or more user processes, wherein the operating system kernel is configured to:
while in a learning mode for a trampoline, record, for each of one or more indirect calls, whose code has been replaced with a trampoline code template containing code for a direct call, an entry in a hash table having a plurality of keys and entries, wherein the recorded entry is a source and destination branch address for an indirect call and a count of a number of occurrences of the source and destination branch address, and the hash table key is a bit-wise combination of the branch source address and the destination address;
while in an update mode for the trampoline, update, based on an entry in the hash table, a destination branch address in the direct call code of trampoline code template associated with the indirect call; and
while in a use mode for the trampoline, execute the trampoline code to redirect the indirect call to the updated direct call.
10. The system of claim 9, wherein the trampoline code template is installed in the operating system kernel at compile time.
11. The system of claim 9, wherein the trampoline has fallback code which allows the trampoline to operate as an indirect call.
12. The system of claim 9, wherein the trampoline has fallback code which allows the trampoline to operate as a retpoline, which is a return trampoline that prevents speculative execution until the destination branch address of the indirect call is determined.
13. The system of claim 9, wherein the trampoline has an expansion mode which allows the trampoline to access a list of destination branch addresses as possible branch addresses.
14. A non-transitory computer-readable medium comprising instructions executable in a computer system, wherein the instructions when executed in the computer system cause the computer system to carry out a method of redirecting an indirect call in an operating system kernel to a direct call, the method comprising:
while in a learning mode, recording, for each of one or more indirect calls, whose code has been replaced with a trampoline code template containing code for a direct call, an entry in a hash table having a plurality of keys and entries, wherein the recorded entry is a source and destination branch address for an indirect call and a count of a number of occurrences of the source and destination branch address, and the hash table key is a bit-wise combination of the branch source and destination address;
while in an update mode, updating, based on an entry in the hash table, a destination branch address in the direct call code of trampoline code template associated with the indirect call; and
while in a use mode, executing the trampoline code to redirect the indirect call to the updated direct call.
15. The non-transitory computer-readable medium of claim 14, wherein the trampoline code template is installed in the operating system kernel at compile time.
16. The non-transitory computer-readable medium of claim 14, wherein the learning mode is operative in response to an epoch event that occurs once every sixty seconds.
17. The non-transitory computer-readable medium of claim 14, wherein the update mode is operative in response to an epoch event that occurs once every second.
18. The non-transitory computer-readable medium of claim 14, wherein the trampoline has fallback code which allows the trampoline to operate as an indirect call.
19. The non-transitory computer-readable medium of claim 14, wherein the trampoline has fallback code which allows the trampoline to operate as a retpoline, which is a return trampoline that prevents speculative execution until the destination branch address of the indirect call is determined.
20. The non-transitory computer-readable medium of claim 14, wherein the trampoline has an expansion mode which allows the trampoline to access a list of destination branch addresses as possible branch addresses.
US16/521,407 2019-07-08 2019-07-24 Target injection safe method for dynamically inlining branch predictions Active US10908912B1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US16/521,407 US10908912B1 (en) 2019-07-08 2019-07-24 Target injection safe method for dynamically inlining branch predictions

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
US201962871573P 2019-07-08 2019-07-08
US16/521,407 US10908912B1 (en) 2019-07-08 2019-07-24 Target injection safe method for dynamically inlining branch predictions

Publications (2)

Publication Number Publication Date
US20210011728A1 true US20210011728A1 (en) 2021-01-14
US10908912B1 US10908912B1 (en) 2021-02-02

Family

ID=73052045

Family Applications (4)

Application Number Title Priority Date Filing Date
US16/521,407 Active US10908912B1 (en) 2019-07-08 2019-07-24 Target injection safe method for dynamically inlining branch predictions
US16/521,396 Active US11016767B2 (en) 2019-07-08 2019-07-24 Target injection safe method for inlining instance-dependent calls
US16/746,731 Active US10871974B1 (en) 2019-07-08 2020-01-17 Target injection safe method for inlining registration calls
US16/748,734 Active US10834255B1 (en) 2019-07-08 2020-01-21 Target injection safe method for inlining large call tables

Family Applications After (3)

Application Number Title Priority Date Filing Date
US16/521,396 Active US11016767B2 (en) 2019-07-08 2019-07-24 Target injection safe method for inlining instance-dependent calls
US16/746,731 Active US10871974B1 (en) 2019-07-08 2020-01-17 Target injection safe method for inlining registration calls
US16/748,734 Active US10834255B1 (en) 2019-07-08 2020-01-21 Target injection safe method for inlining large call tables

Country Status (1)

Country Link
US (4) US10908912B1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11816206B2 (en) * 2021-02-25 2023-11-14 Red Hat, Inc. Function pointer protection

Family Cites Families (31)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5956758A (en) 1997-10-31 1999-09-21 Digital Equipment Corporation Method for determining target address of computed jump instructions in executable programs
US6629123B1 (en) * 1998-10-02 2003-09-30 Microsoft Corporation Interception of unit creation requests by an automatic distributed partitioning system
US6721875B1 (en) 2000-02-22 2004-04-13 Hewlett-Packard Development Company, L.P. Method and apparatus for implementing a single-syllable IP-relative branch instruction and a long IP-relative branch instruction in a processor which fetches instructions in bundle form
US6763104B1 (en) 2000-02-24 2004-07-13 Teltronics, Inc. Call center IVR and ACD scripting method and graphical user interface
US20040068720A1 (en) * 2002-10-02 2004-04-08 Robert Hundt Dynamic instrumentation of an executable program
US7603704B2 (en) * 2002-12-19 2009-10-13 Massachusetts Institute Of Technology Secure execution of a computer program using a code cache
US9344850B2 (en) 2003-08-08 2016-05-17 Telecommunication Systems, Inc. Method and system for collecting, synchronizing, and reporting telecommunication call events
US8340262B1 (en) 2004-11-18 2012-12-25 Verizon Services Corp. Home call router
US7945958B2 (en) * 2005-06-07 2011-05-17 Vmware, Inc. Constraint injection system for immunizing software programs against vulnerabilities and attacks
US7966479B1 (en) * 2005-09-28 2011-06-21 Oracle America, Inc. Concurrent vs. low power branch prediction
CA2633363A1 (en) 2005-11-09 2007-05-08 Vonage Holdings Corp. Method and system for customized caller identification
US8508570B2 (en) 2008-08-12 2013-08-13 Polycom, Inc. Method to populate contact list from recent call log
US8312249B1 (en) * 2008-10-10 2012-11-13 Apple Inc. Dynamic trampoline and structured code generation in a signed code environment
US9189233B2 (en) * 2008-11-24 2015-11-17 Intel Corporation Systems, apparatuses, and methods for a hardware and software system to automatically decompose a program to multiple parallel threads
US8578355B1 (en) 2010-03-19 2013-11-05 Google Inc. Scenario based optimization
US9015027B2 (en) * 2011-04-21 2015-04-21 International Business Machines Corporation Fast emulation of virtually addressed control flow
US9798873B2 (en) 2011-08-04 2017-10-24 Elwha Llc Processor operable to ensure code integrity
US20130024676A1 (en) * 2011-07-19 2013-01-24 Glew Andrew F Control flow integrity
US20130024674A1 (en) 2011-07-20 2013-01-24 International Business Machines Corporation Return address optimisation for a dynamic code translator
US8406384B1 (en) 2012-01-18 2013-03-26 Nuance Communications, Inc. Universally tagged frequent call-routing user queries as a knowledge base for reuse across applications
US10089126B2 (en) * 2013-03-21 2018-10-02 Vmware, Inc. Function exit instrumentation for tail-call optimized code
US9830172B2 (en) * 2012-06-30 2017-11-28 Microsoft Technology Licensing, Llc Implementing functional kernels using compiled code modules
US9351133B2 (en) 2013-08-21 2016-05-24 David William Offen Systems and methods for managing incoming calls
US9361102B2 (en) * 2014-06-09 2016-06-07 Lehigh University Methods for enforcing control flow of a computer program
US9842065B2 (en) * 2015-06-15 2017-12-12 Intel Corporation Virtualization-based platform protection technology
US9965374B2 (en) 2016-08-26 2018-05-08 Qualcomm Incorporated Profile guided indirect function call check for control flow integrity
US10552609B2 (en) * 2016-12-30 2020-02-04 Intel Corporation Malicious object detection in a runtime environment
WO2018236733A1 (en) * 2017-06-18 2018-12-27 Indiana University Research And Technology Corporation Systems and methods of performing probe injection using instruction punning
US10698668B1 (en) * 2018-05-29 2020-06-30 Amazon Technologies, Inc. Custom code transformations during compilation process
US11144631B2 (en) * 2018-09-11 2021-10-12 Apple Inc. Dynamic switching between pointer authentication regimes
US11016773B2 (en) 2019-09-27 2021-05-25 Intel Corporation Processor trace extensions to facilitate real-time security monitoring

Also Published As

Publication number Publication date
US10834255B1 (en) 2020-11-10
US10908912B1 (en) 2021-02-02
US11016767B2 (en) 2021-05-25
US10871974B1 (en) 2020-12-22
US20210011722A1 (en) 2021-01-14
US20210011738A1 (en) 2021-01-14

Similar Documents

Publication Publication Date Title
US20210357231A1 (en) Efficient mitigation of side-channel based attacks against speculative execution processing architectures
US8136091B2 (en) Architectural support for software-based protection
US9063721B2 (en) Continuous run-time validation of program execution: a practical approach
JP7011594B2 (en) Program loop control
US11347507B2 (en) Secure control flow prediction
CA1323940C (en) Preprocessing implied specifiers in a pipelined processor
US9336125B2 (en) Systems and methods for hardware-assisted type checking
JP7011595B2 (en) Branch instruction
US20010005882A1 (en) Circuit and method for initiating exception routines using implicit exception checking
JP2000506636A (en) Flexible implementation of system management mode (SMM) in processors
TWI749000B (en) Program loop control
Amit et al. {JumpSwitches}: Restoring the performance of indirect branches in the era of spectre
US9996356B2 (en) Method and apparatus for recovering from bad store-to-load forwarding in an out-of-order processor
JP2021519458A (en) Speculative side channel hint instructions
US6289444B1 (en) Method and apparatus for subroutine call-return prediction
US6189093B1 (en) System for initiating exception routine in response to memory access exception by storing exception information and exception bit within architectured register
JP2019197442A (en) Arithmetic processing device and control method of arithmetic processing device
Aimoniotis et al. Reorder buffer contention: A forward speculative interference attack for speculation invariant instructions
JPH08320788A (en) Pipeline system processor
US10908912B1 (en) Target injection safe method for dynamically inlining branch predictions
US9639370B1 (en) Software instructed dynamic branch history pattern adjustment
US20040225866A1 (en) Branch prediction in a data processing system
CN111241599B (en) Dynamic identification and maintenance method for processor chip safety dependence
US11216278B2 (en) Multi-thread processing
Park et al. Microarchitectural protection against stack-based buffer overflow attacks

Legal Events

Date Code Title Description
FEPP Fee payment procedure

Free format text: ENTITY STATUS SET TO UNDISCOUNTED (ORIGINAL EVENT CODE: BIG.); ENTITY STATUS OF PATENT OWNER: LARGE ENTITY

AS Assignment

Owner name: VMWARE, INC., CALIFORNIA

Free format text: ASSIGNMENT OF ASSIGNORS INTEREST;ASSIGNORS:AMIT, NADAV;JACOBS, FREDERICK JOSEPH;WEI, MICHAEL;SIGNING DATES FROM 20190729 TO 20191007;REEL/FRAME:050738/0779

STCF Information on status: patent grant

Free format text: PATENTED CASE

AS Assignment

Owner name: VMWARE LLC, CALIFORNIA

Free format text: CHANGE OF NAME;ASSIGNOR:VMWARE, INC.;REEL/FRAME:067103/0030

Effective date: 20231121