(19)
(11)EP 3 667 490 A1

(12)EUROPEAN PATENT APPLICATION
published in accordance with Art. 153(4) EPC

(43)Date of publication:
17.06.2020 Bulletin 2020/25

(21)Application number: 18858920.4

(22)Date of filing:  21.09.2018
(51)International Patent Classification (IPC): 
G06F 9/445(2018.01)
(86)International application number:
PCT/CN2018/106954
(87)International publication number:
WO 2019/057155 (28.03.2019 Gazette  2019/13)
(84)Designated Contracting States:
AL AT BE BG CH CY CZ DE DK EE ES FI FR GB GR HR HU IE IS IT LI LT LU LV MC MK MT NL NO PL PT RO RS SE SI SK SM TR
Designated Extension States:
BA ME
Designated Validation States:
KH MA MD TN

(30)Priority: 21.09.2017 CN 201710856807

(71)Applicant: Huawei Technologies Co., Ltd.
Longgang District Shenzhen, Guangdong 518129 (CN)

(72)Inventors:
  • YANG, Qibin
    Shenzhen Guangdong 518129 (CN)
  • WANG, Fei
    Shenzhen Guangdong 518129 (CN)

(74)Representative: Körber, Martin Hans 
Mitscherlich PartmbB Patent- und Rechtsanwälte Sonnenstrasse 33
80331 München
80331 München (DE)

  


(54)METHOD AND DEVICE FOR DYNAMICALLY MANAGING KERNEL NODE


(57) This application provides a method and a device for managing a node. The method includes: initiating, by an application program, a first request by calling an interface function, where the first request is used to perform an operation on a feature node in a kernel; searching, based on a keyword of the interface function, a table used for node management for an entry corresponding to the feature node, where the entry includes a node identifier of the feature node and a user handle identifier of the feature node; and performing, by the user program, the operation on the feature node based on the user handle identifier. In embodiments of this application, a program running in user space can be prevented from directly accessing a feature node in kernel space, thereby improving system security.




Description


[0001] This application claims priority to Chinese Patent Application No. 201710856807.9, filed with the China National Intellectual Property Administration on September 21, 2017 and entitled "METHOD AND DEVICE FOR DYNAMICALLY MANAGING KERNEL NODE", which is incorporated herein by reference in its entirety.

TECHNICAL FIELD



[0002] This application relates to the communications field, and more specifically, to a method and a device for dynamically managing a kernel node.

BACKGROUND



[0003] In an existing Android (Android) system, a kernel is increasingly frequently upgraded. However, due to an original mechanism of the kernel, an entire kernel system is replaced even if one or some functions are upgraded and modified during an upgrade of the kernel. Based on this, a modular policy is used in a latest Android version, and hardware and software are completely separated, so as to ensure that a software version used by a user is not limited by a chip platform, thereby achieving an independent upgrade between function modules.

[0004] A kernel object (Kernel Object, ko) technology actually implements functions (or referred to as features) by using kernel objects, so that the kernel can support a feature by dynamically loading a ko of the feature. In this way, an Android community can maintain a latest kernel version, and once a problem such as a security vulnerability is found, modification can be performed in a timely manner through an independent upgrade, which does not affect an original function of a device, and can repair the security vulnerability in a timely manner.

[0005] A Linux kernel currently supports dynamic loading and offloading functions of a module. A compiled kernel feature object (for example, XXX.ko) may be loaded to a memory of the system by using an insmod command, so that the kernel supports the feature. If the feature is not required, the feature may be removed from the memory by using an rmmod command. Other features of the kernel are not affected in the foregoing process.

[0006] In the foregoing process, the kernel needs to create a node, so that a program in user space accesses the feature of the kernel. The node may be referred to as a feature node, a kernel node, or a function node. Currently, a node that is usually loaded by using insmod is installed in a /sys/module directory of the kernel. In addition, a name of the node is preset in the program and does not change. In this way, a program in any user space can sense the node and access the node. A parameter in the node may be usually used to control behavior of the feature of the kernel. Consequently, convenience is provided for some malicious programs, and system security is affected.

SUMMARY



[0007] This application provides a method and a device for managing a node, so that a program running in user space can be prevented from directly accessing a feature node in a kernel, thereby improving system security.

[0008] According to a first aspect, an embodiment of this application provides a method for managing a feature node in a kernel. The method includes:

[0009] A first request is initiated by calling an interface function, where the first request is used to perform an operation on a feature node in a kernel.

[0010] Specifically, an operating system that supports modular loading of a kernel function includes an application program, an adaptive node manager, and a kernel, where the adaptive node manager includes an interface management module and an encryption management module. The adaptive node manager may also be referred to as a node manager. Specifically, the interface management module may receive the first request that is initiated by the application program by calling the interface function.

[0011] Specifically, the first request may be used to perform an open operation, a read operation, a write operation, and a close operation on the feature node in the kernel. It may be understood that, in this embodiment of this application, performing the open operation on the feature node may also be creating the feature node, or loading the feature node, in other words, loading the feature node to a memory of a system. Performing the close operation on the feature node may also be deleting the feature node, or offloading the feature node, in other words, offloading the feature node from the memory of the system.

[0012] A table is searched based on a keyword in a function name of the interface function for an entry corresponding to the feature node, where the entry includes a node identifier of the feature node and a user handle identifier of the feature node, the node identifier of the feature node includes the keyword, there is a mapping relationship between the user handle identifier and a kernel handle identifier, and the kernel handle identifier represents an identity of the feature node running in the kernel.

[0013] Herein, the node identifier of the feature node may be used to uniquely identify the feature node. Specifically, the node identifier of the feature node may be a name of the feature node.

[0014] Specifically, the encryption management module searches, based on the interface function, the table used for node management for the entry corresponding to the feature node.

[0015] The user program performs the operation on the feature node based on the user handle identifier.

[0016] Specifically, the interface management module returns the user handle identifier to the user program, and the user program performs the operation on the feature node based on the user handle identifier.

[0017] Therefore, in this embodiment of this application, the first request that is used to perform the operation on the feature node is sent by calling the interface function, and the table used for node management (for example, a hash table) is searched for the entry of the feature node. The entry includes the user handle identifier that has a mapping relationship with the kernel handle identifier, and then the operation corresponding to the first request is performed on the feature node based on the user handle identifier. Therefore, in this embodiment of this application, the user handle identifier can be obtained by searching for the entry of the feature node, and the operation is performed on the feature node based on the user handle identifier, so that a coupling relationship between user space and the feature node in the kernel can be removed, and a program running in the user space performs a transparent operation on the feature node in the kernel, in other words, the program running in the user space can be prevented from directly accessing the feature node in the kernel in this embodiment of this application, thereby improving system security.

[0018] In this embodiment of this application, the following interface function may be defined:
int XXX FEATURE_IOCTL (int cmd, int arg), where
cmd is a control command parameter, and may support an open operation, a close operation, a read operation, and a write operation; and arg is an address corresponding to a parameter required by cmd. If cmd is a read command or a write command, arg is a corresponding data buffer (buffer) address. XXX may be a keyword in a function name of the interface function.

[0019] A return value of the interface function may indicate whether the operation succeeds. For example, if the return value is greater than or equal to 0, it indicates that the operation succeeds; or if the return value is less than 0, it indicates that the operation fails. Specifically, when the operation succeeds, the foregoing user handle identifier may be returned; or when the operation fails, a negative value indicating an error cause may be returned.

[0020] Optionally, in this embodiment of this application, the method further includes: The node identifier of the feature node is determined.

[0021] Specifically, the adaptive node manager further includes a node creation management module and a loading/offloading management module.

[0022] If the first request is not used to delete the feature node, before the encryption management module returns the user handle identifier to the user program, the node creation management module determines the node identifier of the feature node.

[0023] The feature node is loaded based on the node identifier of the feature node.

[0024] Specifically, the loading/offloading module sends the node identifier to the kernel, and the kernel loads the feature node based on the node identifier.

[0025] When the feature node is successfully loaded, the entry including the node identifier of the feature node and the user handle identifier of the feature node is added to the table, where the user handle identifier is a handle identifier in user space to which the kernel handle identifier of the feature node is mapped. Specifically, the encryption management module may add the entry to the table used for node management.

[0026] In this case, when the entry corresponding to the feature node is not found, a request for loading the feature node may be sent to the kernel. When the kernel successfully loads the feature node, the entry corresponding to the kernel node is added to the table used for node management. Therefore, in this embodiment of this application, the kernel node can be dynamically created according to an access requirement of the program in the user space.

[0027] Optionally, in this embodiment of this application, before the feature node is loaded based on the node identifier of the feature node, the method further includes:

a storage path of the feature node is determined, where the storage path is used to indicate a path along which the feature node is loaded to a memory; and

that the feature node is loaded based on the node identifier of the feature node includes:
the feature node is loaded based on the node identifier and the storage path of the feature node.



[0028] Specifically, the node creation management module may further determine the storage path of the feature node, the loading/offloading module sends the storage path to the kernel, and the kernel loads the feature node based on the storage path.

[0029] In this embodiment of this application, kernel nodes of different security levels may exist in different partitions. For example, a security partition may store some information about privacy, payment, and the like that requires high security. The partition may be configured with a high-security-level storage management manner, for example, a kernel node in the partition is accessed only when a security password is entered. A system partition may store some information about system-level data, a system-level program, and the like. The partition may be configured with a medium-security-level storage management manner, for example, the partition is accessed only when a system permission is obtained. A user partition may store data information of less importance such as common data of some users and a third-party program. The partition may be configured with a low-security-level storage management manner, for example, the partition may be read or written by configuring an access permission of the user.

[0030] In this case, compared with a preset node name and a fixed storage path in the prior art, in this embodiment of this application, the feature node can be created in a proper area based on a security level or an importance degree of the feature node, and the hash table can be updated. Therefore, in this embodiment of this application, only an application program related to the kernel node can access the kernel node, and another program in the user space cannot sense the feature node, thereby improving system security.

[0031] Optionally, in this embodiment of this application, before the feature node is loaded based on the node identifier of the feature node, the method further includes:

an access permission of the feature node is determined, where the access permission is used to indicate an application program that is allowed to access the feature node; and

that the feature node is loaded based on the node identifier of the feature node includes:
the feature node is loaded based on the node identifier and the access permission of the feature node.



[0032] Specifically, the node creation management module may further determine the access permission of the feature node, the loading/offloading module sends the storage path to the kernel, and the kernel loads the feature node based on the access permission.

[0033] Optionally, in this embodiment of this application, the entry further includes the access permission of the feature node. The method further includes:

the application program pass the user handle identifier by using the interface function; and

the access permission of the feature node is determined in the entry of the feature node based on the user handle identifier.



[0034] Specifically, the interface management module may further receive the user handle identifier that is passed by the application program by using the interface function. The encryption management module determines the access permission of the feature node in the entry of the feature node based on the user handle identifier.

[0035] If it is determined that the access permission allows the application program to access the feature node, the operation corresponding to the first request is performed on the feature node; or if it is determined that the access permission does not allow the application program to access the feature node, the encryption management module rejects the first request.

