DKMS-based closed source kernel module generation method and system

By reconstructing the source code of the Linux kernel module into a closed source core code layer and a kernel call layer, the DKMS installation package is generated, which solves the module compatibility problem after the kernel upgrade and achieves module compatibility and security during the kernel upgrade. It is applicable Based on a variety of Linux kernel modules, it has automatic upgrades and confidentiality.

CN118567705APending Publication Date: 2024-08-30CHINESE PEOPLES LIBERATION ARMY UNIT 32806
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410682040.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-29
Publication Date
2024-08-30

AI Technical Summary

Technical Problem

Linux kernel modules may be incompatible after a kernel upgrade, resulting in loading failure. Existing solutions such as manual recompiling or using DKMS require open source code and cannot meet closed source requirements.

Method used

By reconstructing the source code of the target kernel module to include a closed source core code layer and a kernel call layer, peeling off the kernel functions in the core code layer and encapsulating them into the kernel call layer, a DKMS installation package is generated to ensure the compatibility of the module during kernel upgrades. and security.

Benefits of technology

It achieves maintaining module compatibility and security during kernel upgrades, meets closed source requirements, is suitable for a variety of Linux kernel modules, and has the advantages of automated upgrades and core code confidentiality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118567705A
    Figure CN118567705A
Patent Text Reader

Abstract

The invention discloses a closed source kernel module generation method and system based on a DKMS. The method comprises the steps that a source code of a target kernel module is reconstructed, layered and split into a core code layer containing a closed source code needing to be protected and other kernel calling layers so that the core code layer and the other kernel calling layers can be correctly compiled; stripping a kernel function of the core code layer and transferring the kernel function into a kernel calling layer; updating a project compiling file of the target kernel module, and combining a target file generated by compiling the core code layer and a source code of the kernel calling layer to generate a target kernel module text which can be loaded successfully; and packaging the DKMS configuration file of the target kernel module, the project compiling file, the source code of the kernel calling layer and a target file generated by compiling the core code layer together to manufacture a DKMS installation package of the target kernel module. According to the method, a developer can utilize the advantages of the DKMS and can use the closed source code, and the compatibility of a closed source kernel module can be guaranteed as much as possible when the kernel is upgraded.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the Linux kernel module development technology in the field of operating systems, and specifically relates to a closed-source kernel module generation method and system based on DKMS. Background Art

[0002] The Linux operating system can load drivers in two ways: static loading and dynamic loading. Static loading is to compile and configure the driver into the Linux kernel in advance, and load it with the kernel through do_initcall() when the operating system starts; dynamic loading is to load the driver independently as a kernel module after the kernel starts. Dynamic loading is more flexible and variable, and is widely used. It is easy to maintain and debug compared to static loading. However, in order to ensure the stability of the kernel, the Linux operating system uses a version verification mechanism for the module when dynamically loading the module into the kernel. When the system environment where the module is expected to be loaded changes, such as after the operating system is upgraded, the new system kernel is inconsistent with the operating system kernel version when the module is compiled, etc., the error of failing to load the module usually occurs.

[0003] The version check of dynamically loaded kernel modules includes vermagic check and CRC check: vermagic is used for version check of kernel modules. It is generated when compiling the kernel. The kernel module will include this vermagic information when compiling. If the vermagic information of the kernel module is inconsistent with the vermagic information of a kernel when loading the kernel module, it will trigger the error of kernel loading failure; if the kernel module passes the vermagic check, it will perform a CRC check again. The kernel saves its external interface API and data interface in the form of export functions (Export symbol) in a Module.symvers file, which also includes the CRC check values ​​of these symbols. The kernel module will include the CRC check value of the called symbol when compiling. If the system environment is inconsistent with the compilation environment or the system environment changes, when loading the kernel module, the CRC check value in the kernel module does not match the CRC check value of the actual kernel, which will trigger the error of kernel loading failure. To solve the problem of failure in dynamically loading kernel modules, one method is to manually recompile the kernel module. Manual compilation is time-consuming and labor-intensive, and has high requirements on users. The second method is to use the weak modules method to determine whether the module is target compatible with the currently installed kernel, and load the target compatible module, but the incompatible module still cannot be loaded. Another way is to force loading through modprobe or turn off the kernel configuration option for version verification, but if there is a compatibility issue, it will cause kernel crash, so it is not recommended.

