CN108009429A - A kind of patch function generation method and device - Google Patents

A kind of patch function generation method and device Download PDF

Info

Publication number
CN108009429A
CN108009429A CN201711311047.XA CN201711311047A CN108009429A CN 108009429 A CN108009429 A CN 108009429A CN 201711311047 A CN201711311047 A CN 201711311047A CN 108009429 A CN108009429 A CN 108009429A
Authority
CN
China
Prior art keywords
lock
source code
patch
function
instruction
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
Application number
CN201711311047.XA
Other languages
Chinese (zh)
Other versions
CN108009429B (en
Inventor
刘天
张建新
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Qihoo Technology Co Ltd
Original Assignee
Beijing Qihoo Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Beijing Qihoo Technology Co Ltd filed Critical Beijing Qihoo Technology Co Ltd
Priority to CN201711311047.XA priority Critical patent/CN108009429B/en
Publication of CN108009429A publication Critical patent/CN108009429A/en
Application granted granted Critical
Publication of CN108009429B publication Critical patent/CN108009429B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/57Certifying or maintaining trusted computer platforms, e.g. secure boots or power-downs, version controls, system software checks, secure updates or assessing vulnerabilities

Abstract

The embodiment of the present invention provides a kind of patch function generation method and device, the described method includes:Corresponding first source code of object function for treating patch installing is obtained, and obtains corresponding second source code of patch function;Based on the first source code and the second source code, competitive resource existing between object function and patch function is determined;According to kernel lock mechanism, competitive resource corresponding first lock in object function is determined from the first source code;According to preset strategy, based on the first lock, the second source code is handled, obtains the patch function after the processing comprising the first lock, wherein, the patch function after processing can be run in kernel at the same time with object function.In this way, due to including the first lock in the patch function after processing, it is that can be run at the same time in kernel with treating the object function of patch installing, thus, it is possible to realize in the case of non-stop-machine, which is replaced with into the patch function after processing.

Description

A kind of patch function generation method and device
Technical field
The present invention relates to computer realm, more particularly to a kind of patch function generation method and device.
Background technology
Kernel is the core of operating system, is responsible for process, memory, device driver, file and the network of system System etc., decides the performance and stability of system.There is defect in kernel, during such as security breaches, if the kernel defect quilt Illegal molecule utilize, it is likely that occur loss of data or distort, privacy of user leakage the problems such as so that, be easy to cause to Bring economy, emotional distress in family.In practical applications, the defects of generally use kernel hot patch technology is to repair kernel, comes real Now avoid system reboot from causing service disconnection, ensure the security and availability of kernel.
At present, existing kernel hot patch technology mainly has following two types:The first, one is used when system starts A kernel, when the object function of patch installing is not carried out, is first suspending the kernel in detecting kernel, then by the target letter Number replaces with corresponding patch function.Second, two kernels are used when system starts, wherein, the first kernel is in dormancy State, the second kernel are in run mode, first, the object function in the first kernel in dormant state are replaced with patch function, Then, then two kernels are switched, the first kernel allowed where the object function for carrying out patch installing operation is entered from dormant state Run mode, allows the second kernel of the object function for not carrying out patch installing operation to enter dormant state from run mode, finally, will locate Object function in the second kernel of dormant state replaces with patch function.
But inventor has found during above-mentioned patch installing operation is performed:Above two method is mainly by true Protect object function and its corresponding patch function only has one running, patch installing operation is carried out to object function to realize.Can See, at least there are the following problems in the prior art:When to object function patch installing, it is necessary to assure object function is not being held OK, it can not realize and object function is replaced with into patch function not shutting down, the process of patch installing is not convenient enough.
The content of the invention
In view of this, the embodiment of the present invention provides a kind of patch function generation method and device, main purpose and is, right Before treating that the object function of patch installing carries out patch installing operation, the corresponding patch function of the object function is handled in advance, The patch function after the processing that can be run at the same time in kernel with object function is obtained, in this way, object function is replaced with this During patch function after processing, just dormant state is in without kernel.
To reach above-mentioned purpose, the embodiment of the present invention mainly provides following technical solution:
In a first aspect, the embodiment of the present invention provides a kind of patch function generation method, the described method includes:Obtain to wait to beat and mend Corresponding first source code of object function of fourth, and corresponding second source code of patch function is obtained, wherein, the patch function It is corresponding with the object function;Based on first source code and second source code, the object function and institute are determined State existing competitive resource between patch function;According to kernel lock mechanism, determined from first source code described competing Strive resource corresponding first lock in the object function;According to preset strategy, based on the described first lock, to second source generation Code is handled, and obtains the patch function after the processing comprising the described first lock, wherein, the patch function after the processing can Run at the same time in kernel with the object function.
Second aspect, the embodiment of the present invention provide a kind of patch function generating means, and described device includes:First obtains list Member, the first determination unit, the second determination unit and processing unit, wherein, the first obtains unit, is mended for obtaining to wait to beat Corresponding first source code of object function of fourth, and corresponding second source code of patch function is obtained, wherein, the patch function It is corresponding with the object function;First determination unit, for based on first source code and second source code, really Make competitive resource existing between the object function and the patch function;Second determination unit, for basis Kernel lock mechanism, determines the competitive resource corresponding first lock in the object function from first source code; The processing unit, for according to preset strategy, based on the described first lock, handling second source code, being wrapped Patch function after processing containing the described first lock, wherein, the patch function after the processing can be same with the object function When run in kernel.
The third aspect, the embodiment of the present invention provide a kind of storage medium, and the storage medium includes the program of storage, its In, equipment where the storage medium is controlled when described program is run performs above-mentioned patch function generation method.
Fourth aspect, the embodiment of the present invention provide a kind of processor, and the processor is used for operation program, wherein, it is described Program performs above-mentioned patch function generation method when running.
A kind of patch function generation method provided in an embodiment of the present invention and device, the object function of patch installing is treated in acquisition Corresponding first source code, and obtain the second source code corresponding to treating the corresponding patch function of patch installing object function with this Afterwards, it is possible to based on the first source code and the second source code, determine competition existing between object function and patch function Resource, then, according to kernel lock mechanism, determines competitive resource corresponding first in object function from the first source code Lock, finally, according to preset strategy, based on the first lock, is handled the second source code, after obtaining the processing comprising the first lock Patch function.In this way, due to treat patch installing object function carry out patch installing operation before, previously according to competitive resource pair The first lock answered, handles the corresponding patch function of the object function, obtains the benefit after the processing comprising the first lock Fourth function so that the patch function after processing can be run in kernel at the same time with object function, then, after the processing When patch function carries out patch installing operation to the object function, pause kernel is avoided the need for or need not be by kernel from run mode Dormant state is switched to, thus, it is possible to realize in the case of non-stop-machine, object function is replaced with to the patch letter after the processing Number.
Brief description of the drawings
By reading the detailed description of hereafter preferred embodiment, it is various other the advantages of and benefit it is common for this area Technical staff will be clear understanding.Attached drawing is only used for showing the purpose of preferred embodiment, and is not considered as to the present invention Limitation.And in whole attached drawing, identical component is denoted by the same reference numerals.In the accompanying drawings:
Fig. 1 shows the flow diagram of the patch function generation method in the embodiment of the present invention one;
Fig. 2 shows the flow diagram of the patch function generation method in the embodiment of the present invention two;
Fig. 3 shows the structure diagram of the patch function generating means in the embodiment of the present invention three;
Fig. 4 shows the structure diagram of the patch function generation equipment in the embodiment of the present invention four.
Embodiment
The exemplary embodiment of the present invention is more fully described below with reference to accompanying drawings.Although the present invention is shown in attached drawing Exemplary embodiment, it being understood, however, that may be realized in various forms the present invention without should be by embodiments set forth here Limited.Conversely, there is provided these embodiments are to be able to be best understood from the present invention, and can be by the scope of the present invention Completely it is communicated to those skilled in the art.
Embodiment one
The embodiment of the present invention provides a kind of patch function generation method, which can be applied to various Need the object function for treating patch installing to carry out the occasion of patch installing operation, run mode is in such as kernel defect repair, in kernel When object function in the kernel is updated.
Fig. 1 be the embodiment of the present invention one in patch function generation method flow diagram, shown in Figure 1, the benefit Fourth function generation method includes:
S101:Corresponding first source code of object function for treating patch installing is obtained, and obtains patch function corresponding second Source code;
Wherein, patch function is corresponding with object function.
In practical applications, when need in the case of non-stop-machine, such as in the case where not suspending kernel or general Kernel from run mode be switched to dormant state in the case of etc., come realize to the object function for treating patch installing in kernel carry out beat mend When fourth operates, it is right that the object function institute that this treats patch installing can be first obtained in the source file where the object function of patch installing is treated Then the first source code answered, obtains the second source code corresponding to the patch function from the source file where patch function,. In this way, just obtaining corresponding first source code of object function for treating patch installing, and obtain patch corresponding with the object function Corresponding second source code of function.
S102:Based on the first source code and the second source code, determine existing between object function and patch function Competitive resource;
Specifically, corresponding first source code of object function for the treatment of patch installing is being obtained, and is obtaining patch function pair After the second source code answered, it is possible to by analyzing the source code of patch function and object function, to determine patch Existing competitive resource between function and object function, to handle patch function so that patch function is beaten with waiting The object function of patch can be run in kernel at the same time.
In practical applications, competitive resource can be a variable, such as shaping variable i nt a, pointer variable void*p, knot Structure body variable struct file ss etc., or one is called and has the function of the variable, such as log (a), sinlog (a), Certainly, competitive resource can be other that, such as one piece of data, here, the embodiment of the present invention is not specifically limited.
It is existing competing in order to determine between patch function and the object function for treating patch installing in specific implementation process Resource is striven, above-mentioned S102 can include:First source code and the second source code are compared, determine object function and patch letter The shared variable that number calls;By shared variable or the subfunction of shared variable is called to be determined as competitive resource.
In practical applications, above-mentioned shared variable is generally global variable.Under normal circumstances, global variable can be multiple Different function call, when global variable either calls the function for having global variable by a number of other functions while write-in or reading When taking, easily trigger the competition of resource.Certainly, above-mentioned shared variable can also be other types, such as the derived change in kernel Amount etc., here, the embodiment of the present invention is not specifically limited.
Exemplarily, ginseng is shown in Table 1, will treat the object function of patch installing the first source code and patch function second Source code is compared, it is found that treats that func_n (void) function in the object function of patch installing also have invoked shaping change Global_count is measured, func (void) function call in patch function shaping variable global_count therefore, can be with Determine to treat that the object function of patch installing have invoked shaping variable global_count with patch function, so that, which becomes Amount global_count is identified shared variable, it is, the competitive resource finally determined.
Table 1
S103:According to kernel lock mechanism, determine competitive resource corresponding in object function from the first source code One lock;
Here, the first lock is the mark for being used to control competitive resource in the object function for treat patch installing.
In practical applications, when patch function and when the object function of patch installing is run in kernel at the same time, benefit is performed The process of fourth function and execution treat that the process of the object function of patch installing can concurrently access competitive resource, so that, cause Race between process.Therefore, competitive resource is operated at the same time by two or more threads at the same time in order to prevent in parallel operation And triggering mistake, linux kernel provides kernel lock mechanism, to protect competitive resource.In order to divide for user for different situations Not or it is used cooperatively, following kernel lock mechanism is mainly provided in linux kernel, including:Atomic operation, spin lock Spinlock, memory barrier, read-write spin lock, sequence lock, semaphore, read-write signal amount, performance, RCU mechanism, BKL (imperial palaces Core is locked) etc., therefore, in specific implementation process, above-mentioned second lock and the first lock can be by mutual exclusion lock mutexlock, spin locks Spinlock, semaphore, atomic weight etc. realize that here, the embodiment of the present invention is not specifically limited.
Exemplarily, it is assumed that be that competitive resource is protected by spin lock in patch function and the object function for treating patch installing , still by taking the source code of the patch function shown in table 1 and the object function for treating patch installing as an example, according to spin lock keyword Spinlock, determines that corresponding first lock of object function is spinlock from the source code of object function for treating patch installing LOCK_A, it is then possible to determine that corresponding second lock of patch function is spinlock from the source code of patch function LOCK_B。
S104:According to preset strategy, based on the first lock, the second source code is handled, obtains the place for including the first lock Patch function after reason.
Wherein, the patch function after processing can be run in kernel at the same time with object function.Here, after due to processing Also the first lock is included in patch function, then, when patch function after treatment is run, and the first lock can be detected, this Sample, the patch function after operation processing and during the object function when patch installing at the same time, the patch function after processing is will not be with Treat that the object function of patch installing produces competition so that, patch function after processing can with to treat the object function of patch installing same When run in kernel.
In specific implementation process, above-mentioned S104 may comprise steps of:
Step 1041:According to kernel lock mechanism, determine that competitive resource is corresponding in patch function from the second source code Second lock, and by second lock and first lock be compared;
Step 1042:If it is determined that the second lock is different with the first lock, according to preset strategy, locked based on first, it is right Second source code is handled, and obtains the patch function after the processing comprising the first lock.
Here, the second lock is the mark for being used to control competitive resource in patch function.
In practical applications, when the second lock is identical with the first lock, and is used to protect identical competitive resource, patch function Object function with treating patch installing can be run, at this time, without handling again patch function, so that the benefit after processing Fourth function can be run in kernel at the same time with treating the object function of patch installing.Therefore, in order to accelerate handle patch function speed Degree, before handling the second source code of patch function, whether the second lock and the first lock are identical under can first comparing, such as It is different that fruit second, which locks and locked with first, then the second source code of patch function is handled, with the benefit after being handled Fourth function.
In specific implementation process, when performing step 1041 and step 1042, compared by the second lock and the first lock After relatively, determine whether identical step can mainly include following two steps for the second lock and the first lock:
The first step, judges whether the kernel lock mechanism belonging to the second lock and the kernel lock mechanism belonging to the first lock are identical;
Specifically, if kernel lock mechanism belonging to the second lock kernel lock mechanism affiliated with the first lock is identical, It can determine that the second lock and the first lock are identical;If the kernel belonging to kernel lock mechanism and the first lock belonging to the second lock is locked Mechanism is different, then needs to determine whether by second step.
Second step, judges whether the lock title of the second lock is identical with the lock title of the first lock.
Specifically, if second lock lock title with first lock lock title be identical, can determine the second lock with First lock is identical;If the lock title of the second lock and the lock title of the first lock are different, the second lock can be determined It is different with the first lock.
Exemplarily, it is assumed that the second lock is spinlock LOCK_B, and the first lock is spinlock LOCK_A, passes through and compares After can draw, second lock and first lock kernel lock mechanism be spin lock spinlock, still, second lock lock title The lock title LOCK_A of the locks of LOCK_B and first is different, hence, it can be determined that going out the kernel lock mechanism belonging to the second lock With first lock belonging to kernel lock mechanism be it is identical, and second lock lock title and first lock lock title be it is different, It is thus possible to determine that the second lock and the first lock are different.
Exemplarily, it is assumed that the second lock is mutexlock LOCK, and the first lock is mutexlock LOCK, after comparison It can draw, the kernel lock mechanism of the second lock and the first lock is mutual exclusion lock mutexlock, and the second lock locks title and first The lock title of lock is LOCK, hence, it can be determined that the kernel gone out belonging to the kernel lock mechanism and the first lock belonging to the second lock is locked Mechanism is identical, and the lock title of the second lock and the lock title of the first lock are also identical, it is thus possible to determine the second lock It is identical with the first lock.
In specific implementation process, when performing step 1042, according to preset strategy, based on the first lock, to the second source generation The method that is handled of code, can with and be not limited to include following three kinds of situations.
The first situation, directly by the corresponding source code for locking instruction and unlock instruction and copying patch function to of the first lock In.
In implementation process, above-mentioned steps 1042 can include:The corresponding locking of the first lock is determined from the first source code Instruction and unlock instruction, and determine that the second lock is corresponding from the second source code and lock instruction and unlock instruction;According to the second lock It is corresponding to lock instruction and position of the unlock instruction in the second source code, by the corresponding locking instruction of the first lock and unlock instruction It is copied in the second source code.
Exemplarily, corresponding instruction and the unlock instruction of locking of the first lock is copied to second in the source code of patch function Lock corresponding lock near instruction and unlock instruction location, it is possible to obtain the patch after processing as shown in table 2 below The source code of function.
Table 2
The second situation, pre-processes to the second lock and the corresponding locking instruction of the first lock and unlock instruction, Corresponding pre-processed results are obtained, then corresponding lock of the second lock in the second source code of patch function is instructed and unlocked Instruction replaces with the pre-processed results.
In implementation process, above-mentioned steps 1042 can include:The corresponding locking of the first lock is determined from the first source code Instruction and unlock instruction, and determine that the second lock is corresponding from the second source code and lock instruction and unlock instruction;By the first lock pair Lock corresponding with the second lock of locking instruction answered instructs progress and operation, obtains locking instruction in combination;First lock is corresponded to Corresponding with the second lock unlock instruction of unlock instruction carry out and operation, obtain united unlock instruction;By in the second source code The corresponding locking instruction of the second lock replace with it is united lock instruction, and by the corresponding unlock of the second lock in the second source code Instruction replaces with united unlock instruction.
Exemplarily, it is assumed that be that competitive resource is protected by spin lock in patch function and the object function for treating patch installing , still by taking the source code of the patch function shown in table 1 and the object function for treating patch installing as an example, the corresponding locking of the second lock Instruct for " spin_lock (&LOCK_B);", the corresponding unlock instruction of the second lock " spin_unlock (&LOCK_B);", first Lock it is corresponding lock instruction " spin_lock (&LOCK_A);", corresponding unlock instruction " the spin_unlock (s &LOCK_ of the first lock A);", then, by second lock locking instruction and first lock it is corresponding lock instruction carry out and operation, obtained it is united add Lock instruction just for " spin_lock (&LOCK_B);spin_lock(&LOCK_A);", by the unlock instruction of the second lock and the first lock Corresponding unlock instruction carries out and operation, the united unlock instruction obtained just for " spin_unlock (&LOCK_A); spin_unlock(&LOCK_B);”.In this way, the corresponding locking instruction of the second lock in the second source code of patch function is replaced It is changed to united lock to instruct, and second in the second source code of patch function is locked into corresponding unlock instruction and united solution After lock instruction, it is possible to obtain the source code of the patch function after processing as shown in Table 2.
It should be noted that in the source code for handled patch function after original unlock instruction and unlock instruction, also Need the declarative statement extern struct spinlock LOCK_A of the lock of increase by first in the source code of patch function.
Certainly, in practical applications, the second lock and the corresponding locking instruction of the first lock and unlock instruction are carried out pre- Processing, obtain corresponding pre-processed results mode be not limited to it is above-mentioned with operation, or or operation, i.e., by second lock with First lock carries out or operation.
The third situation, directly replaces corresponding instruction and the unlock instruction of locking of the second lock in the source code of patch function It is changed to the corresponding locking instruction of the first lock and unlock instruction.
In implementation process, above-mentioned steps 1042 can include:The corresponding locking of the first lock is determined from the first source code Instruction and unlock instruction, and determine that the second lock is corresponding from the second source code and lock instruction and unlock instruction;By the second source generation The corresponding locking instruction of the second lock in yard replaces with corresponding lock of the first lock and instructs, and second in the second source code is locked Corresponding unlock instruction replaces with the corresponding unlock instruction of the first lock.
Corresponding add is locked it should be noted that working as and locking corresponding instruction and the unlock instruction and first of locking according to second Lock instruction and unlock instruction, the method to be handled according to preset rules the second source code corresponding to patch function use upper When stating three kinds of situations to realize, the particular content of preset strategy is also not limited to above-mentioned example explanation.
So far, the generating process of patch function is just completed.
As shown in the above, the patch function generation method that the embodiment of the present invention is provided, patch installing is treated obtaining Corresponding first source code of object function, and obtain and second corresponding to this treats the corresponding patch function of patch installing object function After source code, it is possible to based on the first source code and the second source code, determine existing between object function and patch function Competitive resource, then, according to kernel lock mechanism, determine that competitive resource is corresponding in object function from the first source code First lock, finally, according to preset strategy, based on the first lock, handles the second source code, obtains the processing for including the first lock Patch function afterwards.In this way, due to before carrying out patch installing operation in the object function for treating patch installing, being provided previously according to competition Corresponding first lock in source, is handled the corresponding patch function of the object function, after obtaining the processing comprising the first lock Patch function so that patch function after processing can be run in kernel at the same time with object function, then, use the processing When patch function afterwards carries out patch installing operation to the object function, pause kernel is avoided the need for or need not be by kernel from fortune Row state is switched to dormant state, thus, it is possible to realize in the case of non-stop-machine, object function is replaced with the patch after the processing Function.
Embodiment two
Based on previous embodiment, in practical applications, in order in the case of non-stop-machine, i.e., not suspend kernel or will not Kernel carries out patch installing operation from the object function in the case that run mode is switched to dormant state, treating patch installing, so that, obtaining After obtaining the patch function after the processing including at least the first lock, it is possible to which the object function for treating patch installing is replaced with the processing Patch function afterwards, then, shown in Figure 2, after S104, which can also include:
S201:Obtain patch installing instruction;
Wherein, the object function that patch installing instruction is used to indicate to treat patch installing carries out patch installing operation.
Here, after the patch function after being handled, if expecting to the object function for treating patch installing beat mends Fourth operates, and will obtain corresponding patch installing instruction.
S202:Patch installing instruction is performed, the patch function after processing is loaded onto in the kernel in run mode;
Here, after patch installing instruction is obtained, in order to which the object function for treating patch installing in kernel is replaced with this Patch function after reason, carries out patch installing instruction, the patch function after processing is loaded into the kernel in run mode In.
S203:Patch function after the object function after patch installing in kernel is replaced with processing.
Here, comprising the first lock in the object function due to treating patch installing, and also include in the patch function after handling First lock, then, when the patch function after operation processing is with the object function when patch installing at the same time, the patch after operation processing It is also that can detect the first lock during function, so that, the patch function after processing is will not be with treating the target letter of patch installing Number produces competition, that is to say, that the patch function after processing is can be with treating the object function of patch installing while in kernel Operation, then, it is possible to directly when kernel is in run mode, the object function for treating patch installing in the kernel is replaced with Patch function after processing, is operated with completing to treat the patch installing of the object function of patch installing.
So far, the process for the object function progress patch installing operation for treating patch installing is just completed.
As shown in the above, after the patch function after being handled, if obtaining patch installing instruction, it is possible to Patch function after this is handled is loaded into the kernel for being in run mode, then, directly will treat patch installing in the kernel Object function replace with the patch function after the processing.In this way, due to including the first lock in the patch function after processing, it is It can be run at the same time in kernel with treating the object function of patch installing, then, treated and beaten using the patch function after the processing When the object function of patch carries out patch installing operation, avoid the need for pause kernel or kernel need not be switched to from run mode Dormant state, thus, it is possible to realize in the case where kernel is in run mode, it is possible to which the object function for treating patch installing is replaced with Patch function after the processing.
Embodiment three
Based on same inventive concept, as the realization to the above method, an embodiment of the present invention provides a kind of patch function Generating means, the device embodiment is corresponding with preceding method embodiment, and for ease of reading, present apparatus embodiment is no longer to foregoing side Detail content in method embodiment is repeated one by one, it should be understood that the device in the present embodiment can correspond to realize it is foregoing Full content in embodiment of the method.
Fig. 3 be the embodiment of the present invention three in patch function generating means structure diagram, shown in Figure 3, the benefit Fourth function generating means 30 include:First obtains unit 301, the first determination unit 302, the second determination unit 303 and processing Unit 304, wherein, first obtains unit 301 treats corresponding first source code of object function of patch installing for obtaining, and obtains Corresponding second source code of patch function is obtained, wherein, patch function is corresponding with object function;First determination unit 302, for base In the first source code and the second source code, competitive resource existing between object function and patch function is determined;Second is true Order member 303, for according to kernel lock mechanism, determining competitive resource corresponding in object function from the first source code One lock;Processing unit 304, for according to preset strategy, based on the first lock, handling the second source code, obtains comprising the Patch function after the processing of one lock, wherein, the patch function after processing can be run in kernel at the same time with object function.
In embodiments of the present invention, the first determination unit, for the first source code and the second source code to be compared, really Set the goal the shared variable that function is called with patch function;By shared variable or the subfunction of shared variable is called to be determined as Competitive resource.
In embodiments of the present invention, processing unit, for according to kernel lock mechanism, determining to compete from the second source code Resource corresponding second lock in patch function, and the second lock and the first lock are compared;If it is determined that the second lock and first Lock is different, and according to preset strategy, based on the first lock, the second source code is handled, obtains the place for including the first lock Patch function after reason.
In embodiments of the present invention, processing unit, instruction is locked for determining that the first lock is corresponding from the first source code And unlock instruction, and determine that the second lock is corresponding from the second source code and lock instruction and unlock instruction;Corresponded to according to the second lock Locking instruction and position of the unlock instruction in the second source code, by first lock it is corresponding lock instruction and unlock instruction copy Into the second source code.
In embodiments of the present invention, processing unit, instruction is locked for determining that the first lock is corresponding from the first source code And unlock instruction, and determine that the second lock is corresponding from the second source code and lock instruction and unlock instruction;First lock is corresponding Lock lock corresponding with the second lock of instruction and instruct progress and operation, obtain locking instruction in combination;By the corresponding solution of the first lock Lock instructs unlock instruction corresponding with the second lock to carry out and operate, and obtains united unlock instruction;By in the second source code Two, which lock corresponding locking instruction, replaces with united locking instruction, and second in the second source code is locked corresponding unlock instruction Replace with united unlock instruction.
In embodiments of the present invention, processing unit, instruction is locked for determining that the first lock is corresponding from the first source code And unlock instruction, and determine that the second lock is corresponding from the second source code and lock instruction and unlock instruction;By in the second source code Second lock it is corresponding locking instruction replace with the first lock it is corresponding lock instruction, and by the second source code second lock correspond to Unlock instruction replace with the corresponding unlock instruction of the first lock.
In other embodiments of the present invention, which further includes:Second obtaining unit, execution unit with And replacement unit, wherein, the second obtaining unit, for obtaining patch installing instruction, wherein, patch installing instruction is used to indicate to target Function carries out patch installing operation;Execution unit, for performing patch installing instruction, the patch function after processing is loaded onto in fortune In the kernel of row state;Replacement unit, for the object function in kernel to be replaced with to the patch function after processing.
Above-mentioned patch function generating means include processor and memory, above-mentioned first obtains unit, the first determination unit, Second determination unit and processing unit etc. in memory, are performed by processor as program unit storage and are stored in storage Above procedure unit in device realizes corresponding function.
Above-mentioned processor can be by central processing unit (Central Processing Unit, CPU), microprocessor (Micro Processor Unit, MPU), digital signal processor (Digital Signal Processor, DSP) or field-programmable Gate array (Field Programmable Gate Array, FPGA) etc. is realized.
Memory may include the volatile memory in computer-readable medium, random access memory (Random Access Memory, RAM) and/or the form such as Nonvolatile memory, such as read-only storage (Read Only Memory, ROM) Or flash memory (Flash RAM), memory include at least one storage chip.
Based on same inventive concept, the embodiment of the present invention provides a kind of storage medium, is stored thereon with program, the program quilt Processor realizes above-mentioned patch function generation method when performing.
Based on same inventive concept, the embodiment of the present invention provides a kind of processor, and processor is used for operation program, wherein, Program performs above-mentioned patch function generation method when running.
In practical applications, which can be applied in terminal.Terminal can be come real in a variety of manners Apply.For example, terminal described in the present invention can include such as mobile phone, tablet computer, laptop, palm PC, individual Digital assistants (Personal Digital Assistant, PDA), portable media player (Portable Media Player, PMP), guider, the mobile terminal such as wearable device, and numeral TV, desktop computer, server etc. Fixed terminal.
Example IV
Based on same inventive concept, the embodiment of the present invention provides a kind of patch function generation equipment.Fig. 4 is implemented for the present invention The structure diagram of patch function generation equipment in example four, shown in Figure 3, patch function generation equipment 40 includes:Deposit Reservoir 401, processor 402 and the computer program 403 that can be run on memory 401 and on the processor 402 is stored in, located Following steps are realized when managing device executive program 403:Corresponding first source code of object function for treating patch installing is obtained, and is mended Corresponding second source code of fourth function, wherein, patch function is corresponding with object function;Based on the first source code and the second source generation Code, determines competitive resource existing between object function and patch function;According to kernel lock mechanism, from the first source code Determine competitive resource corresponding first lock in object function;According to preset strategy, based on the first lock, to the second source code into Row processing, obtains the patch function after the processing comprising the first lock, wherein, the patch function after processing can be same with object function When run in kernel.
In embodiments of the present invention, following steps can be also realized during above-mentioned processor executive program:By the first source code and Second source code is compared, and determines the shared variable that object function is called with patch function;By shared variable or calling The subfunction of shared variable is determined as competitive resource.
In embodiments of the present invention, following steps can be also realized during above-mentioned processor executive program:According to kernel lock mechanism, Competitive resource corresponding second lock in patch function is determined from the second source code, and the second lock and the first lock are compared Compared with;If it is determined that the second lock is different with the first lock, according to preset strategy, based on the first lock, the second source code is carried out Processing, obtains the patch function after the processing comprising the first lock.
In embodiments of the present invention, following steps can be also realized during above-mentioned processor executive program:From the first source code Determine the first lock it is corresponding lock instruction and unlock instruction, and from the second source code determine second lock it is corresponding lock instruction and Unlock instruction;Instruction and position of the unlock instruction in the second source code are locked according to the second lock is corresponding, the first lock is corresponded to Locking instruction and unlock instruction be copied in the second source code.
In embodiments of the present invention, following steps can be also realized during above-mentioned processor executive program:From the first source code Determine the first lock it is corresponding lock instruction and unlock instruction, and from the second source code determine second lock it is corresponding lock instruction and Unlock instruction;Locking corresponding lock by first instructs locking corresponding with the second lock to instruct progress and operate, and acquisition adds in combination Lock instruction;The corresponding unlock instruction of first lock unlock instruction corresponding with the second lock is carried out and operated, obtains united unlock Instruction;By the corresponding locking instruction of the second lock in the second source code replace with it is united lock instruction, and by the second source code In the second corresponding unlock instruction of lock replace with united unlock instruction.
In embodiments of the present invention, following steps can be also realized during above-mentioned processor executive program:From the first source code Determine the first lock it is corresponding lock instruction and unlock instruction, and from the second source code determine second lock it is corresponding lock instruction and Unlock instruction;The corresponding locking instruction of the second lock in second source code is replaced with corresponding lock of the first lock to instruct, and will The corresponding unlock instruction of the second lock in second source code replaces with the corresponding unlock instruction of the first lock.
In embodiments of the present invention, following steps can be also realized during above-mentioned processor executive program:Patch installing instruction is obtained, Wherein, patch installing instruction is used to indicate to carry out patch installing operation to object function;Patch installing instruction is performed, by the patch after processing Function is loaded onto in the kernel in run mode;Object function in kernel is replaced with into the patch function after processing.
It should be understood by those skilled in the art that, embodiments herein can be provided as method, system or computer program Product.Therefore, the application can use the reality in terms of complete hardware embodiment, complete software embodiment or combination software and hardware Apply the form of example.Moreover, the application can use the computer for wherein including computer usable program code in one or more Usable storage medium (include but not limited to magnetic disk storage, read-only optical disc (Compact Disc Read-Only Memory, CD-ROM), optical memory etc.) on the form of computer program product implemented.
The application is with reference to the flow according to the method for the embodiment of the present application, equipment (system) and computer program product Figure and/or block diagram describe.It should be understood that it can be realized by computer program instructions every first-class in flowchart and/or the block diagram The combination of flow and/or square frame in journey and/or square frame and flowchart and/or the block diagram.These computer programs can be provided The processors of all-purpose computer, special purpose computer, Embedded Processor or other programmable data processing devices is instructed to produce A raw machine so that the instruction performed by computer or the processor of other programmable data processing devices, which produces, to be used in fact The device for the function of being specified in present one flow of flow chart or one square frame of multiple flows and/or block diagram or multiple square frames.
These computer program instructions, which may also be stored in, can guide computer or other programmable data processing devices with spy Determine in the computer-readable memory that mode works so that the instruction being stored in the computer-readable memory, which produces, to be included referring to Make the manufacture of device, the command device realize in one flow of flow chart or multiple flows and/or one square frame of block diagram or The function of being specified in multiple square frames.
These computer program instructions can be also loaded into computer or other programmable data processing devices so that counted Series of operation steps is performed on calculation machine or other programmable devices to produce computer implemented processing, thus in computer or The instruction performed on other programmable devices is provided and is used for realization in one flow of flow chart or multiple flows and/or block diagram one The step of function of being specified in a square frame or multiple square frames.
In a typical configuration, computing device includes one or more processors (CPU), input/output interface, net Network interface and memory.
Memory may include the volatile memory in computer-readable medium, RAM and/or Nonvolatile memory etc. Form, such as ROM or Flash RAM.Memory is the example of computer-readable medium.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method Or technology come realize information store.Information can be computer-readable instruction, data structure, the module of program or other data. Computer-readable recording medium can be ROM, programmable read only memory (Programmable Read-Only Memory, PROM), Erasable Programmable Read Only Memory EPROM (Erasable Programmable Read-Only Memory, EPROM), electricity Erasable Programmable Read Only Memory EPROM (Electrically Erasable Programmable Read-Only Memory, EEPROM), magnetic RAM (Ferromagnetic Random Access Memory, FRAM), flash Device (Flash Memory), magnetic surface storage, CD or read-only optical disc (Compact Disc Read-Only Memory, The memory such as CD-ROM);Can also be fast flash memory bank or other memory techniques, CD-ROM, digital versatile disc (DVD) or Other optical storages, magnetic cassette tape, the storage of tape magnetic rigid disk or other magnetic storage apparatus or any other non-transmission medium, The information that can be accessed by a computing device available for storage;It can also be including one of above-mentioned memory or be combined various Electronic equipment, such as mobile phone, computer, tablet device, personal digital assistant.Defined according to herein, computer can Reading medium does not include temporary computer readable media (transitory media), such as data-signal and carrier wave of modulation.
It should also be noted that, term " comprising ", "comprising" or its any other variant are intended to nonexcludability Comprising so that process, method, commodity or equipment including a series of elements not only include those key elements, but also wrapping Include other elements that are not explicitly listed, or further include for this process, method, commodity or equipment it is intrinsic will Element.In the absence of more restrictions, the key element limited by sentence "including a ...", it is not excluded that including key element Also there are other identical element in process, method, commodity or equipment.
It will be understood by those skilled in the art that embodiments herein can be provided as method, system or computer program product. Therefore, the application can be using the embodiment in terms of complete hardware embodiment, complete software embodiment or combination software and hardware Form.Deposited moreover, the application can use to can use in one or more computers for wherein including computer usable program code The shape for the computer program product that storage media is implemented on (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) Formula.
It these are only embodiments herein, be not limited to the application.To those skilled in the art, The application can have various modifications and variations.All any modifications made within spirit herein and principle, equivalent substitution, Improve etc., it should be included within the scope of claims hereof.

Claims (10)

  1. A kind of 1. patch function generation method, it is characterised in that the described method includes:
    Corresponding first source code of object function for treating patch installing is obtained, and obtains corresponding second source code of patch function, its In, the patch function is corresponding with the object function;
    Based on first source code and second source code, institute between the object function and the patch function is determined Existing competitive resource;
    According to kernel lock mechanism, determine that the competitive resource is corresponding in the object function from first source code First lock;
    According to preset strategy, based on the described first lock, second source code is handled, is obtained comprising the described first lock Patch function after processing, wherein, the patch function after the processing can be run in kernel at the same time with the object function.
  2. 2. according to the method described in claim 1, it is characterized in that, described be based on first source code and second source generation Code, determines competitive resource existing between the object function and the patch function, including:
    First source code and second source code are compared, determine that the object function and the patch function are equal The shared variable of calling;
    By the shared variable or the subfunction of the shared variable is called to be determined as the competitive resource.
  3. 3. according to the method described in claim 1, it is characterized in that, described according to preset strategy, based on the described first lock, to institute State the second source code to be handled, obtain the patch function after the processing comprising the described first lock, including:
    According to kernel lock mechanism, determine that the competitive resource is corresponding in the patch function from second source code Second lock, and the described second lock and the described first lock are compared;
    If it is determined that second lock is different with the described first lock, according to preset strategy, based on the described first lock, to institute State the second source code to be handled, obtain the patch function after the processing comprising the described first lock.
  4. 4. according to the method described in claim 3, it is characterized in that, described according to preset strategy, based on the described first lock, to institute The second source code is stated to be handled, including:
    Determine that first lock is corresponding from first source code and lock instruction and unlock instruction, and from second source generation Determine that second lock is corresponding in code and lock instruction and unlock instruction;
    Instruction and position of the unlock instruction in second source code are locked according to the described second lock is corresponding, by described first Corresponding instruction and the unlock instruction of locking is locked to be copied in second source code.
  5. 5. according to the method described in claim 3, it is characterized in that, described according to preset strategy, based on the described first lock, to institute The second source code is stated to be handled, including:
    Determine that first lock is corresponding from first source code and lock instruction and unlock instruction, and from second source generation Determine that second lock is corresponding in code and lock instruction and unlock instruction;
    Locking instruction corresponding with the described second lock is instructed to carry out and operate corresponding lock of the described first lock, acquisition is united Lock instruction;
    The corresponding unlock instruction of described first lock unlock instruction corresponding with the described second lock is carried out and operation, acquisition are united Unlock instruction;
    The corresponding locking instruction of second lock in second source code is replaced with united lock to instruct, and will The corresponding unlock instruction of second lock in second source code replaces with the united unlock instruction.
  6. 6. according to the method described in claim 3, it is characterized in that, described according to preset strategy, based on the described first lock, to institute The second source code is stated to be handled, including:
    Determine that first lock is corresponding from first source code and lock instruction and unlock instruction, and from second source generation Determine that second lock is corresponding in code and lock instruction and unlock instruction;
    The corresponding locking instruction of second lock in second source code is replaced with the corresponding locking of first lock to refer to Order, and the corresponding unlock instruction of second lock in second source code is replaced with into the corresponding unlock of first lock and is referred to Order.
  7. 7. according to the method described in claim 1, it is characterized in that, according to preset strategy, locked based on described first, to described Second source code is handled, and after obtaining the patch function after the processing comprising the described first lock, the method further includes:
    Patch installing instruction is obtained, wherein, the patch installing instruction is used to indicate to carry out patch installing operation to the object function;
    The patch installing instruction is performed, the patch function after the processing is loaded onto in the kernel in run mode;
    The object function in the kernel is replaced with to the patch function after the processing.
  8. 8. a kind of patch function generating means, it is characterised in that described device includes:First obtains unit, the first determination unit, Second determination unit and processing unit, wherein,
    The first obtains unit, corresponding first source code of object function of patch installing is treated for obtaining, and obtains patch letter Corresponding second source code of number, wherein, the patch function is corresponding with the object function;
    First determination unit, for based on first source code and second source code, determining the target letter Several existing competitive resources between the patch function;
    Second determination unit, for according to kernel lock mechanism, the competitive resource to be determined from first source code Corresponding first lock in the object function;
    The processing unit, for according to preset strategy, based on the described first lock, handling second source code, obtaining The patch function after the processing of the described first lock must be included, wherein, the patch function after the processing can be with the target letter Number is run in kernel at the same time.
  9. A kind of 9. storage medium, it is characterised in that the storage medium includes the program of storage, wherein, run in described program When control the storage medium where equipment perform such as claim 1 to 7 any one of them patch function generation method.
  10. A kind of 10. processor, it is characterised in that the processor is used for operation program, wherein, performed such as when described program is run Claim 1 to 7 any one of them patch function generation method.
CN201711311047.XA 2017-12-11 2017-12-11 Patch function generation method and device Active CN108009429B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711311047.XA CN108009429B (en) 2017-12-11 2017-12-11 Patch function generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711311047.XA CN108009429B (en) 2017-12-11 2017-12-11 Patch function generation method and device

Publications (2)

Publication Number Publication Date
CN108009429A true CN108009429A (en) 2018-05-08
CN108009429B CN108009429B (en) 2021-09-03

Family

ID=62057936

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711311047.XA Active CN108009429B (en) 2017-12-11 2017-12-11 Patch function generation method and device

Country Status (1)

Country Link
CN (1) CN108009429B (en)

Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101178672A (en) * 2007-11-29 2008-05-14 上海华为技术有限公司 Multi-nucleus processor sharing code segment patching method and apparatus
US7467202B2 (en) * 2003-09-10 2008-12-16 Fidelis Security Systems High-performance network content analysis platform
CN102591843A (en) * 2011-12-30 2012-07-18 中国科学技术大学苏州研究院 Inter-core communication method for multi-core processor
CN103034495A (en) * 2012-12-12 2013-04-10 北京奇虎科技有限公司 Browser capable of isolating plug-in in webpage and webpage plug-in isolating method
US20130104193A1 (en) * 2003-03-10 2013-04-25 Igt Dynamic configuration of a gaming system
CN103946827A (en) * 2011-11-22 2014-07-23 华为技术有限公司 System and method for implementing locks shared between kernel and user space
CN104981813A (en) * 2012-03-30 2015-10-14 爱迪德技术有限公司 Securing accessible systems using dynamic data mangling
CN105094931A (en) * 2015-09-09 2015-11-25 小米科技有限责任公司 Software upgrading method and device
CN105354045A (en) * 2014-08-21 2016-02-24 中兴通讯股份有限公司 Patch making method and apparatus and patch activation method and apparatus
CN105373425A (en) * 2015-10-28 2016-03-02 浪潮(北京)电子信息产业有限公司 Method and device for performance optimization of embedded Linux system
CN105824659A (en) * 2015-07-30 2016-08-03 广东维沃软件技术有限公司 Application program updating method and terminal equipment
CN106980544A (en) * 2017-03-31 2017-07-25 北京奇艺世纪科技有限公司 A kind of thread synchronization method and thread synchronization system
CN107229550A (en) * 2017-05-27 2017-10-03 郑州云海信息技术有限公司 A kind of linux kernel spin lock Deadlock Detection reporting system and method
CN107369181A (en) * 2017-06-13 2017-11-21 华南理工大学 Cloud data collection and processing method based on bi-processor architecture

Patent Citations (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20130104193A1 (en) * 2003-03-10 2013-04-25 Igt Dynamic configuration of a gaming system
US7467202B2 (en) * 2003-09-10 2008-12-16 Fidelis Security Systems High-performance network content analysis platform
CN101178672A (en) * 2007-11-29 2008-05-14 上海华为技术有限公司 Multi-nucleus processor sharing code segment patching method and apparatus
CN103946827A (en) * 2011-11-22 2014-07-23 华为技术有限公司 System and method for implementing locks shared between kernel and user space
CN102591843A (en) * 2011-12-30 2012-07-18 中国科学技术大学苏州研究院 Inter-core communication method for multi-core processor
CN104981813A (en) * 2012-03-30 2015-10-14 爱迪德技术有限公司 Securing accessible systems using dynamic data mangling
CN103034495A (en) * 2012-12-12 2013-04-10 北京奇虎科技有限公司 Browser capable of isolating plug-in in webpage and webpage plug-in isolating method
CN105354045A (en) * 2014-08-21 2016-02-24 中兴通讯股份有限公司 Patch making method and apparatus and patch activation method and apparatus
CN105824659A (en) * 2015-07-30 2016-08-03 广东维沃软件技术有限公司 Application program updating method and terminal equipment
CN105094931A (en) * 2015-09-09 2015-11-25 小米科技有限责任公司 Software upgrading method and device
CN105373425A (en) * 2015-10-28 2016-03-02 浪潮(北京)电子信息产业有限公司 Method and device for performance optimization of embedded Linux system
CN106980544A (en) * 2017-03-31 2017-07-25 北京奇艺世纪科技有限公司 A kind of thread synchronization method and thread synchronization system
CN107229550A (en) * 2017-05-27 2017-10-03 郑州云海信息技术有限公司 A kind of linux kernel spin lock Deadlock Detection reporting system and method
CN107369181A (en) * 2017-06-13 2017-11-21 华南理工大学 Cloud data collection and processing method based on bi-processor architecture

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
FLY晴天里FLY: "深入理解各种锁", 《HTTPS://WWW.JIANSHU.COM/P/5725DB8F07DC》 *

Also Published As

Publication number Publication date
CN108009429B (en) 2021-09-03

Similar Documents

Publication Publication Date Title
US11762982B2 (en) Processor extensions to protect stacks during ring transitions
Ding et al. Autotuning algorithmic choice for input sensitivity
US8806640B2 (en) Program execution integrity verification for a computer system
KR20170132296A (en) Federation-based memory management
Zheng et al. AStitch: enabling a new multi-dimensional optimization space for memory-intensive ML training and inference on modern SIMT architectures
Valero‐Lara et al. cuThomasBatch and cuThomasVBatch, CUDA routines to compute batch of tridiagonal systems on NVIDIA GPUs
Yang et al. Making parallel programs reliable with stable multithreading
CN102708043B (en) Static data race detection and anaylsis
CN109117201A (en) A kind of method that program exits and relevant device
IL294304A (en) Lock-free reading of unitary value sets
US8789060B1 (en) Deterministic, parallel execution with overlapping regions
Jiang et al. WANA: Symbolic execution of wasm bytecode for extensible smart contract vulnerability detection
CN111522730B (en) Program testing method and device, computer device and computer readable medium
CN108009429A (en) A kind of patch function generation method and device
Ozcan et al. Investigation of the performance of LU decomposition method using CUDA
CN116628600A (en) Unbalanced data sampling method and device based on random forest
US10579441B2 (en) Detecting deadlocks involving inter-processor interrupts
Willis et al. An efficient SIMD implementation of pseudo-Verlet lists for neighbour interactions in particle-based codes
KR20170093121A (en) Synchronization in a computing device
US10423792B2 (en) Identifying exploitable code sequences
Agafonov Multithreading in C# 5.0 cookbook
Yeh et al. CPP-ATPG: a circular pipeline processing based deterministic parallel test pattern generator
Verma et al. Transfer Learning Across Heterogeneous Features For Efficient Tensor Program Generation
Weiss et al. EZClone: Improving DNN Model Extraction Attack via Shape Distillation from GPU Execution Profiles
Contreras et al. Multiclass Classification of Software Vulnerabilities with Deep Learning

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