[0036] In a possible implementation, when the feature node is accessed for the first time, the application program may directly call the interface function to access a feature node provided by the kernel, and may directly search, based on a function name of the interface function, the hash table for an entry corresponding to the function name. When the entry corresponding to the function name is not found, the entry may be established. A user handle identifier returned by the node manager is obtained, and then the hash table is searched for the entry based on the user handle identifier. When the application program finds, based on the function name of the interface function, the entry corresponding to the function name in the hash table, the operation corresponding to the request may be performed.

[0037] In another possible implementation, when the feature node is accessed not for the first time, the node manager may search the hash table for the entry based on a user handle identifier passed by the interface function (namely, a user handle identifier returned when the feature node is accessed last time). When the entry corresponding to the user handle identifier is not found (for example, the feature node has been dynamically offloaded), a second request is rejected, and an identifier indicating an access failure is returned to the user program, for example, the identifier may be a negative number, and the negative value may indicate a cause for access rejection. When the entry corresponding to the user handle identifier is found, the operation corresponding to the request may be performed.

[0038] Optionally, when the access permission allows a current process to access the feature node, accessing an attribute of the node may be requested by calling the interface function. In this case, a dialog box indicating whether the current process is allowed to access the feature node is popped up in a user interface, to obtain authorization information of a user. When the user rejects the access, the required function exits, and an identifier indicating an access failure is returned to the user program, for example, the identifier may be a negative number, and the negative value may indicate a cause for access rejection. If the user allows access of the current program, the operation corresponding to the request may be performed.

[0039] Therefore, in this embodiment of this application, when the feature node is accessed by calling the interface function, a permission of a current process corresponding to the application program may be determined based on the access permission of the feature node corresponding to the interface function. In this way, transparent management of the process can be implemented, in other words, another application program that fails security authentication cannot access the feature node corresponding to the process, thereby ensuring secure access of the node.

[0040] In addition, according to the method for managing a node in this embodiment of this application, a development program can be simplified, and a to-be-accessed feature node can be statically configured. Specifically, a developer does not need to learn in detail a storage location of each feature node, a read/write permission required by each feature node, and the like. The process can run in the system, and the process has a specific permission. Therefore, according to the method, a feature node that needs to be accessed by the process may be directly set based on the permission of the process. In this way, not only a program accessing the node is simplified, but also security of the kernel node of the system is enhanced. The program can sense only a feature node with which the program needs to communicate, and cannot sense or access another node. Further, the developer does not need to learn an SE policy, and does not need to modify a file XXX.te, which improves program development efficiency.

[0041] Optionally, in this embodiment of this application, the entry further includes a reference counter of the feature node.

[0042] When the node creation management module creates the feature node, the encryption management module sets a count value of the reference counter to a default value.

[0043] The count value of the reference counter is increased if the first request is used to perform a read operation or a write operation on the feature node. For example, the count value is increased by 1.

[0044] The count value of the reference counter is decreased if the first request is used to delete the feature node. For example, the count value is decreased by 1, and when the count value is equal to a first preset value, the feature node is detected. Specifically, the loading/offloading management module may delete the feature node.

[0045] Optionally, in this embodiment of this application, if the first request is used to delete the feature node, whether the feature node is in a whitelist is queried, where the whitelist includes a feature node that does not need to be deleted. Specifically, the loading/offloading management module may perform a query operation.

[0046] If the feature node is not in the whitelist and the count value is equal to the first preset value, the feature node is deleted. If the feature node is in the whitelist, the feature node is not deleted.

[0047] Optionally, the entry further includes a timer, and the timer is started when the count value is equal to the first preset value. When the timer is equal to a second preset value, if the application program does not initiate, by calling the first interface function, a second request that is used to perform an operation on the feature node, and the second request is not used to delete the feature node, the feature node is deleted.

[0048] When the timer is less than the second preset value, if the interface management module receives the second request that is initiated by the application program by calling the first interface function, the timer stops timing, and the feature node is not deleted.

[0049] In this embodiment of this application, the node manager may further include a permission management module, a clock management module, and a concurrency management module. The permission management module is mainly configured to dynamically configure, based on a permission of a used program, a node that needs to be accessed by the program. The clock management module is configured to manage a clock that needs to be used in the node manager. The concurrency management module supports multi-threaded process concurrency, and can manage a conflict between each process and each thread.

[0050] Therefore, during feature node access in the kernel, a required feature node may be loaded to the memory by dynamically loading/offloading the feature node in this application, and when a feature node is not required, the feature node is removed from the memory. In this way, system resources such as a memory, a CPU, and I/O of the system occupied by a useless feature node can be reduced, so that the system can provide more resources for another running application program or service, thereby ensuring system performance.

[0051] According to a second aspect, an embodiment of this application provides a device for managing a node, configured to perform the method in any one of the first aspect or the possible implementations of the first aspect. Specifically, the device includes a module configured to perform the method in any one of the first aspect or the possible implementations of the first aspect.

[0052] According to a third aspect, an embodiment of this application provides a terminal device, including a memory and a processor. The memory is configured to store an instruction. The processor is configured to execute the instruction stored in the memory. When the processor executes the instruction stored in the memory, the execution enables the processor to perform the method in any one of the first aspect or the possible implementations of the first aspect.

[0053] According to a fourth aspect, an embodiment of this application provides a computer readable medium, configured to store a computer program, where the computer program includes an instruction for performing the method in any one of the first aspect or the possible implementations of the first aspect.

BRIEF DESCRIPTION OF DRAWINGS



[0054] 

FIG. 1 is a schematic diagram of a system architecture according to an embodiment of this application;

FIG. 2 is a schematic diagram of another system architecture according to an embodiment of this application;

FIG. 3 is a schematic flowchart of a method for managing a node according to an embodiment of this application;

FIG. 4 is a schematic flowchart in which a node server and a kernel load a feature node;

FIG. 5 is a schematic flowchart of node creation according to an embodiment of this application;

FIG. 6 is a schematic flowchart of a method for managing a node according to an embodiment of this application;

FIG. 7A and FIG. 7B are a schematic flowchart of a method for managing a node according to an embodiment of this application;

FIG. 8 is a schematic flowchart of a method for managing a node according to an embodiment of this application;

FIG. 9 is a schematic block diagram of a device for managing a node according to an embodiment of this application; and

FIG. 10 is a schematic block diagram of a terminal device according to an embodiment of this application.


DESCRIPTION OF EMBODIMENTS



[0055] The following describes technical solutions of this application with reference to accompanying drawings.

[0056] FIG. 1 is a schematic diagram of a system architecture according to an embodiment of this application. In this embodiment of this application, a node created in kernel space may be referred to as a feature node, a kernel node, or a function node. When an application program (for example, a native app (Native APP) 101 and a java app 102) in user space needs to access a function provided by a kernel, the application program performs an operation by using a negotiated interface function 103 instead of directly enabling the kernel node. Specifically, data is transmitted between the interface function 103, and the native app 101 and the java app 102 through a communications line (a dashed arrow shown in FIG 1). Herein, the application program may also be referred to as a user program.

[0057] Herein, the application programs in the user space may be, for example, the native app 101 and the java app 102 shown in FIG. 1, and may be other apps, for example, other program apps such as a web app and a Python app. This is not limited in this embodiment of this application. When the application program is the java app 102, the application program may further include a java native interface (JNI), and the java program may directly call a local function in a system through the JNI.

[0058] The interface function 103 is specifically implemented in a service module 100. The service module 100 may include the interface function 103, a node manager 104, a node client 105, and a node server 106. Specifically, control information may be transmitted between the interface function 103, the node manager 104, and the node client 105 through a control line (a solid arrow shown in FIG. 1). In addition, data may be transmitted between the interface function 103, the node client 105, and the node server 106 through a communication line. The control information may be transmitted between the node client 105 and a kernel 107 through the control line.

[0059] In this embodiment of this application, the service module 100 can remove a coupling relationship between the user space and a feature node in the kernel 107, so that the program running in the user space performs a transparent operation on the feature node in the kernel 107, in other words, the program running in the user space is not expected to directly access the feature node, thereby improving system security.

[0060] FIG. 2 is a schematic diagram of another system architecture according to an embodiment of this application. In the architecture shown in FIG. 2, an application program 201 may include a plurality of different application programs, for example, may be the native app 101, the java app 102, or another app in FIG. 1. A framework (Framework) 202 is a framework of user space, and is middleware for interaction between the application program and the system. A system service 203 is a service in the user space, including a node manager 216 and various feature services provided for each service and program. The various feature services are, for example, an activity manager 204, an application manager 205, a location manager 206, a display manager 207, and a multimedia manager 208. A local kernel library 217 is a kernel library provided by the system, including a function of a dedicated function, such as libc or Sqlite. A kernel 218 includes, for example, a scheduler 219, a memory 220, a file system 221, a driver 222, and a node 223. The node 223 may include one or more nodes, and each node can support a function or a feature corresponding to the node.

[0061] The node manager 216 may include, for example, a permission management module 209, an encryption management module 210, an interface management module 211, a node creation management module 212, a loading/offloading management module 213, a clock management module 214, and a concurrency management module 215.

[0062] The permission management module 209 is mainly configured to dynamically configure, based on a permission of a used program, a node that needs to be accessed by the program. The encryption management module 210 includes a table used for feature node encryption management, for example, a hash table that is used to manage a status used by a node. The encryption management module 210 can map a kernel node in the system to an ID used by a program in the user space. The interface management module 211 provides a universal interface for the user program. The loading/offloading management module 213 dynamically manages an opened node based on a node status in the hash table by using a clock. The clock management module 214 is configured to manage a clock that needs to be used in the node manager 216. The node creation management module 212 manages a created node based on a message entered by an interface and node information in the hash table. The concurrency management module 215 supports multi-threaded process concurrency, and can manage a conflict between each process and each thread.

[0063] It should be noted that in this embodiment of this application, an example in which the table used for encryption management in the encryption management module 210 is the hash table is used for description. However, in this embodiment of this application, the table is not limited to the hash table, and may be another table having a mapping relationship. This is not limited in this embodiment of this application. When the table in the encryption management module is the hash table, the encryption management module may also be referred to as a hash management module.

[0064] FIG. 3 is a schematic flowchart of a method for managing a node according to an embodiment of this application. It should be understood that FIG. 3 shows steps or operations of the method for managing a node. However, these steps or operations are merely an example, and other operations or variants of the operations in FIG. 3 may be alternatively performed in this embodiment of this application. In addition, the steps in FIG. 3 may be performed based on a sequence different from a sequence presented in FIG. 3, and it is possible that not all operations in FIG. 3 need to be performed.

[0065] 301. A user program calls an interface function.

[0066] In this embodiment of this application, a node manager 216 may provide some native interfaces (native APIs), so that the user program accesses a kernel node. The interface herein may also be referred to as an interface function. In this embodiment of this application, the following interface may be defined:
int XXX FEATURE_IOCTL (int cmd, int arg), where
cmd is a control command parameter, and may support an open (open) operation, a deletion (close) operation, a read (read) operation, and a write (write) operation; and arg is an address corresponding to a parameter required by cmd. If cmd is a read command or a write command, arg is a corresponding data buffer (buffer) address. XXX may be a keyword in a function name of the interface function. A return value of the interface may indicate whether the operation succeeds. For example, if the return value is greater than or equal to 0, it indicates that the operation succeeds; or if the return value is less than 0, it indicates that the operation fails.