[0004] A better way to solve this problem is to use Dynamic Kernel Module Support (DKMS) technology, which can trigger automatic building after the kernel changes, recompile and generate kernel modules to ensure that the new module matches the changed kernel version. DKMS installation packages should be made according to DKMS specifications, with all source code, so that the code generation module can be recompiled when the kernel version changes. This also enables Linux driver writers to provide their drivers as soon as possible without waiting for the release of a new version of the Linux kernel, and also eliminates users' concerns about whether the module can be recompiled on the new kernel. Although DKMS technology can solve the problem of automatically upgrading driver modules, it usually requires all source code to be public because it requires secondary compilation. This is not advisable for developers who have security, confidentiality, closed source and other requirements. Summary of the invention

[0005] The technical problem to be solved by the present invention is as follows: In view of the compatibility, security and other problems existing in kernel module development, a closed-source kernel module generation method and system based on DKMS are provided. The present invention aims to satisfy the needs of developers to utilize the advantages of DKMS to ensure kernel module compatibility while closing the source of the code, and to ensure that the closed-source kernel module is correctly loaded as much as possible when the kernel is upgraded.

[0006] The technical solution adopted by the present invention is: A closed-source kernel module generation method based on DKMS includes the following steps: S101, reconstructing and layering the source code of the target kernel module into a core code layer including the closed source code to be protected and a kernel call layer not including the closed source code to be protected so that the target kernel module can be correctly compiled; S102, stripping the kernel functions of the core code layer and transferring them to the kernel call layer; S103, updating the project compilation file of the target kernel module, combining the target file compiled by the core code layer and the source code of the kernel call layer to generate a target kernel module file that can be successfully loaded on the Linux operating system kernel; S104, packaging the DKMS configuration file of the target kernel module, the project compilation file, the source code of the kernel call layer, and the target file compiled by the core code layer together to produce a DKMS installation package of the target kernel module.

[0007] Optionally, step S101 includes: S201, reconstructing and layering the source code of the target kernel module into a core code layer including closed source code and a kernel call layer not including closed source code; S202, compile the source code of the reconstructed target kernel module. If the source code of the reconstructed target kernel module can be correctly compiled to generate a kernel module file, jump to step S102; otherwise, jump to step S201 to reconstruct the source code of the target kernel module and split it into a core code layer containing closed source code and a kernel call layer that does not contain closed source code.

[0008] Optionally, step S102 includes: S301, extracting the target file generated by compiling the core code layer; S302, judging whether the core code layer still uses kernel functions according to the target file generated by compiling the core code layer, and if so, stripping the code segments still using kernel functions from the core code layer and transferring them to the kernel call layer. Optionally, determining in step S302 whether the core code layer still uses kernel functions includes: using the nm command on the target file generated by the core code layer to obtain the kernel functions called by the code of the core code layer, forming a detection kernel function set with all the obtained kernel functions, and comparing the detection kernel function set with a preset standard kernel function set to determine whether the core code layer still uses kernel functions; if the detection kernel function set and the preset standard kernel function set have the same kernel functions, then determining whether the core code layer still uses kernel functions.

[0009] Optionally, when determining in step S302 whether the core code layer still uses kernel functions, the preset standard kernel function set is an API document from the Linux kernel or the system.map file under the directory / boot of the file system of the Linux operating system.

[0010] Optionally, in step S302, the code segments that still use kernel functions are stripped from the core code layer and transferred to the kernel call layer, including: for the code segments that still use kernel functions in the core code layer, a new encapsulation function is defined in the kernel call layer for the kernel function called by the code segments, the kernel function is called by using the new encapsulation function defined in the kernel call layer, and the call to the intrinsic function in the core code layer is modified to a call to the new encapsulation function defined in the kernel call layer.

[0011] Optionally, step S103 includes: S401, updating the project compilation file of the target kernel module: in the project compilation file of the target kernel module, after finding all the code files under the source code directory of the target kernel module and assigning them to the specified source variable SRC, replacing the source code suffix of the file name of the source code file corresponding to the source variable SRC with the suffix of the target file to generate the target file set OBJS, add a command line for obtaining the target file generated by compiling the core code layer to assign all the target files generated by compiling the core code layer to the specified target variable OBJ_DIR, and add a replacement command line to replace the target file with the renamed source code file of the core code layer in the target file set OBJS with the compiled target file; S402, using the project compilation file of the target kernel module to compile the target file generated by compiling the core code layer and the source code of the kernel call layer to generate a kernel module file of the target kernel module; S403, loading the kernel module file of the target kernel module on the Linux operating system kernel, if the loading is successful, jump to step S104; otherwise, jump to step S401 to re-update the project compilation file of the target kernel module or end and exit.

[0012] Optionally, step S104 includes: S501, putting the DKMS configuration file of the target kernel module, the project compilation file, the source code of the kernel call layer, and the target file compiled by the core code layer into a designated folder; S502, adding code from a specified folder as a DKMS module; S503, compile the code of the DKMS module; S504, install the DKMS module code and check the DKMS status; S505, DKMS installation package of the target kernel module.

[0013] In addition, the present invention also provides a closed-source kernel module generation system based on DKMS, comprising a microprocessor and a memory connected to each other, wherein the microprocessor is programmed or configured to execute the closed-source kernel module generation method based on DKMS.

[0014] In addition, the present invention also provides a computer-readable storage medium, in which a computer program is stored. The computer program is used to be programmed or configured by a microprocessor to execute the closed-source kernel module generation method based on DKMS.

[0015] Compared with the prior art, the present invention mainly has the following advantages: 1. Aiming at the problem that the original kernel module may no longer be applicable after the Linux operating system kernel is upgraded or changed, the present invention is aimed at closed-source kernel modules. When developing kernel modules and making installation packages, the core code that needs to be kept confidential can be closed-source, and the source code closely related to the kernel can be open-source. In this way, the needs of developers can both utilize the advantages of DKMS and use closed-source code, and the compatibility of modules can be guaranteed as much as possible when the kernel is upgraded.

[0016] 2. The method of the present invention has a wide range of applications and can be applied to various Linux kernel modules such as drivers, file systems and system calls. The developed and produced software packages have the advantages of automatic upgrades and core code security and confidentiality.

[0017] 3. The present invention does not rely on the source code development language of the kernel module, and can be applied to various development languages ​​such as C / C++ of the Linux kernel and kernel modules, and has the advantage of good versatility. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 Schematic diagram of the basic flow of the method of the embodiment of the present invention.

[0019] Figure 2 The figure is a flow chart of a closed-source kernel module development method based on DKMS in the implementation of the present invention.

[0020] Figure 3 The present invention is a flowchart of a kernel source code reconstruction method in the implementation of the present invention.

[0021] Figure 4 The present invention is a flowchart of making a DKMS kernel module installation package in the implementation. DETAILED DESCRIPTION

[0022] The kernel provides services to out-of-kernel applications through system calls (syscall), proc file system, and sys file system. System calls and proc and other kernel services and configuration interfaces provide the main way for out-of-kernel users (including core libraries such as C language) to access the kernel, forming the kernel's external application binary interface (ABI). Their updates and changes directly affect the kernel compatibility. In addition, the Linux kernel has another type of interface, that is, the interface between the kernel and the kernel module, which exists in the form of export functions (Export symbol). In the process of kernel evolution, the compatibility of this type of kernel module programming interface is not guaranteed, but keeps changing. The above two reasons lead to prominent kernel module compatibility issues. Automatic compilation after kernel module update based on DKMS technology can solve most compatibility issues, but in order to protect the code, part of the kernel code needs to be closed source. This part of the closed source code must ensure ABI-level compatibility with the kernel, that is, it can be compatible with the kernel without secondary compilation. In this process, a series of challenges are faced, such as which code needs to be closed source, how to design the interface of these closed source codes to be compatible with the kernel to achieve ABI, etc. The following will take the closed source code to be protected in a kernel module example (an example of adding and printing the result) as an example to further explain the closed source kernel module generation method and system based on DKMS of the present invention. The source code of the kernel module example is: #include<linux / init.h> #include<linux / module.h> #include "inc / test.h" int test() { int a=500; int b=600; printk("%d %d\n", a,b); return a + b; } static int hello_init(void){ printk("hello world %d\n", test()); return 0; } static void hello_exit(void){ printk("goodbye\n"); } module_init(hello_init); module_exit(hello_exit); MODULE_AUTHOR("XXX"); MODULE_DESCRIPTION("test"); MODULE_LICENSE("XXX"); In the above formula, #include is a reference to the library and header file, the test function is a closed-source code to be protected (an example of adding and printing the result), the functions hello_init and hello_exit are source codes that do not need to be protected, and MODULE_AUTHOR, MODULE_DESCRIPTION, and MODULE_LICENSE are all description information of the target kernel module. In order to protect the implementation of the test function, the source code can be layered, where the test function part is separated and placed in the core code layer to form a new file test.c; module_init, module_exit, etc. that are closely related to the kernel API are placed in the kernel call layer to form a new file hello.c.

[0023] like Figure 1 and Figure 2 As shown, the closed-source kernel module generation method based on DKMS in this embodiment includes the following steps: S101, reconstructing and layering the source code of the target kernel module (implementing the source code according to the normal development mode of the kernel module, or preparing the existing kernel module source code. The common kernel module code includes kernel header files, source code, and other files such as the project compilation file Makefile) into a core code layer including the closed source code to be protected and a kernel call layer not including the closed source code to be protected so that it can be compiled correctly; S102, stripping the kernel functions of the core code layer and transferring them to the kernel call layer; S103, updating the project compilation file of the target kernel module, combining the target file compiled by the core code layer and the source code of the kernel call layer to generate a target kernel module file so that it can be successfully loaded on the Linux operating system kernel; S104, packaging the DKMS configuration file of the target kernel module, the project compilation file, the source code of the kernel call layer, and the target file compiled by the core code layer together to produce a DKMS installation package of the target kernel module.

[0024] Step S101 is a layering step. Figure 2 and Figure 3 , step S101 includes: S201, reconstructing and layering the source code of the target kernel module into a core code layer including closed source code and a kernel call layer not including closed source code; S202, compile the source code of the reconstructed target kernel module. If the source code of the reconstructed target kernel module can be correctly compiled to generate a kernel module file, jump to step S102; otherwise jump to step S201 to reconstruct the source code of the target kernel module and split it into a core code layer containing closed source code and a kernel call layer that does not contain closed source code. When compiling the source code of the reconstructed target kernel module, execute the make command in the directory where the project compilation file Makefile is located. The codes of the core code layer and the kernel call layer will compile to generate some intermediate files and target files. The intermediate files include the target files (suffix .o) generated by the core code layer and the kernel call layer. At the same time, the kernel module file (suffix .ko, that is, the kernel module file obtained by the conventional method) generated by the entire source code will also be obtained at this time; in this embodiment, the core code to be protected is extracted to form a part of the code file, which we call the core code layer; the function implementation related to the kernel API call forms a part of the file, which we call the kernel call layer. The code in the kernel call layer calls the interface functions and data structures of the Linux kernel API. The implementation of these functions and data structures usually changes with kernel upgrades, so it is necessary to publicly perform secondary compilation. In addition, the code writing and organization of the kernel call layer will follow the development framework of the Linux kernel module. It is a relatively fixed template, and the call is the kernel's public API, so the code implementation is also relatively open, and there is no security risk of leaking the code; in short, the core code layer does not judge the kernel version, does not include the kernel API interface as much as possible, does not include template codes such as kernel modules, network drivers, displays, system calls, and only includes codes that need to be protected and closed source as much as possible. Specifically, the core code layer (test.c) code obtained in this embodiment is: #include "inc / test.h" int test() { int a=500; int b=600; printk("%d %d\n", a,b); return a + b; } The kernel call layer code (hello.c) obtained in the above example is: #include<linux / init.h> #include<linux / module.h> #include "inc / test.h" static int hello_init(void){ printk("hello world %d\n", test()); return 0; } static void hello_exit(void){ printk("goodbye\n"); } module_init(hello_init); module_exit(hello_exit); MODULE_AUTHOR("XXX"); MODULE_DESCRIPTION("test"); MODULE_LICENSE("XXX"); Step S102 is an abstract step. Figure 2 and Figure 3 , step S102 includes: S301, extracting the target file (with the suffix .o) generated by compiling the core code layer; S302, judging whether the core code layer still uses kernel functions according to the target file generated by compiling the core code layer, and if so, stripping the code segments still using kernel functions from the core code layer and transferring them to the kernel call layer. In step S302 of this embodiment, judging whether the core code layer still uses kernel functions according to the target file generated by compiling the core code layer includes: using the nm command on the target file (suffix .o) generated by the core code layer to obtain the kernel functions called by the codes of the core code layer, forming a detection kernel function set with all the obtained kernel functions, and comparing the detection kernel function set with a preset standard kernel function set to judge whether the core code layer still uses kernel functions; if the detection kernel function set and the preset standard kernel function set have the same kernel functions, then judging whether the core code layer still uses kernel functions.

