CN110543322A - hot patching method and device for Loongson platform - Google Patents

hot patching method and device for Loongson platform Download PDF

Info

Publication number
CN110543322A
CN110543322A CN201910660203.6A CN201910660203A CN110543322A CN 110543322 A CN110543322 A CN 110543322A CN 201910660203 A CN201910660203 A CN 201910660203A CN 110543322 A CN110543322 A CN 110543322A
Authority
CN
China
Prior art keywords
patch file
patch
function
file
hot
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.)
Pending
Application number
CN201910660203.6A
Other languages
Chinese (zh)
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.)
Inspur Cisco Networking Technology Co Ltd
Original Assignee
Inspur Cisco Networking 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 Inspur Cisco Networking Technology Co Ltd filed Critical Inspur Cisco Networking Technology Co Ltd
Priority to CN201910660203.6A priority Critical patent/CN110543322A/en
Publication of CN110543322A publication Critical patent/CN110543322A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1415Saving, restoring, recovering or retrying at system level
    • G06F11/1433Saving, restoring, recovering or retrying at system level during software upgrading
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates
    • G06F8/656Updates while running

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Quality & Reliability (AREA)
  • Computer Security & Cryptography (AREA)
  • Stored Programmes (AREA)

Abstract

the invention discloses a hot patching method and a hot patching device for a Loongson platform, wherein the method comprises the following steps of: making a patch file; and loading the patch file. The device comprises: the making module is used for making a patch file; and the loading module is used for loading the patch file. The invention realizes the hot patching technology aiming at linux application, solves the problem of repairing the defects of products or increasing functions under the conditions of not restarting equipment and not interrupting the service, can patch and repair the defects of the Loongson platform at any time, and has the advantages of maturity, stability, wide adaptability, simple realization, safety and reliability.

Description

hot patching method and device for Loongson platform
Technical Field
the invention relates to a hot patching method and device for a Loongson platform, and belongs to the technical field of computer software.
Background
when the network device is deployed as a key device for IT basic communication, the network device is affected very much when a defect causes a network interruption or an abnormality. Therefore, the software of the network device needs to be subjected to rigorous testing, but the system defect is inevitable, so that the system needs to be upgraded. In conventional implementations, a time point needs to be selected according to the service situation, for example, the upgrade is performed on the device in the morning and then the device is restarted. This method is troublesome for both operation and maintenance personnel and network management personnel.
At present, the requirement for the service sustainability of network equipment is higher and higher, so that the hot patching function of the equipment is needed to be realized. The hot patch technology is to upgrade the equipment under the conditions of not restarting the equipment and not interrupting the service. This hot patch is a function level repair with a small impact range. Therefore, network management personnel can patch at any time to repair the defects.
The dragon core is a chip with independent intellectual property rights in China and meets the independent controllable requirement. The method is widely applied to key fields of national defense, aerospace, government affairs and the like. The Linux operating system has the characteristics of open source, stability, customization, wide application and the like. Therefore, the linux network device based on the Loongson has wide application in many fields needing safety and reliability.
At present, most of the realization is directed to x86 chips, and the operating system is also directed to vxworks generally. However, no mature method exists in the linux system hot patch scheme on the market for the Loongson, and the upgrading and defect repair of the application can not be realized under the condition of not restarting the equipment.
Disclosure of Invention
Aiming at the defects of the method, the invention provides a hot patching method and a hot patching device for a Loongson platform, which can realize hot patching repair without interruption and restart for an application program in the operation of the Loongson platform.
The technical scheme adopted for solving the technical problems is as follows:
on one hand, the hot patching method for the Loongson platform provided by the embodiment of the invention comprises the following steps:
Making a patch file;
And loading the patch file.
in combination with a possible implementation manner of this embodiment, the patch file includes a so file to be loaded, an equipment model corresponding to the patch file, software system version information corresponding to the patch file, and patch file verification information.
In combination with a possible implementation manner of this embodiment, the patch file loading process specifically includes:
1) Running a loader, using ptrace to attach a process to be patched, and then searching a symbol table, or using the offset of a fixed program to find the addresses of dlopen, dlclose and malloc functions;
2) Copying a section of assembly code for realizing malloc calling to a safe code section of a target process, transferring the length of the required malloc and the address of a malloc function through a parameter register reg4 and a parameter register reg5), finally setting cp0_ epc, and setting an execution address as the initial address of the code which is just copied;
3) The loader restores the target process to be executed through PTRACE _ CONT of PTRACE, if the execution is successful, the return value of malloc is obtained through reading a return value register reg2, and the path of the patch file is stored;
4) Dlopen functions are executed. The address acquired by the malloc and the address of the dlopen function are used as parameters to be transmitted, and after dlopen is successfully executed, __ attribute __ (constructor) functions in the patch file are triggered to be executed;
5) The init function in the patch file searches a function address needing to be repaired, at an entrance of the address, function jump is achieved through jalr, and the function jump is carried out to the entrance of a new function.
in combination with a possible implementation manner as this embodiment, after dlopen is successfully executed, the loader restores the registers saved from the beginning by restoring some replaced code segments, so that the target process continues to execute.
In combination with a possible implementation manner as this embodiment, when a patch file is unloaded, a corresponding dlclose is executed to unload a corresponding library, and __ attribute __ ((destructor)) function is triggered to restore the code that has been replaced previously.
in combination with this, as a possible implementation manner of this embodiment, the hot patching method further includes the following steps:
And checking the patch file.
In combination with a possible implementation manner as this embodiment, the specific process of checking the patch file is as follows: and the loading program running on the equipment identifies whether the patch files are matched or not by analyzing the equipment model information, the software system information and the patch file verification information of the patch files, otherwise, the system is abnormal.
On the other hand, a hot patch device for a Loongson platform provided in the embodiment of the present invention includes:
The making module is used for making a patch file;
and the loading module is used for loading the patch file.
in combination as a possible implementation manner of this embodiment, the hot patch apparatus further includes:
And the checking module is used for checking the patch file.
in combination with a possible implementation manner of this embodiment, the patch file includes a so file to be loaded, an equipment model corresponding to the patch file, software system version information corresponding to the patch file, and patch file verification information.
The technical scheme of the embodiment of the invention has the following beneficial effects:
aiming at network products such as switches using a Loongson Linux operating system, the invention realizes a hot patch technology aiming at application, solves the problem of repairing or increasing functions of product defects under the conditions of not restarting equipment and not interrupting service, can not only patch and repair the defects of a Loongson platform at any time, but also is mature and stable, has wide adaptability, and is simple to realize, safe and reliable.
Description of the drawings:
FIG. 1 is a flow diagram illustrating a hot patching method for a Loongson platform in accordance with an example embodiment;
fig. 2 is a schematic diagram illustrating a hot-patch apparatus for a Loongson platform, according to an example embodiment.
Detailed Description
The invention is further illustrated by the following examples in conjunction with the accompanying drawings:
In order to clearly explain the technical features of the present invention, the following detailed description of the present invention is provided with reference to the accompanying drawings. The following disclosure provides many different embodiments, or examples, for implementing different features of the invention. To simplify the disclosure of the present invention, the components and arrangements of specific examples are described below. Furthermore, the present invention may repeat reference numerals and/or letters in the various examples. This repetition is for the purpose of simplicity and clarity and does not in itself dictate a relationship between the various embodiments and/or configurations discussed. It should be noted that the components illustrated in the figures are not necessarily drawn to scale. Descriptions of well-known components and processing techniques and procedures are omitted so as to not unnecessarily limit the invention.
FIG. 1 is a flow diagram illustrating a hot patching method for a Loongson platform, according to an example embodiment. As shown in fig. 1, a hot patching method for a Loongson platform provided in an embodiment of the present invention includes the following steps:
Making a patch file;
And loading the patch file.
In combination with a possible implementation manner of this embodiment, the patch file includes a so file to be loaded, an equipment model corresponding to the patch file, software system version information corresponding to the patch file, and patch file verification information.
in combination with a possible implementation manner of this embodiment, the patch file loading process specifically includes:
1) running a loader, using ptrace to attach a process to be patched, and then searching a symbol table, or using the offset of a fixed program to find the addresses of dlopen, dlclose and malloc functions;
2) Copying a section of assembly code for realizing malloc calling to a safe code section of a target process, transferring the length of the required malloc and the address of a malloc function through a parameter register reg4 and a parameter register reg5), finally setting cp0_ epc, and setting an execution address as the initial address of the code which is just copied;
3) the loader restores the target process to be executed through PTRACE _ CONT of PTRACE, if the execution is successful, the return value of malloc is obtained through reading a return value register reg2, and the path of the patch file is stored;
4) Dlopen functions are executed. The address acquired by the malloc and the address of the dlopen function are used as parameters to be transmitted, and after dlopen is successfully executed, __ attribute __ (constructor) functions in the patch file are triggered to be executed;
5) The init function in the patch file searches a function address needing to be repaired, at an entrance of the address, function jump is achieved through jalr, and the function jump is carried out to the entrance of a new function.
In combination with a possible implementation manner as this embodiment, after dlopen is successfully executed, the loader restores the registers saved from the beginning by restoring some replaced code segments, so that the target process continues to execute.
in combination with a possible implementation manner as this embodiment, when a patch file is unloaded, a corresponding dlclose is executed to unload a corresponding library, and __ attribute __ ((destructor)) function is triggered to restore the code that has been replaced previously.
in combination with this, as a possible implementation manner of this embodiment, the hot patching method further includes the following steps:
And checking the patch file.
in combination with a possible implementation manner as this embodiment, the specific process of checking the patch file is as follows: and the loading program running on the equipment identifies whether the patch files are matched or not by analyzing the equipment model information, the software system information and the patch file verification information of the patch files, otherwise, the system is abnormal.
Aiming at network products such as switches using a Loongson Linux operating system, the invention realizes a hot patch technology aiming at application, solves the problem of repairing or increasing functions of product defects under the conditions of not restarting equipment and not interrupting service, can not only patch and repair the defects of a Loongson platform at any time, but also has the advantages of maturity and stability aiming at the Loongson platform, wide adaptability, simple realization, safety and reliability.
Fig. 2 is a schematic diagram illustrating a hot-patch apparatus for a Loongson platform, according to an example embodiment. As shown in fig. 2, the hot patching device for a Loongson platform provided in this embodiment includes:
the making module is used for making a patch file;
And the loading module is used for loading the patch file.
In combination as a possible implementation manner of this embodiment, the hot patch apparatus further includes:
And the checking module is used for checking the patch file.
In combination with a possible implementation manner of this embodiment, the patch file includes a so file to be loaded, an equipment model corresponding to the patch file, software system version information corresponding to the patch file, and patch file verification information.
The implementation process of the hot patch of the linux application based on the Loongson platform comprises the steps of making, loading, verifying, validating and the like of patch files, and the hot patch repair without interruption and restarting is realized on an application program in the operation of the Loongson platform. The specific implementation process is as follows:
1) linux has a function dlopen for loading dynamic libraries, which can dynamically load so libraries during running.
2) the GCC compiler has an extension: __ attribute __ (constructor) can specify that a certain function is executed when the so library is loaded, and corresponding __ attribute __ (constructor) can specify that a certain function is automatically executed when the so library is unloaded.
3) and the loader running on the equipment finds the addresses of the functions of dlopen, dlclose, malloc and free by using ptrace to patch the process attach to be patched and then searching a symbol table or fixing the offset of the program.
4) the loader copies an assembly code implementing malloc calling to a safe code segment of the target process, transfers the required malloc length and the malloc function address through a parameter register (reg4, reg5), and finally sets cp0_ epc to set the execution address as the starting address of the code which is just copied. And the loader restores the target process to be executed through the PTRACE _ CONT of PTRACE.
5) If the execution is successful, the return value of malloc is obtained by reading the return value register (reg2), and the path of the patch file is stored.
6) and executing the flow with the malloc, and executing a dlopen function by the loader. The address acquired by the malloc and the address of the dlopen function are used as parameters, and after the dlopen is successfully executed, __ attribute __ (constructor)) functions in the patch file are triggered to execute.
7) The init function in the patch file searches a function address needing to be repaired, at an entrance of the address, function jump is achieved through jalr, and the function jump is carried out to the entrance of a new function.
8) the patch is actually validated after it is executed by dlopen. The loader then causes the target process to continue execution by restoring the originally saved registers by restoring some of the replaced code fragments.
9) If the unloading is required, the corresponding library can be unloaded by executing the corresponding dlclose. The trigger __ attribute __ (destructor) function restores the code that was replaced previously.
and the loader running on the equipment identifies whether the patch file is matched or not by analyzing the equipment model information, the software system information and the file verification information of the patch file, otherwise, the system is abnormal.
The foregoing is only a preferred embodiment of the present invention, and it will be apparent to those skilled in the art that various modifications and improvements can be made without departing from the principle of the present invention, and these modifications and improvements are also considered to be within the scope of the present invention.

Claims (10)

1. a hot patching method for a Loongson platform is characterized by comprising the following steps:
Making a patch file;
And loading the patch file.
2. the hot patching method for the Loongson platform as claimed in claim 1, wherein the patch file comprises a so file to be loaded, an equipment model corresponding to the patch file, software system version information corresponding to the patch file and patch file verification information.
3. The hot patching method for the Loongson platform as claimed in claim 1, wherein the patch file loading process specifically comprises:
1) Running a loader, using ptrace to attach a process to be patched, and then searching a symbol table, or using the offset of a fixed program to find the addresses of dlopen, dlclose and malloc functions;
2) copying a section of assembly code for realizing malloc calling to a safe code section of a target process, transferring the length of the required malloc and the address of a malloc function through a parameter register reg4 and a parameter register reg5), finally setting cp0_ epc, and setting an execution address as the initial address of the code which is just copied;
3) The loader restores the target process to be executed through PTRACE _ CONT of PTRACE, if the execution is successful, the return value of malloc is obtained through reading a return value register reg2, and the path of the patch file is stored;
4) Dlopen functions are executed. The address acquired by the malloc and the address of the dlopen function are used as parameters to be transmitted, and after dlopen is successfully executed, __ attribute __ (constructor) functions in the patch file are triggered to be executed;
5) the init function in the patch file searches a function address needing to be repaired, at an entrance of the address, function jump is achieved through jalr, and the function jump is carried out to the entrance of a new function.
4. a hot-patching method for loongson platforms as in claim 3, wherein after dlopen is successfully executed, the loader restores the registers saved from the beginning by restoring some of the replaced code sections so that the target process continues to execute.
5. The hot patching method for the Loongson platform is characterized in that when a patch file is unloaded, the corresponding dlclose is executed to unload the corresponding library, and __ attribute __ ((destructor)) function is triggered to restore the replaced code.
6. the method for hot patching of the Loongson platform according to any one of claims 1 to 5, further comprising the following steps:
and checking the patch file.
7. the hot patching method for the Loongson platform as claimed in claim 6, wherein the specific process of the patch file verification is as follows: and the loading program running on the equipment identifies whether the patch files are matched or not by analyzing the equipment model information, the software system information and the patch file verification information of the patch files, otherwise, the system is abnormal.
8. A hot patching device for a Loongson platform is characterized by comprising:
The making module is used for making a patch file;
and the loading module is used for loading the patch file.
9. The hot-patch apparatus for loongson platforms as claimed in claim 6, further comprising:
and the checking module is used for checking the patch file.
10. The hot patching device for the Loongson platform according to claim 8 or 9, wherein the patch file comprises a so file to be loaded, an equipment model corresponding to the patch file, software system version information corresponding to the patch file, and patch file verification information.
CN201910660203.6A 2019-07-19 2019-07-19 hot patching method and device for Loongson platform Pending CN110543322A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910660203.6A CN110543322A (en) 2019-07-19 2019-07-19 hot patching method and device for Loongson platform

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910660203.6A CN110543322A (en) 2019-07-19 2019-07-19 hot patching method and device for Loongson platform

Publications (1)

Publication Number Publication Date
CN110543322A true CN110543322A (en) 2019-12-06

Family

ID=68709996

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910660203.6A Pending CN110543322A (en) 2019-07-19 2019-07-19 hot patching method and device for Loongson platform

Country Status (1)

Country Link
CN (1) CN110543322A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113342555A (en) * 2020-02-18 2021-09-03 炬芯科技股份有限公司 Method and device for repairing ROM and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101587455A (en) * 2008-12-11 2009-11-25 南京南瑞继保电气有限公司 Method for checking memory leak for vxWorks operating system
US8468516B1 (en) * 2008-12-19 2013-06-18 Juniper Networks, Inc. Creating hot patches for embedded systems
CN105159738A (en) * 2015-08-20 2015-12-16 上海斐讯数据通信技术有限公司 Hot patch implementation method and system
CN106775671A (en) * 2016-11-30 2017-05-31 武汉虹信通信技术有限责任公司 A kind of hot patch restorative procedure in the linux environment for communication system
CN107766069A (en) * 2017-10-17 2018-03-06 安徽皖通邮电股份有限公司 A kind of embedded system hot patch implementation method
CN109491698A (en) * 2018-12-29 2019-03-19 武汉思普崚技术有限公司 Method for updating system and device based on hot patch

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101587455A (en) * 2008-12-11 2009-11-25 南京南瑞继保电气有限公司 Method for checking memory leak for vxWorks operating system
US8468516B1 (en) * 2008-12-19 2013-06-18 Juniper Networks, Inc. Creating hot patches for embedded systems
CN105159738A (en) * 2015-08-20 2015-12-16 上海斐讯数据通信技术有限公司 Hot patch implementation method and system
CN106775671A (en) * 2016-11-30 2017-05-31 武汉虹信通信技术有限责任公司 A kind of hot patch restorative procedure in the linux environment for communication system
CN107766069A (en) * 2017-10-17 2018-03-06 安徽皖通邮电股份有限公司 A kind of embedded system hot patch implementation method
CN109491698A (en) * 2018-12-29 2019-03-19 武汉思普崚技术有限公司 Method for updating system and device based on hot patch

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
《精通LINUX完全自学手册》编委会编著: "《精通Linux完全自学手册》", 31 August 2011, 中国铁道出版社 *
KISSLIFECHEN: "Linux热补丁的实现", 《HTTPS://BLOG.CSDN.NET/BYRANTCH/ARTICLE/DETAILS/51231957》 *
肖坤 著: "《嵌入式Linux操作系统编程实验教程》", 31 October 2018, 四川科学技术出版社 *
邹能人: "Linux下动态注入机制的研究与实现", 《中国优秀硕士学位论文全文数据库 信息科技辑》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113342555A (en) * 2020-02-18 2021-09-03 炬芯科技股份有限公司 Method and device for repairing ROM and storage medium
CN113342555B (en) * 2020-02-18 2024-01-09 炬芯科技股份有限公司 ROM repairing method, device and storage medium