[0067] It may be understood that, in this embodiment of this application, performing the open operation on the feature node may also be creating the feature node, or loading the feature node, in other words, loading the feature node to a memory of a system. Performing the close operation on the feature node may also be deleting the feature node, or offloading the feature node, in other words, offloading the feature node from the memory of the system.

[0068] Specifically, an interface management module 211 may receive a request that is initiated by the application program by calling the interface function, where the request is used to perform the operation on the feature node in a kernel. In 301, the request may be a request for performing one of the open operation, the read operation, the write operation, or the like on the feature node.

[0069] In this embodiment of this application, the node manager 216 may dynamically load the kernel node, and therefore the node manager 216 may be referred to as an adaptive node manager. In other words, the node manager may load one feature node to the memory when the application program needs to access the feature node. For example, when the application program calls the interface function, the control command parameter may be used to directly indicate the open operation, to create the feature node. Alternatively, when the application program needs to access the feature node, the control command parameter may be used to indicate the read operation or the write operation, to access the feature node. However, in this case, if there is no to-be-accessed feature node, the node manager may set the control command parameter to the open operation, to create a feature node.

[0070] In this embodiment of this application, one interface function 103 may correspond to one feature node in the kernel. In other words, the application program may access different feature nodes in the kernel by calling different interface functions.

[0071] In this embodiment of this application, a node identifier may uniquely identify the kernel node. In a specific implementation, the function name of the interface function and the node identifier of the kernel node have a same keyword, and the keyword may be, for example, a function corresponding to the node. When receiving a first request that is initiated by the application program by calling an interface function, the interface management module 211 can determine, based on a function name of the interface function, a node identifier of a feature node that needs to be accessed by the application program, and may further determine the feature node that needs to be accessed. Therefore, when the application program calls a first interface function, the node manager 216 may determine a function or a feature node that needs to be accessed by the application program and that corresponds to the first interface function.

[0072] In addition, specifically, the node identifier may be a name of the kernel node. For ease of understanding, an example in which the node identifier of the kernel node is the name of the kernel node is used for description below. However, this embodiment of this application is not limited thereto.

[0073] It may be understood that when the application program needs to access a feature node in the kernel to complete a function, an interface function corresponding to the function in the node manager 216 may be called. In other words, the application program may access different nodes in the kernel by calling different interface functions, so as to implement different functions.

[0074] For example, when the application program needs to implement a photographing function, an interface function corresponding to the photographing function such as a Camaro_FEATURE_IOCTL (int cmd, int arg) interface function in the node manager 216 may be called. In this case, the keyword may be Camaro. For another example, when the application program needs to use a pay function, an interface function corresponding to the pay (Pay) function such as a Pay_FEATURE_IOCTL (int cmd, int arg) interface function in the node manager 216 may be called. In this case, the keyword may be Pay.

[0075] It should be noted that in this embodiment of this application, different application programs may call a same interface function to access a feature node. For example, an application program having a picture processing function may also call the Camaro_FEATURE_IOCTL (int cmd, int arg) interface function in the node manager 216.

[0076] 302. Search a hash table for an entry.

[0077] A hash management module constructs in advance the hash table used for encryption management, and the hash management module may update the hash table based on a loading/offloading status of the feature node. Specifically, based on the interface function in step 301, the hash table is searched for the entry corresponding to the feature node. The entry includes a name and a user handle identifier (user handle ID) of the feature node. The name of the feature node and the function name of the interface function have a same keyword, there is a mapping relationship between the user handle identifier and a kernel handle identifier (kernel handle ID), and the kernel handle identifier represents an identity of the feature node running in the kernel.

[0078] The user handle identifier may also be referred to as a user program identifier (user program ID), and the kernel handle identifier may also be referred to as a kernel program identifier (kernel program ID). It may be understood that the user handle identifier may be a virtual ID of the feature node, and the virtual ID may uniquely correspond to the kernel program ID in the kernel by using the hash table. For example, the user program ID may be obtained by increasing the kernel program ID by one offset value. Because the kernel program ID is a real address of the feature node in the kernel, in this embodiment of this application, a program in user space performs a transparent operation on the feature node in the kernel.

[0079] Specifically, the node manager 216 searches the local hash table to determine whether there is an entry of a feature node corresponding to the interface function. If the entry is found, it indicates that there is the feature node corresponding to the interface function, and 308 is performed. If the entry is not found, it indicates that there is no feature node corresponding to the interface function. In this case, the feature node may be created, and 303 is performed next.

[0080] 303. Call a function used to create a feature node.

[0081] Specifically, when the entry corresponding to the feature node is not found in the hash table, a node creation management module 212 may call an internal function used for feature node creation, such as create_FEATURE ().

[0082] 304. Determine a name, a storage path, and an access permission of the feature node.

[0083] Specifically, the name of the feature node that needs to be created may be determined by parsing the create FEATURE () function.

[0084] In addition, optionally, in 304, the storage path of the feature node and/or the access permission of the application program to the feature node may be further obtained by parsing the create FEATURE () function. Specifically, the storage path and the access permission of the feature node may be determined based on a function corresponding to the feature node. Herein, the storage path is used to indicate a path along which the feature node is loaded to the memory, and the access permission is used to indicate an application program that is allowed to access the feature node.

[0085] For example, a security level required by a kernel node that implements the photographing function may be lower than a security level required by a kernel node that implements the pay function. Therefore, the Pay_FEATURE_IOCTL kernel node and the Camaro_FEATURE_IOCTL kernel node may exist in different partitions.

[0086] Specifically, a security partition may store some information about privacy, payment, and the like that requires high security. The partition may be configured with a high-security-level storage management manner, for example, a kernel node in the partition is accessed only when a security password is entered. A system partition may store some information about system-level data, a system-level program, and the like. The partition may be configured with a medium-security-level storage management manner, for example, the partition is accessed only when a system permission is obtained. A user partition may store data information of less importance such as common data of some users and a third-party program. The partition may be configured with a low-security-level storage management manner, for example, the partition may be read or written by configuring an access permission of the user.

[0087] Therefore, compared with a preset node name and a fixed storage path in the prior art, in this embodiment of this application, different storage paths may be allocated to and different access permissions may be configured for different nodes based on attributes of the node (for example, a security attribute). In this way, the kernel node in this embodiment of this application is invisible to another application program, thereby improving system security.

[0088] 305. Create a node client thread.

[0089] Specifically, the node creation management module 212 may create the node client (Node Client) thread based on the name, the storage path, and the access permission, and a concurrency management module 215 may concurrently manage one or more client thread processes in the node manager 216.

[0090] 306. Receive a message indicating that a node is successfully created.

[0091] Specifically, after the node client thread is created, the node creation management module 212 may wait for a return message indicating whether the feature node is successfully created.

[0092] The node client thread sends, to the node server (which may be a daemon server), a request for loading the feature node. Specifically, the node server may call an insmod function by using the system, and instruct the kernel to load the feature function, in other words, send the request to the kernel. After sending the request, the node server waits for the return message indicating whether the feature node is successfully created.

[0093] FIG. 4 is a schematic flowchart in which the node server and the kernel load a feature node.

3101. The node server creates a node message.

3102. The node server stores a source address of a created feature node.

3103. The node server calls an insmod function, where the insmod function may send a notification message to the kernel, and the notification message is used to instruct the kernel to load the feature node.

3104. The kernel loads the feature node.



[0094] In this case, there may be two loading results of the kernel: One is that the kernel successfully loads the feature node, and the other is that the kernel fails to load the feature node. The kernel may send, to the node server, a response message indicating whether the feature node is successfully loaded.

[0095] 3105. The node server sends a return message to a node client based on the received response message sent by the kernel.

[0096] When the response message that is sent by the kernel and that is received by the node server indicates that the feature node is successfully created, the node server sends, to the node client, a return message indicating that loading succeeds. The return message may include a user program ID and a kernel program ID. The node client then transmits, to the node creation management module, a return message indicating that creation succeeds.

[0097] When the kernel fails to load the feature node, the kernel returns a failure value (the failure value is a negative value) to the node server, and the failure value may indicate a failure cause. When the node server receives the failure value sent by the kernel, the node server returns the failure value to the node client. The node client then returns the failure value to the node manager 216. The node manager 216 may continue to return the failure value to the application program in the user space by using the interface function.

[0098] 307. Update the hash table.

[0099] Specifically, when the return message indicates that the feature node is successfully loaded, the hash management module updates the locally stored hash table based on received information. Specifically, the hash management module may add an entry to the hash table, where the entry may include a name, a storage path, an access permission, the kernel handle ID, the user handle ID, and the like of the feature node.

[0100] In some possible implementations, the entry may further include a reference counter of the feature node, a creation time TM of the node, and other information.

[0101] 308. Return an identifier.

[0102] Specifically, when the hash management module finds the entry of the feature node in the hash table in 302, the user handle identifier is returned to the application program in the user space.

[0103] When the entry of the feature node is not found in 302, the node manager may interact with the kernel, to create the feature node, and update the hash table. After the feature node is created, the node manager returns the user handle identifier of the feature node to the application program in the user space.

[0104] When the feature node fails to be created, a corresponding identifier ID may be returned, for example, the identifier ID may be the foregoing failure value, and the failure value may indicate a failure cause.

[0105] In this embodiment of this application, the user program initiates, by calling the interface function provided by the node manager, a request for accessing the kernel node, and the node manager searches, based on the request, the hash table for the entry corresponding to the kernel node. When the entry is not found in the hash table, the node manager may send, to the kernel, a request for loading the feature node. When the kernel successfully loads the feature node, the node manager adds the entry corresponding to the kernel node to the hash table. Therefore, in this embodiment of this application, the node manager can dynamically create a kernel node according to an access requirement of the user program.

[0106] In addition, in this embodiment of this application, the feature node can be created in a proper area based on a security level or an importance degree of the feature node, and the hash table can be updated. Therefore, in this embodiment of this application, only an application program related to the kernel node can access the kernel node, and another program in the user space cannot sense the feature node, thereby improving system security.

[0107] FIG. 5 is a schematic flowchart of node creation according to an embodiment of this application. Herein, an example in which an application program needs to access a feature node that has a pay function is used for description with reference to a schematic block diagram of a node manager.

[0108] In a command-based request stage, an application program 201 calls a corresponding feature function by using an API interface (as shown in step 1). Specifically, the application program may initiate, by calling Pay_FEATURE_IOCTL (int cmd, int arg), a command-based request for accessing a pay feature node.

[0109] An interface management module 211 in a node manager 203 receives the command-based request that is initiated by the API and that is from the application program or a service (as shown in step 2). The API may be specifically Pay FEATURE IOCTL (int cmd, int arg).

[0110] After receiving the command-based request, the interface management module 211 pass an internal command processing stage of the node manager 203. In this case, a permission management module 209 may check whether an operation of the process is allowed. If the operation is prohibited, the process ends. If the operation is allowed, a next operation is performed.

[0111] When a hash management module 210 cannot find a feature node corresponding to Pay_FEATURE_IOCTL in a hash table, the hash management module 210 may send, to a node creation management module 212, a request for creating a pay feature node (as shown in step 3). After the pay feature node is created, the node creation management module 212 exchanges data with the hash management module 210, and updates an entry of the feature node corresponding to Pay_FEATURE_IOCTL in the hash table (as shown in step 4). The node manager 203 performs agent management on the kernel node by using the hash table, so as to implement an information agent.