[0025] The preset standard kernel function set can be generated in a desired manner as required. For example, as an optional implementation method, in step S302 of this embodiment, when judging whether the core code layer still uses kernel functions according to the target file generated by compiling the core code layer, the preset standard kernel function set is the API document from the Linux kernel or the system.map file under the directory / boot of the file system of the Linux operating system. The command nm *.o is executed on the .o target file generated by the core code layer to obtain the API called by the corresponding code, and all the obtained APIs are formed into a function set together. The function set is traversed by comparing the Linux kernel API document or checking the API in the system.map file under / boot to confirm whether there are still kernel functions in the function set.

[0026] In step S302 of this embodiment, the code segments that still use kernel functions are stripped from the core code layer and transferred to the kernel call layer include: for the code segments that still use kernel functions in the core code layer, define a new encapsulation function in the kernel call layer for the kernel functions that are called, use the new encapsulation function defined in the kernel call layer to call the kernel function, and modify the call to the connotation function in the core code layer to the call to the new encapsulation function defined in the kernel call layer. In the above manner, the abstraction of using kernel functions in the core code layer is realized, and secondary definition and encapsulation are performed through abstraction. If the implementation logic of the core code layer is relatively complex or the function implementation must use certain kernel functions, it is impossible to strip the code segments that include the kernel functions from the core code layer and transfer them to the kernel call layer, then these kernel functions can be secondary defined and encapsulated in the kernel call layer through abstraction. For example, a part of the code in the core code layer calls printk, and the core code layer must use this function, so a new function printk_wrapper is defined in the kernel call layer, and the function of this function is actually to call the kernel function printk, and then the core code layer is modified to select to call printk_wrapper, and no longer call printk. The kernel call layer code (hello.c) obtained is: #include<linux / init.h> #include<linux / module.h> #include "inc / test.h" int printk_wrapper (const char *fmt, ...) / / define encapsulation of printk { va_list args; int r; va_start(args, fmt); r = vprintk(fmt, args); va_end(args); return r; } static int hello_init(void){ printk("hello world %d\n", test()); return 0; } static void hello_exit(void){ printk("goodbye\n"); } module_init(hello_init); module_exit(hello_exit); MODULE_AUTHOR("XXX"); MODULE_DESCRIPTION("test"); MODULE_LICENSE("XXX"); Correspondingly, the abstracted core code layer code becomes: #include "inc / test.h" int test() { int a=500; int b=600; printk_wrapper ("%d %d\n", a,b); return a + b; } In this embodiment, step S103 includes: S401, update the project compilation file (Makefile) of the target kernel module: in the project compilation file of the target kernel module, after finding all code files in the source code directory of the target kernel module and assigning them to the specified source variable SRC, replacing the source code suffix of the file name of the source code file corresponding to the source variable SRC with the suffix of the target file to generate the target file set OBJS, add a command line for obtaining the target file generated by compiling the core code layer to assign all the target files generated by compiling the core code layer to the specified target variable OBJ_DIR, and add a replacement command line to replace the target file with the renamed source code file of the core code layer in the target file set OBJS with the compiled target file; S402, using the project compilation file of the target kernel module to compile the target file generated by compiling the core code layer and the source code of the kernel call layer to generate a kernel module file of the target kernel module; S403, loading the kernel module file of the target kernel module on the Linux operating system kernel, if the loading is successful, jump to step S104; otherwise, jump to step S401 to re-update the project compilation file of the target kernel module or end and exit.

