A SIL4 stack detection method applicable to general operating systems

By declaring the stack protection section and detection algorithm Fcheck in the operating system, the shortcomings of stack overflow and out-of-bounds detection in the existing technology are solved, and a general SIL4 stack detection in various environments is realized, ensuring the accuracy of the SIL4 security program and flexibility.

CN113687968BActive Publication Date: 2024-11-26浙江众合科技股份有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110835650.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-23
Publication Date
2024-11-26
Estimated Expiration
2041-07-23

AI Technical Summary

Technical Problem

Existing operating systems lack effective mechanisms when detecting stack overflow and out-of-bounds exceptions, especially when closed-source systems and insufficient resources, SIL4 security programs cannot accurately sense whether the stack meets security requirements, and the stack detection function is on different CPUs and compiled. Lack of universality in the device environment.

Method used

By declaring the stack protection section and detection algorithm Fcheck, the growth direction and size of the stack space are dynamically detected, and Fsafety is called periodically to ensure that the stack space complies with the SIL4 standard, and exception determination and safe processing are used for specific values.

Benefits of technology

It realizes common stack detection in different CPUs, operating systems and compiler environments, and can adjust the stack protection space as needed to ensure the accurate detection and handling of stack exceptions by SIL4 security programs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113687968B_ABST
    Figure CN113687968B_ABST
Patent Text Reader

Abstract

The invention discloses a SIL4 stack detection method applicable to a general operating system, comprising the following steps: step S1, when a safety program is running, an entry function main declares a stack protection segment StackGuard1 array; step S2, main calls a function Finit; Finit internally declares the stack space Stack array and the stack protection segment StackGuard2 array used by the entire safety program at most; step S3, according to the start and end positions of the same stack array, it is determined whether the operating environment uses the address to grow upward or downward on the stack; step S4, sorting by the size of the stack array, the main function writes a specific value into the stack space used by the safety program and performs a memory detection on the full stack array; step S5, after the detection is completed, the safety business program Fsafety and the stack detection algorithm Fcheck are periodically called; step S6, the stack detection algorithm Fcheck detects the stack space used by the safety program. The stack detection method has strong versatility and can dynamically adapt to various CPUs, operating systems, and compilers, thereby realizing SIL4 level stack memory detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer data structures, and in particular to a SIL4 stack detection method applicable to a general operating system. Background Art

[0002] As a data structure, the stack is a special linear table that can only perform insertion and deletion operations at one end. It stores data according to the last-in-first-out principle. The first data is pushed to the bottom of the stack, and the last data is at the top of the stack. When data needs to be read, it pops up from the top of the stack, and the last data is read out first. The stack has a memory function. There is no need to change the bottom pointer of the stack during the insertion and deletion operations of the stack; some embedded operating systems provide a fixed stack space size and stack detection function. Stack overflow is an important detection item of stack detection. Stack overflow is due to the fact that the C language series has no built-in checking mechanism to ensure that the data copied to the buffer is not larger than the size of the buffer. Therefore, when the data is large enough, it will overflow the range of the buffer; when an exception occurs in the system, there is no interface to notify the SIL4 safety program; for closed-source operating systems, it is impossible to perceive whether its processing meets the SIL4 requirements; some other operating systems have no stack detection function. With sufficient resources, they can arbitrarily allocate as much stack space as they want, but the SIL4 safety program cannot perceive whether the stack has cross-border exceptions. Summary of the invention

[0003] In view of the above-mentioned drawbacks, the purpose of the present invention is to propose a SIL4 stack detection method applicable to a general operating system, which can dynamically adapt to various CPUs, operating systems, and compilers by taking advantage of the fact that the stack only grows in one direction and is pre-allocated, thereby achieving SIL4 level stack memory detection.

[0004] In order to achieve the above technical purpose, a technical solution provided by the present invention is a SIL4 stack detection method applicable to a general operating system, comprising the following steps:

[0005] Step S1, when the safety program is running, the entry function main declares the stack protection segment StackGuard1 array;

[0006] Step S2, main calls function Finit; Finit internally declares the stack space Stack array used by the entire safety program at most, and the stack protection segment StackGuard2 array;

[0007] Step S3, judging whether the operating environment uses addresses on the stack to grow upward or downward according to the start and end positions of the same stack array; and knowing whether the allocation of multiple stack variables grows upward or downward according to the sequence of the three stack arrays;

[0008] Step S4: Sort according to the size of the stack array. The main function writes specific values into the stack space used by the safety program, and performs memory detection on the entire stack array that complies with the SIL4 standard.

[0009] Step S5: After the detection, periodically call the safety service program Fsafety and the stack detection algorithm Fcheck.

[0010] Step S6: The stack detection algorithm Fcheck detects the stack space used by the safety program, and compares and determines whether its value is still the specific value set in advance. If not, it determines that the stack is abnormal and thus performs safety-oriented processing. If so, the stack is abnormal and no alarm is given.

[0011] Preferably, step S1 further includes: using the global variable P3 to record the starting position of the StackGuard1 array and using the global variable P4 to record the ending position of the StackGuard1 array.

[0012] Preferably, step S2 further includes: using the global variable P1 to record the starting position of the Stack array and using the global variable P2 to record the ending position of the Stack array, and then returning.

[0013] Preferably, step S2 further includes: using the global variable P5 to record the starting position of the StackGuard2 array and using the global variable P6 to record the ending position of the StackGuard2 array, and then returning.

[0014] Preferably, the same stack array is any one of the Stack array, the StackGuard1 array, or the StackGuard2 array.

[0015] Preferably, the stack used by Fsafety and the Stack array declared by Finit are the same memory space.

[0016] Preferably, sorting according to the size of the stack array is expressed as: P1 < P2 < P3 < P4 < P5 < P6, where the sections [P1, P2] and [P5, P6] are the stack spaces used by the safety program, and the section [P3, P4] is the stack space protected by the stack.

[0017] Advantages of the present invention: The SIL4 stack detection method applicable to a general operating system of the present invention has strong versatility, does not depend on the operating system in which the safety program runs, does not depend on the target CPU, and does not depend on the stack growth direction allocation of the compiler used. The SIL4 safety program can adjust the size of the stack protection space as needed, select specific values, detect the stack space used by the safety program through the stack detection algorithm Fcheck, and determine abnormal situations by comparing the similarities and differences of characteristic values. Description of the Drawings

[0018] Figure 1 The present invention is a flow chart of a SIL4 stack detection method applicable to a general operating system. DETAILED DESCRIPTION

[0019] In order to make the objectives, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific implementation method described herein is only an optimal embodiment of the present invention, which is only used to explain the present invention and does not limit the scope of protection of the present invention. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0020] Example: Figure 1 As shown, a flow chart of a SIL4 stack detection method applicable to a general operating system includes the following steps;

[0021] Step S1, when the safety program is running, the entry function main declares the stack protection segment StackGuard1 array; uses the global variable P3 to record the starting position of the StackGuard1 array and uses the global variable P4 to record the ending position of the StackGuard1 array.

[0022] Step S2, main calls function Finit; Finit internally declares the stack space Stack array and the stack protection segment StackGuard2 array used by the entire safety program at most; wherein, the global variable P1 is used to record the starting position of the Stack array and the global variable P2 is used to record the ending position of the Stack array, and then returns; the global variable P5 is used to record the starting position of the StackGuard2 array and the global variable P6 is used to record the ending position of the StackGuard2 array, and then returns.

[0023] Step S3, according to the start and end positions of the same stack array (any one of the Stack array, StackGuard1 array or StackGuard2 array), determine whether the operating environment uses addresses on the stack to grow upward (memory addresses become larger) or downward (memory addresses become smaller); at the same time, according to the sequence of the three stack arrays, know whether the allocation of multiple stack variables by the operating environment grows upward (memory addresses become larger) or downward (memory addresses become smaller).