[0112] After the hash entry is updated, the node creation management module 212 may send, to a loading/offloading management module 213, a request for loading the feature node (as shown in step 5). The loading/offloading management module 213 may exchange data with a concurrency management module 215 (as shown in step 6), to determine whether to load the kernel node (that is, deliver a command). If the loading/offloading module 213 determines to load/offload the feature node, the loading/offloading module 213 sends a load/offload request to the concurrency management module 215 (as shown in step 6). The concurrency management module 215 may perform interactive communication with the kernel in a thread pool manner (that is, execute a command).

[0113] Then, the process enters a kernel processing stage. The kernel receives a loading/offloading command sent by the concurrency management module 215 (as shown in step 7), and completes loading/offloading of the kernel node.

[0114] After completing the loading/offloading operation on the feature node, the kernel sends a return message to the concurrency management module 215 (as shown in step 8). The concurrency management module 215 may send the return message to the loading/offloading management module 213 (as shown in step 9). The loading/offloading management module 213 sends the return message to the hash management module based on the return message, so that the hash management module 210 updates the entry of the pay feature node in the hash table based on the return message (as shown in step 10). In this case, the node creation management module 212 may send a response message indicating that creation is completed to the permission management module 209 (as shown in step 11). Then, the interface management module 211 may send the return message to the application program 201 (as shown in step 12). When the application program 201 receives a return message indicating that the operation of the interface function succeeds, calling of the API function is completed.

[0115] In this embodiment of this application, the user program initiates, by calling the interface function provided by the node manager, the request for accessing the kernel node, and the node manager searches, based on the request, the hash table for the entry corresponding to the kernel node. When the entry is not found, the node manager sends, to the kernel, the request for loading the feature node. When the kernel successfully loads the feature node, the node manager adds the entry corresponding to the kernel node to the hash table. Therefore, in this embodiment of this application, the node manager can dynamically create the kernel node according to an access requirement of the user program.

[0116] In addition, in this embodiment of this application, the feature node can be created in a proper area based on a security level or an importance degree of the feature node, the hash table is updated, and the kernel node is managed by using the hash table, so that only an application program related to the kernel node can access the kernel node, and another program in the user space cannot sense the feature node, thereby improving system security.

[0117] FIG. 6 is a schematic flowchart of a method for managing a node according to an embodiment of this application. It should be understood that FIG. 6 shows steps or operations of the method for managing a node. However, these steps or operations are merely an example, and other operations or variants of the operations in FIG. 6 may be alternatively performed in this embodiment of this application. In addition, the steps in FIG. 6 may be performed based on a sequence different from a sequence presented in FIG. 6, and it is possible that not all operations in FIG. 6 need to be performed.

[0118] 601. An application program calls an interface function.

[0119] Specifically, an interface management module 211 may receive a request that is initiated by the application program by calling the interface function, where the request is used to perform an operation on a feature node in a kernel. In 601, the request may be a request for performing one of an open operation, a read operation, a write operation, or the like on the feature node.

[0120] Specifically, for description of the interface function, refer to the description in 301. To avoid repetition, details are not described herein again.

[0121] 602. Search a hash table for an entry.

[0122] Specifically, a node manager searches the local hash table to determine whether there is an entry of a feature node corresponding to the interface function. If the entry is found, it indicates that there is the feature node corresponding to the interface function, and 603 is performed. If the entry is not found, it indicates that there is no feature node corresponding to the interface function, and a corresponding ID is directly returned, for example, the corresponding ID may be a negative number, and the negative number may indicate a failure cause.

[0123] Specifically, for the entry in 602, refer to the foregoing description in 302. To avoid repetition, details are not described herein again.

[0124] In a possible implementation, when the feature node is accessed for the first time, the application program may directly call the interface function to access a feature node provided by the kernel, and may directly search, based on a function name of the interface function, the hash table for an entry corresponding to the function name. When the entry corresponding to the function name is not found, the entry may be established. A user handle identifier returned by the node manager is obtained, and then the hash table is searched for the entry based on the user handle identifier according to the foregoing method. When the application program finds, based on the function name of the interface function, the entry corresponding to the function name in the hash table, 603 may be performed.

[0125] In another possible implementation, when the feature node is accessed not for the first time, the node manager may search the hash table for the entry based on a user handle identifier passed by the interface function (for example, the user handle identifier returned in FIG. 3, namely, a user handle identifier returned when the feature node is accessed last time). When the entry corresponding to the user handle identifier is not found (for example, the feature node has been dynamically offloaded), a second request is rejected, and 606 is performed: An identifier indicating an access failure is returned to the user program, for example, the identifier may be a negative number, and the negative value may indicate a cause for access rejection. When the entry corresponding to the user handle identifier is found, 603 is performed.

[0126] 603. Determine, based on a PID of the user program, whether the user program has an access permission.

[0127] In this embodiment of this application, the access permission in the entry includes a process ID PID of an application program that is allowed to access the feature node, or the access permission includes a name and a PID of an application program that is allowed to access the feature node.

[0128] Specifically, a permission management module may set the process ID of the application program that can access the feature node. When an application program needs to access the feature node, the permission management module may determine whether a process ID of the application program is a process ID that is allowed for access.

[0129] It may be understood that when the application program enables a process to execute a function, the kernel allocates a specific process ID to the application program, and the process ID of the process does not change before the process is killed. After the process is killed, the kernel may allocate the process ID to a next running process of the application program in the system. In this case, a hash management module may update the hash table and change an access permission of the feature node.

[0130] When the entry corresponding to the user handle identifier is found in the hash table, it may be further determined whether the current process is included in the entry, and the entry includes the access permission of the feature node.

[0131] Specifically, a process ID and a program name of the current process may be obtained, and a permission configuration attribute configured in mainfest is accessed by using a function checkSelfPermission. The permission configuration attribute includes the process ID PID of the program that is allowed to access the feature node. After a permission configuration is obtained by using checkSelfPermission, it may be determined, based on the permission configuration, whether the current application has a permission to access a feature node indicated by the current ID.

[0132] When the permission configuration attribute prohibits the current process from accessing the feature node, the access exits, and 606 is performed: An identifier indicating an access failure is returned to the user program, for example, the identifier may be a negative number, and the negative value may indicate a cause for access rejection.

[0133] 604. Determine whether a user is authorized.

[0134] Specifically, when a configuration file allows the current process to access the feature node, the current process may further continue to apply for an access permission. In this case, accessing an attribute of a node may be requested by using an interface function requestPermission. In this case, a dialog box indicating whether the current process is allowed to access the feature node is popped up in a user interface, to obtain authorization information of the user. In this case, blocking is required to wait for an authorization result. When the user rejects the access, the required function exits, and an identifier indicating an access failure is returned to the user program, for example, the identifier may be a negative number, and the negative value may indicate a cause for access rejection.

[0135] If the user allows access of the current program, 605 is performed.

[0136] 605. Set the application program to be visible to the node.

[0137] In this case, the user program can access the feature node in the kernel, to complete a function requested by the user application.

[0138] 606. Return an identifier.

[0139] When the procedure proceeds from 605 to 606, the user handle identifier in the hash table may be returned to the user program.

[0140] It should be noted that when the user program fails in the access, the returned identifier indicating an access failure is a negative value, and the negative value indicates a cause for access rejection. Therefore, the user returns different identifiers for exits in steps 602, 603, and 604.

[0141] Therefore, in this embodiment of this application, when the feature node is accessed by calling the interface function, a permission of a current process corresponding to the application program may be determined based on the access permission of the feature node corresponding to the interface function. In this way, transparent management of the process can be implemented, in other words, another application program that fails security authentication cannot access the feature node corresponding to the process, thereby ensuring secure access of the node.

[0142] In addition, according to the method for managing a node in this embodiment of this application, a development program can be simplified, and a to-be-accessed feature node can be statically configured. Specifically, a developer does not need to learn in detail a storage location of each feature node, a read/write permission required by each feature node, and the like. The process can run in the system, and the process has a specific permission. Therefore, according to the method, a feature node that needs to be accessed by the process may be directly set based on the permission of the process. In this way, not only a program accessing the node is simplified, but also security of the kernel node of the system is enhanced. The program can sense only a feature node with which the program needs to communicate, and cannot sense or access another node. Further, the developer does not need to learn an SE policy, and does not need to modify a file XXX.te, which improves program development efficiency.

[0143] FIG. 7A and FIG. 7B are a schematic flowchart of a method for managing a node according to an embodiment of this application. It should be understood that FIG. 7A and FIG. 7B show steps or operations of the method for managing a node. However, these steps or operations are merely an example, and other operations or variants of the operations in FIG. 7A and FIG. 7B may be alternatively performed in this embodiment of this application. In addition, the steps in FIG. 7A and FIG. 7B may be performed based on a sequence different from a sequence presented in FIG. 7A and FIG. 7B, and it is possible that not all operations in FIG. 7A and FIG. 7B need to be performed.

[0144] 701. An application program calls an interface function.

[0145] Herein, an interface management module 211 may receive a request that is initiated by the application program by calling the interface function, where the request is used to perform an open operation, a read operation, a write operation, or a close operation on a feature node in a kernel. For example, when the application program determines that the application program does not access a feature node in a time period, the application program may call the interface function to perform the close operation on the feature node, so as to release the currently used feature node.

[0146] Specifically, for description of the interface function, refer to the description in 301. To avoid repetition, details are not described herein again.

[0147] 702. Search a hash table for an entry.

[0148] Specifically, a node manager searches the local hash table to determine whether there is an entry of a feature node corresponding to the interface function. If the entry is found, it indicates that there is the feature node corresponding to the interface function, and 703 is performed. If the entry is not found, it indicates that there is no feature node corresponding to the interface function, and a corresponding identifier is directly returned, for example, the corresponding identifier may be a negative number, and the negative number may indicate a failure cause.

[0149] Specifically, for the entry, refer to the foregoing description. To avoid repetition, details are not described herein again.

[0150] 703. Determine, based on a PID of the user program, whether the user program has an access permission.

[0151] Specifically, when the user program has the access permission, 704 is performed next. When the user program does not have the access permission, a corresponding identifier is directly returned, for example, the corresponding identifier may be a negative number, and the negative number may indicate a failure cause. Specifically, for details about how to determine the access permission of the user program based on the PID, refer to the description in 603. To avoid repetition, details are not described herein again.

[0152] 704. Obtain a reference counter.

[0153] In this embodiment of this application, an entry of each feature node in the hash table may further include a reference counter of the feature node, and when the feature node is created, a count value RC of the reference counter may be set to a default value, for example, the default value may be 0 or another integer.

[0154] 705. Determine whether a current operation is a deletion operation.

[0155] 706. Increase the count value if the first request is used to perform a read operation or a write operation on the feature node. For example, the count value is increased by 1 (to be specific, RC++).

[0156] 707. Decrease the count value if the first request is used to delete the feature node. For example, the count value is decreased by 1 (to be specific, RC-).

[0157] Specifically, when the application program performs the read operation or the write operation on the feature node, for example, when the application program calls the interface function to perform the open operation, the read operation, or the write operation, the count value of the counter is increased. When the application program deletes the feature node, for example, when the application program calls the interface function to perform the close operation, the count value of the counter is decreased.

[0158] 708. Determine whether the count value is equal to a first preset value.

