Processing method and electronic equipment

By reading and verifying data information in one instruction and utilizing state switching keys and adjacent storage locations, the security protection issues of multi-process reading and writing and data change data are solved, achieving efficient and accurate data verification.

CN120724488APending Publication Date: 2025-09-30HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410375059.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-28
Publication Date
2025-09-30

AI Technical Summary

Technical Problem

Existing technologies are unable to effectively protect and verify data that changes during multi-process reading and writing or operation.

Method used

By reading data and verification information simultaneously in one instruction, using keys in different states (user state and kernel state) to generate verification information, ensuring the matching of data and verification information, using adjacent storage locations to store data and verification information, and cyclically verifying or locking data to improve accuracy.

Benefits of technology

It improves the security protection and verification accuracy of multi-process reading and writing and data change data, reduces costs and improves processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120724488A_ABST
    Figure CN120724488A_ABST
Patent Text Reader

Abstract

The invention provides a processing method and electronic equipment, the method is applied to the electronic equipment, and the method comprises the following steps: in response to a first instruction in a target program, obtaining first data stored in a first storage position and first verification information of the first data stored in a second storage position; generating second verification information of the first data according to the first data; if the second verification information is the same as the first verification information, determining that the first data verification is passed; and if the second verification information is different from the first verification information, determining that the first data verification fails. The method can be used for performing security protection and verification on data which are allowed to be read and written by multiple processes or data which can be changed in an operation process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of electronic equipment, and in particular to a processing method and electronic equipment. Background Art

[0002] Currently, electronic devices can use pointer authentication codes (PACs) to securely protect and verify key data (or important data) in programs of reduced instruction set computers (RISC) microprocessors (Advanced RISC Machines, ARMv8.3) above version 8.3. Specifically, after storing the key data, the electronic device can perform encryption calculations based on the key data that needs to be protected, obtain the PAC corresponding to the key data, and store it in other locations. When reading the key data later, the electronic device can recalculate the PAC based on the read key data and compare it with the previously stored PAC. Based on whether the recalculated PAC is consistent with the previously stored PAC, it can be determined whether the stored key data is secure.

[0003] The above method can only protect and verify the data that the electronic device reads and writes through a single process or the data that does not change during operation, and cannot protect and verify the data that allows multiple processes to read and write or the data that changes during operation. Summary of the Invention

[0004] The present application provides a processing method and electronic device for securely protecting and verifying data that allows multi-process reading and writing or data that may change during operation.

[0005] In a first aspect, an embodiment of the present application provides a processing method, which is applied to an electronic device, and the method includes: in response to a first instruction in a target program, obtaining first data stored in a first storage location and first verification information of the first data stored in a second storage location; generating second verification information of the first data based on the first data; if the second verification information is the same as the first verification information, determining that the first data verification has passed; if the second verification information is different from the first verification information, determining that the first data verification has failed.

[0006] Optionally, the electronic device may execute the method through a first process.

[0007] In this method, during the execution of the target program, the electronic device can complete the operations of reading data and verifying the data in a single instruction, namely the first instruction. Therefore, the electronic device can synchronously read the data and the verification information for the data, thereby achieving the effect of simultaneously reading the data and the verification information. By reading the data and the verification information in a single instruction, it is possible to reduce or avoid the problem of mismatches or inconsistencies between the data and the verification information during the reading of the data and the reading of the verification information due to process switching or data changes, thereby improving the accuracy of data protection and verification. Therefore, the above method can perform security protection and verification on data that allows multi-process reading and writing, or data that changes during operation, and improve the accuracy of security protection and verification.

[0008] In a possible design, the address of the first storage location and the address of the second storage location are adjacent. Through this method, data and verification information of the data can be read more conveniently and quickly, thereby improving processing efficiency.

[0009] In one possible design, generating second verification information of the first data based on the first data includes: obtaining a secret key stored in a first register; wherein, when the electronic device is in kernel state, the secret key stored in the first register is a first secret key, and the first secret key is the secret key used when the electronic device is in the kernel state; when the electronic device is in user state, the secret key stored in the first register is a second secret key, and the second secret key is the secret key used when the electronic device is in the user state; generating the second verification information based on the first data and the secret key stored in the first register.

[0010] Optionally, the electronic device may execute the method through a first process.

[0011] Through this method, the key stored in the first register is different when the electronic device is in user mode or kernel mode. Therefore, the electronic device uses different keys in user mode and kernel mode, providing enhanced security. In either user mode or kernel mode, the electronic device can obtain the key required to generate data verification information from a single register, namely the first register, thereby reducing costs.

[0012] In one possible design, the method further includes: when switching from the user state to the kernel state, setting the key stored in the first register to the first key; or, when switching from the kernel state to the user state, setting the key stored in the first register to the second key; or, when the CPU in the electronic device wakes up from a sleep state, writing the first key in the first register.

[0013] Optionally, the electronic device may execute the method through a kernel mode process.

[0014] In this method, the electronic device can switch the key in the first register based on the change of the state it is in, thereby achieving the effect of using a set of registers to store different secret keys used by the electronic device in different states, thereby reducing costs while ensuring security.

[0015] In one possible design, the first register is a register in the CPU; before writing the first key in the first register, the method also includes: obtaining the first key from a first storage area; wherein the first storage area is a storage area corresponding to a memory outside the CPU.

[0016] Optionally, the electronic device may execute the method through a kernel mode process.

[0017] Optionally, the first storage area is a storage space used when the electronic device is in kernel mode. Optionally, the first storage area may be an area for storing global variables.

[0018] Before setting the key stored in the first register as the second key, the method further includes:

[0019] The second secret key is obtained from a second storage area; wherein the second storage area is a storage area corresponding to a memory outside the CPU.

[0020] Optionally, the second storage area is a storage space used when the electronic device is in user mode. Optionally, the second storage area may be an area for storing structures corresponding to user mode processes.

[0021] Through the above method, it can be ensured that the electronic device can store and obtain the secret keys used in kernel mode and user mode.

[0022] In one possible design, the method further includes: storing second data in a third storage location in response to a second instruction in the target program, and storing third verification information of the second data in a fourth storage location.

[0023] Optionally, the electronic device may execute the method through a first process, or the electronic device may execute the method through a second process.

[0024] Through this method, during the execution of the target program, the electronic device can complete the operation of storing or writing data and verification information of the data in one instruction, namely the second instruction. Therefore, the electronic device can synchronously store the data and the verification information of the data, thereby achieving the effect of storing the data and the verification information at the same time. By storing the data and the verification information in one instruction, it is possible to reduce or avoid the problem of mismatch or non-correspondence between the data and the verification information of the data due to process switching or data changes during the process of storing the data and the verification information of the data, thereby improving the accuracy of data protection and verification. Therefore, the above method can perform security protection and verification on data that allows multi-process reading and writing or data that changes during operation, and improve the accuracy of security protection and verification.

[0025] In a possible design, the address of the third storage location is adjacent to the address of the fourth storage location. Through this method, data and verification information of the data can be stored more conveniently and quickly, thereby improving processing efficiency.

[0026] In one possible design, before obtaining the first data stored in the first storage location and the first verification information of the first data stored in the second storage location in response to the first instruction in the target program, the method also includes: obtaining a source program; wherein the source program includes a third instruction, and the third instruction is used to instruct to obtain the first data; compile the source program to obtain a target program; wherein the target program includes the first instruction, the first instruction is generated based on the third instruction, and the first instruction is used to instruct: obtain the first data and the first verification information of the first data.

[0027] Through this method, the electronic device can obtain the target program described in the aforementioned method, and then read the data and verify the information according to the aforementioned method during the execution of the target program, so as to achieve the effect of security protection and verification of data that allows multi-process reading and writing or data that will change during operation.

[0028] In one possible design, the target program also includes a fourth instruction and a fifth instruction; wherein the fourth instruction is used to instruct the generation of the second verification information of the first data, and the fifth instruction is used to instruct the comparison of whether the first verification information and the second verification information are the same.

[0029] In one possible design, the source program also includes a sixth instruction, which is used to indicate the storage of the second data; the target program also includes a seventh instruction, which is generated based on the sixth instruction and is used to indicate the storage of the second data and the third verification information of the second data.

[0030] Through this method, the electronic device can store data and verification information according to the above method during the execution of the target program, so as to achieve the effect of security protection and verification of data that allows multi-process reading and writing or data that may change during operation.

[0031] In one possible design, before compiling the source program to obtain the target program, the method further includes: obtaining a first configuration file; wherein the first configuration file includes first information, and the first information is used to indicate the variable name of the first data; obtaining the third instruction in the source code, and the third instruction includes an operand indicated by the variable name.

[0032] This method can mark the data involved in the program that needs to be protected and verified in the configuration file, thereby avoiding modification of the source program and ensuring the versatility of the source program.

[0033] In one possible design, the first verification information is a first pointer check code, and the second verification information is a second pointer check code.

[0034] In a second aspect, an embodiment of the present application provides a processing method, which includes: obtaining a source program; wherein the source program includes a first instruction, and the first instruction is used to instruct the acquisition of first data; compiling the source program to obtain a target program; wherein the target program includes a second instruction, and the second instruction is generated based on the first instruction, and the second instruction is used to instruct: obtaining the first data and the first verification information of the first data; or, the target program includes: multiple instructions executed in sequence, and a third instruction; wherein the multiple instructions and the third instruction are generated based on the first instruction; the multiple instructions include: an instruction for instructing the acquisition of the first data, an instruction for instructing the acquisition of the first verification information of the first data, an instruction for instructing the generation of the second verification information of the first data, and an instruction for instructing the comparison of whether the second verification information and the first verification information are the same; the third instruction is used to instruct to re-execute the multiple instructions when it is determined that the second verification information and the first verification information are different and the set time length has not been reached.

[0035] The target program can be obtained by this method. Among them, in the target program, by reading the data and the verification information of the data in one instruction, the problem of mismatching or non-corresponding data and verification information due to process switching or data changes in the process of reading data and reading the verification information of the data can be reduced or avoided, thereby improving the accuracy of data protection and verification. Alternatively, in the case of reading data and reading the verification information of the data through two instructions, the problem of mismatching or non-corresponding data and verification information due to process switching or data changes in the process of reading data and reading the verification information of the data can be reduced by cyclically executing the verification process, thereby improving the accuracy of data protection and verification. Therefore, the above method can obtain a target program that supports security protection and verification of data that allows multi-process reading and writing or data that will change during operation.

[0036] The first data is stored in a first storage location, the first verification information is stored in a second storage location, and an address of the first storage location is adjacent to an address of the second storage location.

[0037] In one possible design, when the target program includes the second instruction, the target program also includes a fourth instruction and a fifth instruction; wherein the fourth instruction is used to indicate the generation of second verification information of the first data, and the fifth instruction is used to indicate the comparison of whether the first verification information and the second verification information are the same.

[0038] In one possible design, the source program also includes a sixth instruction, which is used to indicate the storage of second data; the target program also includes a seventh instruction, which is generated based on the sixth instruction and is used to indicate the storage of the second data and third verification information of the second data.

[0039] In the target program obtained by this method, by storing data and verification information in a single instruction, it is possible to reduce or avoid the problem of data and verification information mismatches or inconsistencies caused by process switching or data changes during the data and verification process, thereby improving the accuracy of data protection and verification. Therefore, the above method can be used to obtain a target program that supports security protection and verification of data that can be read and written by multiple processes or data that changes during operation.

[0040] In one possible design, the second data is stored in a third storage location, the third verification information is stored in a fourth storage location, and the address of the third storage location is adjacent to the address of the fourth storage location.

[0041] In one possible design, before compiling the source program to obtain the target program, the method further includes: obtaining a first configuration file; wherein the first configuration file includes first information, and the first information is used to indicate the variable name of the first data; obtaining the first instruction in the source code, and the first instruction includes an operand indicated by the variable name.

[0042] This method can mark the data involved in the program that needs to be protected and verified in the configuration file, thereby avoiding modification of the source program and ensuring the versatility of the source program.

[0043] In one possible design, the first verification information is a first pointer check code, and the second verification information is a second pointer check code.

[0044] In a third aspect, an embodiment of the present application provides a processing method, which is applied to an electronic device, and the method includes: repeatedly executing a verification process until a termination condition is met and stopping; wherein, the verification process includes: obtaining first data in response to a first instruction in a target program; obtaining first verification information of the first data in response to a second instruction in the target program; generating second verification information of the first data based on the first data; if the second verification information is the same as the first verification information, determining that the first data verification has passed; if the second verification information is different from the first verification information, this verification process ends; the termination condition includes: the second verification information is the same as the first verification information, or the set time length is reached.

[0045] Optionally, the electronic device may execute the method through a first process.

[0046] In this method, while executing the target program, the electronic device can loop through the verification process until the verification succeeds or times out. By increasing the number of executions, the likelihood of reading matching data and verification information can be increased, thereby reducing or avoiding data and verification information mismatches or inconsistencies caused by process switching or data changes during the reading of data and verification information, thereby improving the accuracy of data protection and verification. Therefore, the above method can provide security protection and verification for data that can be read and written by multiple processes or data that changes during operation, and improve the accuracy of security protection and verification.

[0047] In one possible design, when the termination condition includes reaching a set time length, after repeatedly executing the verification process until the termination condition is met and stopping, the method further includes: determining that the first data verification has failed.

[0048] In one possible design, second verification information of the first data is generated based on the first data, including: obtaining a secret key stored in a first register; wherein, when the electronic device is in kernel state, the secret key stored in the first register is a first secret key, and the first secret key is the secret key used when the electronic device is in the kernel state; when the electronic device is in user state, the secret key stored in the first register is a second secret key, and the second secret key is the secret key used when the electronic device is in the user state; the second verification information is generated based on the first data and the secret key stored in the first register.

[0049] Optionally, the electronic device may execute the method through a first process.

[0050] In one possible design, the method further includes: when switching from the user state to the kernel state, setting the key stored in the first register to the first key; or, when switching from the kernel state to the user state, setting the key stored in the first register to the second key; or, when the CPU in the electronic device wakes up from a sleep state, writing the first key in the first register.

[0051] Optionally, the electronic device may execute the method through a kernel mode process.

[0052] In one possible design, the first register is a register in the CPU; before writing the first key in the first register, the method also includes: obtaining the first key from a first storage area; wherein the first storage area is a storage area corresponding to a memory outside the CPU.

[0053] Optionally, the electronic device may execute the method through a kernel mode process.

[0054] Optionally, the first storage area is a storage space used when the electronic device is in kernel mode. Optionally, the first storage area may be an area for storing global variables.

[0055] Before setting the key stored in the first register as the second key, the method further includes:

[0056] The second secret key is obtained from a second storage area; wherein the second storage area is a storage area corresponding to a memory outside the CPU.

[0057] Optionally, the second storage area is a storage space used when the electronic device is in user mode. Optionally, the second storage area may be an area for storing structures corresponding to user mode processes.

[0058] In one possible design, before repeatedly executing the verification process until the termination condition is met and stopping, the method further includes: obtaining a source program; wherein the source program includes a third instruction, and the third instruction is used to instruct the acquisition of the first data; compiling the source program to obtain a target program; wherein the target program includes: multiple instructions executed in sequence, and a fourth instruction; wherein the multiple instructions and the fourth instruction are generated based on the third instruction; the multiple instructions include: the first instruction for instructing the acquisition of the first data, the second instruction for instructing the acquisition of the first verification information of the first data, the instruction for instructing the generation of the second verification information of the first data, and the instruction for instructing the comparison of whether the second verification information and the first verification information are the same; the fourth instruction is used to instruct to re-execute the multiple instructions when it is determined that the second verification information and the first verification information are different and the set time length has not been reached.

[0059] Through this method, the electronic device can obtain a target program that supports security protection and verification of data that allows multi-process reading and writing or data that changes during operation.

[0060] In one possible design, before compiling the source program to obtain the target program, the method further includes: obtaining a first configuration file; wherein the first configuration file includes first information, and the first information is used to indicate the variable name of the first data; obtaining the third instruction in the source code, and the third instruction includes an operand indicated by the variable name.

[0061] In a fourth aspect, an embodiment of the present application provides a processing method, which is applied to a first process in an electronic device, and the method includes: in response to a first instruction in a target program, querying reference information corresponding to first data in multiple reference information; wherein different reference information in the multiple reference information corresponds to different data, and any reference information is: first information used to indicate that the corresponding data is not locked, or second information used to indicate that the corresponding data is locked; when it is determined that the reference information corresponding to the first data is the first information, the reference information corresponding to the first data is updated to the second information, and the first verification information of the first data and the first data is obtained; in response to a second instruction in the target program, the reference information corresponding to the first data is updated to the first information; based on the first data, second verification information of the first data is generated; if the second verification information is the same as the first verification information, it is determined that the first data verification has passed; if the second verification information is different from the first verification information, it is determined that the first data verification has failed.

[0062] In this method, before reading data and data verification information, the first process in the electronic device can first lock the data and verification information, thereby preventing other processes from reading and writing the data and verification information, which would cause the first process to read mismatched data and verification information. After reading the data and verification information, the first process can unlock the data and verification information, allowing other processes to read and write the data and verification information. This method can ensure that only one process reads the data and verification information at a time, thereby reducing or avoiding the problem of data and verification information mismatches or inconsistencies caused by process switching or data changes during the process of reading data and data verification information, thereby improving the accuracy of data protection and verification. Therefore, the above method can provide security protection and verification for data that can be read and written by multiple processes or data that may change during operation, and improve the accuracy of security protection and verification.

[0063] In one possible design, obtaining the first data and the first verification information of the first data includes: obtaining the first data in response to a third instruction in the target program; and obtaining the first verification information of the first data in response to a fourth instruction in the target program.

[0064] In one possible design, generating second verification information of the first data based on the first data includes: obtaining a secret key stored in a first register; wherein, when the electronic device is in kernel state, the secret key stored in the first register is a first secret key, and the first secret key is the secret key used when the electronic device is in the kernel state; when the electronic device is in user state, the secret key stored in the first register is a second secret key, and the second secret key is the secret key used when the electronic device is in the user state; generating the second verification information based on the first data and the secret key stored in the first register.

[0065] Optionally, the electronic device may execute the method through a first process.

[0066] In one possible design, the method further includes: when switching from the user state to the kernel state, setting the key stored in the first register to the first key; or, when switching from the kernel state to the user state, setting the key stored in the first register to the second key; or, when the CPU in the electronic device wakes up from a sleep state, writing the first key in the first register.

[0067] Optionally, the electronic device may execute the method through a kernel mode process.

[0068] In one possible design, the first register is a register in the CPU; before writing the first key in the first register, the method also includes: obtaining the first key from a first storage area; wherein the first storage area is a storage area corresponding to a memory outside the CPU.

[0069] Optionally, the electronic device may execute the method through a kernel mode process.

[0070] Optionally, the first storage area is a storage space used when the electronic device is in kernel mode. Optionally, the first storage area may be an area for storing global variables.

[0071] Before setting the key stored in the first register as the second key, the method further includes:

[0072] The second secret key is obtained from a second storage area; wherein the second storage area is a storage area corresponding to a memory outside the CPU.

[0073] Optionally, the second storage area is a storage space used when the electronic device is in user mode. Optionally, the second storage area may be an area for storing structures corresponding to user mode processes.

[0074] In one possible design, before querying reference information corresponding to the first data in multiple reference information in response to a first instruction in the target program, the method also includes: obtaining a source program; wherein the source program includes a fifth instruction, and the fifth instruction is used to instruct to obtain the first data; compiling the source program to obtain a target program; wherein the target program includes: the first instruction; an instruction for indicating that when the reference information corresponding to the first data is determined to be the first information, the reference information corresponding to the first data is updated to the second information; an instruction for indicating to obtain the first data and first verification information of the first data; the second instruction; an instruction for indicating to generate second verification information of the first data based on the first data.