[0027] When the project compilation file of the target kernel module is updated in step S401 of the present embodiment, in the project compilation file (Makefile) of the target kernel module, after all the code files under the source code directory of the target kernel module are found and assigned to the specified source variable SRC, and the source code suffix of the file name of the source code file corresponding to the source variable SRC is replaced with the suffix of the target file to generate the target file set OBJS, a command line for obtaining the target file generated by compiling the core code layer is added to assign all the target files generated by compiling the core code layer to the specified target variable OBJ_DIR, and a replacement command line is added to replace the target file renamed by the source code of the core code layer in the target file set OBJS with the compiled target file, wherein all the code files under the source code directory of the target kernel module are assigned to the specified source variable SRC, and the source code suffix of the file name of the source code file corresponding to the source variable SRC is replaced with the suffix of the target file to generate the target file set OBJS is an existing command, wherein the code is represented as: SRC = $(wildcard . / src / *.c) OBJS = $(patsubst %.c ,%.o ,$(src)) Among them, wildcard means using wildcards, which is used to assign any .c file in the / src directory to the source variable SRC; the patsubst function is used to replace the file pattern, which is used to replace the source code suffix .c of each file src in the source variable SRC with the suffix .o of the target file, where % is a wildcard, which is used to refer to the file name of the file src. Adding a command line to obtain the target file generated by the compilation of the core code layer to assign all the target files generated by the compilation of the core code layer to the specified target variable OBJ_DIR, and adding a replacement command line to replace the target file renamed by the source code of the core code layer in the target file set OBJS with the compiled target file can be expressed as: OBJ_DIR=. / closed_objs OBJS += $(foreach dir, $(OBJ_DIR), $(wildcard $(dir) / *.c)) In the above formula, / closed_objs is the directory where the target files generated by the compilation of the core code layer are stored, "+=" is an operator appended to the original value, and $(dir) is each directory under OBJS obtained by traversing foreach dir. Add the command line for obtaining the target files generated by the compilation of the core code layer to assign all the target files generated by the compilation of the core code layer to the specified target variable OBJ_DIR, and add the replacement command line to replace the target files renamed from the source code of the core code layer in the target file set OBJS with the target files generated by the compilation. The commands after that are the same as the original project compilation file (Makefile), including: example-objs = $(OBJS) obj-m := example.o all: $(MAKE) -C $(KERNELDIR) M=$(shell pwd) modules clean: rm -rf *.o *.ko *.depend *.mod.o *.mod.c Module.* modules.* .*.cmd.tmp_versions The first line indicates that the target file set OBJS is assigned to the object example-objs of the kernel module example. The second line is used to specify the output target file example.o for the kernel module example. The third line is the compilation parameter of make, and the second line is the clear command executed after compilation.

[0028] In this embodiment, the kernel module file of the target kernel module loaded on the Linux operating system kernel in step S403 refers to the kernel module file of the target kernel module loaded on the Linux operating system kernel through the insmod or modprobe command, specifically refers to the kernel module file of the target kernel module compiled in step S402.

[0029] like Figure 4 As shown, step S104 of this embodiment includes: S501, putting the DKMS configuration file of the target kernel module, the project compilation file, the source code of the kernel call layer, and the target file generated by the compilation of the core code layer into a specified folder. For example, the specific content of the DKMS configuration file of the target kernel module in this embodiment is as follows: PACKAGE_NAME="example" PACKAGE_VERSION="1.0.0" CLEAN="make clean" MAKE[0]="make all" BUILT_MODULE_NAME[0]="example" DEST_MODULE_LOCATION[0]=" / updates" AUTOINSTALL="yes" Among them, PACKAGE_NAME is used to specify the name of the target kernel module, PACKAGE_VERSION is used to specify the version of the target kernel module, CLEAN is used to specify the cleanup method of the target kernel module, MAKE[0] is used to specify the compilation method of the target kernel module, BUILT_MODULE_NAME[0] is used to specify the module name of the target kernel module, DEST_MODULE_LOCATION[0] is used to specify the module location of the target kernel module, and AUTOINSTALL is used to specify the automatic installation parameters of the target kernel module; S502, add code from the specified folder as a DKMS module, for example, the command in this embodiment is: dkms add -m exmaple -v 1.0.0; S503, compile the code of the DKMS module. For example, the command in this embodiment is: dkms build -m example -v 1.0.0; S504, installing the DKMS module code and checking the DKMS status. For example, in this embodiment, the command for installing the DKMS module code is: dkms install -m example -v 1.0.0, and the command for checking the DKMS status is: dkms status; S505, generating a DKMS installation package for the target kernel module. For example, the command in this embodiment is: dkms mkdeb -m example -v 1.0.0.

[0030] Based on the method proposed in this example, a communication kernel module is developed in this embodiment. The communication kernel module is suitable for data transmission under harsh communication conditions. The communication kernel module adopts neighborhood broadcast communication and no network routing, and customizes network protocols such as limited hop forwarding and probabilistic forwarding to meet the minimum network connectivity requirements. The network protocol, message mechanism and other codes in the communication kernel module are closed source to ensure the security of the core code. The compatibility of the communication kernel module is verified by simulating changes in the operating system version, kernel version and other environments. The test results are shown in the following table:

[0031] It can be seen from the test results that the communication kernel module developed based on the DKMS closed-source module generation method in this embodiment can cope with most kernel upgrade situations, can cross major version numbers such as kernel 4.18 and 5.4, and has relatively good compatibility.

[0032] In summary, the closed-source kernel module generation method based on DKMS in this embodiment can satisfy developers to take advantage of the advantages of DKMS while keeping the source code closed. When developing kernel modules and making installation packages, the core code that needs to be kept confidential will be closed source, and the source code closely related to the kernel will be open source, so that the compatibility of the module can be guaranteed as much as possible when the kernel is upgraded. The closed-source kernel module generator based on DKMS in this embodiment has a wide range of applications and can be applied to various Linux kernel modules such as drivers, file systems, and system calls. The developed and produced software packages have the advantages of automatic upgrades and core code security and confidentiality. Because the mainstream Linux kernel and kernel modules are developed in C / C++ language, the closed-source kernel module generator based on DKMS in this embodiment is mainly applicable to C / C++ code, but the closed-source kernel module generator based on DKMS in this embodiment does not depend on a specific language and has the advantage of good versatility.

[0033] In addition, this embodiment also provides a closed-source kernel module generation system based on DKMS, including a microprocessor and a memory connected to each other, and the microprocessor is programmed or configured to execute the closed-source kernel module generation method based on DKMS. This embodiment also provides a computer-readable storage medium, in which a computer program is stored, and the computer program is used to be programmed or configured by the microprocessor to execute the closed-source kernel module generation method based on DKMS.

[0034] Those skilled in the art should understand that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present application can take the form of a computer program product implemented on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the process Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be stored in a computer-readable memory that can guide a computer or other programmable data processing device to work in a specific way, so that the instructions stored in the computer-readable memory produce a product including an instruction device, which implements the functions specified in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to produce a computer-implemented process, so that the instructions executed on the computer or other programmable device provide for implementing the process in the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0035] The above is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should also be regarded as the protection scope of the present invention.

Claims

1. A closed-source kernel module generation method based on DKMS, characterized in that: The following steps are involved: S101, reconstructing and layering the source code of the target kernel module into a core code layer including the closed source code to be protected and a kernel call layer not including the closed source code to be protected so that the target kernel module can be correctly compiled; S102, stripping the kernel functions of the core code layer and transferring them to the kernel call layer; S103, updating the project compilation file of the target kernel module, combining the target file compiled by the core code layer and the source code of the kernel call layer to generate a target kernel module file that can be successfully loaded on the Linux operating system kernel; S104, packaging the DKMS configuration file of the target kernel module, the project compilation file, the source code of the kernel call layer, and the target file compiled by the core code layer together to produce a DKMS installation package of the target kernel module.

2. The closed-source kernel module generation method based on DKMS according to claim 1, characterized in that: Step S101 includes: S201, reconstructing and layering the source code of the target kernel module into a core code layer including closed source code and a kernel call layer not including closed source code; S202, compile the source code of the reconstructed target kernel module. If the source code of the reconstructed target kernel module can be correctly compiled to generate a kernel module file, jump to step S102; otherwise, jump to step S201 to reconstruct the source code of the target kernel module and split it into a core code layer containing closed source code and a kernel call layer that does not contain closed source code.

3. The closed-source kernel module generation method based on DKMS according to claim 1, characterized in that: Step S102 includes: S301, extracting the target file generated by compiling the core code layer; S302, judging whether the core code layer still uses kernel functions according to the target file generated by compiling the core code layer, and if so, stripping the code segments still using kernel functions from the core code layer and transferring them to the kernel call layer.

4. The closed-source kernel module generation method based on DKMS according to claim 3, characterized in that: Determining in step S302 whether the core code layer still uses kernel functions includes: using the nm command on the target file generated by the core code layer to obtain the kernel functions called by the code of the core code layer, forming a detection kernel function set with all the obtained kernel functions, and comparing the detection kernel function set with the preset standard kernel function set to determine whether the core code layer still uses kernel functions; if the detection kernel function set and the preset standard kernel function set have the same kernel functions, then determining whether the core code layer still uses kernel functions.

5. The closed-source kernel module generation method based on DKMS according to claim 4, characterized in that: When determining whether the core code layer still uses kernel functions in step S302, the preset standard kernel function set is an API document from the Linux kernel or the system.map file under the directory / boot of the file system of the Linux operating system.

6. The closed-source kernel module generation method based on DKMS according to claim 3, characterized in that: In step S302, the code segments that still use kernel functions are stripped from the core code layer and transferred to the kernel call layer, including: for the code segments that still use kernel functions in the core code layer, a new encapsulation function is defined in the kernel call layer for the kernel function called by it, the kernel function is called by using the new encapsulation function defined in the kernel call layer, and the call to the intrinsic function in the core code layer is modified to a call to the new encapsulation function defined in the kernel call layer.

7. The closed-source kernel module generation method based on DKMS according to claim 1, characterized in that: Step S103 includes: S401, update the project compilation file of the target kernel module: in the project compilation file of the target kernel module, after finding all the code files under the source code directory of the target kernel module and assigning them to the specified source variable SRC, replacing the source code suffix of the file name of the source code file corresponding to the source variable SRC with the suffix of the target file to generate the target file set OBJS, add a command line for obtaining the target file generated by compiling the core code layer to assign all the target files generated by compiling the core code layer to the specified target variable OBJ_DIR, and add a replacement command line to replace the target file with the renamed source code file of the core code layer in the target file set OBJS with the compiled target file; S402, using the project compilation file of the target kernel module to compile the target file generated by compiling the core code layer and the source code of the kernel call layer to generate a kernel module file of the target kernel module; S403, loading the kernel module file of the target kernel module on the Linux operating system kernel, if the loading is successful, jump to step S104; otherwise, jump to step S401 to re-update the project compilation file of the target kernel module or end and exit.

8. The closed-source kernel module generation method based on DKMS according to claim 1, characterized in that: Step S104 includes: S501, putting the DKMS configuration file of the target kernel module, the project compilation file, the source code of the kernel call layer, and the target file compiled by the core code layer into a designated folder; S502, adding code from a specified folder as a DKMS module; S503, compile the code of the DKMS module; S504, install the DKMS module code and check the DKMS status; S505, DKMS installation package of the target kernel module.

9. A closed-source kernel module generation system based on DKMS, comprising a microprocessor and a memory connected to each other, characterized in that: The microprocessor is programmed or configured to execute the closed-source kernel module generation method based on DKMS as described in any one of claims 1 to 8.

10. A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, characterized in that: The computer program is used to be programmed or configured by a microprocessor to execute the closed-source kernel module generation method based on DKMS as described in any one of claims 1 to 8.

Citation Information

Cited By

  • Network card performance optimization method and device and storage medium

    CN119201215A