[0159] The first preset value may be preconfigured in the node manager, and in addition, the first preset value may be set according to experience, for example, may be greater than, equal to, or less than the default value of the count value. This is not limited in this embodiment of this application. In an example, the first preset value may be 0.

[0160] In a possible implementation, when the count value is equal to the first preset value (which may be preconfigured), the feature node may be directly offloaded.

[0161] In another possible implementation, when the count value is equal to the first preset value, the feature node may not be offloaded immediately, and whether the feature node needs to be offloaded is further determined. In this case, 709 may be performed next.

[0162] 709. Determine whether the feature node is in a whitelist.

[0163] Specifically, when it is determined in 708 that the feature node is offloaded, whether the feature node is in the whitelist may be further determined. The whitelist includes a feature node that does not need to be deleted.

[0164] It may be understood that when the feature node is a hardware-related feature node, a large quantity of registers need to be initialized each time the feature node is loaded, which takes a large amount of time. Such a feature node may be in the whitelist. Alternatively, when memory space occupied by a process related to the feature node is not large, such a feature node may also be in the whitelist. Herein, the whitelist may be preconfigured in the node manager 216.

[0165] If the feature node is not in the whitelist, the feature node may be directly deleted. Alternatively, 710 may be performed next.

[0166] If the feature node is in the whitelist, the feature node is not deleted. In this case, a corresponding identifier is returned, for example, the corresponding identifier may be a negative number, and the negative number may indicate a failure cause.

[0167] 710. Start a timer.

[0168] In this embodiment of this application, an entry of each feature node in the hash table may further include the timer.

[0169] 711. Determine whether the timer expires.

[0170] Specifically, a second preset value may be preconfigured in the timer, and in addition, the second preset value may be set according to experience, and different second preset values may be configured for different feature nodes. This is not limited in this embodiment of this application.

[0171] When the timer is less than the second preset value after the timer is started, if a request for accessing the feature node that is initiated by the application program by calling the first interface function is received, for example, the request is to perform an operation such as open, read, or write on the feature node, the timer stops timing, and in this case, the feature node is not deleted. When the timer is equal to the second preset value, if the request for accessing the feature node that is initiated by the application program by calling the first interface function is not received, 712 is performed next.

[0172] 712. Search the hash table for the entry.

[0173] Specifically, the feature node may be deleted when the procedure proceeds from 702 to 712. Therefore, the hash table may be searched for the entry again herein. If the entry is found, 713 is performed next; or if the entry is not found, 715 is performed: A corresponding identifier is returned, for example, the corresponding identifier may be a negative number, and the negative number may indicate a failure cause.

[0174] 713. Delete the entry

[0175] 714. The kernel offloads the feature node.

[0176] Specifically, after updating the hash table, a hash management module may trigger a loading/offloading management module 213 to offload the feature node corresponding to the entry. Specifically, dynamic offloading may be performed by calling an rmmod function by the system.

[0177] 715. Return an identifier.

[0178] For details, refer to the description in 606. To avoid repetition, details are not described herein again.

[0179] During feature node access in the kernel, a required feature node may be loaded to a memory by dynamically loading/offloading the feature node in this application, and when a feature node is not required, the feature node is removed from the memory. In this way, system resources such as a memory, a CPU, and I/O of the system occupied by a useless feature node can be reduced, so that the system can provide more resources for another running application program or service, thereby ensuring system performance.

[0180] For example, if an application program needs to access 100 feature nodes during running, when the application program exits the system, these feature nodes may not be used by another application program for a short time or a long time. In this case, these feature nodes may be offloaded. It is assumed that a system memory occupied by each feature node is 100 KB, if these feature nodes are not offloaded, the 100 feature nodes need to occupy a memory of 10 MB. In addition, these feature nodes may also monitor some event information, for example, a heartbeat, which wastes valuable system resources.

[0181] FIG. 8 is a schematic flowchart of a method for managing a node according to an embodiment of this application. The method for managing a node in this embodiment of this application may be implemented in an operating system that supports modular loading of a kernel function, and the operating system is, for example, an operating system based on a Linux kernel (such as an Android operating system). The operating system includes an application program, an adaptive node manager, and a kernel, where the adaptive node manager includes an interface management module and an encryption management module.

[0182] Specifically, for description of the application program, the adaptive node manager, and the kernel, refer to the foregoing description. To avoid repetition, details are not described herein again.

[0183] 810. Initiate a first request by calling an interface function, where the first request is used to perform an operation on a feature node in a kernel.

[0184] Specifically, the interface management module receives the first request that is initiated by the application program by calling the interface function. Herein, the first request may be used to perform an open operation, a read operation, a write operation, and a close operation on the feature node in the kernel.

[0185] 820. Search, based on a keyword in a function name of the interface function, a table used for node management for an entry corresponding to the feature node.

[0186] Specifically, the encryption management module searches, based on the keyword in the function name of the interface function, the table used for node management for the entry corresponding to the feature node, where the entry includes a node identifier of the feature node and a user handle identifier of the feature node, the node identifier of the feature node includes the keyword, there is a mapping relationship between the user handle identifier and a kernel handle identifier, and the kernel handle identifier represents an identity of the feature node running in the kernel.

[0187] For example, the node identifier of the feature node may be specifically a name of the feature node.

[0188] 830. Perform the operation on the feature node based on the user handle identifier.

[0189] Specifically, the interface management module returns the user handle identifier to the user program, and the user program performs the operation on the feature node based on the user handle identifier.

[0190] Specifically, for 810, 820, and 830, refer to the foregoing description in FIG. 3, FIG. 6, or FIG. 7A and FIG. 7B. To avoid repetition, details are not described herein again.

[0191] Therefore, in this embodiment of this application, the first request that is used to perform the operation on the feature node is sent by calling the interface function, and the table used for node management (for example, a hash table) is searched for the entry of the feature node. The entry includes the user handle identifier that has a mapping relationship with the kernel handle identifier, and then the operation corresponding to the first request is performed on the feature node based on the user handle identifier. Therefore, in this embodiment of this application, the user handle identifier can be obtained by searching for the entry of the feature node, and the operation is performed on the feature node based on the user handle identifier, so that a coupling relationship between user space and the feature node in the kernel can be removed, and a program running in the user space performs a transparent operation on the feature node in the kernel, in other words, the program running in the user space can be prevented from directly accessing the feature node in the kernel space in this embodiment of this application, thereby improving system security.

[0192] Optionally, in this embodiment of this application, the method further includes: The node identifier of the feature node is determined.

[0193] Specifically, the adaptive node manager further includes a node creation management module and a loading/offloading management module. If the first request is not used to delete the feature node, before the encryption management module returns the user handle identifier to the user program, the node creation management module determines the name of the feature node.

[0194] The feature node is loaded based on the node identifier of the feature node.

[0195] Specifically, the loading/offloading module sends the name to the kernel, so that the kernel loads the feature node based on the name.

[0196] When the feature node is successfully loaded, the kernel handle identifier is obtained, and the user handle identifier is determined based on the kernel handle identifier, where the user handle identifier is a handle identifier in the user space to which the kernel handle identifier of the feature node is mapped.

[0197] Specifically, when determining that the kernel successfully loads the feature node, the loading/offloading module obtains the kernel handle identifier of the feature node, and determines the user handle identifier based on the kernel handle identifier.

[0198] The entry including the node identifier of the feature node and the user handle identifier of the feature node is added to the table. Specifically, the encryption management module adds the entry to the table.

[0199] In this case, when the encryption management module does not find the entry in the hash table, the node manager may send, to the kernel, a request for loading the feature node. When the kernel successfully loads the feature node, the node manager adds the entry corresponding to the kernel node to the hash table. Therefore, in this embodiment of this application, the node manager can dynamically create a kernel node according to an access requirement of the user program.

[0200] Optionally, in this embodiment of this application, before the feature node is loaded based on the node identifier of the feature node, the method further includes:

a storage path of the feature node is determined, where the storage path is used to indicate a path along which the feature node is loaded to a memory; and

that the feature node is loaded based on the node identifier of the feature node includes:
the feature node is loaded based on the node identifier and the storage path of the feature node.



[0201] Specifically, the node creation management module may further determine the storage path of the feature node, the loading/offloading module sends the storage path to the kernel, and the kernel loads the feature node based on the storage path.

[0202] Optionally, in this embodiment of this application, before the feature node is loaded based on the node identifier of the feature node, the method further includes:

an access permission of the feature node is determined, where the access permission is used to indicate an application program that is allowed to access the feature node; and

that the feature node is loaded based on the node identifier of the feature node includes:
the feature node is loaded based on the node identifier and the access permission of the feature node.



[0203] Specifically, the node creation management module may further determine the access permission of the feature node, the loading/offloading module sends the storage path to the kernel, and the kernel loads the feature node based on the access permission.

[0204] Specifically, for the steps performed by the node creation management module and the loading/offloading module, refer to the foregoing description in FIG. 3. To avoid repetition, details are not described herein again.

[0205] In this case, in this embodiment of this application, the feature node can be created in a proper area based on a security level or an importance degree of the feature node, and the hash table can be updated. Therefore, in this embodiment of this application, only an application program related to the kernel node can access the kernel node, and another program in the user space cannot sense the feature node, thereby improving system security.

[0206] Optionally, in this embodiment of this application, the entry further includes the access permission of the feature node. The method further includes:

the application program pass the user handle identifier by using the interface function; and

the access permission of the feature node is determined in the entry of the feature node based on the user handle identifier.



[0207] Specifically, the interface management module may further receive the user handle identifier that is passed by the application program by using the interface function.

[0208] The encryption management module determines the access permission of the feature node in the entry of the feature node based on the user handle identifier.

[0209] If it is determined that the access permission allows the application program to access the feature node, the operation corresponding to the first request is performed on the feature node; or if it is determined that the access permission does not allow the application program to access the feature node, the encryption management module rejects the first request.

[0210] Specifically, for the steps performed by the encryption management module and the encryption management module, refer to the foregoing description in FIG. 6. To avoid repetition, details are not described herein again.

[0211] Therefore, in this embodiment of this application, when the feature node is accessed by calling the interface function, a permission of a current process corresponding to the application program may be determined based on the access permission of the feature node corresponding to the interface function. In this way, transparent management of the process can be implemented, in other words, another application program that fails security authentication cannot access the feature node corresponding to the process, thereby ensuring secure access of the node.

[0212] In addition, according to the method for managing a node in this embodiment of this application, a development program can be simplified, and a to-be-accessed feature node can be statically configured. Specifically, a developer does not need to learn in detail a storage location of each feature node, a read/write permission required by each feature node, and the like. The process can run in the system, the process has a specific permission. Therefore, according to the method, a feature node that needs to be accessed by the process may be directly set based on the permission of the process. In this way, not only a program accessing the node is simplified, but also security of the kernel node of the system is enhanced. The program can sense only a feature node with which the program needs to communicate, and cannot sense or access another node. Further, the developer does not need to learn an SE policy, and does not need to modify a file XXX.te, which improves program development efficiency.

[0213] Optionally, in this embodiment of this application, the entry further includes a reference counter of the feature node. When the node creation management module creates the feature node, the encryption management module may set a count value of the reference counter to a default value.

[0214] The count value of the reference counter is increased if the first request is used to perform a read operation or a write operation on the feature node. For example, the count value is increased by 1.