[0075] Through this method, the electronic device can obtain a target program that supports security protection and verification of data that allows multi-process reading and writing or data that changes during operation.

[0076] In one possible design, before compiling the source program to obtain the target program, the method further includes: obtaining a first configuration file; wherein the first configuration file includes first information, and the first information is used to indicate the variable name of the first data; obtaining the fifth instruction in the source code, and the fifth instruction includes an operand indicated by the variable name.

[0077] In one possible design, the method further includes: in response to a sixth instruction in the target program, querying the reference information corresponding to the second data in the multiple reference information; when it is determined that the reference information corresponding to the second data is the first information, updating the reference information corresponding to the second data to the second information, and obtaining the second data and the third verification information of the second data; in response to a seventh instruction in the target program, updating the reference information corresponding to the second data to the first information; generating fourth verification information of the second data based on the second data; if the fourth verification information is the same as the third verification information, determining that the second data verification has passed; if the fourth verification information is different from the third verification information, determining that the second data verification has failed.

[0078] In a fifth aspect, the present application provides an electronic device, comprising a memory and one or more processors; wherein the memory is used to store computer program code, and the computer program code comprises computer instructions; when the computer instructions are executed by the one or more processors, the electronic device executes the method described in the first aspect or any possible design of the first aspect, or executes the method described in the second aspect or any possible design of the second aspect, or executes the method described in the third aspect or any possible design of the third aspect, or executes the method described in the fourth aspect or any possible design of the fourth aspect.

[0079] In a sixth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer program runs on an electronic device, the electronic device executes the method described in the first aspect or any possible design of the first aspect.

[0080] In the seventh aspect, the present application provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are run on an electronic device, the electronic device executes the method described in the first aspect or any possible design of the first aspect, or executes the method described in the second aspect or any possible design of the second aspect, or executes the method described in the third aspect or any possible design of the third aspect, or executes the method described in the fourth aspect or any possible design of the fourth aspect.

[0081] In an eighth aspect, the present application provides a chip system, comprising a processor and a memory, wherein the memory stores instructions; when the instructions are executed by the processor, the method described in the first aspect or any possible design of the first aspect is implemented, or the method described in the second aspect or any possible design of the second aspect is implemented, or the method described in the third aspect or any possible design of the third aspect is implemented, or the method described in the fourth aspect or any possible design of the fourth aspect is implemented. The chip system may be composed of a chip, or may include a chip and other discrete devices.

[0082] The beneficial effects of the fifth to eighth aspects can refer to the corresponding beneficial effects of the first, second, or third aspects, and will not be repeated here. The beneficial effects of some of the contents of the second to fourth aspects can refer to the beneficial effects of the corresponding contents of the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0083] Figure 1a A schematic diagram of a data storage method;

[0084] Figure 1b A schematic diagram of a data reading method;

[0085] Figure 2 A schematic diagram of the hardware architecture of an electronic device provided in an embodiment of the present application;

[0086] Figure 3 A schematic diagram of the software architecture of an electronic device provided in an embodiment of the present application;

[0087] Figure 4 A schematic diagram of a processing method provided in an embodiment of the present application;

[0088] Figure 5 A flowchart of a data protection method based on a simultaneous access mechanism provided in an embodiment of the present application;

[0089] Figure 6 A flowchart of a data protection method based on a cyclic verification mechanism provided in an embodiment of the present application;

[0090] Figure 7 A flowchart of a method for obtaining key data and a PAC corresponding to the key data provided in an embodiment of the present application;

[0091] Figure 8 A flowchart of a data protection method based on a data lock mechanism provided in an embodiment of the present application;

[0092] Figure 9A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0093] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the accompanying drawings.

[0094] In the description of the embodiments of this application, the terms "first" and "second" are used for descriptive purposes only and should not be understood to indicate or imply relative importance or implicitly specify the number of technical features indicated. Therefore, features specified as "first" or "second" may explicitly or implicitly include one or more of the features.

[0095] To facilitate understanding, exemplary descriptions of concepts related to this application are provided for reference.

[0096] 1) Electronic devices, which can be devices with processing and computing capabilities.

[0097] In some embodiments of the present application, the electronic device may be a computing device such as a server. For example, the electronic device may be a cloud server.

[0098] In some embodiments of the present application, the electronic device may also be a portable device, such as a mobile phone, a tablet computer, a wearable device with wireless communication function (such as a watch, a bracelet, etc.), a vehicle-mounted terminal device, augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), smart home devices (such as smart TVs, smart speakers, etc.), smart robots, workshop equipment, wireless terminals in self-driving, wireless terminals in remote medical surgery, wireless terminals in smart grids, wireless terminals in transportation safety, wireless terminals in smart cities, or wireless terminals in smart homes, flying equipment (such as smart robots, drones, airplanes), etc.

[0099] Among them, a wearable device is a portable device that a user can wear directly on the body or integrate into the user's clothes or accessories.

[0100] In some embodiments of the present application, the electronic device may also be a portable terminal device that also includes other functions such as a personal digital assistant and / or a music player. Or a portable terminal device with other operating systems. The portable terminal device may also be other portable terminal devices, such as a laptop computer with a touch-sensitive surface (e.g., a touch panel). It should also be understood that in some other embodiments of the present application, the electronic device may not be a portable terminal device, but a desktop computer with a touch-sensitive surface (e.g., a touch panel).

[0101] 2) Compilation is the process of converting a program written in one programming language (the source language) into a program written in another language (the target language). The source language can be the language used by the user to write the target program, and the target language can be the language of the device on which the user wishes to run the target program. For example, compilation can convert the high-level language used to write the source program into a binary language that can be understood by a machine (such as a computer or an executor) for easy recognition and execution.

[0102] 3) Registers are small storage areas within the CPU used to store data. Registers can be used to temporarily store data involved in calculations, calculation results, and other data.

[0103] The key register described in the embodiments of the present application refers to a register used to store a key.

[0104] 4) Structure: A structure is a collection of data consisting of a series of data of the same or different types. By operating on the internal variables of the structure, data can be stored in memory to complete data storage and operation.

[0105] It should be understood that in the embodiments of the present application, "at least one" refers to one or more, and "more" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: the existence of A alone, the existence of A and B at the same time, and the existence of B alone, where A and B can be singular or plural. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can represent: a, b, c, a and b, a and c, b and c, or a, b and c, where a, b, c can be single or multiple.

[0106] Attackers can modify the key data in the program to control the program flow and thus attack the program. Therefore, in order to enhance the security of the program, it is necessary to protect the key data in the program.

[0107] Currently, electronic devices can use pointer checking technology to protect critical data in programs. Pointer checking technology provides a variety of encryption keys (or encryption instructions, such as PACIA, PACIB, PACDA, PACDB, PACGA, etc.), which can be used to encrypt, protect, and verify data.

[0108] Currently, in data protection solutions based on pointer verification technology, electronic devices can use a secret key and other information to encrypt the data to be protected to obtain a PAC, which is then stored elsewhere. When reading data, the electronic device can recalculate the PAC and compare it with the previously stored PAC. If the comparison is consistent, the verification passes and subsequent processes can proceed normally. If the comparison is inconsistent, the verification fails and the ongoing process can be interrupted.

[0109] The process corresponding to the above method may include a data writing (ie, storing data) phase and a data reading (ie, obtaining stored data) phase. When the above method is applied to an electronic device, such as Figure 1a As shown in , the process of the data writing phase may include the following steps 1 to 3:

[0110] Step 1: During execution of a target program, the electronic device stores key data in response to a first instruction in the target program.

[0111] The target program is the program obtained by compiling the source program.

[0112] Step 2: The electronic device calculates the PAC corresponding to the key data in response to the second instruction in the target program.

[0113] Step 3: The electronic device stores the PAC corresponding to the key data in response to the third instruction in the target program.

[0114] The PAC corresponding to the key data is different from the storage location of the key data.

[0115] like Figure 1b As shown in , the process of the data reading phase may include the following steps 4 to 7:

[0116] Step 4: During the execution of the target program, the electronic device reads the stored key data in response to the fourth instruction in the target program.

[0117] Step 5: The electronic device reads the stored PAC in response to the fifth instruction in the target program.

[0118] Step 6: The electronic device calculates the PAC corresponding to the read key data in response to the sixth instruction in the target program.

[0119] Step 7: The electronic device responds to the seventh instruction in the target program and compares the calculated PAC with the read stored PAC to see if they are the same; if so, it is determined that the security verification is successful; otherwise, it is determined that the security verification fails.

[0120] If the PAC calculated by the electronic device is the same as the stored PAC, it indicates that the critical data to be protected has not been tampered with by the attacker, and the security verification is considered successful. If the PAC calculated by the electronic device is different from the stored PAC, it indicates that the critical data to be protected has been tampered with by the attacker, and the security verification is considered failed.

[0121] Based on the above method, the electronic device can securely protect data during program execution, thereby improving data security.

[0122] However, the above method can only be used to protect data read and written by a single process or static data (that is, data that does not change during operation). It cannot protect data that will be read and written by multiple processes during operation or dynamic data (that is, data that will change during operation). For example, it cannot protect data protected by sequential locks or data that is used bit by bit and does not need to be locked after optimization.

[0123] In steps 2 and 5 above, the electronic device may calculate the PAC corresponding to the key data by calculating the PAC based on the key data, a key, and other information according to a predetermined calculation logic. Currently, to further enhance security, the key used by the electronic device when calculating the PAC in kernel mode differs from the key used when calculating the PAC in user mode. In specific implementations, the electronic device may be configured with two sets of key registers, one for storing kernel mode keys and the other for storing user mode keys. When the electronic device is in kernel mode, the key registers for storing kernel mode keys may be enabled and the key registers for storing user mode keys may be disabled, thereby calculating the PAC using the kernel mode keys. When the electronic device is in user mode, the key registers for storing user mode keys may be enabled and the key registers for storing kernel mode keys may be disabled, thereby calculating the PAC using the user mode keys. Kernel mode refers to the state in which an electronic device is running an operating system program. In this state, processes running on the electronic device have access to all memory spaces and objects. User mode refers to the state in which an electronic device is running a user program. In this state, processes running on the electronic device have limited access to memory spaces and objects.

