Method for securely protecting execution of software code from physical attacks
By inserting function address storage instructions into the software code and dynamically activating security countermeasures using a detection system, the high cost and execution overhead of protecting software code from physical attacks in existing technologies are solved, achieving dynamic protection of attacked functions and reducing code usage and execution time overhead.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- THALES DIS FRANCE SA
- Filing Date
- 2024-09-13
- Publication Date
- 2026-05-01
AI Technical Summary
Existing technologies for protecting software code from physical attacks suffer from problems such as high cost, slow execution speed, complex code design, and non-adaptive coverage. In particular, the overhead on the code execution environment is large when countermeasures are activated and cannot be dynamically adjusted.
By inserting instructions into the software code to store function addresses into global variables, the system can detect attacks during function execution and record attack information in non-volatile memory, dynamically activating and deactivating security countermeasures against the attacked function, including hardware or software countermeasures.
It enables dynamic activation of protection during the attacked function, reducing code space and execution time overhead, and provides protection only for the attacked part, avoiding unnecessary activation of countermeasures.
Smart Images

Figure CN121970050A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of protecting software execution on electronic devices from physical attacks (especially fault injection attacks), and more specifically to methods for dynamically activating countermeasures. Background Technology
[0002] Software execution on electronic devices can be vulnerable to various attacks that allow attackers to maliciously modify the execution of software code on electronic devices or gain knowledge of sensitive data stored on secure devices, such as secret encryption keys or banking information.
[0003] Various countermeasures have been designed to prevent or resist such attacks. A major drawback of these countermeasures is their high cost, which slows down code execution on protected electronic devices when the countermeasures are activated.
[0004] To avoid permanently activating multiple countermeasures at very high performance costs, each designed to target a different type of attack, methods have been proposed to activate such countermeasures only when executing specific code sections requiring a high level of protection. These methods typically require manual modification of the software code to be protected, adding activation and deactivation commands for each desired countermeasure at the beginning and end of each code section to be protected by a particular countermeasure.
[0005] Such methods are very cumbersome for code designers. They can also have a significant impact on code size. Furthermore, even if they are less expensive in terms of execution time than methods that imply the need for permanently activated countermeasures, they still incur overhead regardless of the execution environment of the protected electronic device, and this overhead remains the same even when the device is not the target of any attack.
[0006] Such methods also have the drawback of lacking adaptability in terms of coverage: they only protect the predetermined portions of the code for which countermeasure activation commands have been added. The parts of the code outside the scope of countermeasure activation will always remain unprotected unless the code is manually modified to permanently alter the portion protected by the countermeasure.
[0007] Therefore, there is a need for a method for secure software execution on electronic devices that enables the dynamic activation of protection for fine-tuning only the limited portions of code that have been attacked, with minimal code footprint and execution time overhead. Summary of the Invention
[0008] Therefore, according to the first aspect, the present invention relates to a method for securely protecting the execution of software code from physical attacks.
[0009] The software code includes calls to multiple functions, and instructions to store the address of the first function in a global variable before calling the first function.
[0010] The method is executed by an electronic system including a hardware processor, non-volatile memory, and a detection system configured to detect attacks on the electronic system during the execution of one of the plurality of functions, and the method includes:
[0011] - During the execution of the first function, the detection system detects attacks on the electronic system.
[0012] - After the attack is detected, the address from which the first function was called is retrieved, the retrieved address is stored in the non-volatile memory, and the execution of the first function is stopped.
[0013] - Upon the next startup of the electronic system:
[0014] o determines whether an attack has occurred during the previous execution of the first function by checking whether the address of the call to the first function is stored in the non-volatile memory.
[0015] When it is determined that an attack has occurred during a previous execution of the first function, the software code in the non-volatile memory is updated by replacing the call to the first function with a call to the function at the address stored in the non-volatile memory, the function: activating security countermeasures, calling the first function using the address stored in the global variable, and deactivating the activated security countermeasures after the first function is executed.
[0016] This approach allows countermeasures to be dynamically activated only during the execution of the attacked function, with minimal footprint on the executed code.
[0017] The activated security measures may include software measures that are disabled by default.
[0018] The activated security measures may include hardware security measures that are disabled by default.
[0019] Activating or deactivating the security measures may include changes to the software or hardware parameters or security configuration of the electronic system.
[0020] The method according to the first aspect may include: pre-updating the software code by inserting an instruction in the software code to store the address of the function in a global variable before each call to the function, the update being performed during the compilation of the software code or after the compilation but before linking the software code.
[0021] According to a second aspect, the present invention relates to a method for executing software code protected by the method according to the first aspect, and includes calls to a plurality of functions, and instructions for storing the address of a first function in a global variable prior to a call to the first function among the plurality of functions.
[0022] The method includes calling a function, wherein the function is:
[0023] oActivate security measures
[0024] o uses the address stored in the global variable to call the first function, and,
[0025] o Deactivate the activated security measures after executing the first function.
[0026] According to a third aspect, the present invention relates to a computer program product capable of being directly loaded into the memory of at least one computer, the computer program product comprising software code instructions for performing the steps of the methods according to the first and second aspects of the present invention when the product is run on the computer.
[0027] According to a fourth aspect, the present invention relates to an electronic system comprising a hardware processor, a non-volatile memory, and a detection system configured to perform steps of the methods according to the first and second aspects of the present invention.
[0028] In order to achieve the foregoing and related objectives, one or more embodiments include the features fully described below and specifically pointed out in the claims. Attached Figure Description
[0029] The following description and accompanying drawings illustrate certain exemplary aspects in detail and indicate only a few of the various ways in which the principles of the embodiments can be adopted. Other advantages and novel features will become apparent from the following detailed description when considered in conjunction with the accompanying drawings, and the disclosed embodiments are intended to include all such aspects and their equivalents.
[0030] • Figure 1 This is a schematic diagram of the electronic system according to the present invention;
[0031] • Figure 2This is a schematic diagram of a method for securely protecting the execution of software code from physical attacks according to an embodiment of the present invention;
[0032] • Figure 3 It is according to the invention for performing by Figure 1 A schematic diagram illustrating the method for protecting software code as illustrated. Detailed Implementation
[0033] According to a first aspect, the present invention relates to a method for protecting the execution of software code by an electronic system 1 from attacks, the software code comprising calls to multiple functions. To protect the execution of such functions from attacks, the method enables the electronic system to detect the occurrence of an attack during the execution of the functions and to dynamically apply one or more security countermeasures to protect the attacked function only during the next execution of the attacked function.
[0034] In the following paragraphs, the term "function" is used as a general term for the set of operations in any programming language, encompassing functions in any imperative programming language, methods in object-oriented programming languages, routines, and so on.
[0035] like Figure 1 The electronic system described includes a hardware processor 101 for executing software code to be protected, and at least one memory 102, such as non-volatile memory (NVM), RAM, and / or ROM memory in which the software code is stored. This electronic system can be, for example, a tamper-proof smart card, a smartphone, a personal computer, or a server. The electronic system may also include an input / output interface 103 that provides an interface to the device administrator, such as one or more screens, speakers, a mouse, a touch surface, a keyboard, etc.
[0036] The main idea of this invention is to activate countermeasures during the execution of a function that has been attacked during previous execution. To this end, attacks are detected during the operation of the electronic system. Therefore, the electronic system includes a detection system 104 configured to detect attacks on the electronic system during the execution of one of a plurality of functions called in the code to be protected.
[0037] To dynamically activate countermeasures, the first idea of this invention is to replace the call to the function to be protected with a call to another function in the software code. We can then call a wrapper function that not only executes the function to be protected, but also activates the appropriate countermeasures before that execution and deactivates the countermeasures when the function's execution ends.
[0038] The challenge of this solution is ensuring that the wrapper function calls the correct function without requiring any manual verification from the programmer. Therefore, another idea behind the method according to the invention is to modify the software code by adding an instruction to store the address of the function in a global variable before each call to the function. By doing so, the wrapper function that replaces the function call can find the address of the function it should call in that global variable.
[0039] The following paragraphs describe in detail the steps of the method for protecting the execution of software code in an electronic system according to the present invention, such as... Figure 2 As shown below. For illustrative purposes, it is assumed that an attack will occur during the execution of the protected function of the software code (hereinafter referred to as the "first function").
[0040] As previously described, a prerequisite for the method according to the invention is that the address of the first function is stored in a global variable before the first function is called, such that a wrapper function replacing the call can read the address of the first function from the global variable for calling the first function. To this end, in the preceding step S0, the software code can be updated by inserting instructions in the software code to store the address of the function in a global variable before each call to the function. To make wrapper functions easier, all such instructions can use the same unique global variable to store the address to be saved.
[0041] Such updates can be performed by the compiler itself during the compilation of the software code. Alternatively, this can be done by the compiler or by external tools at the end of compilation or after compilation and before linking the compiled software code. Alternatively, such updates can be performed in the source code of the software code before the source code is compiled.
[0042] Then, the method according to the invention described herein should be performed during the execution of the software code updated in the previous step S0 as described above in the electronic system.
[0043] In the first step S1, the detection system of the electronic system detects attacks on the electronic system during the execution of the first function. Such detection can be performed continuously during the operation of the electronic system until an attack is detected. Since the first function is the last function that has been called, the global variable used to store the address of the called function now stores the address of the first function. Such detection can be performed at the hardware level by a sensor. Therefore, additional software may not be required to detect the attack. Such detection can also be performed at the software level, for example, when a redundancy check fails.
[0044] In the second step S2, after the attack is detected in the first step S2, the electronic system retrieves the address from which it calls the first function and stores the retrieved address in the electronic system's non-volatile memory. This is the address of the call to the first function, which must be replaced by a call to the wrapper function described above to activate countermeasures before the first function is called. After the execution of the first function ends, it can be retrieved from the address of the next instruction, which, for processors using a program counter, may correspond to the program counter. This address of the next instruction may, for example, be stored in the LR register of the hardware processor or the C stack. For other types of processors, other registers may be of interest in retrieving the address of the next instruction. Then, at the end of the second step, the electronic system stops executing the first function to prevent the detected attack from developing further. The electronic system may even be restarted.
[0045] Then, the following steps are performed the next time the electronic system is started.
[0046] In the third step S3, the electronic system can determine whether an attack has occurred during the previous execution of the first function by checking whether the address of the call to the first function is stored in non-volatile memory.
[0047] When an attack occurs, the electronic system can update the software code in non-volatile memory by replacing a call to the first function with a call to a function previously known as a wrapper function at an address stored in non-volatile memory. This wrapper function activates security countermeasures, calls the first function using the address stored in global variables, and deactivates the activated security countermeasures after the first function is executed.
[0048] Such countermeasures can be hardware or software measures, which can be disabled by default and activated only by a wrapper function when the specific function to be protected (such as the first function described above) is executed. These countermeasures can include, for example, timing desynchronization, such as clock jitter, power smoothing, activation code anti-rerouting mechanisms, and memory access redundancy.
[0049] After the third step is completed, as Figure 3As illustrated, updated software code can eventually be executed, which includes calls to multiple functions, including a call to the first function by a wrapper function inserted in the software code in the third step. During its execution, just before the call to the wrapper function is executed, the electronic system executes an instruction to store the address of the first function in a global variable. It then calls the wrapper function, which activates security countermeasures in the first execution step E11, calls the first function using the address stored in the global variable in the second execution step E12, and finally deactivates the activated security countermeasures in the third execution step E13 after the execution of the first function has ended. Thus, the execution of the first function is protected by countermeasures that remain active only during the execution of the first function, which minimizes the system load generated by its activation. The activation or deactivation of the security countermeasures may include changes to the electronic system's software and hardware parameters or security configurations, such as security levels.
[0050] According to a second aspect, the present invention relates to a computer program product capable of being directly loaded into the memory of at least one computer, the computer program product comprising software code instructions for performing the steps of the methods previously described herein when the product is run on the computer.
[0051] According to a third aspect, the present invention relates to an electronic system 1, the electronic system including a hardware processor 101, a non-volatile memory 102, and a detection system 104 configured to perform the steps of the methods previously described herein.
[0052] In addition to these features, the computer program according to the second aspect of the invention and the electronic system according to the third aspect of the invention may be configured to perform or may include any other features described herein.
[0053] Therefore, the electronic system and method proposed in this paper enable the efficient triggering of additional countermeasures on specific parts of the code to be protected, where the space occupied on the code is very limited and the impact on execution time is limited because no countermeasures are activated during the execution of functions that do not require protection.
Claims
1. A method for securely protecting the execution of software code from physical attacks. The software code includes calls to multiple functions, and instructions to store the address of the first function in a global variable before calling the first function. The method is executed by an electronic system including a hardware processor (101), non-volatile memory (102), and a detection system (104) configured to detect attacks on the electronic system during the execution of a function among the plurality of functions, and the method includes: - During the execution of the first function, an attack on the electronic system is detected by the detection system (S1). - After the attack is detected, the address from which the first function was called is retrieved, the retrieved address is stored in the non-volatile memory, and the execution of the first function is stopped (S2). -At the next startup of the electronic system (S3): o determines whether an attack has occurred during the previous execution of the first function by checking whether the address of the call to the first function is stored in the non-volatile memory. When it is determined that an attack has occurred during a previous execution of the first function, the software code in the non-volatile memory is updated by replacing the call to the first function with a call to the function at the address stored in the non-volatile memory, the function: activating security countermeasures, calling the first function using the address stored in the global variable, and deactivating the activated security countermeasures after the first function is executed.
2. The method according to claim 1, wherein the activated security countermeasures include software countermeasures that are disabled by default.
3. The method according to claim 1 or 2, wherein the activated security measures include hardware security measures that are disabled by default.
4. The method according to any one of claims 1 to 3, wherein the activation or deactivation of the security countermeasures includes changes to the software or hardware parameters or security configuration of the electronic system.
5. The method according to any one of claims 1 to 4, wherein the method comprises: The software code is pre-updated (S0) by inserting an instruction into the software code before each call to the function to store the address of the function into a global variable. The update is performed during the compilation of the software code or after the compilation but before linking the software code.
6. A method for executing software code, said software code protected by the method according to any one of claims 1 to 5, and comprising calling a plurality of functions, and, prior to calling a first function among the plurality of functions, storing the address of the first function in a global variable. The method includes calling a function (E1), the function being: o Activate security measures (E11). o uses the address stored in the global variable to call the first function (E12), and, o Deactivate the activated security measures (E13) after executing the first function.
7. A computer program product capable of being directly loaded into the memory of at least one computer, the computer program product comprising software code instructions for performing the steps of any one of claims 1 to 6 when the product is run on the computer.
8. An electronic system comprising a hardware processor (101), a non-volatile memory (102), and a detection system (104) configured to perform the steps according to any one of claims 1 to 6.