[0215] The count value of the reference counter is decreased if the first request is used to delete the feature node. For example, the count value is decreased by 1, and when the count value is equal to a first preset value, the loading/offloading management module deletes the feature node.

[0216] Optionally, in this embodiment of this application, if the first request is used to delete the feature node, whether the feature node is in a whitelist is queried, where the whitelist includes a feature node that does not need to be deleted. Specifically, the loading/offloading management module may perform the query operation.

[0217] If the feature node is not in the whitelist and the count value is equal to the first preset value, the feature node is deleted. If the feature node is in the whitelist, the feature node is not deleted.

[0218] Optionally, the entry further includes a timer, and the timer is started when the count value is equal to the first preset value. When the timer is equal to a second preset value, if the application program does not initiate, by calling the first interface function, a second request that is used to perform an operation on the feature node, and the second request is not used to delete the feature node, the feature node is deleted.

[0219] When the timer is less than the second preset value, if the interface management module receives the second request that is initiated by the application program by calling the first interface function, the timer stops timing, and the feature node is not deleted.

[0220] Specifically, for the reference counter, the whitelist, and the timer, refer to the foregoing description in FIG. 7A and FIG. 7B. Specifically, for a process in which the loading/offloading management module dynamically offloads the feature node, refer to the foregoing description in FIG. 7A and FIG. 7B. To avoid repetition, details are not described herein again.

[0221] Therefore, during feature node access in the kernel, a required feature node may be loaded to the memory by dynamically loading/offloading the feature node in this application, and when a feature node is not required, the feature node is removed from the memory. In this way, system resources such as a memory, a CPU, and I/O of the system occupied by a useless feature node can be reduced, so that the system can provide more resources for another running application program or service, thereby ensuring system performance.

[0222] FIG. 9 is a schematic block diagram of a device 900 for managing a node according to an embodiment of this application. The device 900 may be a terminal device on which an operating system that supports modular loading of a kernel function is installed, for example, a tablet computer and a smartwatch. The device 900 includes an interface unit 910, a searching unit 920, an execution unit 930.

[0223] The interface unit 910 is configured to initiate a first request by calling an interface function, where the first request is used to perform an operation on a feature node in a kernel.

[0224] The searching unit 920 is configured to search, based on a keyword in a function name of the interface function, a table for an entry corresponding to the feature node, where the entry includes a node identifier of the feature node and a user handle identifier of the feature node, the node identifier of the feature node includes the keyword, there is a mapping relationship between the user handle identifier and a kernel handle identifier, and the kernel handle identifier represents an identity of the feature node running in the kernel.

[0225] The execution unit 930 is further configured to perform the operation on the feature node based on the user handle identifier.

[0226] Therefore, in this embodiment of this application, the first request that is used to perform the operation on the feature node is sent by calling the interface function, and the table used for node management (for example, a hash table) is searched for the entry of the feature node. The entry includes the user handle identifier that has a mapping relationship with the kernel handle identifier, and then the operation corresponding to the first request is performed on the feature node based on the user handle identifier. Therefore, in this embodiment of this application, the user handle identifier can be obtained by searching for the entry of the feature node, and the operation is performed on the feature node based on the user handle identifier, so that a coupling relationship between user space and the feature node in the kernel can be removed, and a program running in the user space performs a transparent operation on the feature node in the kernel, in other words, the program running in the user space can be prevented from directly accessing the feature node in the kernel space in this embodiment of this application, thereby improving system security.

[0227] Optionally, the device further includes:

a determining unit, configured to determine the node identifier of the feature node;

a loading unit, configured to load the feature node based on the node identifier of the feature node; and

an adding unit, configured to: when the feature node is successfully loaded, add the entry including the node identifier of the feature node and the user handle identifier of the feature node to the table, where the user handle identifier is a handle identifier in user space to which the kernel handle identifier of the feature node is mapped.



[0228] In this case, when the entry corresponding to the feature node is not found, a request for loading the feature node may be sent to the kernel. When the kernel successfully loads the feature node, the entry corresponding to the kernel node is added to the table used for node management. Therefore, in this embodiment of this application, the kernel node can be dynamically created according to an access requirement of the program in the user space.

[0229] Optionally, the determining unit is further configured to determine a storage path of the feature node, where the storage path is used to indicate a path along which the feature node is loaded to a memory.

[0230] The loading unit is specifically configured to:
load the feature node based on the node identifier and the storage path of the feature node determined by the determining unit.

[0231] Optionally, the determining unit is further configured to determine an access permission of the feature node, where the access permission is used to indicate an application program that is allowed to access the feature node.

[0232] The loading unit is specifically configured to:
load the feature node based on the node identifier and the access permission of the feature node determined by the determining unit.

[0233] In this case, in this embodiment of this application, the feature node can be created in a proper area based on a security level or an importance degree of the feature node, and the table used for node management is updated. Therefore, in this embodiment of this application, only an application program related to the kernel node can access the kernel node, and another program in the user space cannot sense the feature node, thereby improving system security.

[0234] Optionally, the entry further includes the access permission of the feature node. The interface unit 910 is further configured to pass the user handle identifier by using the interface function, and the determining unit is further configured to determine the access permission of the feature node in the entry of the feature node based on the user handle identifier.

[0235] If it is determined that the access permission allows the application program to access the feature node, the operation corresponding to the first request is performed on the feature node.

[0236] If it is determined that the access permission does not allow the application program to access the feature node, the first request is rejected.

[0237] Therefore, in this embodiment of this application, when the feature node is accessed by calling the interface function, a permission of a current process corresponding to the application program may be determined based on the access permission of the feature node corresponding to the interface function. In this way, transparent management of the process can be implemented, in other words, another application program that fails security authentication cannot access the feature node corresponding to the process, thereby ensuring secure access of the node.

[0238] In addition, according to the method for managing a node in this embodiment of this application, a development program can be simplified, and a to-be-accessed feature node can be statically configured. Specifically, a developer does not need to learn in detail a storage location of each feature node, a read/write permission required by each feature node, and the like. The process can run in the system, the process has a specific permission. Therefore, according to the method, a feature node that needs to be accessed by the process may be directly set based on the permission of the process. In this way, not only a program accessing the node is simplified, but also security of the kernel node of the system is enhanced. The program can see only a feature node with which the program needs to communicate, and cannot see or access another node. Further, the developer does not need to learn an SE policy, and does not need to modify a file XXX.te, which improves program development efficiency.

[0239] Optionally, the entry further includes a reference counter of the feature node, and when the feature node is created, a count value of the reference counter may be further set to a default value.

[0240] The count value of the reference counter is increased if the first request is used to perform a read operation or a write operation on the feature node. For example, the count value is increased by 1.

[0241] The device further includes a deletion unit. The count value of the reference counter is decreased if the first request is used to delete the feature node. For example, the count value is decreased by 1. When the count value is equal to a first preset value, the deletion unit is further configured to delete the feature node.

[0242] Optionally, if the first request is used to delete the feature node, whether the feature node is in a whitelist is queried, where the whitelist includes a feature node that does not need to be deleted. If the feature node is not in the whitelist and the count value is equal to the first preset value, the deletion unit is configured to delete the feature node. If the feature node is in the whitelist, the feature node is not deleted.

[0243] Optionally, the entry further includes a timer, and the timer is started when the count value is equal to the first preset value.

[0244] When the timer is equal to a second preset value, if the application program does not initiate, by calling the first interface function, a second request that is used to perform an operation on the feature node, and the second request is not used to delete the feature node, the deletion unit is further configured to delete the feature node.

[0245] Therefore, during feature node access in the kernel, a required feature node may be loaded to the memory by dynamically loading/offloading the feature node in this application, and when a feature node is not required, the feature node is removed from the memory. In this way, system resources such as a memory, a CPU, and I/O of the system occupied by a useless feature node can be reduced, so that the system can provide more resources for another running application program or service, thereby ensuring system performance.

[0246] It should be noted that the technical solutions of the embodiments of the present invention may be applied to various terminal devices (also referred to as user equipment) on which an operating system that supports modular loading of a kernel function is installed, for example, a mobile phone, a wristband, a tablet computer, a notebook computer, an ultra-mobile personal computer (UMPC), a personal digital assistant (PDA) device, a handheld device with a wireless communication function, a computing device or another processing device connected to a wireless modem, a vehicle-mounted device, and a wearable device. The terminal device is not limited to a communications terminal.

[0247] FIG. 10 is a schematic block diagram of a mobile phone 1000 according to an embodiment of this application. The mobile phone 1000 may include components such as a radio frequency (RF) circuit 1010, a memory 1020, an input unit 1030, a wireless fidelity (Wi-Fi) module 1070, a display unit 1040, a sensor 1050, an audio frequency circuit 1060, a processor 1080, and a power supply 1090.

[0248] A person skilled in the art may understand that a structure of the mobile phone shown in FIG. 10 is only an example instead of a limitation, and the mobile phone may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.

[0249] The RF circuit 1010 may be configured to: receive and send a signal in an information receiving and sending process or a communication process; particularly, after receiving downlink information of a base station, send the downlink information to the processor 1080 for processing; and in addition, send uplink data of the mobile phone to the base station. Generally, the RF circuit includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (low noise amplifier, LNA), and a duplexer. In addition, the RF circuit 1010 may further communicate with a network and another device through wireless communication. The wireless communication may use any communications standard or protocol, including but not limited to global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), long term evolution (LTE), an email, and a short message service (SMS).

[0250] In this embodiment of this application, the interface unit 910, the searching unit 920, and the execution unit 930 may be implemented by the processor. Specifically, the memory 1020 is configured to store program code. The processor 1080 is configured to execute the program code stored in the memory 1020, and when the program code is executed, the processor 1080 is configured to:

initiate a first request by calling an interface function, where the first request is used to perform an operation on a feature node in a kernel;

search, based on a keyword in a function name of the interface function, a table for an entry corresponding to the feature node, where the entry includes a node identifier of the feature node and a user handle identifier of the feature node, the node identifier of the feature node includes the keyword, there is a mapping relationship between the user handle identifier and a kernel handle identifier, and the kernel handle identifier represents an identity of the feature node running in the kernel; and

perform the operation on the feature node based on the user handle identifier.



[0251] Therefore, in this embodiment of this application, the first request that is used to perform the operation on the feature node is sent by calling the interface function, and the table used for node management (for example, a hash table) is searched for the entry of the feature node. The entry includes the user handle identifier that has a mapping relationship with the kernel handle identifier, and then the operation corresponding to the first request is performed on the feature node based on the user handle identifier. Therefore, in this embodiment of this application, the user handle identifier can be obtained by searching for the entry of the feature node, and the operation is performed on the feature node based on the user handle identifier, so that a coupling relationship between user space and the feature node in the kernel can be removed, and a program running in the user space performs a transparent operation on the feature node in the kernel, in other words, the program running in the user space can be prevented from directly accessing the feature node in the kernel space in this embodiment of this application, thereby improving system security.

[0252] Optionally, in this embodiment of this application, the processor 1080 is further configured to: determine the node identifier of the feature node;
load the feature node based on the node identifier of the feature node; and
when the feature node is successfully loaded, add the entry including the node identifier of the feature node and the user handle identifier of the feature node to the table, where the user handle identifier is a handle identifier in user space to which the kernel handle identifier of the feature node is mapped.