[0124] The above solution places high demands on the hardware of the electronic device, requiring the configuration of two sets of key registers. Furthermore, electronic devices without specialized hardware (i.e., those that do not or cannot configure two sets of key registers) cannot use the above solution for key management and must use the same key in both kernel and user mode. However, the user mode environment is less secure, so this method carries the risk of kernel key exposure, resulting in lower security.

[0125] Furthermore, in the above method, the source program includes tags for identifying key data, as well as instructions for security protection and verification of key data. Therefore, when the electronic device executes the target program generated by the compiler after compiling the source program, it can identify the key data and perform security protection and verification on the key data according to the above method. However, this method requires embedding the relevant code into the source program, which will modify the source program.

[0126] Based on the above problems, in order to achieve security protection and verification of data or dynamic data that will be read and written by multiple processes during operation, improve the security of key management, and avoid changes to the source program, the embodiment of the present application provides a processing method and electronic device, which can be divided into three parts: data protection method, key management method and program compilation method. Among them, the data protection method can not only provide security protection for data or static data read and written by a single process, but also provide security protection for data or dynamic data that will be read and written by multiple processes during operation, so it has high practicality. The key management method can achieve safe and efficient key management at a lower cost. The program compilation method can add relevant processing logic for data security protection and verification on the basis of not changing the source program, so that the electronic device can smoothly perform data security protection when running the target program compiled from the source program.

[0127] The technical solutions provided in the embodiments of this application can be executed by any computing device with processing and computing capabilities, or by a system composed of multiple computing devices with processing, computing, and communication capabilities. The computing device can be an electronic device, etc. For an introduction to the performance of the electronic device, please refer to the description in the above conceptual description or the relevant description below.

[0128] The following description will be made using the application of the technical solution of the present application in an electronic device or in a system including multiple electronic devices as an example. The implementation process of the application in other computing devices is similar and will not be repeated.

[0129] See below Figure 2 , the structure of the electronic device to which the method provided in the embodiments of the present application is applicable is introduced.

[0130] like Figure 2As shown in , the electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a USB interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a SIM card interface 195, etc.

[0131] The sensor module 180 may include a gyroscope sensor, an acceleration sensor, a proximity light sensor, a fingerprint sensor, a touch sensor, a temperature sensor, a pressure sensor, a distance sensor, a magnetic sensor, an ambient light sensor, an air pressure sensor, a bone conduction sensor, and the like.

[0132] It is understandable that Figure 2 The electronic device 100 shown is merely an example and does not constitute a limitation to the electronic device, and the electronic device may have more or fewer components than shown in the figure, may combine two or more components, or may have a different component configuration. Figure 2 The various components shown in the drawings may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.

[0133] The processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units can be independent devices or integrated into one or more processors. Among them, the controller can be the nerve center and command center of the electronic device 100. The controller can generate an operation control signal based on the instruction opcode and timing signal to complete the control of instruction fetching and execution.

[0134] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly access the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.

[0135] The execution of the processing method provided in the embodiment of the present application can be controlled by the processor 110 or completed by calling other components, such as calling the processing program of the embodiment of the present application stored in the internal memory 121, or calling the processing program of the embodiment of the present application stored in a third-party device through the external memory interface 120, to control the wireless communication module 160 to communicate data with other devices, thereby improving the intelligence and convenience of the electronic device 100 and enhancing the user experience. The processor 110 can include different devices. For example, when a CPU and a GPU are integrated, the CPU and the GPU can cooperate to execute the processing method provided in the embodiment of the present application. For example, part of the algorithm in the processing method is executed by the CPU, and another part of the algorithm is executed by the GPU to obtain faster processing efficiency.

[0136] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include one or N display screens 194, where N is a positive integer greater than 1. The display screen 194 can be used to display information input by the user or information provided to the user, as well as various graphical user interfaces (GUIs). For example, the display screen 194 can display photos, videos, web pages, or files.

[0137] In the embodiment of the present application, the display screen 194 can be an integrated flexible display screen, or a spliced ​​display screen consisting of two rigid screens and a flexible screen located between the two rigid screens.

[0138] Camera 193 (either a front-facing camera or a rear-facing camera, or one camera serving as both) is used to capture still images or videos. Typically, camera 193 includes a photosensitive element, such as a lens assembly and an image sensor. The lens assembly includes multiple lenses (convex or concave) that capture light signals reflected from the object to be photographed and transmit the captured light signals to the image sensor. The image sensor generates an original image of the object to be photographed based on the light signals.

[0139] The internal memory 121 can be used to store computer executable program code, which includes instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. Among them, the program storage area can store the code of the operating system, application program (such as the function corresponding to the solution of the present application, etc.). The data storage area can store data created during the use of the electronic device 100, etc.

[0140] The internal memory 121 may also store one or more computer programs corresponding to the algorithms of the present application. The one or more computer programs are stored in the internal memory 121 and configured to be executed by the one or more processors 110. The one or more computer programs include instructions that can be used to perform the various steps in the following embodiments.

[0141] In addition, the internal memory 121 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0142] Of course, the code of the algorithm of the embodiment of the present application can also be stored in an external memory. In this case, the processor 110 can run the code of the algorithm of the embodiment of the present application stored in the external memory through the external memory interface 120.

[0143] A touch sensor, also known as a "touch panel," can be provided on the display screen 194. The touch sensor and the display screen 194 form a touch display screen, also known as a "touch screen." The touch sensor is used to detect touch operations applied to or near the touch sensor. The touch sensor can transmit the detected touch operations to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor can also be provided on the surface of the electronic device 100, at a location different from that of the display screen 194.

[0144] The wireless communication function of the electronic device 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.

[0145] Antenna 1 and Antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve antenna utilization. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In other embodiments, the antennas can be used in conjunction with a tuning switch.

[0146] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G applied to the electronic device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110. In an embodiment of the present application, the mobile communication module 150 can also be used to exchange information with other devices.

[0147] The modem processor may include a modulator and a demodulator. The modulator is used to modulate the low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After being processed by the baseband processor, the low-frequency baseband signal is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to the speaker 170A, the receiver 170B, etc.) or displays an image or video through the display screen 194. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.

[0148] The wireless communication module 160 can provide wireless communication solutions applied to the electronic device 100, including wireless local area networks (WLAN) (such as wireless fidelity (WiFi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared technology (IR), etc. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, frequency modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110. The wireless communication module 160 can also receive the signal to be transmitted from the processor 110, frequency modulate it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2. In the embodiment of the present application, the wireless communication module 160 can be used to establish a connection with other electronic devices and exchange data. Or the wireless communication module 160 can be used to access an access point device, send control instructions to other electronic devices, or receive data sent from other electronic devices.

[0149] In addition, the electronic device 100 can implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor. For example, music playback, recording, etc. The electronic device 100 can receive input from the key 190 and generate key signal input related to the user settings and function control of the electronic device 100. The electronic device 100 can use the motor 191 to generate a vibration prompt (such as an incoming call vibration prompt). The indicator 192 in the electronic device 100 can be an indicator light, which can be used to indicate the charging status, power changes, and can also be used to indicate messages, missed calls, notifications, etc. The SIM card interface 195 in the electronic device 100 is used to connect the SIM card. The SIM card can be inserted into the SIM card interface 195 or pulled out from the SIM card interface 195 to achieve contact and separation with the electronic device 100.

[0150] It should be understood that in actual applications, the electronic device 100 may include Figure 2The embodiments of the present application are not limited to more or fewer components shown. The illustrated electronic device 100 is merely an example, and the electronic device 100 may have more or fewer components than shown, may combine two or more components, or may have a different component configuration. The various components shown in the figures may be implemented in hardware, including one or more signal processing and / or application-specific integrated circuits, software, or a combination of hardware and software.

[0151] The software system of the electronic device 100 can adopt a layered architecture, an event-driven architecture, a micro-kernel architecture, a microservice architecture, or a cloud architecture. The layered architecture divides the software into several layers, each with a clear role and division of labor. The layers communicate with each other through software interfaces. For example, Figure 3 As shown in the figure, the software architecture can be divided into four layers, from top to bottom: application layer, application framework layer (framework, FWK), runtime and system library, and (Linux) kernel layer.

[0152] The application layer is the top layer of the operating system, including native applications of the operating system, such as camera, gallery, calendar, Bluetooth, music, video, information, etc., and may also include third-party applications. The application involved in the embodiment of the present application is referred to as application (APP), which is a software program that can realize one or more specific functions. Typically, multiple applications can be installed in an electronic device, such as a camera application, a mailbox application, etc. The applications mentioned below can be system applications that are installed on the electronic device when it leaves the factory, or they can be third-party applications that the user downloads from the Internet or obtains from other electronic devices while using the electronic device.

[0153] Of course, developers can write applications and install them into this layer. In one possible implementation, applications can be developed using the Java language by calling the application programming interface (API) provided by the application framework layer. Developers can use the application framework to interact with the underlying layer of the operating system (such as the kernel layer) and develop their own applications.

[0154] The application framework layer provides the application API and programming framework. It includes predefined functions and can include a window manager, content provider, view system, telephony manager, resource manager, and notification manager.

[0155] The window manager is used to manage window programs. The window manager can obtain the display size, determine whether there is a status bar, lock the display (or screen), capture the display, etc.

[0156] Content providers are used to store and retrieve data and make it accessible to applications. The data may include files (such as documents, videos, images, audio), text, and other information.

[0157] The view system includes visual controls, such as those that display text, images, and documents. The view system is used to build applications. The interface within a display window can be composed of one or more views. For example, the interface for a text notification icon might include a view that displays text and a view that displays an image.

[0158] The phone manager provides communication functionality for electronic devices. The notification manager enables applications to display notifications in the status bar, which can be used to convey informational messages and automatically disappear after a short period of time without user interaction.

[0159] The runtime includes the core library and the virtual machine. The runtime is responsible for the scheduling and management of the system.

[0160] The system's core library consists of two parts: one containing the Java language's callable functions and the other the system's core library. The application layer and application framework layer run within a virtual machine. For example, in Java, the virtual machine executes Java files from the application and framework layers as binary files. The virtual machine manages object lifecycles, stack management, thread management, security and exception management, and garbage collection.

[0161] The system library can include multiple functional modules. For example: surface manager, media library, 3D graphics processing library (for example: OpenGL ES), 2D graphics engine (for example: SGL), image processing library, etc. The surface manager is used to manage the display subsystem and provides the fusion of 2D and 3D layers for multiple applications. The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.564, MP3, AAC, AMR, JPG, PNG, etc. The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis and layer processing, etc. The 2D graphics engine is a drawing engine for 2D drawing.

[0162] The kernel layer provides the operating system's core system services, such as security, memory management, process management, the network protocol stack, and the driver model. These services are all implemented at the kernel layer. The kernel layer also serves as an abstraction layer between the hardware and software stacks. This layer contains many drivers related to electronic devices, including the display driver, the keyboard driver for input devices, the Flash driver for memory-based devices, the camera driver, the audio driver, the Bluetooth driver, and the Wi-Fi driver.

[0163] It should be understood that the functional services described above are only examples. In actual applications, electronic devices can also be divided into more or fewer functional services according to other factors, or the functions of each service can be divided in other ways, or the functional services can be not divided but work as a whole.

[0164] The following describes in detail the implementation method of the solution provided in the embodiment of the present application in conjunction with the accompanying drawings.

[0165] like Figure 4 As shown in , the solutions provided by the embodiments of this application may include methods for program compilation, key management, and data protection. The program compilation method can be executed during the program compilation phase. The key management method can be executed after program compilation. The data protection method can be executed during the target program execution phase. The following provides an overview of the program compilation method, key management method, and data protection method.

[0166] 1. Program compilation method

[0167] The program compilation method is used to configure data protection related processing logic in the process of compiling a source program to obtain a target program, and compile to obtain the target program.

[0168] For ease of description, the data that needs to be protected is referred to as key data in the following embodiments of this application.

[0169] like Figure 4 As shown in , the program compilation method may include key data marking and compilation processes that are performed sequentially. Detailed descriptions are given below.

[0170] 1. Key data marking process

[0171] As an optional implementation, during the data marking process, after obtaining the source program, the electronic device may obtain a configuration file associated with the source program, where the configuration file includes information for marking key data involved in the source program.

[0172] For example, taking the scenario of storing key data in the form of a structure as an example, the information used to mark the key data in the configuration file can be implemented in the following format: struct.<structure name>.<field name>. Among them, struct is used to indicate that the storage type of the key data is a structure. The structure name is the name of the structure to which the key data belongs. The field name is the name of the field where the key data is located in the structure to which it belongs. Based on this information, the electronic device can determine the structure to which the key data belongs based on the structure name, and then locate the key data from the structure based on the field name, and then determine the key data.

[0173] In the above method, by marking the key data involved in the source program in the configuration file, it is possible to avoid modifying the source program, thereby ensuring the versatility of the source program.

[0174] 2. Compilation process

[0175] During the compilation process, the electronic device can add processing logic corresponding to the data protection method (i.e., PAC verification code insertion) to the key data in the processed program when compiling the source program to obtain the target program. The electronic device can identify the key data based on the configuration file and the read and write instructions of the key data based on the source program, and then add processing logic corresponding to the data protection method to the read and write instructions of the key data.

[0176] The read and write instructions include write instructions and / or read instructions. The write instruction can be used to instruct writing data, ie storing data, and the read instruction can be used to instruct reading data, ie obtaining stored data.

[0177] In the embodiment of the present application, writing can also be understood as storing, and reading can also be understood as acquiring.

[0178] The processing logic corresponding to the data protection method may include:

[0179] 1) During the critical data writing phase, the PAC corresponding to the critical data is determined and stored.

[0180] During the compilation process, the electronic device may insert the instructions corresponding to the processing logic after the write instructions for the key data, or use the instructions corresponding to the processing logic to replace the write instructions for the key data.

[0181] 2) During the key data read phase, the PAC corresponding to the read key data (which may be the same as or different from the key data stored during the key data write phase) is re-determined and compared with the PAC corresponding to the previously stored key data. If the comparison is consistent, the subsequent process continues; if not, the current process is interrupted.

[0182] During the compilation process, the electronic device may insert the instruction corresponding to the processing logic after the read instruction for the key data, or replace the read instruction for the key data with the instruction corresponding to the processing logic.

[0183] In some embodiments of the present application, anti-competition logic can be added to the processing logic corresponding to the data protection method. By adding anti-competition logic, it is possible to support the protection of data or dynamic data that allows multi-process reading and writing during the execution of the target program. Figure 4 As shown in , the anti-contention logic can be implemented by a simultaneous access mechanism, a cyclic check mechanism, or a data lock mechanism.

[0184] Among them, regarding the simultaneous access mechanism, the cyclic check mechanism, and the data lock mechanism, reference may be made to the descriptions of the following embodiment 1, embodiment 2, and embodiment 3 respectively, and will not be described in detail here.

[0185] In some embodiments of the present application, the electronic device may include a compiler, and the compiler may be used to perform the above-mentioned compilation process.

[0186] 2. Key Management Method

[0187] The key management method is used to manage the kernel-state keys and user-state keys required for data protection.

[0188] like Figure 4 As shown in , the key management method may include key initialization, key switching, key recovery and other processes. Detailed descriptions are given below.

[0189] 1) Secret key initialization

[0190] In the embodiments of the present application, the electronic device can be in kernel mode or user mode, and can switch between kernel mode and user mode. To improve the security of kernel space, the electronic device can use different keys when protecting data in kernel mode and user mode. In the embodiments of the present application, the key used by the electronic device in kernel mode can be referred to as a kernel mode key, and the key used by the electronic device in user mode can be referred to as a user mode key.

[0191] In some embodiments of the present application, the electronic device may randomly generate a kernel state key during the kernel startup phase and store the kernel state key in a storage space corresponding to the kernel state. For example, the electronic device may store the kernel state key in a global variable.

[0192] In some embodiments of the present application, an electronic device may generate a user-state key corresponding to a user-state process during the user-state process startup phase. The user-state keys corresponding to different user-state processes may be different. In a data protection method executed by a user-state process, the electronic device may use the user-state key corresponding to the user-state process. In one possible solution, the electronic device may store the generated user-state key in a storage space corresponding to the user state. For example, the electronic device may store the user-state key corresponding to the user-state process in a structure of the user-state process. In another possible solution, the electronic device may also store the generated user-state key in a storage space corresponding to the kernel state.

[0193] The storage space corresponding to the kernel state is the storage space used by the electronic device in the kernel state, and the storage space corresponding to the user state is the storage space used by the electronic device in the user state.

[0194] Optionally, the key switching in the key register in the above method can be completed by a kernel mode process.

[0195] 2) Key Switching

[0196] In some embodiments of the present application, the electronic device includes a key register, which can be used to store a key for use when executing the data protection method. The electronic device can read the key from the key register and use it when executing the data protection method.

[0197] In order to ensure that the key read from the key register when the electronic device executes the data protection method is the key corresponding to the current state of the electronic device, the electronic device can switch the key stored in the key register according to the state it is in. Specifically, the electronic device can switch the key in the key register to the kernel state key when exiting the user state or entering the kernel state. For example, the electronic device can switch the key in the key register to the kernel state key when the kernel's process 0 (el0) enters the kernel's entry function (kernel_entry) logic. The electronic device can switch the key in the key register to the user state key when exiting the kernel state or entering the user state. For example, the electronic device can switch the key in the key register to the user state key when exiting the kernel space (kernel_exit) logic.

[0198] In this method, the electronic device only needs to be configured with one set of key registers, which is relatively low cost. By switching the keys in the key registers, it is possible to use different keys in kernel mode and user mode, thereby ensuring the security of kernel space.

[0199] Optionally, a set of key registers may include at least one secret register, each key register in the at least one key register may store a type of key, and different key registers may store different types of keys.

[0200] 3) Secret key recovery

[0201] In some embodiments of the present application, the electronic device may include one or more CPUs, and each CPU of the electronic device may be configured with a set of key registers.

[0202] In a scenario where an electronic device includes multiple CPUs, the configurations related to the key registers corresponding to the multiple CPUs are consistent. Each of the multiple CPUs can switch between a working state (i.e., a power-on state) and a sleep state (i.e., a power-off state). When any CPU of the electronic device switches from a working state to a sleep state, the key register of the CPU no longer stores the key. Thereafter, when the CPU switches from a sleep state to a working state, the key stored in the key register of the CPU needs to be reset. Therefore, the electronic device can restore the key in the key register of each CPU in the multiple CPUs to a kernel state key when any one or more of the CPUs in the multiple CPUs are awakened from sleep (i.e., switched from a sleep state to a working state), thereby ensuring the consistency of the key registers of the multiple CPUs.

[0203] 3. Data Protection Methods

[0204] The data protection method is used to protect the data that needs to be protected during program execution (ie, critical data).

[0205] The program compilation method and data protection method provided in the embodiments of the present application can be applied to the same electronic device or to different electronic devices respectively. When the program compilation method and data protection method provided in the embodiments of the present application are applied to the same electronic device, the electronic device can refer to the program compilation method to compile the source program to obtain the target program, and can also refer to the data protection method to protect the key data in the process of executing the target program. For example, taking the electronic device as a mobile phone as an example, the source program can be the program of the application installation package downloaded by the electronic device, the process of installing the application by the electronic device is the process of compiling the source program, and the application installed by the electronic device is the target program. When the program compilation method and data protection method provided in the embodiments of the present application are applied to different electronic devices, one electronic device can refer to the program compilation method to compile the source program to obtain the target program, and can provide the target program to another electronic device. Another electronic device can refer to the data protection method to protect the key data in the process of executing the acquired target program. For example, a cloud server can compile the source program to obtain the target program, and other electronic devices such as mobile phones can obtain the target program from the cloud server and execute it.