Similar Documents

Publication Publication Date Title
CN101821727B (en) Managing updates to create virtual machine facsimile
US9910743B2 (en) Method, system and device for validating repair files and repairing corrupt software
US8495615B2 (en) Method, system and computer program for distributing software patches
CN112906008B (en) Kernel vulnerability restoration method, device, server and system
CN101154187A (en) Method and apparatus for run-time in-memory patching of code from a service processor
CN107783776B (en) Processing method and device of firmware upgrade package and electronic equipment
CN111562934B (en) Software system upgrading method based on hot patch, terminal and storage medium
CN103942073A (en) Method and device for realizing system hot patching
CN110837383B (en) Application installation-free upgrading method and device
WO2022111262A1 (en) Hotfix generation method and apparatus, server, and machine readable storage medium
CN110806884A (en) Method and device for repairing operating system fault
CN111142922B (en) Application program updating method, device, terminal and server
CN110543322A (en) hot patching method and device for Loongson platform
US20190286544A1 (en) Method, device and server for checking a defective function
CN114490103A (en) Operating system interface calling method and device and electronic equipment
CN111949290B (en) Hot patch management method and device, electronic equipment and storage medium
CN115629779A (en) Hot updating method, device, equipment and computer storage medium
CN108958769A (en) A kind of embedded device software systems restorative procedure and system
CN112559349B (en) Program running method and running device
CN113254941A (en) Linux kernel source code processing method, device and equipment
US8141055B2 (en) Method for dynamic discovery of code segments in instrumented binary modules
US11868763B2 (en) Method for implementing Linux kernel hot patch, electronic device, and computer readable medium
CN116414408A (en) Software uploading method based on RS422
CN113127044A (en) BMC upgrading method and device and related components
CN115729564A (en) Method for judging compatibility of native application to Linux Arm64

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20191206

RJ01 Rejection of invention patent application after publication