Software-based write protection apparatus and method
By using software-level write protection devices and methods to obtain write protection area information and intercept write operation commands, the write protection problem of NAND flash memory is solved, achieving effective write protection functionality, saving storage space and reducing code compilation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-29
- Publication Date
- 2026-03-27
AI Technical Summary
Existing technologies struggle to implement effective write protection in NAND flash memory because conventional hardware write protection methods are not compatible with NAND flash memory, making critical areas of the operating system vulnerable to tampering and causing system crashes.
A software-based write protection device and method are provided. By acquiring write protection area information, determining whether the write address matches the protection range, and intercepting the write operation command when a match is found, write protection is achieved at the software level.
It implements write protection for NAND flash memory, preventing tampering with critical areas, saving storage space, reducing code compilation, and has good adaptability, making it suitable for flash memory without hardware support from a controller.
Smart Images

Figure CN115408312B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of storage technology, and in particular to a software-based write protection device and method. Background Technology
[0002] With the development of technology, embedded devices have become increasingly common. This has brought with it security issues, among which the most significant threat is the potential for tampering with critical areas of the operating system. This can lead to system crashes, rendering the embedded device unusable. To address this, write protection is typically implemented in advance for these critical areas, preventing data and parameters from being altered through write operations.
[0003] Currently, conventional write protection methods are generally hardware write protection, which relies on the flash memory hardware supporting the operating system to circumvent write operations, thus achieving write protection functionality. The most common example is eMMC flash memory. eMMC flash memory (embedded Multi Media Card) is essentially a combination of flash memory and a controller. eMMC flash memory uses a unified MMC standard interface, encapsulating high-density storage cells and the controller on a single chip. This means that based on the controller hardware structure of eMMC flash memory, it can support hardware write protection to control write operations. However, in practical applications, for ordinary NAND flash memory, because its hardware structure does not involve controllers, conventional write protection methods are difficult to implement to control write operations due to different hardware settings. In other words, conventional hardware write protection methods are incompatible with NAND flash memory. Therefore, how to implement a compatible write protection function for storage devices like NAND flash memory that do not support hardware write protection has become a pressing problem in the field. Summary of the Invention
[0004] This application provides a software-based write protection device and method, the main purpose of which is to implement a write protection function adapted to NAND flash memory and meet the user's control requirements for the writing behavior of NAND flash memory.
[0005] To address the aforementioned technical problems, this application provides the following technical solutions:
[0006] In a first aspect, this application provides a software-based write protection device, the device comprising:
[0007] The acquisition unit is used to acquire write protection area information from a preset storage area, wherein the write protection area information includes a protection range for performing control operations on write operations, and the protection range includes at least one address information that needs to be protected.
[0008] The determining unit is used to determine write address information from the write operation instruction when a write operation instruction is received;
[0009] The judgment unit is used to determine whether the write address information matches the address information in the write protection area information;
[0010] An execution unit is configured to intercept the write operation instruction if the write address information matches the address information in the write protection area information.
[0011] Optionally, the write address information includes at least one write address, and the write protection area information includes one or more partition information, wherein the partition information is used to characterize whether the corresponding partition allows the write operation to be performed when a write operation is detected;
[0012] The judgment unit includes:
[0013] The first determining module is configured to determine, based on the partition information, a partition among multiple partitions in the operating system area that is not allowed to perform the write operation, as a write-protected partition, wherein the write-protected partition includes at least one protection address;
[0014] The judgment module is used to determine whether the write address matches the protection address;
[0015] The execution unit is specifically configured to intercept the write operation instruction if the write address matches the protection address.
[0016] Optionally, the partition information includes a starting address, length information, and partition attributes; the length information is used to characterize the address length starting from the starting address; the partition attributes are used to characterize whether the partition corresponding to the partition attributes allows the write operation to be performed;
[0017] The first determining module is specifically used to determine the partition range of each partition based on the starting address information and the length information, and to determine the partition range whose partition attributes are not allowed to perform the write operation from multiple partition ranges based on the partition attributes, and to use it as the write-protected partition;
[0018] The judgment module is specifically used to determine whether the write address is located within the partition range of the write-protected partition;
[0019] The execution unit is further configured to intercept the write operation instruction if the write address is located within the partition range of the write-protected partition.
[0020] Optionally, the determination unit further includes:
[0021] The second determining module is used to determine the non-protected partition corresponding to the write address if the write address is not located within the partition range of the write-protected partition.
[0022] The first execution module is used to perform the write operation on the unprotected partition.
[0023] Optionally, the partition attributes may further include stage information, which is used to characterize the operating system stage that allows the write operation to be performed;
[0024] The judgment unit further includes:
[0025] The acquisition module is used to acquire the stage information of the unprotected partition and determine whether the execution time of the write operation is consistent with the stage information of the unprotected partition.
[0026] The second execution module is used to intercept the write operation instruction if the execution time of the write operation is inconsistent with the stage information of the unprotected partition.
[0027] Optionally, the preset storage area is a region built on NAND flash memory for storing the operating system, and the preset storage area is equipped with hardware devices for controlling the write operation; the preset storage area includes an RPMB region.
[0028] Secondly, this application also provides a software-based write protection method, the method comprising:
[0029] Retrieve write protection area information from a preset storage area, wherein the write protection area information includes a protection range for performing control operations on write operations, and the protection range includes at least one address information that needs to be protected;
[0030] When a write operation instruction is received, the write address information is determined from the write operation instruction;
[0031] Determine whether the write address information matches the address information in the write protection area information;
[0032] If a match is found, the write operation instruction is intercepted.
[0033] Optionally, the write address information includes at least one write address, and the write protection area information includes one or more partition information, wherein the partition information is used to characterize whether the corresponding partition allows the write operation to be performed when a write operation is detected;
[0034] The step of determining whether the write address information matches the address information in the write protection area information includes:
[0035] Based on the partition information, a partition that is not allowed to perform the write operation is determined from multiple partitions in the operating system area and designated as a write-protected partition, wherein the write-protected partition includes at least one protected address;
[0036] Determine whether the write address matches the protection address;
[0037] If the write address information matches the address information in the write-protected area information, then the write operation instruction is intercepted, including:
[0038] If the write address matches the protection address, the write operation instruction is intercepted.
[0039] Optionally, the partition information includes a starting address, length information, and partition attributes; the length information is used to characterize the address length starting from the starting address; the partition attributes are used to characterize whether the partition corresponding to the partition attributes allows the write operation to be performed;
[0040] The step of determining, based on the partition information, from among multiple partitions in the operating system area, the partition that is not allowed to perform the write operation, as a write-protected partition, includes:
[0041] The partition range of each partition is determined based on the starting address information and the length information, and the partition range whose partition attributes are not allowed to perform the write operation is determined from multiple partition ranges based on the partition attributes, and is used as the write-protected partition;
[0042] The step of determining whether the write address matches the protection address includes:
[0043] Determine whether the write address is within the partition range of the write-protected partition;
[0044] If the write address matches the protection address, then the write operation instruction is intercepted, including:
[0045] If the write address is within the partition range of the write-protected partition, then the write operation instruction is intercepted.
[0046] Optionally, after determining whether the write address is within the partition range of the write-protected partition, the method further includes:
[0047] If the write address is not located within the partition range of the write-protected partition, then the non-protected partition corresponding to the write address is determined.
[0048] Perform the write operation on the unprotected partition.
[0049] Optionally, the partition attributes may further include stage information, which is used to characterize the operating system stage that allows the write operation to be performed;
[0050] Before performing the write operation on the unprotected partition, the method further includes:
[0051] Obtain the stage information of the unprotected partition and determine whether the execution time of the write operation is consistent with the stage information of the unprotected partition;
[0052] If there is a discrepancy, the write operation command will be intercepted.
[0053] Optionally, the preset storage area is a region built on NAND flash memory for storing the operating system, and the preset storage area is equipped with hardware devices for controlling the write operation; the preset storage area includes an RPMB region.
[0054] Thirdly, this application also provides a storage medium including a stored program, wherein, when the program is executed, it controls the device where the storage medium is located to perform the software-based write protection method described in the second aspect.
[0055] Fourthly, this application also provides a software-based write protection device, the device including a storage medium; and one or more processors, the storage medium being coupled to the processors, the processors being configured to execute program instructions stored in the storage medium; the program instructions, when executed, perform the software-based write protection method described in any one of the second aspects.
[0056] By employing the above-described technical solution, the technical solution provided in this application has at least the following advantages:
[0057] This application provides a software-based write protection device and method. The device first acquires write protection region information from a preset storage area using an acquisition unit. This write protection region information includes a protection range for controlling write operations, and the protection range includes at least one address information to be protected. Then, when a write operation command is received, a determination unit determines the write address information from the write operation command. Next, a judgment unit determines whether the write address information matches the address information in the write protection region information. Finally, if the write address information matches the address information in the write protection region information, an execution unit intercepts the write operation command, thereby achieving software-based write protection and satisfying the user's control over NAND flash memory write behavior. Compared to existing technologies, the software-based write protection method of this application, during execution, utilizes the write protection region information acquired by the acquisition unit, which includes the protection range for control operations on write operations. This means it determines which areas of the NAND flash memory cannot be written to. Therefore, after the judgment unit determines that the write address information in the write operation instruction matches the address information in the write protection region information, it can be determined that the write operation instruction actually needs to be performed within the protected range. At this point, the execution unit intercepts the write operation instruction, preventing the write operation from being performed on data within the protected range. This achieves the function of protecting the areas of the NAND flash memory that require write protection. Furthermore, since the above process is implemented at the software level without hardware support, it has good adaptability for flash memory such as NAND flash memory that lacks hardware support such as a controller. In addition, existing hardware write protection schemes require address alignment operations within the flash memory during execution. After the alignment operation, the storage space for the unaligned addresses is not allocated for data storage, resulting in wasted storage space. The solution of this application does not require address alignment operations, thus saving storage space in the flash memory. Furthermore, in this application, for areas that do not require protection, the write protection area information can be directly used for setting. In other words, when it is necessary to reset whether a certain area needs to be write protected, the setting can be done directly based on the write protection area information. This avoids the need to set additional unlocking code during the hardware write protection process in the prior art, which is based on hardware. This reduces the amount of code that engineers need to compile, especially when there are multiple flash memory devices with different hardware forms. It is not necessary to compile different types of write protection unlocking code, which can greatly reduce the amount of code that engineers need to compile.
[0058] The above description is only an overview of the technical solution of this application. In order to better understand the technical means of this application and to implement it in accordance with the contents of the specification, and to make the above and other objects, features and advantages of this application more obvious and understandable, the following are specific embodiments of this application. Attached Figure Description
[0059] The above and other objects, features, and advantages of exemplary embodiments of this application will become readily understood by reading the following detailed description with reference to the accompanying drawings. In the drawings, several embodiments of this application are illustrated by way of example and not limitation, with the same or corresponding reference numerals denoteing the same or corresponding parts, wherein:
[0060] Figure 1 This illustration shows a block diagram of a software-based write protection device provided in an embodiment of this application;
[0061] Figure 2 This illustration shows a block diagram of another software-based write protection device provided in an embodiment of this application;
[0062] Figure 3 A flowchart of a software-based write protection method provided in an embodiment of this application is shown. Detailed Implementation
[0063] Exemplary embodiments of this application will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of this application are shown in the drawings, it should be understood that this application may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of this application and to fully convey the scope of this application to those skilled in the art.
[0064] It should be noted that, unless otherwise stated, the technical or scientific terms used in this application shall have the ordinary meaning as understood by one of ordinary skill in the art to which this application pertains.
[0065] This application provides a block diagram of a software-based write protection device, such as... Figure 1 As shown, the device includes:
[0066] The acquisition unit 11 can be used to acquire write protection area information from a preset storage area, wherein the write protection area information includes a protection range for performing control operations on write operations, and the protection range includes at least one address information that needs to be protected.
[0067] The determining unit 12 can be used to determine the write address information from the write operation instruction when a write operation instruction is received;
[0068] The judgment unit 13 can be used to determine whether the write address information matches the address information in the write protection area information;
[0069] The execution unit 14 can be used to intercept the write operation instruction if the write address information matches the address information in the write protection area information.
[0070] NAND flash memory is a more convenient and efficient storage device than conventional hard disk drives (HDDs), especially in low-capacity applications of up to 4GB. As the demand for products with lower power consumption, lighter weight, and better performance continues to grow, NAND flash memory has significant development potential compared to conventional storage devices. Because NAND flash memory is a non-volatile storage technology, meaning it retains data even after power is lost, its development goal is to reduce the cost per bit and increase storage capacity. Since NAND flash memory only contains storage cells, unlike eMMC flash memory which has a controller, conventional hardware write protection cannot be implemented with it.
[0071] In view of this, in this embodiment, the write protection method can be executed based on the device of this embodiment. The software-based write protection device can be set on the driver layer in the operating system framework. That is, after a normal write operation is issued, the driver layer in the normal system framework will execute the corresponding write behavior based on the write operation. However, in this embodiment, when a write operation is issued, the driver layer in the system framework will not respond directly, but the device of this embodiment will execute the above method according to the above unit.
[0072] Therefore, in this embodiment, to implement the write protection function, it is first necessary to determine which parts of the operating system's region require write protection and which parts do not. Thus, the acquisition unit 11 can first obtain write protection region information from a preset storage region. Since the write protection region information reflects which parts of the operating system need to control the write operation during execution, i.e., the protection range, and this protection range includes at least one address, the write protection region information obtained by the acquisition unit 11 actually indicates which addresses(s) in the operating system's region are not allowed to perform write operations.
[0073] At the same time, the address where the write operation actually needs to be performed can be determined from the write operation instruction based on the determining unit 12, that is, the write address information. The write address information can be a specific address or multiple addresses, depending on the write operation instruction, that is, it is determined based on the user's specific operation.
[0074] Once the write address information and the address information corresponding to the protection range are determined, the judgment unit 13 can be used to judge whether the two match. That is, it determines whether the address targeted by the write operation is the address corresponding to the write protection operation. When the two match, it means that the current write operation is to tamper with the protected address; otherwise, it means that the address that is not protected is being modified.
[0075] As described above, when the write address information matches the address information in the write protection area information, it can be understood that the write operation is intended to modify important parts of the operating system, i.e., data within the protection range. Such behavior should be prohibited. Therefore, the write operation instruction can be intercepted by the execution unit 14 to avoid modifying the critical areas or important parts of the operating system based on the write operation instruction, thereby realizing the software-based write protection function.
[0076] Based on this, this embodiment provides a software-based write protection device. Compared with the prior art, when the software-based write protection method of this application is executed, since the write protection area information acquired by the acquisition unit includes the protection range for control operations on write operations, that is, it determines which areas in the NAND flash memory cannot be written to, after the judgment unit determines that the write address information in the write operation instruction matches the address information in the write protection area information, it can be determined that the write operation instruction actually needs to be performed within the protected range. At this time, the execution unit intercepts the write operation instruction, thus avoiding the situation where the write operation is performed on the data within the protected range, realizing the function of protecting the areas in the NAND flash memory that need to be written to. At the same time, since the above process is implemented at the software level and does not require hardware support, it has good adaptability for flash memory such as NAND flash memory that does not have hardware support such as a controller. Furthermore, existing hardware write protection schemes require address alignment operations within the flash memory during execution. After alignment, the storage space for unaligned addresses is not allocated for data storage, resulting in wasted storage space. The solution described in this application eliminates the need for address alignment, thus saving flash memory storage space. Additionally, in this application, areas that do not require protection can be directly set based on write protection area information. This means that when resetting write protection for a specific area, the setting can be done directly based on that write protection area information, avoiding the need for additional write protection code setup required in existing hardware write protection schemes. This reduces the amount of code compiled by engineers, especially when multiple flash memory types with different hardware configurations exist, as different types of write protection write protection code do not need to be compiled, significantly reducing the amount of code that engineers need to compile.
[0077] In some embodiments, such as Figure 2 As shown, the write address information includes at least one write address, and the write protection area information includes one or more partition information, wherein the partition information is used to characterize whether the corresponding partition is allowed to perform the write operation when a write operation is detected.
[0078] The judgment unit 13 includes:
[0079] The first determining module 131 can be used to determine, based on the partition information, a partition among multiple partitions in the operating system area that is not allowed to perform the write operation, as a write-protected partition, wherein the write-protected partition includes at least one protection address;
[0080] The judgment module 132 can be used to determine whether the write address matches the protection address;
[0081] Specifically, the execution unit 14 can be used to intercept the write operation instruction if the write address matches the protection address.
[0082] In practical applications, some parts of the operating system's area allow write operations, while others do not. Therefore, in this embodiment, the write-protected area information can be further refined into partition information. This partition information indicates whether the target partition allows write operations when a write operation is detected. Thus, each partition in this embodiment corresponds to a different part of the aforementioned operating system. When the judgment unit 13 determines whether the write address information matches the address information in the write-protected area information, the specific execution process can first, based on the first determining module 131, determine which partition(s) in the operating system are not allowed to perform write operations, i.e., partitions requiring write protection, denoted as write-protected partitions. The address contained in these write-protected partitions is the protection address that requires write protection. Then, the judgment module 132 determines whether the write address and the protection address are consistent.
[0083] Based on this, during the specific execution of the execution unit 14, when it is determined that the write address and the protection address are consistent, it is necessary to indicate that the write operation needs to operate on the address for which write protection is performed, which is not allowed. Therefore, the execution unit 14 can intercept the write operation instruction in this case.
[0084] By using partition information to determine whether write operations are allowed on the target partition, it is ensured that during write protection, the user can freely select the protected address from multiple addresses in the operating system by setting the partition information according to their needs. This ensures flexible control over whether write protection needs to be performed on each address in the operating system region.
[0085] In some embodiments, such as Figure 2 As shown, the partition information includes a starting address, length information, and partition attributes; the length information is used to characterize the address length starting from the starting address; the partition attributes are used to characterize whether the partition corresponding to the partition attributes allows the write operation to be performed;
[0086] The first determining module 131 can be specifically used to determine the partition range of each partition based on the starting address information and the length information, and to determine the partition range whose partition attributes are not allowed to perform the write operation from multiple partition ranges based on the partition attributes, and to use it as the write-protected partition;
[0087] The judgment module 132 can be specifically used to determine whether the write address is located within the partition range of the write-protected partition;
[0088] The execution unit 14 can also be specifically used to intercept the write operation instruction if the write address is located within the partition range of the write-protected partition.
[0089] In practical applications, partitions can be set up as described in this embodiment. By determining the starting address and length information of each partition, it is possible to determine the specific address at which the partition ends. Simultaneously, based on partition attributes, it is possible to set whether write operations are allowed on the target partition. In other words, it is possible to determine which partition(s) require write protection based on partition attributes. Therefore, in this embodiment, the first determining module 131 can determine the specific range of each partition, i.e., the partition range, based on the starting address and length information. Then, based on the partition attributes, it is determined which of these partitions require write protection, i.e., the write-protected partitions. Since each partition corresponds to its partition range, and this partition range can be understood as a continuous set of ranges containing the starting and ending addresses, the determining module 132 can determine whether the write address is within the partition range of the write-protected partition. When the write address is within the partition range of the write-protected partition, it indicates that the write operation corresponds to a region requiring write protection, and therefore the write operation needs to be prohibited. Thus, the execution unit 14 can intercept the write operation instruction when it determines that the write address is within the partition range of the write-protected partition.
[0090] By setting partition information using the starting address, length information, and partition attributes, it is possible to ensure that the "attributes" of each partition range are determined in a way that corresponds to a partition range. This means that it is determined whether write protection is allowed for each range of consecutive addresses. Thus, when the judgment module 132 makes a judgment, it can directly determine whether the write address information is within the partition range of the write-protected partition, thereby improving the accuracy of the judgment process.
[0091] In some embodiments, such as Figure 2 As shown, the judgment unit 13 further includes:
[0092] The second determining module 133 can be used to determine the non-protected partition corresponding to the write address if the write address is not located within the partition range of the write-protected partition.
[0093] The first execution module 134 can be used to perform the write operation on the unprotected partition.
[0094] As described in the foregoing embodiments, when the determining module 132 determines whether the write address is within the partition range of the write-protected partition, there may be a situation where the write address is not within the partition range of the write-protected partition. This indicates that the write operation targets an address outside the write-protected partition, and such a write operation is actually allowed. Therefore, in this embodiment, when it is determined that the write address is not within the partition range of the write-protected partition, the second determining module 133 can determine the non-protected partition corresponding to the write address. This non-protected partition can be understood as a partition outside the write-protected partition described in the foregoing embodiments, whose attribute allows write operations. Then, the first execution module 134 performs the write operation on the non-protected partition.
[0095] Therefore, when it is determined that the write address is not within the write-protected partition range, the non-protected partition corresponding to the write address can be determined based on the second determining module 133. In this way, the write operation can be performed on the non-protected partition according to the first execution module 134, thus realizing the smooth execution of the write operation when the write operation is aimed at a partition that does not need to be written protected.
[0096] In some embodiments, such as Figure 2 As shown, the partition attributes also include stage information, which is used to characterize the operating system stage that allows the write operation to be performed;
[0097] The judgment unit 13 further includes:
[0098] The acquisition module 135 can be used to acquire the stage information of the unprotected partition and determine whether the execution time of the write operation is consistent with the stage information of the unprotected partition.
[0099] The second execution module 136 can be used to intercept the write operation instruction if the execution time of the write operation is inconsistent with the stage information of the unprotected partition.
[0100] In practical applications, because the operating system operates in different phases, and each phase has different drivers, services, and functions, the behaviors allowed to be performed by users also differ in each phase. For write operations, since they modify certain important information and data, it is necessary to analyze the situation based on the phase to avoid the possibility of system tampering caused by write operations occurring in phases where they are not permitted.
[0101] In view of this, in this embodiment, during the process of determining whether the write address information matches the address information in the protected area information, the determining unit 13 can further utilize the acquisition module 135 to acquire the stage information of each non-protected partition, and then determine whether the execution time of the write operation is consistent with the stage information. This allows for further determination of whether the stage at which the partition is allowed to perform the write operation and the specific execution time of the write operation match when it is determined that the write operation corresponds to a non-protected partition that allows write operations. When the execution time of the write operation is inconsistent with the stage information of the non-protected partition, the execution of the write operation can be intercepted by the second execution module 136.
[0102] For example, if a write operation is performed when the operating system is in stage B, and the stage information of the non-protected partition corresponding to the write operation is stage A, then even if the address corresponding to the write operation is not an address in the write-protected partition, it will still fail to modify because the execution time does not meet the allowed modification stage.
[0103] For example, when the address corresponding to the write operation is region A, and the method of this embodiment determines that the data in region A can only be modified during the system's boot loading phase, that is, the execution of the write operation is allowed during the uboot phase, and the execution time of the current write operation is determined to be the system's real-time operation phase, that is, the kernel phase. Since the two phases are not consistent, it can be understood that the execution time of the current write operation does not conform to the phase in which the write operation is allowed in region A. The write operation is very likely to be a tampering behavior, so the write operation should be intercepted.
[0104] In this way, by further restricting write operations based on stage information, write protection for unprotected partitions is indirectly achieved, while also avoiding the problem of data and information in the operating system being tampered with when write operations should not be performed.
[0105] In some embodiments, such as Figure 2 As shown, the preset storage area is a region built on NAND flash memory for storing the operating system, and the preset storage area is equipped with hardware devices for controlling the write operation; the preset storage area includes the RPMB area.
[0106] In this embodiment, since the methods described in the preceding embodiments are all based on write-protected area information, the security of the write-protected area information directly affects the overall implementation effect of software-based write protection. To ensure the security of this write-protected area information, in this embodiment, the preset storage area can be set in a storage device that can restrict write operations at the hardware level. In specific applications, this preset storage area can be an RPMB (Replay Protected Memory Block), which is a partition with security features in the storage device. When there is a write operation to the RPMB area, the RPMB area will verify the legality of the operation. Only the designated host, i.e., the administrator, can perform the write operation. At the same time, a signature mechanism is also provided when reading data to ensure that the data read by the host is the real data in the RPMB area, and not data forged by the attacker. In practical applications, RPMB is usually used to store data that needs to be protected from illegal tampering, such as public keys and serial numbers related to fingerprint payment on mobile phones. RPMB can authenticate write operations, but reading does not require authentication. Anyone can perform read operations. Therefore, data stored in RPMB is usually encrypted before storage.
[0107] In this way, by specifically applying the preset storage area to the RPMB area, the security of the write protection area information can be ensured, and the tampering of the write protection area information can be avoided, thus affecting the accuracy of write protection and laying the foundation for the accurate execution of subsequent write protection.
[0108] Furthermore, as a response to the above Figure 1 and Figure 2 In addition to the implementation of the illustrated device, another embodiment of this application also provides a software-based write protection method. This method embodiment corresponds to the foregoing method embodiments. For ease of reading, this device embodiment will not repeat the details of the foregoing method embodiments, but it should be understood that the method in this embodiment can implement all the contents of the foregoing device embodiments. This method aims to achieve a write protection function adapted to NAND flash memory, meeting the user's control requirements for NAND flash memory write behavior, specifically as follows... Figure 3 As shown, the device includes:
[0109] 301. Obtain write-protected area information from the preset storage area.
[0110] The write protection area information includes a protection range for performing control operations on write operations, and the protection range includes at least one address information that needs to be protected.
[0111] 302. When a write operation instruction is received, the write address information is determined from the write operation instruction.
[0112] 303. Determine whether the address information written matches the address information in the write-protected area information.
[0113] 304. If the write address information matches the address information in the write protection area information, then the write operation command is intercepted.
[0114] In the above steps, the write address information includes at least one write address, and the write protection area information includes one or more partition information, wherein the partition information is used to characterize whether the corresponding partition allows the write operation to be performed when a write operation is detected.
[0115] Step 303 above, determining whether the write address information matches the address information in the write-protected region information, includes:
[0116] Based on the partition information, a partition that is not allowed to perform the write operation is determined from multiple partitions in the operating system area and designated as a write-protected partition, wherein the write-protected partition includes at least one protected address;
[0117] Determine whether the write address matches the protection address;
[0118] If, in step 304 above, the write address information matches the address information in the write-protected area information, then the write operation instruction is intercepted, including:
[0119] If the write address matches the protection address, the write operation instruction is intercepted.
[0120] In the above steps, the partition information includes a starting address, length information, and partition attributes; the length information is used to characterize the address length starting from the starting address; the partition attributes are used to characterize whether the partition corresponding to the partition attributes allows the write operation to be performed;
[0121] The aforementioned steps, based on the partition information, determine, from among multiple partitions in the operating system area, the partitions where the write operation is not permitted, as write-protected partitions, including:
[0122] The partition range of each partition is determined based on the starting address information and the length information, and the partition range whose partition attributes are not allowed to perform the write operation is determined from multiple partition ranges based on the partition attributes, and is used as the write-protected partition;
[0123] The aforementioned step of determining whether the write address matches the protection address includes:
[0124] Determine whether the write address is within the partition range of the write-protected partition;
[0125] If the write address matches the protection address in the aforementioned steps, the write operation instruction is intercepted, including:
[0126] If the write address is within the partition range of the write-protected partition, then the write operation instruction is intercepted.
[0127] In the above steps, after determining whether the write address is within the partition range of the write-protected partition, the method further includes:
[0128] If the write address is not located within the partition range of the write-protected partition, then the non-protected partition corresponding to the write address is determined.
[0129] Perform the write operation on the unprotected partition.
[0130] In the above steps, the partition attributes also include stage information, which is used to characterize the operating system stage that allows the write operation to be performed;
[0131] Before performing the write operation on the unprotected partition in the foregoing steps, the method further includes:
[0132] Obtain the stage information of the unprotected partition and determine whether the execution time of the write operation is consistent with the stage information of the unprotected partition;
[0133] If there is a discrepancy, the write operation command will be intercepted.
[0134] In the above steps, the preset storage area is a region built on NAND flash memory for storing the operating system, and the preset storage area is equipped with hardware devices for controlling the write operation; the preset storage area includes the RPMB area.
[0135] To achieve the above objectives, according to another aspect of this application, an embodiment of this application also provides a storage medium, the storage medium including a stored program, wherein, when the program is executed, it controls the device where the storage medium is located to execute the software-based write protection method described above.
[0136] To achieve the above objectives, according to another aspect of this application, embodiments of this application also provide a software-based write protection device, the device including a storage medium; and one or more processors, the storage medium being coupled to the processors, the processors being configured to execute program instructions stored in the storage medium; the program instructions executing the software-based write protection method described above.
[0137] This application provides a software-based write protection device and method. First, an acquisition unit obtains write protection region information from a preset storage area. This write protection region information includes a protection range for controlling write operations, and the protection range includes at least one address information to be protected. Then, when a write operation instruction is received, a determination unit determines the write address information from the write operation instruction. Next, a judgment unit determines whether the write address information matches the address information in the write protection region information. Finally, if the write address information matches the address information in the write protection region information, an execution unit intercepts the write operation instruction, thereby realizing a software-based write protection function and satisfying the user's control over the write behavior of NAND flash memory. Compared to existing technologies, the software-based write protection method of this application, during execution, utilizes the write protection region information acquired by the acquisition unit to include the protection range for write operations, thus determining which areas of the NAND flash memory cannot be written to. Therefore, after the judgment unit determines that the write address information in the write operation instruction matches the address information in the write protection region information, it can be determined that the write operation instruction actually needs to be performed within the protected range. At this point, the execution unit intercepts the write operation instruction, preventing the write operation from being performed on data within the protected range. This achieves the function of protecting the areas of the NAND flash memory that require write protection. Furthermore, since the above process is implemented at the software level without hardware support, it has good adaptability for flash memory such as NAND flash memory that lacks hardware support such as a controller. In addition, existing hardware write protection schemes require address alignment operations within the flash memory during execution. After alignment, the storage space for the unaligned addresses is not allocated for data storage, resulting in wasted storage space. The solution of this application does not require address alignment, thus saving storage space in the flash memory. Furthermore, in this application, for areas that do not require protection, the write protection area information can be directly used for setting. In other words, when it is necessary to reset whether a certain area needs to be write protected, the setting can be done directly based on the write protection area information. This avoids the need to set additional unlocking code during the hardware write protection process in the prior art, which is based on hardware. This reduces the amount of code that engineers need to compile, especially when there are multiple flash memory devices with different hardware forms. It is not necessary to compile different types of write protection unlocking code, which can greatly reduce the amount of code that engineers need to compile.
[0138] The software-based write protection device includes a processor and a memory. The aforementioned acquisition unit, determination unit, judgment unit, execution unit, etc., are all stored in the memory as program units, and the processor executes the aforementioned program units stored in the memory to realize the corresponding functions.
[0139] The processor contains a kernel, which retrieves the corresponding program unit from memory. One or more kernels can be configured, and by adjusting kernel parameters, a write protection function adapted to NAND flash memory can be implemented to meet user needs for controlling NAND flash memory write behavior.
[0140] This application provides a software-based write protection device, the device including a storage medium and one or more processors, the storage medium being coupled to the processors, the processors being configured to execute program instructions stored in the storage medium; the program instructions, when executed, perform the software-based write protection method described in any of the preceding claims.
[0141] This application provides a storage medium including a stored program, wherein the program, when running, controls the device where the storage medium is located to execute the software-based write protection method described above.
[0142] Storage media may include non-permanent memory in the form of computer-readable media, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0143] This application provides a device including a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps: obtaining write protection region information from a preset storage region, wherein the write protection region information includes a protection range for performing control operations on write operations, and the protection range includes at least one address information that needs to be protected; when a write operation instruction is received, determining write address information from the write operation instruction; determining whether the write address information matches the address information in the write protection region information; if they match, intercepting the write operation instruction.
[0144] Furthermore, the write address information includes at least one write address, and the write protection area information includes one or more partition information, wherein the partition information is used to characterize whether the corresponding partition allows the write operation to be performed when a write operation is detected.
[0145] The step of determining whether the write address information matches the address information in the write protection area information includes:
[0146] Based on the partition information, a partition that is not allowed to perform the write operation is determined from multiple partitions in the operating system area and designated as a write-protected partition, wherein the write-protected partition includes at least one protected address;
[0147] Determine whether the write address matches the protection address;
[0148] If the write address information matches the address information in the write-protected area information, then the write operation instruction is intercepted, including:
[0149] If the write address matches the protection address, the write operation instruction is intercepted.
[0150] Furthermore, the partition information includes a starting address, length information, and partition attributes; the length information is used to characterize the address length starting from the starting address; the partition attributes are used to characterize whether the partition corresponding to the partition attributes allows the write operation to be performed;
[0151] The step of determining, based on the partition information, from among multiple partitions in the operating system area, the partition that is not allowed to perform the write operation, as a write-protected partition, includes:
[0152] The partition range of each partition is determined based on the starting address information and the length information, and the partition range whose partition attributes are not allowed to perform the write operation is determined from multiple partition ranges based on the partition attributes, and is used as the write-protected partition;
[0153] The step of determining whether the write address matches the protection address includes:
[0154] Determine whether the write address is within the partition range of the write-protected partition;
[0155] If the write address matches the protection address, then the write operation instruction is intercepted, including:
[0156] If the write address is within the partition range of the write-protected partition, then the write operation instruction is intercepted.
[0157] Furthermore, after determining whether the write address is within the partition range of the write-protected partition, the method further includes:
[0158] If the write address is not located within the partition range of the write-protected partition, then the non-protected partition corresponding to the write address is determined.
[0159] Perform the write operation on the unprotected partition.
[0160] Furthermore, the partition attributes also include stage information, which is used to characterize the operating system stage that allows the write operation to be performed;
[0161] Before performing the write operation on the unprotected partition, the method further includes:
[0162] Obtain the stage information of the unprotected partition and determine whether the execution time of the write operation is consistent with the stage information of the unprotected partition;
[0163] If there is a discrepancy, the write operation command will be intercepted.
[0164] Furthermore, the preset storage area is a region built on NAND flash memory for storing the operating system, and the preset storage area is equipped with hardware devices for controlling the write operation; the preset storage area includes an RPMB region.
[0165] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing program code with the following initialization method steps: obtaining write protection area information from a preset storage area, wherein the write protection area information includes a protection range for performing control operations on write operations, and the protection range includes at least one address information that needs to be protected; when a write operation instruction is received, determining write address information from the write operation instruction; determining whether the write address information matches the address information in the write protection area information; if they match, intercepting the write operation instruction.
[0166] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0167] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0168] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0169] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0170] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0171] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0172] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0173] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0174] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0175] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A software-based write protection device, characterized in that, The device includes: The acquisition unit is used to acquire write protection area information from a preset storage area, wherein the write protection area information includes a protection range for controlling write operations, and the protection range includes at least one address information that needs to be protected. The determining unit is used to determine write address information from the write operation instruction when a write operation instruction is received; The judgment unit is used to determine whether the write address information matches the address information in the write protection area information; An execution unit is configured to intercept the write operation instruction if the write address information matches the address information in the write protection area information. The write address information includes at least one write address; the write protection area information includes one or more partition information, the partition information includes partition attributes, the partition attributes are used to characterize whether the partition corresponding to the partition attributes is allowed to perform write operations, the partition attributes also include stage information, the stage information is used to characterize the operating system stage that allows the write operation to be performed; The judgment unit includes: The acquisition module is used to acquire the stage information of the unprotected partition and determine whether the execution time of the write operation is consistent with the stage information of the unprotected partition. The write address is located in the partition range of the unprotected partition, and the partition attribute of the unprotected partition is a partition that allows write operations. The second execution module is used to intercept the write operation instruction if the execution time of the write operation is inconsistent with the stage information of the unprotected partition.
2. The apparatus according to claim 1, characterized in that, The write address information includes at least one write address; the write protection area information includes one or more partition information, the partition information being used to characterize whether the corresponding partition allows the write operation to be performed when a write operation is detected. The judgment unit includes: The first determining module is configured to determine, based on the partition information, a partition among multiple partitions in the operating system area that is not allowed to perform the write operation, as a write-protected partition, wherein the write-protected partition includes at least one protection address; The judgment module is used to determine whether the write address matches the protection address; The execution unit is specifically configured to intercept the write operation instruction if the write address matches the protection address.
3. The apparatus according to claim 2, characterized in that, The partition information includes a starting address, length information, and partition attributes; the length information is used to characterize the address length starting from the starting address; the partition attributes are used to characterize whether the partition corresponding to the partition attributes allows the write operation to be performed; The first determining module is specifically used to determine the partition range of each partition based on the starting address information and the length information, and to determine the partition range whose partition attributes are not allowed to perform the write operation from multiple partition ranges based on the partition attributes, and to use it as the write-protected partition; The judgment module is specifically used to determine whether the write address is located within the partition range of the write-protected partition; The execution unit is further configured to intercept the write operation instruction if the write address is located within the partition range of the write-protected partition.
4. The apparatus according to claim 3, characterized in that, The judgment unit further includes: The second determining module is used to determine the non-protected partition corresponding to the write address if the write address is not located within the partition range of the write-protected partition. The first execution module is used to perform the write operation on the unprotected partition.
5. The apparatus according to any one of claims 1-4, characterized in that, The preset storage area is a region built on NAND flash memory for storing the operating system; the preset storage area includes the RPMB area.
6. A software-based write protection method, characterized in that, The method includes: Retrieve write protection area information from a preset storage area, wherein the write protection area information includes a protection range for performing control operations on write operations, and the protection range includes at least one address information that needs to be protected; When a write operation instruction is received, the write address information is determined from the write operation instruction; Determine whether the write address information matches the address information in the write protection area information; If a match is found, the write operation instruction is intercepted; The write address information includes at least one write address; the write protection area information includes one or more partition information, the partition information includes partition attributes, the partition attributes are used to characterize whether the partition corresponding to the partition attributes is allowed to perform write operations, the partition attributes also include stage information, the stage information is used to characterize the operating system stage that allows the write operation to be performed; The method further includes: Obtain the stage information of the unprotected partition and determine whether the execution time of the write operation is consistent with the stage information of the unprotected partition. The write address is located within the partition range of the unprotected partition, and the partition attribute of the unprotected partition is a partition that allows write operations. If there is a discrepancy, the write operation command will be intercepted.
7. The method according to claim 6, characterized in that, The write address information includes at least one write address, and the write protection area information includes one or more partition information, wherein the partition information is used to characterize whether the corresponding partition is allowed to perform the write operation when a write operation is detected. The step of determining whether the write address information matches the address information in the write protection area information includes: Based on the partition information, a partition that is not allowed to perform the write operation is determined from multiple partitions in the operating system area and designated as a write-protected partition, wherein the write-protected partition includes at least one protected address; Determine whether the write address matches the protection address; If the write address information matches the address information in the write-protected area information, then the write operation instruction is intercepted, including: If the write address matches the protection address, the write operation instruction is intercepted.
8. A storage medium, characterized in that, The storage medium includes a stored program, wherein, when the program is executed, it controls the device containing the storage medium to perform the software-based write protection method according to any one of claims 6-7.
9. A software-based write protection device, characterized in that, The device includes a storage medium; and one or more processors, the storage medium being coupled to the processors, the processors being configured to execute program instructions stored in the storage medium; the program instructions, when executed, perform the software-based write protection method according to any one of claims 6-7.
Citation Information
Patent Citations
Data protection method and device, computing equipment and storage medium
CN112825098A