[0206] Example 1

[0207] In a first possible solution, the electronic device can implement data protection based on a simultaneous access mechanism. In this solution, the target program obtained by the electronic device is a target program obtained by adding anti-contention logic based on the simultaneous access mechanism during the compilation process based on the aforementioned program compilation method.

[0208] The simultaneous access mechanism is a mechanism for simultaneously accessing (i.e., reading and writing) key data and PAC. The simultaneous access is achieved by instructing the storage of key data and PAC through a single instruction in the program.

[0209] For example, when using a simultaneous access mechanism, the procedures for writing critical data may include:

[0210] pacga R_pac_comput, R_data, R_address

[0211] stp R_data, R_pac, [R_address]

[0212] In this command, pacga is a PAC calculation instruction, stp is a storage instruction, R_pac_comput is the calculated PAC, R_data represents the key data to be stored, R_pac represents the PAC to be stored, and R_address represents the storage address of the key data and PAC. "pacga R_pac_comput, R_data, R_address" indicates the calculation of the PAC corresponding to the key data, and "stp R_data, R_pac, [R_address]" indicates the storage of the key data along with the calculated PAC.

[0213] For another example, when a simultaneous access mechanism is used, the procedures corresponding to the stage of reading key data may include:

[0214] ldp R_data, R_pac, [R_address]

[0215] pacga R_pac_comput, R_data, R_address

[0216] cmp R_pac, R_pac_comput

[0217] b.ne panic

[0218] Among them, ldp is a read data instruction, and cmp is a compare data instruction. ldp R_data, R_pac, [R_address] is an instruction that instructs to directly read key data and PAC from the storage area. pacga R_pac_comput, R_data, R_address is an instruction that instructs to calculate the PAC corresponding to the key data. cmp R_pac, R_pac_comput is an instruction that compares the calculated PAC with the stored PAC. b.ne panic is an instruction that interrupts the program and indicates an exception if they are not equal.

[0219] The foregoing Figure 1a In the existing solution shown, two instructions are used to indicate writing key data and PAC respectively. Figure 1b In the existing solution shown, two instructions are used to instruct the reading of key data and PAC respectively. In a multi-process scenario, each process can write or read key data, and switching between different processes may occur between any two adjacent instructions. Figure 1a and Figure 1b The existing solution shown in the figure may cause the key data and PAC to change out of sync due to the switching of different processes, resulting in the failure of subsequent PAC verification, affecting the data protection effect. Figure 1a and Figure 1bThe existing solution shown cannot protect critical data that can be read and written by multiple processes, and the same applies to dynamic data. However, in the embodiments of the present application, through a simultaneous access mechanism, the operations of storing critical data and PAC can be completed in a single instruction, and the operations of reading critical data and PAC can be completed in a single instruction. Therefore, each process can write critical data and PAC simultaneously and read critical data and PAC simultaneously. Therefore, switching between different processes in a multi-process scenario will not affect the correspondence between critical data and PAC, and thus will not affect the effectiveness of data protection.

[0220] Reference Figure 5 The process of a data protection method based on a simultaneous access mechanism provided in an embodiment of the present application may include:

[0221] S501: The electronic device determines a PAC corresponding to first key data.

[0222] Optionally, the electronic device may execute step S501 in response to a first PAC calculation instruction, wherein the first PAC calculation instruction is used to instruct determination of a PAC corresponding to the first key data.

[0223] Optionally, the data volume of the first key data is less than or equal to the set data volume.

[0224] In each embodiment of the present application, the set data amount is the maximum amount of data that can be read at one time when the electronic device reads data and PAC at the same time. Exemplarily, the set value can be 8 bits.

[0225] Optionally, the electronic device may determine the first PAC according to the first key data, the secret key, and other setting information in accordance with a set calculation method. The electronic device may obtain the currently used secret key based on the aforementioned key management method.

[0226] S502: The electronic device stores first key data in a first storage location in response to a first write instruction, and stores a PAC corresponding to the first key data in a second storage location.

[0227] The first write instruction may be used to instruct the storage of the first key data and the PAC corresponding to the first key data.

[0228] In the embodiment of the present application, the PAC corresponding to any key data is used to verify the key data.

[0229] Optionally, the address of the second storage location may be adjacent to the address of the first storage location.

[0230] Alternatively, in the aforementioned example program, one ldp instruction can read 128 bits of content, and one stp instruction can read 128 bits of content, while the PAC data size is 64 bits. Therefore, when the size of the critical data is less than or equal to 64 bits, or 8 bytes, a single ldp instruction can simultaneously read the critical data and the PAC, and a single stp instruction can simultaneously store the critical data and the PAC.

[0231] Steps S501 to S502 are steps that need to be executed in the process of writing key data. The electronic device can execute the above steps S501 to S502 through the same process.

[0232] Optionally, after step S502, the following steps S503 to S507 may be further included. Alternatively, after step S502, after executing other set processing flows, the following steps S503 to S507 may be further included. Regarding other processing flows, there is no specific limitation in the embodiments of the present application.

[0233] S503: The electronic device reads the second key data stored in the first storage location and the PAC stored in the second storage location in response to the first read instruction.

[0234] The first read instruction may be used to instruct reading of the data stored in the first storage location and the PAC corresponding to the data, and the PAC stored in the second storage location is the PAC corresponding to the data.

[0235] Optionally, the second key data may also be referred to as the first data, and the first read instruction may also be referred to as the first instruction. The PAC stored in the second storage location may serve as the first verification information of the first data.

[0236] In some embodiments of the present application, the second key data may be the same as the first key data, or may be different from the second key data. The PAC stored in the second storage location may be the same as the PAC corresponding to the first key data, or may be different from the PAC corresponding to the first key data. Specifically, there may be the following four situations:

[0237] 1) When the first key data and the PAC corresponding to the first key data have not changed, the second key data is the same as the first key data, and the PAC stored in the second storage location is the same as the PAC corresponding to the first key data.

[0238] 2) When both the first key data and the PAC corresponding to the first key data change, the second key data is different from the first key data, and the PAC stored in the second storage location is different from the PAC corresponding to the first key data.

[0239] For example, in the case where steps S501 to S502 are executed by a first process in an electronic device, after step S502, a second process in the electronic device performs read and write operations on the first key data and the PAC corresponding to the first key data (for example, the second process modifies the first key data and the PAC corresponding to the first key data), the second key data is different from the first key data, and the PAC stored in the second storage location is different from the PAC corresponding to the first key data.

[0240] 3) When the first key data changes and the PAC corresponding to the first key data does not change, the second key data is different from the first key data, and the PAC stored in the second storage location is the same as the PAC corresponding to the first key data.

[0241] For example, in the case where steps S501 to S503 are all executed by the first process in the electronic device, after step S502 and before step S503, in a scenario where the attacker tampered with the first key data, the second key data is different from the first key data, and the PAC stored in the second storage location is the same as the PAC corresponding to the first key data.

[0242] 4) When the first key data does not change and the PAC corresponding to the first key data changes, the second key data is the same as the first key data, and the PAC stored in the second storage location is different from the PAC corresponding to the first key data.

[0243] The changes in the first key data and / or the changes in the PAC corresponding to the first key data in the above four situations may be known or unknown to the process of executing steps S501 to S503.

[0244] S504: The electronic device generates a PAC corresponding to the second key data according to the second key data.

[0245] Optionally, the electronic device may execute step S504 in response to a second PAC calculation instruction, wherein the second PAC calculation instruction is used to instruct determination of a PAC corresponding to the second key data.

[0246] Optionally, when the second key data is used as the first data, the PAC corresponding to the second key data can be used as the second verification information of the first data.

[0247] Optionally, the electronic device may determine the PAC corresponding to the second key data according to the second key data, the secret key, and other setting information in accordance with a set calculation method. The electronic device may obtain the secret key used based on the aforementioned key management method.

[0248] S505: The electronic device compares the PAC stored in the second storage location with the PAC corresponding to the second key data to see if they are the same; if so, execute step S506; otherwise, execute step S507.

[0249] Optionally, the electronic device may execute step S505 in response to a PAC comparison instruction, wherein the PAC comparison instruction may be used to instruct to compare whether the PAC stored in the second storage location is the same as the PAC corresponding to the second key data.

[0250] S506: The electronic device determines that the data security verification is successful.

[0251] Optionally, after determining that the security verification is successful, the electronic device may continue to execute subsequent processes. For example, the electronic device may respond to the data processing instruction and execute corresponding processing.

[0252] S507: The electronic device determines that the data security verification fails.

[0253] Optionally, after determining that the security check has failed, the electronic device may perform at least one of the following: interrupting the current process, executing a predetermined exception handling process, or displaying a first interface indicating an exception. Exemplarily, the first interface may be a black screen interface, a frozen interface, or the like, which is not specifically limited in the embodiments of this application.

[0254] Steps S503 to S507 are steps that need to be executed in the process of reading key data, and the electronic device can execute steps S503 to S507 through the same process.

[0255] Optionally, the electronic device may execute the above steps S501 to S502 and the above steps S503 to S507 through the same process, or may execute the above steps S501 to S502 and the above steps S503 to S507 successively through two different processes.

[0256] In some embodiments of the present application, the target program acquired by the electronic device may include the first to fifth instructions described in the above process. Optionally, the target program may also include the sixth instruction described in the above process. The electronic device may complete the execution of steps S501 to S507 during the execution of the target program.

[0257] Example 2

[0258] In a second possible solution, the electronic device can implement data protection based on a cyclic check mechanism. In this solution, the target program obtained by the electronic device is a target program obtained by adding anti-race logic based on the cyclic check mechanism during the compilation process based on the aforementioned program compilation method.

[0259] A cyclic verification mechanism involves repeatedly executing the verification process during the critical data reading phase until the verification succeeds or times out. The verification process includes: reading the stored critical data, reading the PAC used to verify the critical data; determining the PAC corresponding to the critical data based on the critical data; and comparing the PAC corresponding to the critical data with the read PAC to ensure consistency.