[0024] Step S4: Sort according to the size of the stack array, expressed as: P1 < P2 < P3 < P4 < P5 < P6, where the sections [P1, P2] and [P5, P6] are the stack spaces used by the safety program, and the section [P3, P4] is the stack space protected by the stack; the main function writes the stack space used by the safety program to a specific value; and performs a memory check on the entire stack array that meets the SIL4 standard.

[0025] Step S5: After the detection is completed, periodically call the safety service program Fsafety and the stack detection algorithm Fcheck; the stack used by Fsafety and the Stack array declared by Finit are the same memory space.

[0026] Step S6: The stack detection algorithm Fcheck detects the stack space used by the safety program and compares and determines whether its value is still the specific value set in advance; if not, it is determined that the stack is abnormal (stack overflow or damaged by the OS), and thus a safety-oriented process is performed; if so, the stack is abnormal and no alarm is issued.

[0027] The above specific implementation manner is a preferred implementation manner of a SIL4 stack detection method for a general operating system applicable to the present invention, and does not limit the specific implementation scope of the present invention. The scope of the present invention includes but is not limited to this specific implementation manner. Any equivalent changes made according to the shape and structure of the present invention are within the protection scope of the present invention.

Claims

1. A SIL4 stack detection method applicable to a general operating system, characterized in that: It includes the following steps: Step S1: When the security program runs, the entry function main declares the StackGuard1 array in the stack protection section; Step S2: main calls the function Finit; Finit internally declares the Stack array for the maximum stack space used by the entire security program and the StackGuard2 array in the stack protection section; Step S3: Determine whether the running environment grows the address upward or downward on the stack according to the start and end positions of the same stack array; at the same time, know whether the running environment allocates multiple stack variables upward or downward according to the order of the three stack arrays; Step S4: Sort by the size of the stack array, and the main function writes specific values to the stack space used by the security program; and performs memory detection that complies with the SIL4 standard on the entire stack array; Step S5: After the detection is completed, periodically call the security service program Fsafety and the stack detection algorithm Fcheck; Step S6: The stack detection algorithm Fcheck detects the stack space used by the security program and compares and determines whether its value is still the specific value set in advance; if not, it determines that the stack is abnormal and thus performs a guided security process; if so, the stack is abnormal and no alarm is given; Sorting by the size of the stack array is expressed as: P1 < P2 < P3 < P4 < P5 < P6, where the sections [P1, P2] and [P5, P6] are the stack spaces used by the security program, the section [P3, P4] is the stack space for stack protection, P1 records the start position of the Stack array, P2 records the end position of the Stack array, P3 records the start position of the StackGuard1 array, P4 records the end position of the StackGuard1 array, P5 records the start position of the StackGuard2 array, and P6 records the end position of the StackGuard2 array.

2. A method for detecting a SIL4 stack applicable to a general operating system according to claim 1, characterized in that: Step S1 also includes: Using the global variable P3 to record the start position of the StackGuard1 array and using the global variable P4 to record the end position of the StackGuard1 array.

3. A SIL4 stack detection method applicable to a general operating system according to claim 1 or 2, characterized in that: Step S2 also includes: Using the global variable P1 to record the start position of the Stack array and using the global variable P2 to record the end position of the Stack array, and then return.

4. A method for detecting a SIL4 stack applicable to a general operating system according to claim 3, characterized in that: Step S2 also includes: Using the global variable P5 to record the start position of the StackGuard2 array and using the global variable P6 to record the end position of the StackGuard2 array, and then return.

5. A SIL4 stack detection method applicable to a general operating system according to claim 1 or 2, characterized in that: The same stack array is any one of the Stack array, the StackGuard1 array, or the StackGuard2 array.

6. A method for detecting a SIL4 stack applicable to a general operating system according to claim 1, characterized in that: The stack used by Fsafety and the Stack array declared by Finit are the same memory space.