[0253] When the encryption management module does not find the entry in the hash table, the node manager may send, to the kernel, a request for loading the feature node. When the kernel successfully loads the feature node, the node manager adds the entry corresponding to the kernel node to the hash table. Therefore, in this embodiment of this application, the node manager can dynamically create a kernel node according to an access requirement of the user program.

[0254] Optionally, in this embodiment of this application, the processor 1080 is further configured to: determine a storage path of the feature node, where the storage path is used to indicate a path along which the feature node is loaded to a memory, and load the feature node based on the node identifier and the storage path of the feature node.

[0255] Optionally, in this embodiment of this application, the processor 1080 is further configured to: determine an access permission of the feature node, where the access permission is used to indicate an application program that is allowed to access the feature node, and load the feature node based on the node identifier and the access permission of the feature node.

[0256] In this case, in this embodiment of this application, the feature node can be created in a proper area based on a security level or an importance degree of the feature node, and the hash table can be updated. Therefore, in this embodiment of this application, only an application program related to the kernel node can access the kernel node, and another program in the user space cannot sense the feature node, thereby improving system security.

[0257] Optionally, in this embodiment of this application, the entry further includes the access permission of the feature node. The processor 1080 is further configured to:

pass, by the application program, the user handle identifier by using the interface function; and

determine the access permission of the feature node in the entry of the feature node based on the user handle identifier.



[0258] If it is determined that the access permission allows the application program to access the feature node, the operation corresponding to the first request is performed on the feature node; or if it is determined that the access permission does not allow the application program to access the feature node, the encryption management module rejects the first request.

[0259] Therefore, in this embodiment of this application, when the feature node is accessed by calling the interface function, a permission of a current process corresponding to the application program may be determined based on the access permission of the feature node corresponding to the interface function. In this way, transparent management of the process can be implemented, in other words, another application program that fails security authentication cannot access the feature node corresponding to the process, thereby ensuring secure access of the node.

[0260] In addition, according to the method for managing a node in this embodiment of this application, a development program can be simplified, and a to-be-accessed feature node can be statically configured. Specifically, a developer does not need to learn in detail a storage location of each feature node, a read/write permission required by each feature node, and the like. The process can run in the system, the process has a specific permission. Therefore, according to the method, a feature node that needs to be accessed by the process may be directly set based on the permission of the process. In this way, not only a program accessing the node is simplified, but also security of the kernel node of the system is enhanced. The program can see only a feature node with which the program needs to communicate, and cannot see or access another node. Further, the developer does not need to learn an SE policy, and does not need to modify a file XXX.te, which improves program development efficiency.

[0261] Optionally, in this embodiment of this application, the entry further includes a reference counter of the feature node. The processor 1080 is further configured to: when the feature node is created, set, by the encryption management module, a count value of the reference counter to a default value

[0262] The count value of the reference counter is increased if the first request is used to perform a read operation or a write operation on the feature node. For example, the count value is increased by 1.

[0263] The count value of the reference counter is decreased if the first request is used to delete the feature node. For example, the count value is decreased by 1, and when the count value is equal to a first preset value, the loading/offloading management module deletes the feature node.

[0264] Optionally, in this embodiment of this application, the processor 1080 is further configured to:
if the first request is used to delete the feature node, query whether the feature node is in a whitelist, where the whitelist includes a feature node that does not need to be deleted. Specifically, the loading/offloading management module may perform the query operation.

[0265] If the feature node is not in the whitelist and the count value is equal to the first preset value, the feature node is deleted. If the feature node is in the whitelist, the feature node is not deleted.

[0266] Optionally, the entry further includes a timer, and the timer is started when the count value is equal to the first preset value. The processor 1080 is further configured to:
when the timer is equal to a second preset value, if the application program does not initiate, by calling the first interface function, a second request that is used to perform an operation on the feature node, and the second request is not used to delete the feature node, delete the feature node.

[0267] When the timer is less than the second preset value, if the interface management module receives the second request that is initiated by the application program by calling the first interface function, the timer stops timing, and the feature node is not deleted.

[0268] Therefore, during feature node access in the kernel, a required feature node may be loaded to the memory by dynamically loading/offloading the feature node in this application, and when a feature node is not required, the feature node is removed from the memory. In this way, system resources such as a memory, a CPU, and I/O of the system occupied by a useless feature node can be reduced, so that the system can provide more resources for another running application program or service, thereby ensuring system performance.

[0269] The memory 1020 may mainly include a program storage area and a data storage area, where the program storage area may store an operating system, an application program required by at least one function (such as a voice playing function and an image playing function), and the like, and the data storage area may store data (such as audio data and a phone book) created according to usage of the mobile phone, and the like. In addition, the memory 1020 may include a high-speed random access memory, and may further include a nonvolatile memory, for example, at least one magnetic disk storage device, a flash storage device, or another volatile solid-state storage device.

[0270] In this embodiment of this application, the processor may be an integrated circuit chip, and has a signal processing capability. In an implementation process, steps in the foregoing method embodiments can be implemented by using a hardware integrated logical circuit in the processor, or by using instructions in a form of software. The foregoing processor may be a central processing unit (CPU), the processor may further be another general purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or another programmable logical device, a discrete gate or transistor logic device, or a discrete hardware component. It may implement or perform the methods, the steps, and logical block diagrams that are disclosed in the embodiments of this application. The general purpose processor may be a microprocessor, or the processor may be any conventional processor or the like. The steps of the methods disclosed with reference to the embodiments of this application may be directly performed by a hardware decoding processor, or may be performed by using a combination of hardware and a software unit in the decoding processor. The software unit may be located in a mature storage medium in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, or the like. The storage medium is located in the memory, and a processor reads information in the memory and completes the steps in the foregoing methods in combination with hardware of the processor.

[0271] It may be understood that the memory in the embodiments of this application may be a volatile memory or a nonvolatile memory, or may include a volatile memory and a nonvolatile memory. The nonvolatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), used as an external cache. Through example but not limitative description, many forms of RAMs may be used, for example, a static random access memory (static RAM, SRAM), a dynamic random access memory (dynamic RAM, DRAM), a synchronous dynamic random access memory (synchronous DRAM, SDRAM), a double data rate synchronous dynamic random access memory (double data rate SDRAM, DDR SDRAM), an enhanced synchronous dynamic random access memory (enhanced SDRAM, ESDRAM), a synchronous link dynamic random access memory (synchlink DRAM, SLDRAM), and a direct rambus dynamic random access memory (direct rambus RAM, DRRAM). It should be noted that the memory of the systems and methods described in this specification includes but is not limited to these and any memory of another proper type.

[0272] A network device or a terminal device in an apparatus embodiment fully corresponds to a network device or a terminal device in a method embodiment. A corresponding module performs a corresponding step. For example, a sending module or a transmitter performs a sending step in the method embodiment, and a receiving module or a receiver performs a receiving step in the method embodiment. Steps other than the sending and receiving steps may be performed by a processing module or a processor. For a function of a specific module, refer to a corresponding method embodiment. Details are not described herein again.

[0273] In an implementation process, steps in the foregoing methods can be implemented by using a hardware integrated logical circuit in the processor 1080, or by using instructions in a form of software. The steps of the methods disclosed with reference to the embodiments of this application may be directly performed by a hardware processor, or may be performed by using a combination of hardware and a software module in the processor. The software module may be located in a mature storage medium in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, an electrically erasable programmable memory, a register, or the like. The storage medium is located in the memory 1020, and the processor 1080 reads information in the memory 1020 and completes the steps in the foregoing methods in combination with hardware of the processor. To avoid repetition, details are not described herein again.

[0274] The input unit 1030 may be configured to: receive entered digital or character information, and generate a key signal related to user settings and function control of the terminal device 1000. Specifically, the input unit 1030 may include a touch panel 1031, a camera device 1032, and another input device 1033. The camera device 1032 may perform photographing to obtain a required image, so as to transmit the image to the processor 1080 for processing, and finally the image is present to a user through a display panel 1041. The touch panel 1031, also referred to as a touchscreen, may collect a touch operation of the user on or near the touch panel 1031 (such as an operation of the user on or near the touch panel 1031 performed by using any suitable object or accessory such as a finger or a stylus), and drive a corresponding connection apparatus based on a preset program.

[0275] Optionally, the touch panel 1031 may include two parts: a touch detection apparatus and a touch controller. The touch detection apparatus detects a touch location of the user, detects a signal brought by a touch operation, and transmits the signal to the touch controller. The touch controller receives touch information from the touch detection apparatus, converts the touch information into touch point coordinates, and sends the touch point coordinates to the processor 1080. In addition, the touch controller can receive and execute a command sent by the processor 1080. In addition, the touch panel 1031 may be implemented in a plurality of types such as a resistive type, a capacitive type, an infrared type, and a surface acoustic wave type. In addition to the touch panel 1031 and the camera device 1032, the input unit 1030 may further include another input device 1032. Specifically, the another input device 1032 may include, but is not limited to, one or more of a physical keyboard, a functional button (such as a sound volume control button or a power button), a trackball, a mouse, and a joystick.

[0276] The display unit 1040 may be configured to display information that is input by the user or information provided for the user and various menus of the mobile phone. The display unit 1040 may include a display panel 1041. Optionally, the display panel 1041 may be configured by using a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like. Further, the touch panel 1031 may cover the display panel 1041. When detecting the touch operation on or near the touch panel 1031, the touch panel 1031 transmits the touch operation to the processor 1080 to determine a type of a touch event, and then the processor 1080 provides corresponding visual output on the display panel 1041 based on the type of the touch event.

[0277] The external display panel 1041 of visual output that can be identified by human eyes may be used as a display device in this embodiment of the present invention, and is configured to display text information or image information. In FIG. 10, the touch panel 1031 and the display panel 1041 are used as two independent components to implement input and output functions of the mobile phone. However, in some embodiments, the touch panel 1031 and the display panel 1041 may be integrated to implement the input and output functions of the mobile phone.

[0278] In addition, the terminal device 1000 may further include at least one sensor 1050, such as an attitude sensor, a distance sensor, and other sensors.

[0279] Specifically, the attitude sensor may also be referred to as a motion sensor. In addition, as the motion sensor, an angular velocity sensor (also referred to as a gyroscope) may be enumerated. When the gyroscope is disposed in the mobile phone, the gyroscope is configured to measure a rotational angular velocity of the mobile phone in a motion state in a case of deflection or tilt, so that the gyroscope can accurately analyze and determine an actual action of a user who uses the mobile phone, and a corresponding operation can be performed on the mobile phone, for example, a motion sense, a shake (shaking the mobile phone to implement some functions), controlling a visual angle in a game by panning/rotating/moving the mobile phone, or implementing inertial navigation based on a motion status of an object when a global positioning system (Global Positioning System, "GPS" for short) has no signal (for example, in a tunnel).

[0280] In addition, in this embodiment of the present invention, another sensor such as a barometer, a hygrometer, a thermometer, or an infrared sensor may be further configured as the sensors 150. Details are not described herein.

[0281] An optical sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor may adjust brightness of the display panel 1041 based on light and shade of ambient light, and the proximity sensor may close the display panel 1041 and/or backlight when the mobile phone moves to an ear.