[0260] Through the circular verification mechanism, in multi-process scenarios, verification failures caused by different processes reading and writing critical data can be reduced or avoided, thereby achieving the effect of protecting critical data that allows multiple processes to read and write.

[0261] Reference Figure 6 The process of a data protection method based on a cyclic verification mechanism provided in an embodiment of the present application may include:

[0262] S601: The electronic device obtains first key data stored in a first storage location, and generates a PAC corresponding to the first key data according to the first key data.

[0263] Optionally, before step S601, the electronic device may store the first key data in the first storage location, and determine and store the PAC corresponding to the first key data. The PAC corresponding to the first key data may be stored in the second storage location. Optionally, the address of the second storage location may be adjacent to the address of the first storage location. Optionally, the electronic device may refer to the aforementioned Figure 1a 、 Figure 1b The method shown or the aforementioned Figure 5 The method shown implements the storage of the first key data and the PAC corresponding to the first key data, which will not be described in detail in this embodiment.

[0264] Optionally, the electronic device may determine the PAC corresponding to the first key data according to the first key data, the secret key, and other setting information in accordance with a set calculation method. The electronic device may obtain the secret key used based on the aforementioned key management method.

[0265] Optionally, the electronic device may obtain the first key data stored in the first storage location in response to the first instruction.

[0266] Optionally, the first key data may also be referred to as first data. The PAC corresponding to the first key data may serve as second verification information of the first data.

[0267] In one possible scenario, when the amount of the first key data is less than or equal to a set amount of data, the electronic device may, in response to a first read instruction, retrieve the first key data stored in the first storage location; and in response to a first PAC calculation instruction, determine the PAC corresponding to the first key data based on the first key data. The first read instruction may be used to instruct reading the data stored in the first storage location, and the first PAC calculation instruction may be used to instruct determining the PAC corresponding to the first key data based on the first key data.

[0268] In another possible case, when the amount of the first key data is greater than the set amount of data, refer to Figure 7 The specific implementation process of step S601 may include:

[0269] S1: The electronic device reads a key data from a first storage location.

[0270] The key data in step S1 includes part of the first key data, and the amount of the key data in step S1 is less than or equal to the set amount of data.

[0271] S2: The electronic device determines a PAC based on a key data read.

[0272] S3: The electronic device continues to read a key data from the first storage location.

[0273] The piece of data in step S3 includes part or all of the unread data in the first key data, and the data volume of the piece of data in step S3 is less than or equal to the set data volume.

[0274] S4: The electronic device re-determines a PAC based on the read key data and the last determined PAC.

[0275] S5: The electronic device determines whether the first key data has been read. If so, step S6 is executed; otherwise, step S3 is executed.

[0276] S6: Use the latest determined PAC as the PAC corresponding to the first key data.

[0277] S602: The electronic device obtains the PAC stored in the second storage location.

[0278] The PAC stored in the second location is a PAC that has been stored and is used to verify the first key data.

[0279] Optionally, the address of the second storage location may be adjacent to the address of the first storage location.

[0280] Optionally, the electronic device may execute step S602 in response to a second read instruction, wherein the second read instruction may be used to instruct to read a PAC corresponding to the first key data.

[0281] Optionally, the second read instruction may also be referred to as a second instruction. When the first key data is used as the first data, the PAC stored in the second storage location may be used as the first verification information of the first data.

[0282] S603: The electronic device compares the PAC corresponding to the first key data with the PAC stored in the second storage location to see if they are the same; if so, execute step S604; otherwise, execute step S605.

[0283] Optionally, the electronic device may execute step S603 in response to a PAC comparison instruction, wherein the PAC comparison instruction may be used to instruct to compare whether the PAC corresponding to the first key data is the same as the PAC stored in the second storage location.

[0284] S604: The electronic device determines that the data security verification is successful.

[0285] S605: The electronic device determines whether the set time has been reached; if so, execute step S606; otherwise, execute step S601.

[0286] In some embodiments of the present application, when executing step S601, the electronic device can start a timer or a timer (such as a watchdog timer, etc.) to perform timing, and then determine whether the set duration is reached based on the timing duration of the timer or the timer.

[0287] S606: The electronic device determines that the data security verification has failed.

[0288] Steps S601 to S606 are steps that need to be executed in the process of reading key data, and the electronic device can execute S601 to S606 through the same process.

[0289] In some embodiments of the present application, the target program acquired by the electronic device may include the first instruction and the second instruction described in the above process, or may include Figure 7 The target program may further include the third to seventh instructions described in the above process. The electronic device may complete the execution of the above steps S501 to S507 during the execution of the target program.

[0290] Example 3

[0291] In a third possible solution, the electronic device can implement data protection based on a data lock mechanism. In this solution, the target program obtained by the electronic device is a target program obtained by adding anti-race logic based on the data lock mechanism during the compilation process based on the aforementioned program compilation method.

[0292] The data lock mechanism temporarily locks the critical data when any process reads the critical data and PAC, and releases the lock on the critical data after the process reads the critical data and PAC.

[0293] In some embodiments of the present application, the electronic device can lock and unlock critical data and PAC by means of reference counting. Specifically, the electronic device can maintain a table for recording the locking status of critical data and PAC. The table may include information for indicating the critical data (such as the storage address of the critical data, etc.), information for indicating the PAC corresponding to the critical data (such as the storage address of the PAC corresponding to the critical data, etc., which is not specifically limited in the embodiments of the present application), and status information for indicating the locking status of the critical data and the corresponding PAC. The status information in the table is: first information for indicating that the critical data is not locked, or second information for indicating that the critical data is locked.

[0294] When any process in an electronic device reads critical data, it can determine the lock status of the critical data and the corresponding PAC based on a table. If it is determined that the critical data and the corresponding PAC are unlocked, the status information corresponding to the critical data and the corresponding PAC in the table can be set to locked, and the critical data and the corresponding PAC can be read. After reading the critical data and the corresponding PAC, the status information corresponding to the critical data and the corresponding PAC in the table can be set to unlocked. If it is determined that the critical data and the corresponding PAC are locked, the critical data and the corresponding PAC can be read after waiting for the lock status of the critical data and the corresponding PAC to become unlocked.

[0295] In an example, taking the first information as 0 and the second information as 1 as an example, the table maintained by the electronic device may refer to the following Table 1.

[0296] Table 1 Key data, PAC lock status table

[0297] Key Data PAC corresponding to key data Locked state D1 A1 0 D2 A2 0 D3 A3 0 … … …

[0298] For example, D1 to D3 shown in Table 1 may be storage addresses of key data 1 to 3, respectively, and A1 to A3 may be storage addresses of PACs corresponding to key data 1 to 3, respectively.

[0299] When process 1 needs to read key data 1, it can determine from Table 1 that key data 1 and the corresponding PAC are in an unlocked state. Process 1 can then switch the state of key data 1 and the corresponding PAC to a locked state before reading key data 1 and the corresponding PAC. When process 1 switches the state of key data 1 and the corresponding PAC to a locked state, Table 1 is updated to the following Table 2.

[0300] Table 2 Key data, PAC lock status table

[0301] Key Data PAC corresponding to key data Locked state D1 A1 1 D2 A2 0 D3 A3 0 … … …

[0302] As shown in Table 2, compared to Table 1, the lock status of key data 1 and the corresponding PAC has been switched to the locked state. At this time, processes other than process 1 do not read or write key data 1 and the corresponding PAC. After process 1 completes reading key data 1 and the corresponding PAC, the status of key data 1 and the corresponding PAC recorded in Table 2 can be switched to the unlocked state.

[0303] Based on the aforementioned data lock mechanism, while one process is reading critical data and the PAC, other processes are prevented from reading or writing critical data and the corresponding PAC. This ensures that only one process can read critical data and the corresponding PAC at a time. In multi-process scenarios, this prevents verification failures caused by different processes reading and writing critical data, thereby effectively protecting critical data that can be read and written by multiple processes.

[0304] Based on the above method, refer to Figure 8 The process of a data protection method based on a data lock mechanism provided in an embodiment of the present application may include:

[0305] S801: The electronic device locks the first key data stored in the first storage location and the PAC stored in the second storage location.

[0306] The PAC stored in the second storage location is a PAC that has been stored and is used to verify the first key data.

[0307] S802: The electronic device obtains first key data stored in a first storage location, and determines a PAC corresponding to the first key data based on the first key data.

[0308] Regarding step S802, it can be implemented with reference to the aforementioned step S601 and will not be described in detail here.

[0309] S803: The electronic device obtains the PAC stored in the second storage location.

[0310] Regarding step S803, it can be implemented with reference to the aforementioned step S602 and will not be described in detail here.

[0311] S804: The electronic device unlocks the first key data stored in the first storage location and the PAC stored in the second storage location.

[0312] S805: The electronic device compares whether the PAC corresponding to the first key data is the same as the PAC stored in the second storage location; if so, execute step S806; otherwise, execute step S807.

[0313] S806: The electronic device determines that the data security verification is successful.

[0314] S807: The electronic device determines that the data security verification has failed.

[0315] It should be noted that similarities or repetitions in the methods provided in the above embodiments can be used as references to each other, and this application does not elaborate on each embodiment in detail. The implementation processes provided in the above embodiments are merely examples of the method processes applicable to the embodiments of this application. The execution order of each step in each embodiment can be adjusted accordingly according to actual needs, and other steps can be added or some steps can be reduced.

[0316] Based on the above embodiments and the same technical concept, the embodiment of the present application further provides an electronic device, which is used to implement the processing method applied to the electronic device provided in the embodiment of the present application. Figure 9 As shown in FIG, electronic device 900 may include: a memory 901, one or more processors 902, and one or more computer programs (not shown). The above components may be coupled via one or more communication buses 903. Optionally, electronic device 900 may further include a display screen 904.

[0317] Among them, one or more computer programs (codes) are stored in the memory 901, and one or more computer programs include computer instructions; one or more processors 902 call the computer instructions stored in the memory 901, so that the electronic device 900 executes the processing method applied to the electronic device provided in the above-mentioned embodiment of the present application.

[0318] In a specific implementation, the memory 901 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more disk storage devices, flash memory devices, or other non-volatile solid-state storage devices. The memory 901 can store an operating system (hereinafter referred to as the system), such as an embedded operating system such as ANDROID, IOS, WINDOWS, or LINUX. The memory 901 can be used to store the implementation program of the embodiment of the present application. The memory 901 can also store a network communication program, which can be used to communicate with one or more additional devices, one or more user devices, and one or more network devices.

[0319] The one or more processors 902 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present application.

[0320] The display screen 904 is used to display application interfaces and other related user interfaces.

[0321] It should be noted that Figure 9 This is only one implementation of the electronic device 900 provided in the embodiment of the present application. In actual applications, the electronic device 900 may also include more or fewer components. Figure 2 The specific structure and description shown here are not limiting.

[0322] Based on the above embodiments and the same technical concept, an embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the computer program runs on a computer, the computer executes the method applied to an electronic device provided in the above embodiments.

[0323] Based on the above embodiments and the same technical concept, an embodiment of the present application also provides a computer program product, which includes a computer program or instructions. When the computer program or instructions are run on a computer, the computer executes the method applied to an electronic device provided in the above embodiments.

[0324] The methods provided in the embodiments of the present application may be implemented in whole or in part through software, hardware, firmware, or any combination thereof. When implemented using software, they may be implemented in whole or in part in the form of a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the embodiments of the present invention are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, a network device, a user device, or other programmable device. Computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. A computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media. Available media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., digital video discs (DVDs), or semiconductor media (e.g., SSDs), etc.

[0325] Obviously, those skilled in the art may make various changes and modifications to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include these modifications and variations.

Claims

1. A processing method, characterized in that: Applied to electronic equipment, the method includes: In response to a first instruction in the target program, obtaining first data stored in a first storage location and first verification information of the first data stored in a second storage location; generating second verification information of the first data according to the first data; If the second verification information is the same as the first verification information, it is determined that the first data verification has passed; if the second verification information is different from the first verification information, it is determined that the first data verification has failed.

2. The method according to claim 1, wherein The address of the first storage location and the address of the second storage location are adjacent.

3. The method according to claim 1, wherein Generating second verification information of the first data according to the first data includes: Obtaining a secret key stored in a first register; wherein, when the electronic device is in kernel state, the secret key stored in the first register is a first secret key, and the first secret key is the secret key used by the electronic device when in kernel state; when the electronic device is in user state, the secret key stored in the first register is a second secret key, and the second secret key is the secret key used by the electronic device when in user state; The second verification information is generated according to the first data and the secret key stored in the first register.

4. The method according to claim 3, wherein The method further comprises: When switching from the user state to the kernel state, setting the key stored in the first register as the first key; or When switching from the kernel state to the user state, setting the key stored in the first register to the second key; or When the CPU in the electronic device wakes up from a sleep state, the first key is written into the first register.

5. The method according to claim 4, wherein The first register is a register in the CPU; before writing the first secret key into the first register, the method further includes: The first secret key is obtained from a first storage area; wherein the first storage area is a storage area corresponding to a memory outside the CPU.

6. The method according to any one of claims 1 to 5, wherein: The method further comprises: In response to a second instruction in the target program, second data is stored in a third storage location, and third verification information of the second data is stored in a fourth storage location.

7. The method according to claim 6, wherein The address of the third storage location is adjacent to the address of the fourth storage location.

8. The method according to claim 6 or 7, wherein: Before obtaining, in response to the first instruction in the target program, the first data stored in the first storage location and the first verification information of the first data stored in the second storage location, the method further includes: Obtaining a source program; wherein the source program includes a third instruction, and the third instruction is used to instruct to obtain the first data; The source program is compiled to obtain a target program; wherein the target program includes the first instruction, the first instruction is generated according to the third instruction, and the first instruction is used to instruct: to obtain the first data and the first verification information of the first data.

9. The method according to claim 8, wherein The target program further includes a fourth instruction and a fifth instruction; The fourth instruction is used to instruct generation of the second verification information of the first data, and the fifth instruction is used to instruct comparison of whether the first verification information and the second verification information are the same.

10. The method according to claim 8 or 9, characterized in that The source program further includes a sixth instruction, wherein the sixth instruction is used to instruct to store the second data; The target program further includes a seventh instruction, which is generated according to the sixth instruction and is used to instruct storage of the second data and the third verification information of the second data.

11. The method according to any one of claims 8 to 10, wherein: Before compiling the source program to obtain the target program, the method further includes: Obtaining a first configuration file; wherein the first configuration file includes first information, and the first information is used to indicate a variable name of the first data; The third instruction in the source code is obtained, where the third instruction includes an operand indicated by the variable name.

12. A processing method, characterized in that: The method comprises: Obtaining a source program; wherein the source program includes a first instruction, and the first instruction is used to instruct to obtain first data; Compiling the source program to obtain a target program; in, The target program includes a second instruction, the second instruction is generated according to the first instruction, and the second instruction is used to instruct: obtaining the first data and first verification information of the first data; or The target program includes: multiple instructions that are executed in sequence, and a third instruction; wherein the multiple instructions and the third instruction are generated based on the first instruction; the multiple instructions include: an instruction for instructing to obtain the first data, an instruction for instructing to obtain first verification information of the first data, an instruction for instructing to generate second verification information of the first data, and an instruction for instructing to compare whether the second verification information and the first verification information are the same; the third instruction is used to instruct to re-execute the multiple instructions when it is determined that the second verification information and the first verification information are different and the set time length has not been reached.

13. The method according to claim 12, wherein: When the target program includes the second instruction, the target program also includes a fourth instruction and a fifth instruction; The fourth instruction is used to instruct generation of second verification information of the first data, and the fifth instruction is used to instruct comparison of whether the first verification information and the second verification information are the same.

14. The method according to claim 12 or 13, wherein: The source program further includes a sixth instruction, wherein the sixth instruction is used to instruct to store the second data; The target program further includes a seventh instruction, which is generated according to the sixth instruction and is used to instruct storage of the second data and third verification information of the second data.

15. The method according to any one of claims 12 to 14, wherein: Before compiling the source program to obtain the target program, the method further includes: Obtaining a first configuration file; wherein the first configuration file includes first information, and the first information is used to indicate a variable name of the first data; The first instruction in the source code is obtained, where the first instruction includes an operand indicated by the variable name.

16. A processing method, characterized in that: Applied to electronic equipment, the method includes: Repeat the verification process until the termination condition is met; The verification process includes: obtaining first data in response to a first instruction in the target program; obtaining first verification information of the first data in response to a second instruction in the target program; generating second verification information of the first data based on the first data; if the second verification information is the same as the first verification information, determining that the first data has passed verification; if the second verification information is different from the first verification information, ending the verification process; The termination condition includes: the second verification information is the same as the first verification information, or a set time period is reached.

17. The method according to claim 16, wherein When the termination condition includes reaching a set time, after repeatedly executing the verification process until the termination condition is met and stopping, the method further includes: It is determined that the first data verification fails.

18. The method according to claim 16 or 17, wherein: Generating second verification information of the first data according to the first data includes: Obtaining a secret key stored in a first register; wherein, when the electronic device is in kernel state, the secret key stored in the first register is a first secret key, and the first secret key is the secret key used by the electronic device when in kernel state; when the electronic device is in user state, the secret key stored in the first register is a second secret key, and the second secret key is the secret key used by the electronic device when in user state; The second verification information is generated according to the first data and the secret key stored in the first register.

19. The method according to claim 18, wherein The method further comprises: When switching from the user state to the kernel state, setting the key stored in the first register as the first key; or When switching from the kernel state to the user state, setting the key stored in the first register to the second key; or When the CPU in the electronic device wakes up from a sleep state, the first key is written into the first register.

20. The method according to claim 19, wherein The first register is a register in the CPU; before writing the first secret key into the first register, the method further includes: The first secret key is obtained from a first storage area; wherein the first storage area is a storage area corresponding to a memory outside the CPU.

21. The method according to any one of claims 16 to 20, wherein: Before repeatedly executing the verification process until a termination condition is met, the method further includes: Obtaining a source program; wherein the source program includes a third instruction, and the third instruction is used to instruct to obtain the first data; The source program is compiled to obtain a target program; wherein the target program includes: multiple instructions to be executed in sequence, and a fourth instruction; wherein the multiple instructions and the fourth instruction are generated based on the third instruction; the multiple instructions include: the first instruction for instructing to obtain the first data, the second instruction for instructing to obtain the first verification information of the first data, the instruction for instructing to generate the second verification information of the first data, and the instruction for instructing to compare whether the second verification information and the first verification information are the same; the fourth instruction is used to instruct to re-execute the multiple instructions when it is determined that the second verification information and the first verification information are different and the set time length has not been reached.

22. The method according to claim 21, wherein Before compiling the source program to obtain the target program, the method further includes: Obtaining a first configuration file; wherein the first configuration file includes first information, and the first information is used to indicate a variable name of the first data; The third instruction in the source code is obtained, where the third instruction includes an operand indicated by the variable name.

23. An electronic device, characterized in that: The electronic device includes a memory and one or more processors; The memory is used to store computer program code, which includes computer instructions; when the computer instructions are executed by the one or more processors, the electronic device executes the method according to any one of claims 1 to 11, or executes the method according to any one of claims 12 to 15, or executes the method according to any one of claims 16 to 22.

24. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program. When the computer program is run on an electronic device, the electronic device executes the method according to any one of claims 1 to 11, or the method according to any one of claims 12 to 15, or the method according to any one of claims 16 to 22.

25. A computer program product, characterized in that The computer program product includes a computer program or instructions. When the computer program or instructions are run on an electronic device, the electronic device executes the method according to any one of claims 1 to 11, or the method according to any one of claims 12 to 15, or the method according to any one of claims 16 to 22.