Memory and code protection system based on FreeRTOS
By designing memory and code protection systems in the FreeRTOS operating system, the security and stability problems caused by access can be accessed between tasks and memory, realizing task isolation and memory protection, and enhanced the safety and stability of the system.
Patent Information
- Application Number
- CN202411374103.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2025-01-28
AI Technical Summary
In the existing FreeRTOS operating system, tasks can access code and memory from each other, resulting in the impact of system security and stability.
Design a memory and code protection system based on FreeRTOS, including task allocation modules, memory protection modules, task security modules and task monitoring modules. By being isolated into different operating environments, the memory area of the task is dynamically protected, and the safety and reliability of each task is enhanced.
Realize the memory and code isolation between tasks, enhance the security and stability of the system, and prevent errors interference and malware attack between tasks.
Smart Images

Figure CN119376923A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of embedded systems, and in particular to a memory and code protection system based on FreeRTOS. Background Art
[0002] In the existing embedded system development, multi-tasking operating systems such as FreeRTOS are widely used in ARMCortex-based hardware platforms to implement multi-tasking. However, in traditional FreeRTOS applications, all user tasks share the same address space, which poses a security risk that tasks can access each other's code and memory. This design not only increases the potential risk of error interference, but also increases the possibility of malware attacks. Summary of the invention
[0003] The purpose of this application is to provide a memory and code protection system based on FreeRTOS to solve the technical problem that the existing FreeRTOS operating system in the prior art has mutual access and affects the system security. The many technical effects that can be produced by the preferred technical solution among the many technical solutions provided in this application are described in detail below.
[0004] To achieve the above objectives, this application provides the following technical solutions:
[0005] The present application provides a memory and code protection system based on FreeRTOS, comprising: a task allocation module, a memory protection module, a task security module and a task monitoring module; the task allocation module is configured to isolate each task to a different operating environment; the memory protection module is configured to dynamically protect the memory area of the task; the task security module is configured to enhance the security and reliability of each task during operation.
[0006] In some embodiments, the task allocation module includes a compilation unit and an allocation unit; the compilation unit is configured to use an isolated compilation server and independent compilation parameters to set an independent compilation environment for each task; the allocation unit is configured to allocate a fixed memory area for each task.
[0007] In some embodiments, the compiling unit is further configured to place the code segment of each task in an independent read-only memory area; when each task is started, the allocating unit allocates an independent memory partition to each task.
[0008] In some embodiments, the memory protection module includes an adjustment unit and a recording unit; the adjustment unit is configured to adjust the size and permissions of the memory protection area; and the recording unit is configured to record the memory access status of each task.
[0009] In some embodiments, the task safety module includes a checking unit and a protection unit; the checking unit is configured to verify the integrity of each task and perform a boundary check on each task; the protection unit is configured to transmit communication data between tasks using a secure channel.
[0010] In some embodiments, the task monitoring module includes a monitoring unit, an isolation unit, a prediction unit and a recovery unit; the monitoring unit is configured to monitor memory access patterns and task behaviors to obtain monitoring results; the isolation unit is configured to isolate abnormal tasks in the monitoring results; the prediction unit is configured to analyze historical fault data and system operating status to predict fault conditions; the recovery unit is configured to use a multi-level fault recovery mechanism to perform fault handling.
[0011] In some embodiments, the FreeRTOS-based memory and code protection system also includes a resource management module; the resource management module is configured to allocate resources according to the importance of the task and resource requirements to achieve optimization; the resource management module includes a resource allocation unit and an optimization unit; the resource allocation unit is configured to dynamically optimize memory and processor usage using a resource management algorithm; the optimization unit is configured to allocate processor time slices according to the importance of the task and resource requirements.
[0012] In some embodiments, the optimization unit is configured to optimize energy efficiency of the system.
[0013] In some embodiments, the FreeRTOS-based memory and code protection system also includes an update module; the update module includes a firmware update unit, a boot unit and a configuration management unit; the firmware update unit is configured to protect the firmware update package; the boot unit is configured to verify the boot loader; the configuration management unit is configured to centrally manage and adjust the task security configuration.
[0014] Implementing one of the above-mentioned technical solutions of the present application has the following advantages or beneficial effects: In the present application, by isolating each task to a different operating environment, protecting the executing tasks and the memory areas of the tasks, and processing the abnormal tasks at the same time, it can ensure that different tasks cannot directly access each other's memory and code areas, thereby achieving task isolation and memory protection, and further enhancing the security and stability of the system. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. It is obvious that the drawings described below are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative work. In the drawings:
[0016] Figure 1 It is a structural block diagram of the memory and code protection system based on FreeRTOS in an embodiment of the present application.
[0017] In the figure: 1. Memory and code protection system based on FreeRTOS; 10. Task allocation module; 20. Memory protection module; 30. Task security module; 40. Task monitoring module; 50. Resource management module; 60. Update module; 11. Compile unit; 12. Allocation unit; 21. Adjustment unit; 22. Recording unit; 23. Data encryption unit; 24. Virtual memory unit; 31. Check unit; 32. Protection unit; 41. Monitoring unit; 42. Isolation unit; 43. Prediction unit; 44. Recovery unit; 51. Resource allocation unit; 52. Optimization unit; 61. Firmware update unit; 62. Boot unit; 63. Configuration management unit. DETAILED DESCRIPTION
[0018] In order to make the purpose, technical solutions and advantages of the present application clearer, the various exemplary embodiments to be described below will refer to the corresponding drawings, which constitute a part of the exemplary embodiments, wherein various exemplary embodiments that may be used to implement the present application are described. Unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation methods described in the following exemplary embodiments do not represent all implementation methods consistent with the present disclosure. It should be understood that they are only examples of processes, methods, and devices that are consistent with some aspects disclosed in the present application as detailed in the attached claims, and other embodiments may also be used, or the embodiments listed herein may be modified in structure and function without departing from the scope and essence of the present application.
[0019] In the description of the present application, it should be understood that the terms "center", "longitudinal", "lateral", etc. indicate the orientation or positional relationship based on the drawings, which is only for the convenience of describing the present application and simplifying the description, rather than indicating or implying that the elements referred to must have a specific orientation, be constructed and operated in a specific orientation. The terms "first", "second", etc. are only used for descriptive purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. The term "multiple" means two or more. The terms "connected" and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, an integral connection, a mechanical connection, an electrical connection, a communication connection, a direct connection, an indirect connection through an intermediate medium, and can be the internal connection of two elements or the interaction relationship between two elements. The term "and / or" includes any and all combinations of one or more related listed items. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances.
[0020] In order to illustrate the technical solution described in the present application, a specific embodiment is provided below, and only the parts related to the embodiment of the present application are shown.
[0021] FreeRTOS is a real-time operating system (RTOS) for embedded devices and microcontrollers. FreeRTOS can provide task management, synchronization, and communication mechanisms that can be used to simplify multitasking and ensure that tasks are executed according to predetermined time constraints.
[0022] The embodiments of the present application can be applied to a system running on FreeRTOS, such as an ARM Cortex microcontroller system based on FreeRTOS.
[0023] like Figure 1 As shown, the present application provides a memory and code protection system 1 based on FreeRTOS, which may include: a task allocation module 10, a memory protection module 20, a task security module 30 and a task monitoring module 40.
[0024] In some embodiments, the task allocation module 10 can be configured to isolate each task into a different operating environment; the memory protection module 20 can be configured to dynamically protect the memory area of the task; the task security module 30 can be configured to enhance the security and reliability of each task during operation; the task monitoring module 40 can be configured to monitor the tasks in real time and handle abnormal tasks.
[0025] In some embodiments, the operating environment may refer to the environment in which the task is located during the development phase and the environment in which the task is located during the operating phase.
[0026] In some embodiments, the task allocation module 10 may include a compiling unit 11 and an allocating unit 12 .
[0027] In some embodiments, the compilation unit 11 can be configured to use an isolated compilation server and independent compilation parameters to set an independent compilation environment for each task. That is, each task can correspond to a different compilation environment. Compilation can refer to the process of using a compiler to compile a task into executable code. The isolated compilation server can refer to a server specifically used to compile source code, which can be isolated from other development environments. For example, the compilation server can have an independent CPU, memory, storage and network resources, etc. Independent compilation parameters can refer to configuration options during the compilation process. In this case, the compilation unit 11 can isolate the code during the compilation process and avoid cross contamination; at the same time, the independent compilation environment can effectively prevent interference and security vulnerabilities between different tasks during the compilation process.
[0028] In some embodiments, the compiling unit 11 may also be configured to place the code segment of each task in an independent read-only memory area, thereby preventing other tasks from modifying the code segment, thereby improving the integrity and security of the code segment.
[0029] In some embodiments, the allocation unit 12 can be configured to allocate a fixed memory area for each task. The allocation unit 12 can allocate memory areas according to the security level and memory requirements of each task. When the tasks are in different memory areas, it can be ensured that the memory between the tasks is not accessed by each other. In some embodiments, the allocation unit 12 can generate a link script. In this case, the allocation unit 12 can dynamically adjust the memory allocation according to the actual requirements of the task, and improve the memory usage efficiency while ensuring security.
[0030] In some embodiments, when each task is started, the allocation unit 12 can allocate an independent memory partition to each task. The allocation unit 12 can embed the partition information representing the allocated memory partition into the task control block (TCB). Thus, the dynamic binding and management of tasks and memory partitions can be realized by using TCB. In this case, it is possible to prevent tasks from accidentally or intentionally accessing the memory area of other tasks during operation.
[0031] In some embodiments, the memory protection module 20 may include an adjustment unit 21 and a recording unit 22 .
[0032] In some embodiments, the adjustment unit 21 can be configured to adjust the size and permissions of the memory protection area. Specifically, the adjustment unit 21 can automatically adjust the memory protection area according to the real-time monitoring data of the task. Specifically, when the adjustment unit 21 detects an attempt to cross-border access, the adjustment unit 21 can automatically reduce the accessible memory area of the task. In this case, the adjustment unit 21 can improve the accuracy of memory protection while maintaining system performance.
[0033] In some embodiments, the recording unit 22 may be configured to record the memory access of each task. The memory access may include at least one of the memory access address, access time, and access type. The recording unit 22 may generate an access log according to the memory access and store the access log. This facilitates subsequent analysis.
[0034] In some embodiments, the memory protection module 20 may further include a data encryption unit 23 and a virtual memory unit 24 .
[0035] In some embodiments, the data encryption unit 23 can be configured to perform encryption and decryption operations on the data. Specifically, when the data needs to be stored in the memory, the data encryption unit 23 can encrypt the data; when the data in the memory needs to be accessed, the data encryption unit 23 can decrypt the data. In some embodiments, the data encryption unit 23 can use an encryption algorithm, such as the AES-256 encryption algorithm, to perform encryption and decryption operations. In some embodiments, the data encryption unit 23 can also select different encryption strategies and encryption strengths according to the importance of the data.
[0036] In some embodiments, the virtual memory unit 24 may be configured to create an independent virtual memory space for each task. The virtual memory unit 24 may be a virtual memory management system based on a page table, and may implement dynamic allocation and protection of memory through page table mapping.
[0037] In some embodiments, the task safety module 30 may include a checking unit 31 and a protection unit 32 .
[0038] In some embodiments, the checking unit 31 can be configured to verify the integrity of each task. Specifically, when the task is switched, the checking unit 31 can check whether the code and data of the task to be run have been tampered with. In this case, the security and reliability of the task to be switched can be ensured, and multiple verification steps before task switching are added, which can further improve the system's anti-attack capability.
[0039] In some embodiments, the checking unit 31 can also be configured to perform boundary checks on each task. Specifically, the checking unit 31 can automatically perform boundary checks on the stack and buffer each time the task is switched to prevent buffer overflow and stack overflow attacks. In this case, real-time detection and early warning can be achieved to reduce the possibility of security vulnerabilities being exploited.
[0040] In some embodiments, the protection unit 32 can be configured to use a secure channel to transmit communication data between tasks. Specifically, during inter-task communication, data can be transmitted through the secure channel of the protection unit 32, and the secure channel can encrypt and perform integrity verification on the transmitted data. In this case, the security and data integrity of inter-task communication can be enhanced.
[0041] In some embodiments, the protection unit 32 can also be used to protect the interrupt service routine (ISR) and perform integrity check on the ISR. In this case, the interference of other tasks in the interrupt handling process can be reduced, and the interrupt code can be prevented from being tampered with.
[0042] In some embodiments, the task monitoring module 40 may include a monitoring unit 41 , an isolation unit 42 , a prediction unit 43 , and a recovery unit 44 .
[0043] In some embodiments, the monitoring unit 41 may be configured to monitor memory access patterns and task behaviors to obtain monitoring results. The monitoring unit 41 may use a machine learning algorithm to identify abnormal patterns, wherein the abnormal patterns may at least include abnormal memory access rates or patterns. Thus, by introducing a machine learning algorithm, the accuracy and response speed of abnormality detection can be improved.
[0044] In some embodiments, the isolation unit 42 can be configured to isolate abnormal tasks in the monitoring results. Specifically, when abnormal behavior of a task or abnormal mode of memory is detected, that is, when an abnormal task is detected, the isolation unit 42 can automatically isolate the abnormal task, suspend the execution of the abnormal task, and audit and recover the execution environment of the abnormal task. In some embodiments, the isolation unit 42 can also be used to provide fault logs and analysis results related to the abnormal task. In this way, it can be ensured that the system can respond quickly when an abnormality occurs, and the scope of the fault impact can be reduced.
[0045] In some embodiments, the prediction unit 43 may be configured to analyze historical fault data and system operating status to predict fault conditions. The prediction unit 43 may take preventive measures based on the fault conditions. The preventive measures may include adjusting task priorities or reallocating resources, etc. Thus, the occurrence of faults can be reduced.
[0046] In some embodiments, the recovery unit 44 can be configured to use a multi-level fault recovery mechanism for fault handling. The multi-level fault recovery mechanism may include at least one of task-level recovery, system-level restart, and data-level rollback. Thus, faults can be effectively handled and recovered at different levels. Task-level recovery may refer to performing a recovery operation on a single task when a single task fails; system-level restart may refer to restoring service by restarting the entire system when a failure occurs in the operating system or the entire system; data-level rollback may refer to restoring data consistency by rolling back to a previous state when a problem occurs in a database or data storage.
[0047] In some embodiments, the FreeRTOS-based memory and code protection system 1 may further include a resource management module 50 .
[0048] In some embodiments, the resource management module 50 may be configured to allocate resources according to the importance of the task and the resource requirements to achieve optimization.
[0049] In some embodiments, the resource management module 50 may include a resource allocation unit 51 and an optimization unit 52 .
[0050] In some embodiments, the resource allocation unit 51 can be configured to dynamically optimize memory and processor usage using a resource management algorithm. Specifically, the resource allocation unit 51 can allocate necessary resources to high-priority tasks, and at the same time, the resource allocation unit 51 can make low-priority tasks wait or release the resources of low-priority tasks. Thus, the overall operating efficiency and response speed of the system can be improved. In some embodiments, the resource management algorithm can include at least one of a CPU scheduling algorithm, a memory management algorithm, a file system algorithm, a network scheduling algorithm, a load balancing algorithm, and a storage allocation algorithm.
[0051] In some embodiments, the resource allocation unit 51 can also be configured to dynamically adjust the resource allocation of tasks according to the resource usage status. The resource allocation unit 51 can monitor the system resource usage in real time and obtain the system resource usage status. Thus, the rationality of system resource allocation and the efficiency of system resource utilization can be improved.
[0052] In some embodiments, the optimization unit 52 can be configured to allocate processor time slices according to the importance of the task and resource requirements. The processor time slice can refer to the time interval obtained by dividing the time resources of the CPU. The optimization unit 52 can allocate processor time slices using a task scheduling algorithm. In this way, the response speed and overall efficiency of the system can be improved.
[0053] In some embodiments, the optimization unit 52 can be configured to optimize the energy efficiency of the system. Specifically, the optimization unit 52 can adjust the running frequency and sleep state of the task, and optimize the energy consumption mode of the task. In this case, the optimization unit 52 can extend the running time of the device running the system, and can extend the working life of the device.
[0054] In some embodiments, the FreeRTOS-based memory and code protection system 1 may further include an update module 60. In some embodiments, the update module 60 may include a firmware update unit 61, a boot unit 62, and a configuration management unit 63.
[0055] In some embodiments, the firmware update unit 61 may be configured to protect the firmware update package. In some embodiments, the firmware update unit 61 may add a digital signature to the firmware update package, or encrypt the firmware update package. The firmware update package may refer to a collection of files used to update or upgrade the device firmware. The firmware update package may include an updated firmware image, a configuration file, an update script, etc.
[0056] In some embodiments, the boot unit 62 may be configured to verify a boot loader, which may be the first software program that runs when the system starts up; the boot loader is activated when the system is powered on or restarted, and may be used to load the system and initialize the hardware.
[0057] In some embodiments, the configuration management unit 63 can be configured to centrally manage and adjust the task security configuration. Thus, the security and consistency of the configuration can be ensured. The task security configuration can refer to the security measures and parameters set for the tasks in the system. The task security configuration can include the settings of the task's permissions, resource access, and network communication.
[0058] As described above, by setting up the resource management module 50 and the update module 60, the present application can improve the system security while optimizing the resource utilization efficiency and system responsiveness.
[0059] In the present application, by isolating each task into a different operating environment, protecting the executing tasks and the memory areas of the tasks, and processing the abnormal tasks, it can be ensured that different tasks cannot directly access each other's memory and code areas, thereby achieving task isolation and memory protection, and further enhancing the security and stability of the system.
[0060] The present application also relates to a memory and code protection method, which may include:
[0061] Isolate each task into a different operating environment; dynamically protect the task's memory area; enhance the security and reliability of each task during runtime; monitor tasks in real time and handle abnormal tasks.
[0062] Those skilled in the art can understand that all or part of the features / steps of the above-mentioned method embodiments can be implemented by methods, data processing systems or computer programs, and these features can be implemented without hardware, entirely by software, or by a combination of hardware and software. The aforementioned computer program can be stored in one or more computer-readable storage media, and the storage medium stores the computer program. When the computer program is executed (such as by a processor), the steps of the above-mentioned memory and code protection method embodiments are executed.
[0063] The aforementioned storage media that can store program codes include: static hard disks, solid-state hard disks, random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), optical storage devices, magnetic storage devices, flash memory, magnetic disks or optical disks and / or combinations of the above devices, that is, it can be implemented by any type of volatile or non-volatile storage device or a combination thereof.
[0064] The present application also provides an embodiment of a processing device, comprising one or more processors and a memory; wherein the memory is used to store one or more computer programs, and the one or more processors are used to execute one or more computer programs stored in the memory, so that the processor performs the features / steps of the above-mentioned memory and code protection method embodiment.
[0065] The above is only the preferred embodiment of the present application. Those skilled in the art will appreciate that various changes or equivalent substitutions may be made to these features and embodiments without departing from the spirit and scope of the present application. In addition, under the guidance of the present application, these features and embodiments may be modified to adapt to specific circumstances and materials without departing from the spirit and scope of the present application. Therefore, the present application is not limited to the specific embodiments disclosed herein, and all embodiments falling within the scope of the claims of the present application belong to the protection scope of the present application.
Claims
1. A memory and code protection system based on FreeRTOS, characterized in that: include: Task allocation module, memory protection module, task safety module and task monitoring module; The task allocation module is configured to isolate each task into a different execution environment; The memory protection module is configured to dynamically protect the memory area of the task; The task safety module is configured to enhance the safety and reliability of each task during its operation; The task monitoring module is configured to monitor tasks in real time and process abnormal tasks.
2. The FreeRTOS-based memory and code protection system according to claim 1, characterized in that: The task allocation module includes a compilation unit and an allocation unit; the compilation unit is configured to use an isolated compilation server and independent compilation parameters to set an independent compilation environment for each task; the allocation unit is configured to allocate a fixed memory area for each task.
3. The FreeRTOS-based memory and code protection system according to claim 2, characterized in that: The compiling unit is further configured to place the code segment of each task in an independent read-only memory area; when each task is started, the allocating unit allocates an independent memory partition to each task.
4. The FreeRTOS-based memory and code protection system according to claim 1, characterized in that: The memory protection module includes an adjustment unit and a recording unit; the adjustment unit is configured to adjust the size and permissions of the memory protection area; the recording unit is configured to record the memory access status of each task.
5. The FreeRTOS-based memory and code protection system according to claim 1, characterized in that: The task safety module includes a checking unit and a protection unit; the checking unit is configured to verify the integrity of each task and perform a boundary check on each task; the protection unit is configured to transmit communication data between tasks using a secure channel.
6. The FreeRTOS-based memory and code protection system according to claim 1, characterized in that: The task monitoring module includes a monitoring unit, an isolation unit, a prediction unit and a recovery unit; the monitoring unit is configured to monitor memory access patterns and task behaviors to obtain monitoring results; the isolation unit is configured to isolate abnormal tasks in the monitoring results; the prediction unit is configured to analyze historical fault data and system operating status to predict fault conditions; the recovery unit is configured to use a multi-level fault recovery mechanism to perform fault processing.
7. The FreeRTOS-based memory and code protection system according to claim 1, characterized in that: It also includes a resource management module; the resource management module is configured to allocate resources according to the importance of the task and the resource requirements to achieve optimization; the resource management module includes a resource allocation unit and an optimization unit; the resource allocation unit is configured to dynamically optimize memory and processor usage using a resource management algorithm; the optimization unit is configured to allocate processor time slices according to the importance of the task and the resource requirements.
8. The FreeRTOS-based memory and code protection system according to claim 7, characterized in that: The optimization unit is configured to optimize the energy efficiency of the system.
9. The FreeRTOS-based memory and code protection system according to claim 1, characterized in that: It also includes an update module; the update module includes a firmware update unit, a boot unit and a configuration management unit; the firmware update unit is configured to protect the firmware update package; the boot unit is configured to verify the boot loader; the configuration management unit is configured to centrally manage and adjust the task security configuration.
10. The FreeRTOS-based memory and code protection system according to claim 1, characterized in that: The memory protection module also includes a data encryption unit and a virtual memory unit; the data encryption unit is configured to perform encryption and decryption operations on data; and the virtual memory unit is configured to create an independent virtual memory space for each task.