[0282] The audio frequency circuit 1060, a loudspeaker 1061, and a microphone 1062 may provide an audio interface between the user and the mobile phone. The audio frequency circuit 1060 may convert received audio data into an electrical signal, and then transmit the electrical signal to the loudspeaker 1061, and the loudspeaker 1061 converts the electrical signal into a sound signal for output. In addition, the microphone 1062 converts a collected sound signal into an electrical signal. The audio frequency circuit 1060 receives the electrical signal, converts the electrical signal into audio data, and then outputs the audio data to the processor 1080 for processing. After the processing, the processor 880 sends the audio data to, for example, another mobile phone by using the RF circuit 1010, or outputs the audio data to the memory 1020 for further processing.

[0283] Wi-Fi belongs to a short-range wireless transmission technology. The mobile phone may help, by using the Wi-Fi module 1070, the user receive and send an email, browse a web page, access streaming media, and the like. The Wi-Fi module 1070 provides wireless broadband Internet access for the user. Although FIG. 10 shows the Wi-Fi module 1070, it may be understood that the Wi-Fi module 1070 is not a mandatory part of the terminal device 1000, and may be omitted based on a requirement without changing the essence of the present invention.

[0284] As a control center of the mobile phone, the processor 1080 connects various parts of the entire mobile phone by using various interfaces and lines, and performs various functions of the mobile phone and processes data by running or executing the software program and/or the module stored in the memory 1020 and by invoking data stored in the memory 1020, to perform overall monitoring on the mobile phone. Optionally, the processor 1080 may include one or more processing units. Preferably, an application processor and a modem processor may be integrated into the processor 1080. The application processor mainly processes an operating system, a user interface, an application program, and the like. The modem processor mainly processes wireless communication.

[0285] It may be understood that, alternatively, the modem processor may not be integrated into the processor 1080.

[0286] The terminal device 1000 further includes the power supply 1090 that supplies power for each part.

[0287] Preferably, the power supply 190 may be logically connected to the processor 1080 by using a power supply management system, to implement functions such as charging management, discharging management, and power consumption management by using the power supply management system. Although not shown, the terminal device 1000 may further include a Bluetooth module, a headset jack, and the like. Details are not described herein.

[0288] The device 900 shown in FIG. 9 or the terminal device 1000 shown in FIG. 10 can implement the processes corresponding to the foregoing method embodiments shown in FIG. 3 to FIG. 8. Specifically, for the device 900 or the terminal device 1000, refer to the foregoing description in FIG. 3 to FIG. 8. To avoid repetition, details are not described herein again.

[0289] An embodiment of this application further provides a computer readable medium, configured to store a computer program. The computer program includes an instruction executed by the device for managing a node in the implementations in FIG. 3 and FIG. 8.

[0290] A person of ordinary skill in the art may be aware that, in combination with the examples described in the embodiments disclosed in this specification, units and algorithm steps may be implemented by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are performed by hardware or software depends on particular applications and design constraint conditions of the technical solutions. A person skilled in the art may use different methods to implement the described functions for each particular application, but it should not be considered that the implementation goes beyond the scope of this application.

[0291] It may be clearly understood by a person skilled in the art that, for the purpose of convenient and brief description, for a detailed working process of the foregoing system, apparatus, and unit, refer to a corresponding process in the foregoing method embodiments, and details are not described herein again.

[0292] In the several embodiments provided in this application, it should be understood that the disclosed system, apparatus, and method may be implemented in other manners. For example, the described apparatus embodiment is merely an example. For example, the unit division is merely logical function division and may be other division in actual implementation. For example, a plurality of units or components may be combined or integrated into another system, or some features may be ignored or not performed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections may be implemented by using some interfaces. The indirect couplings or communication connections between the apparatuses or units may be implemented in electronic, mechanical, or other forms.

[0293] The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one position, or may be distributed on a plurality of network units. Some or all of the units may be selected based on actual requirements to achieve the objectives of the solutions of the embodiments.

[0294] In addition, functional units in the embodiments of this application may be integrated into one processing unit, or each of the units may exist alone physically, or two or more units are integrated into one unit.

[0295] All or some of the foregoing embodiments may be implemented through software, hardware, firmware, or any combination thereof. When software is used to implement the embodiments, the embodiments may be implemented completely or partially in a form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the procedure or functions according to the embodiments of this application are all or partially generated. The computer may be a general-purpose computer, a dedicated computer, a computer network, or other programmable apparatuses. The computer instructions may be stored in a computer-readable storage medium or may be transmitted from a computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website, computer, server, or data center to another website, computer, server, or data center in a wired (for example, a coaxial cable, an optical fiber, or a digital subscriber line (DSL)) or wireless (for example, infrared, radio, or microwave) manner. The computer-readable storage medium may be any usable medium accessible by a computer, or a data storage device, such as a server or a data center, integrating one or more usable media. The usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, or a magnetic tape), an optical medium (for example, a DVD), a semiconductor medium (for example, a solid state drive (SSD)), or the like.

[0296] The foregoing descriptions are merely specific implementations of this application, but are not intended to limit the protection scope of this application. Any variation or replacement readily figured out by a person skilled in the art within the technical scope disclosed in this application shall fall within the protection scope of this application. Therefore, the protection scope of this application shall be subject to the protection scope of the claims.


Claims

1. A method for managing a feature node in a kernel, comprising:

initiating a first request by calling an interface function, wherein the first request is used to perform an operation on a feature node in a kernel;

searching, based on a keyword in a function name of the interface function, a table for an entry corresponding to the feature node, wherein the entry comprises a node identifier of the feature node and a user handle identifier of the feature node, the node identifier of the feature node comprises the keyword, there is a mapping relationship between the user handle identifier and a kernel handle identifier, and the kernel handle identifier represents an identity of the feature node running in the kernel; and

performing the operation on the feature node based on the user handle identifier.


 
2. The method according to claim 1, wherein the method further comprises:

determining the node identifier of the feature node;

loading the feature node in the kernel based on the node identifier of the feature node; and

when the feature node is successfully loaded, adding the entry comprising the node identifier of the feature node and the user handle identifier of the feature node to the table, wherein the user handle identifier is a handle identifier in user space to which the kernel handle identifier of the feature node is mapped.


 
3. The method according to claim 2, wherein the loading the feature node in the kernel based on the node identifier of the feature node comprises:
loading the feature node based on the node identifier and a storage path of the feature node, wherein the storage path is used to indicate a path along which the feature node is loaded to the kernel.
 
4. The method according to claim 2 or 3, wherein the loading the feature node in the kernel based on the node identifier of the feature node comprises:
loading the feature node based on the node identifier and an access permission of the feature node, wherein the access permission is used to indicate an application program that is allowed to access the feature node.
 
5. The method according to claim 4, wherein the entry further comprises the access permission, and the method further comprises:

passing, by the application program, the user handle identifier by using the interface function; and

determining the access permission of the feature node in the entry of the feature node based on the user handle identifier.


 
6. The method according to any one of claims 1 to 5, wherein the entry further comprises a reference counter of the feature node, and the method further comprises:

increasing a count value of the reference counter if the first request is used to perform a read operation or a write operation on the feature node; or

decreasing a count value of the reference counter if the first request is used to delete the feature node, and deleting the feature node when the count value is equal to a first preset value.


 
7. The method according to claim 6, further comprising:

if the first request is used to delete the feature node, querying whether the feature node is in a whitelist, wherein the whitelist comprises a feature node that does not need to be deleted; and

if the feature node is not in the whitelist and the count value is equal to the first preset value, deleting the feature node; or

if the feature node is in the whitelist, skipping deleting the feature node.


 
8. The method according to claim 6 or 7, wherein the entry further comprises a timer, and the deleting the feature node comprises:

starting the timer when the count value is equal to the first preset value; and

when the timer is equal to a second preset value, if the application program does not initiate, by calling the first interface function, a second request that is used to perform an operation on the feature node, and the second request is not used to delete the feature node, deleting the feature node.


 
9. A device for managing a feature node in a kernel, comprising:

an interface unit, configured to initiate a first request by calling an interface function, wherein the first request is used to perform an operation on a feature node in a kernel;

a searching unit, configured to search, based on a keyword in a function name of the interface function, a table for an entry corresponding to the feature node, wherein the entry comprises a node identifier of the feature node and a user handle identifier of the feature node, the node identifier of the feature node comprises the keyword, there is a mapping relationship between the user handle identifier and a kernel handle identifier, and the kernel handle identifier represents an identity of the feature node running in the kernel; and

an execution unit, configured to perform the operation on the feature node based on the user handle identifier.


 
10. The device according to claim 9, wherein the device further comprises:

a determining unit, configured to determine the node identifier of the feature node;

a loading unit, configured to load the feature node in the kernel based on the node identifier of the feature node; and

an adding unit, configured to: when the feature node is successfully loaded, add the entry comprising the node identifier of the feature node and the user handle identifier of the feature node to the table, wherein the user handle identifier is a handle identifier in user space to which the kernel handle identifier of the feature node is mapped.


 
11. The device according to claim 10, wherein the loading unit is specifically configured to:
load the feature node based on the node identifier of the feature node determined by the determining unit and the storage path, wherein the storage path is used to indicate a path along which the feature node is loaded to the kernel.
 
12. The device according to claim 10 or 11, wherein the loading unit is specifically configured to:
load the feature node based on the node identifier of the feature node determined by the determining unit and the access permission, wherein the access permission is used to indicate an application program that is allowed to access the feature node.
 
13. The device according to claim 12, wherein the entry further comprises the access permission;
the interface unit is further configured to pass the user handle identifier by using the interface function; and
the determining unit is further configured to determine the access permission of the feature node in the entry of the feature node based on the user handle identifier.
 
14. The device according to any one of claims 9 to 13, wherein the device further comprises a deletion unit, and the entry further comprises a reference counter of the feature node;
a count value of the reference counter is increased if the first request is used to perform a read operation or a write operation on the feature node; or
a count value of the reference counter is decreased if the first request is used to delete the feature node, and the deletion unit is configured to delete the feature node when the count value is equal to a first preset value.
 
15. The device according to claim 14, wherein the deletion unit is specifically configured to:

if the first request is used to delete the feature node, query whether the feature node is in a whitelist, wherein the whitelist comprises a feature node that does not need to be deleted; and

if the feature node is not in the whitelist and the count value is equal to the first preset value, delete the feature node; or

if the feature node is in the whitelist, skip deleting the feature node.


 
16. The device according to claim 14 or 15, wherein the entry further comprises a timer, and the deletion unit is specifically configured to:

start the timer when the count value is equal to the first preset value; and

when the timer is equal to a second preset value, if the application program does not initiate, by calling the first interface function, a second request that is used to perform an operation on the feature node, and the second request is not used to delete the feature node, the deletion unit is configured to delete the feature node.


 
17. A device for managing a feature node in a kernel, comprising:

a memory, configured to store a computer program; and

a processor, configured to execute the computer program stored in the memory, so that the apparatus is enabled to perform the method according to any one of claims 1 to 8.


 
18. A computer readable storage medium, comprising a computer program, wherein when the computer program runs on a computer, the computer is enabled to perform the method according to any one of claims 1 to 8.
 




Drawing


































Search report










Cited references

REFERENCES CITED IN THE DESCRIPTION



This list of references cited by the applicant is for the reader's convenience only. It does not form part of the European patent document. Even though great care has been taken in compiling the references, errors or omissions cannot be excluded and the EPO disclaims all liability in this regard.

Patent documents cited in the description