CN108959085A - A kind of method and system detecting kernel module suspend mode mistake in atom context - Google Patents
A kind of method and system detecting kernel module suspend mode mistake in atom context Download PDFInfo
- Publication number
- CN108959085A CN108959085A CN201810711766.9A CN201810711766A CN108959085A CN 108959085 A CN108959085 A CN 108959085A CN 201810711766 A CN201810711766 A CN 201810711766A CN 108959085 A CN108959085 A CN 108959085A
- Authority
- CN
- China
- Prior art keywords
- function
- code
- atom
- context
- candidate functions
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/362—Software debugging
- G06F11/366—Software debugging using diagnostics
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/36—Preventing errors by testing or debugging software
- G06F11/362—Software debugging
- G06F11/3628—Software debugging of optimised code
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Hardware Design (AREA)
- Quality & Reliability (AREA)
- Software Systems (AREA)
- Debugging And Monitoring (AREA)
Abstract
The present invention provides a kind of method and system for detecting kernel module suspend mode mistake in atom context, which comprises is compiled to the source code of kernel module to be detected, obtains the intermediate code of the kernel module to be detected;Atom context used in the kernel module to be detected is obtained, static analysis is carried out to the intermediate code, obtains the function called in the atom context in the intermediate code, each function that the atom context is called is as candidate functions;If when judgement knows that the candidate functions call preset dormancy function, then reporting that there are suspend mode mistakes for calling of each candidate functions in the atom context according to calling figure of each candidate functions in operating system nucleus code.The present invention detects suspend mode mistake of the kernel module in atom context automatically, improves the efficiency and correctness of detection, to enhance the reliability of kernel module.
Description
Technical field
The invention belongs to computer operating systems and software testing technology field, more particularly, to a kind of detection kernel
The method and system of module suspend mode mistake in atom context.
Background technique
Component in modern operating system exists mostly in the form of kernel module, including driver, file system and network
Management program etc..In order to improve performance, kernel module often can be executed concurrently, and interrupt processing code can be used and come fastly
Speed response hardware interrupts.In both cases, in order to protect shared data contention access do not occur, kernel module usually makes
Data are protected with atom context.
Atom context is a kind of special kernel execution state, is embodied in two kinds of executive conditions: being obtained from
Rotation is locked and is executed in interrupt handling routine.In atom context, the thread of kernel module can monopolize a processor core
It executes, until the execution of atom context terminates.In the meantime, other threads in operating system are not available the processor core
The heart, and the processor core can only be waited to be occupied or executed using other processor cores by solution.If kernel module exists
Suspend mode in atom context, that is, abandon current processor core, then it is occupied and can not wake up to be likely to occur the processor core
The case where suspend mode thread, to cause system deadlock.However, due to the uncertainty that operating system concurrently executes, the deadlock feelings
Condition can't occur always in actual motion, so being difficult to be found at runtime.Therefore, it is necessary to kernel module in atom
Suspend mode mistake in context is effectively detected.
In order to detect such mistake, developer generally requires to read kernel module and operating system nucleus code manually, so
Afterwards according to the understanding to code come the case where checking each function call one by one.Since the size of code of kernel module is larger, code
The reasons such as logic is complicated, the function call number of plies is more, efficiently and accurately find out all behaviour of the kernel module in atom context
It makes comparisons difficulty.Moreover, it is judged that whether an operation in kernel module can generally require more rich kernel exploitation with suspend mode
Experience.In view of the above two o'clock, the method for detecting such mistake manually is often time-consuming and laborious, and is easy to appear problem.
Therefore, a kind of method for designing good automatic detection kernel module suspend mode mistake in atom context becomes behaviour
Make urgent problem to be solved in system development and test.
Summary of the invention
To overcome the method for above-mentioned existing detection kernel module suspend mode mistake in atom context time-consuming and laborious, and hold
It is also easy to produce the problem of mistake or at least is partially solved the above problem, the present invention provides a kind of detection kernel module on atom
The hereinafter method and system of suspend mode mistake.
According to the first aspect of the invention, a kind of side for detecting kernel module suspend mode mistake in atom context is provided
Method, comprising:
The source code of kernel module to be detected is compiled, the intermediate code of the kernel module to be detected is obtained;
Atom context used in the kernel module to be detected is obtained, static analysis is carried out to the intermediate code,
The function called in the atom context in the intermediate code is obtained, each letter that the atom context is called
Number is used as candidate functions;
If the candidate functions are known in judgement according to calling figure of each candidate functions in operating system nucleus code
When calling preset dormancy function, then report that there are suspend mode mistakes for calling of each candidate functions in the atom context.
A kind of system detecting kernel module suspend mode mistake in atom context, packet are provided according to a second aspect of the present invention
It includes:
Collector is compiled for the source code to kernel module to be detected, obtains the kernel module to be detected
Intermediate code;
Analysis module, for obtaining atom context used in the kernel module to be detected, to the intermediate code
Static analysis is carried out, the function called in the atom context in the intermediate code is obtained, by the atom context
Each function called is as candidate functions;
Module is checked, in the calling figure according to each candidate functions in operating system nucleus code, judgement to be obtained
When knowing that the candidate functions call preset dormancy function, then calling of each candidate functions in the atom context is reported
There are suspend mode mistakes.
The present invention provides a kind of method and system for detecting kernel module suspend mode mistake in atom context, and this method is logical
It crosses and static analysis is carried out to the intermediate code of kernel module to be detected, can accurately and efficiently find out from intermediate code in original
The function called in sub- context;This method checked using the function that function call graph calls atom context, can
Accurately judge whether the function that atom context calls can be with suspend mode, so that detection kernel module is in atom context automatically
Suspend mode mistake, the efficiency and correctness of detection are improved, to enhance the reliability of kernel module.
Detailed description of the invention
Fig. 1 is the method bulk flow of detection kernel module suspend mode mistake in atom context provided in an embodiment of the present invention
Journey schematic diagram;
Fig. 2 is that detection kernel module provided in an embodiment of the present invention is adaptive in the method for suspend mode mistake in atom context
Answer flow sensitive analysis flow diagram;
Fig. 3 is that the system of detection kernel module suspend mode mistake in atom context provided in an embodiment of the present invention is integrally tied
Structure schematic diagram;
Fig. 4 is electronic equipment overall structure diagram provided in an embodiment of the present invention.
Specific embodiment
With reference to the accompanying drawings and examples, specific embodiments of the present invention will be described in further detail.Implement below
Example is not intended to limit the scope of the invention for illustrating the present invention.
A kind of side for detecting kernel module suspend mode mistake in atom context is provided in one embodiment of the invention
Method, Fig. 1 are that detection kernel module method overall flow of suspend mode mistake in atom context provided in an embodiment of the present invention is shown
It is intended to, this method comprises: S101, is compiled the source code of kernel module to be detected, obtains in kernel module to be detected
Between code;
Wherein, kernel module to be detected is the kernel module for needing to carry out suspend mode error detection.Kernel module to be detected
Source code is usually write by C language, since the grammer of C language is flexible and form is changeable, so being difficult directly to carry out program to it
Analysis.Therefore, the present embodiment is compiled the source code of kernel module to be detected, and acquisition can be carried out directly in program analysis
Between code, be convenient for subsequent static analysis.
S102 obtains atom context used in kernel module to be detected, carries out static analysis to intermediate code, obtains
The function called in atom context in intermediate code, each function that atom context is called is as candidate functions;
Wherein, atom context is a kind of special kernel execution state, is embodied in two kinds of executive conditions: having obtained
It takes spin lock and is executed in interrupt handling routine.Static analysis is carried out to intermediate code to refer in the mode for not running code
Under, intermediate code is scanned by technologies such as morphological analysis, syntactic analysis, control stream, data-flow analysis, Validation Code is
A kind of no code analysis techniques for meeting the indexs such as normalization, safety, reliability, maintainability.Obtain kernel mould to be detected
Atom context used in block.Static analysis is carried out to intermediate code, is obtained all in atom context in intermediate code
The function of calling, as candidate functions.
S103, if the calling figure according to each candidate functions in operating system nucleus code, candidate functions tune is known in judgement
When with preset dormancy function, then report that there are suspend mode mistakes for calling of each candidate functions in atom context.
Wherein, each candidate functions are in the calling figure in operating system nucleus code between each candidate functions and other functions
Call relation.Preset dormancy function is the preset function that can cause suspend mode.By static analysis to each candidate letter
Calling figure of the number in operating system nucleus code is checked, judges whether each candidate functions call preset dormancy function.If
Each candidate functions have invoked preset dormancy function, then know that the candidate functions can be with suspend mode, and adjusted in atom context
With that is, there are suspend mode mistakes for calling of the candidate functions in atom context.Current embodiment require that providing kernel module to be measured
Source code, operating system nucleus code and preset dormancy function.
The present embodiment carries out static analysis by intermediate code to kernel module to be detected, can accurately and efficiently from
The function called in atom context is found out in intermediate code, the letter then called using function call graph to atom context
Number is checked can accurately judge whether the function that atom context calls can be with suspend mode, to detect kernel mould automatically
Suspend mode mistake of the block in atom context, improves the efficiency and correctness of detection, to enhance the reliability of kernel module.
On the basis of the above embodiments, the source code of kernel module to be detected is compiled in the present embodiment, is obtained
The intermediate code of kernel module to be detected, specific steps include: right respectively based on the front-end compiler in LLVM compiler framework
Each source code file of kernel module to be detected is compiled, and generates the intermediate code file of each source code file;Based on LLVM
Each intermediate code file mergences is an intermediate code file, from after merging by the code combiner in compiler framework
Between obtain intermediate code in code file.
Specifically, direct compilation is carried out to kernel module usually using GCC compiler, but GCC compiler can not the side of generation
Convenient for the intermediate code of program analysis.LLVM compiler framework completely can support C language to compile, and can generate convenient for journey
The intermediate code of sequence analysis.Therefore the present embodiment is compiled using source code of the LLVM compiler framework to kernel module to be detected
It translates.Firstly, literary to each source code of kernel module to be detected using the front-end compiler Clang that LLVM compiler framework provides
Part is compiled respectively, generates corresponding intermediate code file.Secondly, the code combiner provided using LLVM compiler framework
All intermediate code file mergencess are the intermediate code file of a totality by llvm-link, from overall intermediate code file
Middle acquisition intermediate code is convenient for subsequent static analysis.
On the basis of the above embodiments, static analysis is carried out to intermediate code in the present embodiment, obtained in intermediate code
The function called in atom context, specific steps include: the function to the operation for changing atom context in intermediate code
Flow sensitive analysis is carried out, the function for the operation for not changing atom context in intermediate code is carried out to flow insensitive analysis, is obtained
The function called in atom context in intermediate code.
Specifically, the present embodiment carries out self adaptation stream sensibility analysis to intermediate code.Specifically in intermediate code comprising changing
The function for becoming atom context operations carries out flow sensitive analysis, traverses all possible code path in function, changes to not including
The function for becoming atom context operations carries out flowing insensitive analysis, only traverses code all in function.The present embodiment by pair
Intermediate code carries out self adaptation stream sensibility analysis, takes into account the accuracy of flow sensitive analysis and flows the high efficiency of insensitive analysis, and
And both analytical technologies are reasonably selected and are used according to the logic of intermediate code, can accurately and efficiently analyze to
The intermediate code for surveying kernel module, to obtain the function that may be called in atom context in intermediate code.
On the basis of the above embodiments, the function for changing the operation of atom context in the present embodiment includes that spin lock obtains
Function and spin lock is taken to discharge function;Correspondingly, static analysis is carried out to intermediate code, obtained in intermediate code above and below atom
The function called in text, specific steps include that specific steps include that specific steps include: to obtain all spins in intermediate code
Lock the function call obtained and interrupt processing function, and obtain the code basic block where the function call that each spin lock obtains and
The entry code basic block of each interrupt processing function;
Wherein, the function call that spin lock obtains is for calling spin lock to obtain function.Spin lock obtain function be for
The function of spin lock is obtained, interrupt processing function is the function for carrying out interrupt processing.Static analysis is carried out to intermediate code
When, the function call position that the entrance of interrupt processing function and spin lock are obtained is as the entrance of static analysis.
The function call that each spin lock obtains is carried out according to the code basic block, spin lock stack and interrupt status at place quiet
State analysis carries out static analysis to each interrupt processing function according to entry code basic block, spin lock stack and institute's interrupt status, obtains
The function for taking atom context to be called;Wherein, when the function call obtained to each spin lock carries out static analysis, shape is interrupted
State is false;When carrying out static analysis to each interrupt processing function, interrupt status is true.
Specifically, the static analysis in the present embodiment is self adaptation stream sensibility analysis.Static point is being carried out to intermediate code
Maintenance breaks state and spin lock stack are needed during analysis.Wherein, interrupt status spins for identifying whether to interrupt
Lock stack is for identifying whether that spin lock, which can occur, obtains and discharge operation.When analyzing interrupt processing function, interrupt status is set as true.
When analyzing non-interrupted processing function, interrupt status is set as false.When the function for getting spin lock acquisition or release in analytic process
When calling, stacking or the Pop operations of corresponding spin lock stack are carried out.When interrupt status is true or spin lock stack is not sky,
Show the code of present analysis in atom context.
The following are the pseudocodes of self adaptation stream sensibility analysis algorithm:
Wherein, the number before every line code is line number.The algorithm maintains three information in the analysis process: interrupting shape
State intr_flag, spin lock stack lock_stack and code path information path_info.The algorithm has used two subalgorithms
HanCall and HanBlock, wherein HanCall is for handling function call, and HanBlock is for handling code basic block.From
Adapting to flow sensitive analysis algorithm mainly has three steps:
(1) the set lock_call_set of the function call of spin lock acquisition and the set of interrupt processing function are found out
intr_func_set。
(2) each function call lock_call in lock_call_set is handled.Function call place is obtained first
Code basic block block, then by spin lock stack lock_stack and analyzed code path information path_info and emptied,
Interrupt status intr_flag is set as false.Subalgorithm HanBlock is recycled to handle code basic block block, and by lock_
Stack, intr_flag and path_info are incoming as parameter.
(3) each interrupt processing function intr_func in intr_func_set is handled.Entering for the function is obtained first
Then mouthful code basic block entry_block by spin lock stack lock_stack and has analyzed code path information path_info
It empties, interrupt status intr_flag is set as true.Subalgorithm HanBlock is recycled to handle entry code basic block entry_
Block, and be passed to lock_stack, intr_flag and path_info as parameter.
On the basis of the above embodiments, according to the code basic block at place, spin lock stack and interruption shape in the present embodiment
State carries out static analysis to the function call that each spin lock obtains, if specific steps include: each letter in the code basic block at place
Number calls spin lock to obtain function, then carries out stack-incoming operation to spin lock stack;If each function in the code basic block at place
It calls spin lock to discharge function, then Pop operations is carried out to spin lock stack;If spin lock stack is not null value or interrupt status
It is that very, then the function that each function call is called in the code basic block where knowing is called by atom context.
Specifically, the following are the pseudocodes of subalgorithm HanBlock:
Wherein, the number before every line code is line number.The subalgorithm is used to handle code basic block myblock, and will
Spin lock stack lock_stack, interrupt status intr_flag and analyzed code path information path_info as input ginseng
Number.Firstly, the subalgorithm checks whether myblock exists in path_info, if it is present directly return, thus
Avoid duplicate analysis;Otherwise myblock is added in path_info.Then, using every in subalgorithm processing myblock
A function call func_call.If func_call has invoked spin lock and obtains function, to spin lock stack lock_stack
Carry out stack-incoming operation;If func_call has invoked spin lock release function, pop to spin lock stack lock_stack
Operation;If func_call is not the relevant function of the above two classes spin lock, func_ is handled using subalgorithm HanCall
call.After again, the subalgorithm judge spin lock stack lock_stack whether be empty and interrupt status intr_flag whether be
Vacation, if it is, the code for knowing present analysis then directly returns not in atom context.Finally, the subalgorithm recurrence makes
The subsequent code basic block of each of myblock is handled with HanBlock.
The following are the pseudocodes of subalgorithm HanCall:
Wherein, the number before every line code is line number.The subalgorithm is used to handle function call mycall, and will spin
Lock stack lock_stack, interrupt status intr_flag and the code path information path_info searched for are as input parameter.
Firstly, the subalgorithm judges whether spin lock stack lock_stack is whether empty and interrupt status intr_flag is false, if
It is then to prove that the code of present analysis not in atom context, directly returns.Then, which obtains mycall calling
Function myfunc, and recorded using the function as candidate functions.After again, which handles function myfunc, and
According to it includes function call situation judge using flow sensitive analysis or the insensitive analysis of stream.If function myfunc packet
Containing acquisition/release spin lock function call, then prove that function myfunc includes the operation for changing atom context, it is therefore desirable to
Carry out flow sensitive analysis.Specifically, the entry code basic block entry_block of function myfunc is obtained, then using son
Algorithm HanBlock is analyzed it.Otherwise, it carries out flowing insensitive analysis, i.e. recurrence is handled using subalgorithm HanCall
Each function call in myfunc.
For example, the source code of one section of exemplary kernel module to be detected presented below:
Wherein, the number before every line code is line number.The source code of kernel module to be detected include function MyFunc,
FuncA and FuncB, wherein MyFunc has invoked FuncA and FuncB, and MyFunc and FuncB have invoked spin lock and obtain function
Spin_lock and spin lock discharge function spin_unlock, need to carry out flow sensitive analysis to MyFunc and FuncB.FuncA
The relevant function of spin lock is not called, so needing to carry out FuncA to flow insensitive analysis.Fig. 2 is illustrated with function
MyFunc is the static analysis process of entrance, and indicated with function call Path form, digital representation pair in interior joint
The code line number answered.In Fig. 2, the node in dotted line frame 1 is function MyFunc, and the node in dotted line frame 2 is function FuncA, empty
Node in wire frame 3 is function FuncB.Function MyFunc has invoked spin lock in the 5th row and obtains function spin_lock, so
It needs to carry out stack-incoming operation to spin lock stack;Function FuncB has invoked spin lock release function spin_unlock in the 24th row,
So needing since spin lock stack is sky at this time, then directly to return, no longer analyze to Pop operations are carried out in spin lock stack
Subsequent path in FuncB function.Finally according to self adaptation stream sensibility analysis algorithm, analyzed using function MyFunc as entrance
When, only need to analyze two useful function call paths, such as the solid line with the arrow in Fig. 2, and be omitted other two it is useless
Function call path, as the dotted line with the arrow in Fig. 2 effectively increases algorithm to reduce useless route searching
Analysis efficiency.
Self adaptation stream sensibility analysis algorithm in the present embodiment has taken into account the accuracy and insensitive point of stream of flow sensitive analysis
The high efficiency of analysis, so as to accurately and efficiently analyze the code of tested kernel module.
On the basis of the above embodiments, according to the code basic block at place, spin lock stack and interruption shape in the present embodiment
The step of state carries out static analysis to the function call that each spin lock obtains further include: if each function in the code basic block at place
Calling called function is not that spin lock obtains function or spin lock release function, then to each letter in the code basic block at place
Number calls each function call in called function to carry out static analysis.
On the basis of the above embodiments, according to the code basic block at place, spin lock stack and interruption shape in the present embodiment
The step of state carries out static analysis to the function call that each spin lock obtains further include: if the code basic block at place is being analyzed
Exist in code path information, then directly returns;If the code basic block at place is not present in having analyzed code path information,
Then the routing information of the code basic block at place is added to and has been analyzed in code path information.
On the basis of the various embodiments described above, in the present embodiment according to each candidate functions in operating system nucleus code
Calling figure then reports tune of each candidate functions in atom context when judgement knows that candidate functions call preset dormancy function
If being preset dormancy function with including: each candidate functions there are suspend mode mistake specific steps, report each candidate functions on atom
There are suspend mode mistakes for calling hereinafter;If each candidate functions exist in function cache table, according to each in function cache table
The label of candidate functions reports calling of each candidate functions in atom context with the presence or absence of suspend mode mistake;If each candidate's letter
Number is not present in function cache table, then the function called to each function call in each candidate functions carries out static analysis, and
Each function call is called in each candidate functions, each candidate functions function and analysis result are added in function cache table.
Specifically, the following are the pseudocodes that function suspend mode checks algorithm:
Wherein, the number before every line code is line number.The algorithm has used the insensitive analysis of stream, according in operating system
Core code, come check given function myfunc whether can suspend mode, and used a function cache table duplicate to reduce
It checks.Firstly, the algorithm judge myfunc whether be it is basic can be with the function of suspend mode, if it is, returning true.Then, should
Algorithm can check myfunc whether in function cache table, if, returned according to the label result in cache table it is true or
Person is false.After again, each function call call in algorithm meeting circular test myfunc, and obtain the function of call calling
Func, then recurrence check func using CheckFunc.If return value is that very, representative function func can then will with suspend mode
Myfunc is added in function cache table, and marks it can be with suspend mode, and return very, indicates that myfunc can be with suspend mode.Finally, such as
Fruit circulation in do not return, then it represents that myfunc will not suspend mode, then myfunc is added in function cache table, and mark it not
Meeting suspend mode, and return to vacation.
Check that algorithm carries out flowing insensitive analysis based on function suspend mode in the present embodiment, it being capable of rapidly and accurately discriminant function
Whether can be with suspend mode, and rechecking is reduced using function cache table, to effectively improve inspection efficiency.
On the basis of the various embodiments described above, calling of each candidate functions in atom context is being reported in the present embodiment
There are after suspend mode mistake further include: the title of the source code file where the calling path of candidate functions, candidate functions
With line number of the candidate functions in source code file, generation error report.
Wherein, error reporting generated contains the source code text of candidate functions called where path, candidate functions
Line number of the title and candidate functions of part in source code file, to facilitate developer and tester to read and check.
A kind of detection kernel module suspend mode mistake in atom context is provided in another embodiment of the present invention
System, Fig. 3 are the overall system architecture of detection kernel module suspend mode mistake in atom context provided in an embodiment of the present invention
Schematic diagram, the system include collector 301, analysis module 302 and inspection module 303;Wherein:
Collector 301 obtains the kernel mould to be detected for being compiled to the source code of kernel module to be detected
The intermediate code of block;Analysis module 302 is for obtaining atom context used in the kernel module to be detected, in described
Between code carry out static analysis, the function called in the atom context in the intermediate code is obtained, by the atom
Each function that context calls is as candidate functions;Check module 303 for operating according to each candidate functions
Calling figure in system kernel code when judgement knows that the candidate functions call preset dormancy function, reports each candidate
There are suspend mode mistakes for calling of the function in the atom context.
On the basis of the above embodiments, collector is specifically used in the present embodiment: based in LLVM compiler framework
Front-end compiler each source code file of the kernel module to be detected is compiled respectively, generate each source code text
The intermediate code file of part;Based on the code combiner in the LLVM compiler framework, each intermediate code file is closed
And be an intermediate code file, intermediate code is obtained from the intermediate code file after merging.
On the basis of the above embodiments, analysis module is specifically used in the present embodiment: to changing in the intermediate code
The function of the operation of the atom context carries out flow sensitive analysis, to not changing the atom context in the intermediate code
The function of operation carry out flowing insensitive analysis, obtain the function called in the atom context in the intermediate code.
On the basis of the above embodiments, the function for changing the operation of the atom context in the present embodiment includes spin
Lock obtains function and spin lock discharges function;Correspondingly, analysis module is specifically used for: obtaining all spins in the intermediate code
The function call obtained and interrupt processing function are locked, and the code where obtaining the function call that each spin lock obtains is basic
The entry code basic block of block and each interrupt processing function;According to the code basic block, spin lock stack and institute at the place
It states the function call that interrupt status obtains each spin lock and carries out static analysis, according to the entry code basic block, institute
It states spin lock stack and institute's interrupt status and static analysis is carried out to each interrupt processing function, obtain the atom context and adjusted
Function;Wherein, when the function call obtained to each spin lock carries out static analysis, the interrupt status is true;
When carrying out static analysis to each interrupt processing function, the interrupt status is false.
On the basis of the above embodiments, analysis module is further used in the present embodiment: if the code base at the place
The called spin lock of each function call in this block obtains function, then carries out stack-incoming operation to spin lock stack;If the place
The called spin lock of each function call in code basic block discharges function, then carries out Pop operations to the spin lock stack;If
The spin lock stack is not null value or the interrupt status is very, then to know each function call in the code basic block at the place
The function called is called by the atom context.
On the basis of the above embodiments, analysis module is also used in the present embodiment: if the code basic block at the place
In the function that is called of each function call be not that the spin lock obtains function or spin lock release function, then to the institute
Code basic block in the function that is called of each function call each function call carry out static analysis.
On the basis of the above embodiments, analysis module is also used in the present embodiment: if the code basic block at the place
Exist in having analyzed code path information, then directly returns;If the code basic block at the place is analyzing code path
It is not present in information, then the routing information of the code basic block at the place is added to and described has analyzed code path information
In.
Check that module is specifically used on the basis of the various embodiments described above, in the present embodiment: if for suspend mode false judgment
Each candidate functions be preset dormancy function, report that the calling of each candidate functions in the atom context exists
Suspend mode mistake;If each candidate functions exist in function cache table, according to each candidate functions in the function cache table
Label, report that the calling of each candidate functions in the atom context whether there is suspend mode mistake;If each time
Select function to be not present in the function cache table, then using each function call is called in each candidate functions function as
It is used for the candidate functions of suspend mode false judgment next time.
It further include generation module in the present embodiment on the basis of the various embodiments described above, for according to the candidate functions
Call path, the title of source code file where the candidate functions and the candidate functions in the source code file
Line number, generation error report.
The present embodiment carries out static analysis by intermediate code to kernel module to be detected, can accurately and efficiently from
The function called in atom context is found out in intermediate code, the letter then called using function call graph to atom context
Number is checked can accurately judge whether the function that atom context calls can be with suspend mode, to detect kernel mould automatically
Suspend mode mistake of the block in atom context, improves the efficiency and correctness of detection, to enhance the reliability of kernel module.
The present embodiment provides a kind of electronic equipment, Fig. 4 is electronic equipment overall structure provided in an embodiment of the present invention signal
Figure, which includes: at least one processor 401, at least one processor 402 and bus 403;Wherein,
Processor 401 and memory 402 pass through bus 403 and complete mutual communication;
Memory 402 is stored with the program instruction that can be executed by processor 401, and the instruction of processor caller is able to carry out
Method provided by above-mentioned each method embodiment, for example, the source code of kernel module to be detected is compiled, obtain to
Detect the intermediate code of kernel module;Atom context used in kernel module to be detected is obtained, intermediate code is carried out quiet
State analysis obtains the function called in atom context in intermediate code, and each function that atom context is called is as time
Select function;If knowing that candidate functions call default stop according to calling figure judgement of each candidate functions in operating system nucleus code
Dormancy function then reports that there are suspend mode mistakes for calling of each candidate functions in atom context.
The present embodiment provides a kind of non-transient computer readable storage medium, non-transient computer readable storage medium storages
Computer instruction, computer instruction make computer execute method provided by above-mentioned each method embodiment, for example, to be checked
The source code for surveying kernel module is compiled, and obtains the intermediate code of kernel module to be detected;Obtain kernel module institute to be detected
The atom context used carries out static analysis to intermediate code, obtains the letter called in atom context in intermediate code
Number, each function that atom context is called is as candidate functions;If according to each candidate functions in operating system nucleus code
Calling figure, judgement know candidate functions call preset dormancy function when, then report each candidate functions in atom context
There are suspend mode mistakes for calling.
Those of ordinary skill in the art will appreciate that: realize that all or part of the steps of above method embodiment can pass through
The relevant hardware of program instruction is completed, and program above-mentioned can be stored in a computer readable storage medium, the program
When being executed, step including the steps of the foregoing method embodiments is executed;And storage medium above-mentioned includes: ROM, RAM, magnetic disk or light
The various media that can store program code such as disk.
Electronic equipment embodiment described above is only schematical, wherein unit can as illustrated by the separation member
It is physically separated with being or may not be, component shown as a unit may or may not be physics list
Member, it can it is in one place, or may be distributed over multiple network units.It can be selected according to the actual needs
In some or all of the modules achieve the purpose of the solution of this embodiment.Those of ordinary skill in the art are not paying creativeness
Labour in the case where, it can understand and implement.
Through the above description of the embodiments, those skilled in the art can be understood that each embodiment can
It realizes by means of software and necessary general hardware platform, naturally it is also possible to pass through hardware.Based on this understanding, on
Stating technical solution, substantially the part that contributes to existing technology can be embodied in the form of software products in other words, should
Computer software product may be stored in a computer readable storage medium, such as ROM/RAM, magnetic disk, CD, including several fingers
It enables and using so that a computer equipment (can be personal computer, server or the network equipment etc.) executes each implementation
The method of certain parts of example or embodiment.
Finally, the present processes are only preferable embodiment, it is not intended to limit the scope of the present invention.It is all
Within the spirit and principles in the present invention, any modification, equivalent replacement, improvement and so on should be included in protection of the invention
Within the scope of.
Claims (10)
1. a kind of method for detecting kernel module suspend mode mistake in atom context characterized by comprising
The source code of kernel module to be detected is compiled, the intermediate code of the kernel module to be detected is obtained;
Atom context used in the kernel module to be detected is obtained, static analysis is carried out to the intermediate code, is obtained
The function called in the atom context in the intermediate code, each function that the atom context is called are made
For candidate functions;
If judgement knows that the candidate functions are called according to calling figure of each candidate functions in operating system nucleus code
When preset dormancy function, then report that there are suspend mode mistakes for calling of each candidate functions in the atom context.
2. being obtained the method according to claim 1, wherein being compiled to the source code of kernel module to be detected
The intermediate code of the kernel module to be detected is taken, specific steps include:
Based on the front-end compiler in LLVM compiler framework respectively to each source code file of the kernel module to be detected into
Row compiling, generates the intermediate code file of each source code file;
It is an intermediate generation by each intermediate code file mergences based on the code combiner in the LLVM compiler framework
Code file, obtains intermediate code from the intermediate code file after merging.
3. the method according to claim 1, wherein to intermediate code progress static analysis, described in acquisition
The function called in the atom context in intermediate code, specific steps include:
Flow sensitive analysis is carried out to the function for the operation for changing the atom context in the intermediate code, to the intermediate generation
The function for the operation for not changing the atom context in code carries out flowing insensitive analysis, obtains in the intermediate code described
The function called in atom context.
4. according to the method described in claim 3, it is characterized in that, the function for changing the operation of the atom context includes certainly
Rotation lock obtains function and spin lock discharges function;
Correspondingly, static analysis is carried out to the intermediate code, obtains in the intermediate code and is adjusted in the atom context
Function, specific steps include:
The function call and interrupt processing function that all spin locks obtain in the intermediate code are obtained, and obtains each spin
The entry code basic block of code basic block and each interrupt processing function where the function call that lock obtains;
The function tune that each spin lock is obtained according to the code basic block, spin lock stack and the interrupt status at the place
With carrying out static analysis, according to the entry code basic block, the spin lock stack and institute's interrupt status to each interruption at
It manages function and carries out static analysis, obtain the function that the atom context is called;
Wherein, when the function call obtained to each spin lock carries out static analysis, the interrupt status is false;
When carrying out static analysis to each interrupt processing function, the interrupt status is true.
5. according to the method described in claim 4, it is characterized in that, according to the code basic block at the place, spin lock stack and
The interrupt status, the function call obtained to each spin lock carry out static analysis, and specific steps include:
If each function call calls spin lock to obtain function in the code basic block at the place, stacking is carried out to spin lock stack
Operation;
If each function call calls spin lock to discharge function in the code basic block at the place, the spin lock stack is carried out
Pop operations;
If the spin lock stack is not null value or the interrupt status is very, to know each letter in the code basic block at the place
Number calls called function to be called by the atom context.
6. according to the method described in claim 5, it is characterized in that, according to the code basic block at the place, spin lock stack and
The interrupt status, the step of static analysis is carried out to the function call that each spin lock obtains further include:
If the function that each function call is called in the code basic block at the place is not that the spin lock obtains function or institute
State spin lock release function, then each function call in the function called to each function call in the code basic block at the place
Carry out static analysis.
7. according to the method described in claim 4, it is characterized in that, according to the code basic block at the place, spin lock stack and
The interrupt status, the step of static analysis is carried out to the function call that each spin lock obtains further include:
If the code basic block at the place exists in having analyzed code path information, directly return;
If the code basic block at the place is not present in having analyzed code path information, and the code at the place is basic
The routing information of block is added to described analyzed in code path information.
8. -7 any method according to claim 1, which is characterized in that according to each candidate functions in operating system
Calling figure in core code then reports each candidate functions when judgement knows that the candidate functions call preset dormancy function
There are suspend mode mistake, specific steps include: calling in the atom context
If each candidate functions are preset dormancy function, calling of each candidate functions in the atom context is reported
There are suspend mode mistakes;
If each candidate functions exist in function cache table, according to the mark of each candidate functions in the function cache table
Note reports that calling of each candidate functions in the atom context whether there is suspend mode mistake;
If each candidate functions are not present in the function cache table, to function call institute each in each candidate functions
The function of calling carries out static analysis, and each function call in each candidate functions, each candidate functions is called
Function and analysis result are added in the function cache table.
9. -7 any method according to claim 1, which is characterized in that reporting each candidate functions in the atom
There are after suspend mode mistake for calling in context further include:
The title of source code file where the calling path of the candidate functions, the candidate functions and the candidate letter
Line number of the number in the source code file, generation error report.
10. a kind of system for detecting kernel module suspend mode mistake in atom context characterized by comprising
Collector is compiled for the source code to kernel module to be detected, is obtained in the kernel module to be detected
Between code;
Analysis module carries out the intermediate code for obtaining atom context used in the kernel module to be detected
Static analysis obtains the function called in the atom context in the intermediate code, and the atom context is called
Each function as candidate functions;
Module is checked, in the calling figure according to each candidate functions in operating system nucleus code, institute to be known in judgement
When stating candidate functions calling preset dormancy function, then report that calling of each candidate functions in the atom context exists
Suspend mode mistake.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810711766.9A CN108959085B (en) | 2018-06-25 | 2018-06-25 | Method and system for detecting sleep error of kernel module in atomic context |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810711766.9A CN108959085B (en) | 2018-06-25 | 2018-06-25 | Method and system for detecting sleep error of kernel module in atomic context |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108959085A true CN108959085A (en) | 2018-12-07 |
CN108959085B CN108959085B (en) | 2020-09-01 |
Family
ID=64484902
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810711766.9A Active CN108959085B (en) | 2018-06-25 | 2018-06-25 | Method and system for detecting sleep error of kernel module in atomic context |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108959085B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112527302A (en) * | 2019-09-19 | 2021-03-19 | 北京字节跳动网络技术有限公司 | Error detection method and device, terminal and storage medium |
Citations (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101403979A (en) * | 2008-10-27 | 2009-04-08 | 成都市华为赛门铁克科技有限公司 | Locking method for self-spinning lock and computer system |
US20110154297A1 (en) * | 2009-12-21 | 2011-06-23 | International Business Machines Corporation | Dynamic instrumentation |
CN102222015A (en) * | 2010-04-13 | 2011-10-19 | 三星电子(中国)研发中心 | System and method for detecting deadlock in multithreaded program |
CN102819466A (en) * | 2012-06-29 | 2012-12-12 | 华为技术有限公司 | Method and device for processing operating system exceptions |
CN103399818A (en) * | 2013-08-13 | 2013-11-20 | 中国科学技术大学苏州研究院 | Deadlock detection method in operating system |
CN103605921A (en) * | 2013-10-28 | 2014-02-26 | 清华大学 | Kernel extension safety access method and device |
US8875107B2 (en) * | 2009-03-24 | 2014-10-28 | International Business Machines Corporation | Component lock tracing by associating component type parameters with particular lock instances |
CN104317723A (en) * | 2014-11-14 | 2015-01-28 | 清华大学 | Method and system for tracking running information of drive program |
CN104603750A (en) * | 2012-08-30 | 2015-05-06 | 微软公司 | Layout and execution of software applications using BPRAM |
CN104899111A (en) * | 2015-06-09 | 2015-09-09 | 烽火通信科技股份有限公司 | Method and system for dealing with kernel panic of home gateway system |
CN105159807A (en) * | 2015-09-06 | 2015-12-16 | 浪潮(北京)电子信息产业有限公司 | Method for detecting potential sector errors |
CN106294137A (en) * | 2016-08-01 | 2017-01-04 | 浪潮(北京)电子信息产业有限公司 | A kind of linux User space spin lock deadlock detection method and system |
-
2018
- 2018-06-25 CN CN201810711766.9A patent/CN108959085B/en active Active
Patent Citations (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101403979A (en) * | 2008-10-27 | 2009-04-08 | 成都市华为赛门铁克科技有限公司 | Locking method for self-spinning lock and computer system |
US8875107B2 (en) * | 2009-03-24 | 2014-10-28 | International Business Machines Corporation | Component lock tracing by associating component type parameters with particular lock instances |
US20110154297A1 (en) * | 2009-12-21 | 2011-06-23 | International Business Machines Corporation | Dynamic instrumentation |
CN102222015A (en) * | 2010-04-13 | 2011-10-19 | 三星电子(中国)研发中心 | System and method for detecting deadlock in multithreaded program |
CN102819466A (en) * | 2012-06-29 | 2012-12-12 | 华为技术有限公司 | Method and device for processing operating system exceptions |
CN104603750A (en) * | 2012-08-30 | 2015-05-06 | 微软公司 | Layout and execution of software applications using BPRAM |
CN103399818A (en) * | 2013-08-13 | 2013-11-20 | 中国科学技术大学苏州研究院 | Deadlock detection method in operating system |
CN103605921A (en) * | 2013-10-28 | 2014-02-26 | 清华大学 | Kernel extension safety access method and device |
CN104317723A (en) * | 2014-11-14 | 2015-01-28 | 清华大学 | Method and system for tracking running information of drive program |
CN104899111A (en) * | 2015-06-09 | 2015-09-09 | 烽火通信科技股份有限公司 | Method and system for dealing with kernel panic of home gateway system |
CN105159807A (en) * | 2015-09-06 | 2015-12-16 | 浪潮(北京)电子信息产业有限公司 | Method for detecting potential sector errors |
CN106294137A (en) * | 2016-08-01 | 2017-01-04 | 浪潮(北京)电子信息产业有限公司 | A kind of linux User space spin lock deadlock detection method and system |
Non-Patent Citations (2)
Title |
---|
FLY晴天里FLY: "深入理解各种锁", 《HTTPS://WWW.JIANSHU.COM/P/5725DB8F07DC》 * |
HP0773: "BUG: sleeping function called from invalid context at ......(might_sleep函数说明)", 《HTTPS://BLOG.CSDN.NET/HP0773/ARTICLE/DETAILS/12658501》 * |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112527302A (en) * | 2019-09-19 | 2021-03-19 | 北京字节跳动网络技术有限公司 | Error detection method and device, terminal and storage medium |
CN112527302B (en) * | 2019-09-19 | 2024-03-01 | 北京字节跳动网络技术有限公司 | Error detection method and device, terminal and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN108959085B (en) | 2020-09-01 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10558554B2 (en) | Machine learning based software correction | |
US20190205106A1 (en) | Partitioning based migration of systems to container and microservice based platforms | |
US9612937B2 (en) | Determining relevant events in source code analysis | |
US8468499B2 (en) | Directed testing for property violations | |
JP6369736B2 (en) | Alarm type classification method in error detection of source code, computer program therefor, and recording medium therefor | |
CN109033843B (en) | Java file dependency analysis method and module for distributed static detection system | |
US11567126B2 (en) | Methods and systems for fault injection testing of an integrated circuit hardware design | |
EP1236110A1 (en) | A method for isolating a fault from error messages | |
CN108491228A (en) | A kind of binary vulnerability Code Clones detection method and system | |
CN108804326A (en) | A kind of software code automatic testing method | |
CN104090798A (en) | Dynamic and static combined interrupt drive program data race detection method | |
CN112306841B (en) | Automatic testing method, device and equipment for track service | |
CN108959085A (en) | A kind of method and system detecting kernel module suspend mode mistake in atom context | |
CN106155880B (en) | A kind of automated procedures analysis system and method based on strategy | |
US7210128B2 (en) | Event-driven observability enhanced coverage analysis | |
CN114047913A (en) | Counter-example-guided sparse spatial flow model detection method and system | |
US6704912B2 (en) | Method and apparatus for characterizing information about design attributes | |
CN112395199B (en) | Distributed software instance testing method based on cloud computing and software development platform | |
US20220075875A1 (en) | Language-independent application monitoring through aspect-oriented programming | |
US8010477B2 (en) | Integrated problem solving system | |
CN113626823A (en) | Reachability analysis-based inter-component interaction threat detection method and device | |
CN110244954A (en) | A kind of Compilation Method and equipment of application program | |
CN113961475B (en) | Protocol-oriented error processing defect detection method and system | |
Dwyer | Modular flow analysis for concurrent software | |
KR101694778B1 (en) | False alarm reducing method in finding potential bug in a source code, computer program for the same, recording medium storing computer program for the same |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |