假设某个进程希望发出只能由特权进程发出的系统调用。
Linux如何知道是否允许进程发出这样的系统调用? Linux是查看进程的fsuid (文件系统用户ID)以查看它是否是根进程,还是查看进程的功能是否具有发出系统调用所需的能力,或者Linux是否以其他方式知道?
发布于 2019-02-27 14:12:07
通常,内核会查看流程的功能,以确定它是否具有所需的功能。您将在相关系统调用的手册页中找到这些信息,该页面将注意到“流程需要功能CAP_XYZ”以执行操作。例如,查看kill(2)的手册页面,我们看到:
For a process to have permission to send a signal, it must either
be privileged (under Linux: have the CAP_KILL capability in the
user namespace of the target process), or the real or effective
user ID of the sending process must equal the real or saved set-
user-ID of the target process.类似地,在create_module(2)页面中,我们看到:
DESCRIPTION
create_module() attempts to create a loadable module entry and
reserve the kernel memory that will be needed to hold the module.
This system call requires privilege.
...
ERRORS
...
EPERM The caller was not privileged (did not have the
CAP_SYS_MODULE capability).内核能够进行这些检查,因为功能是内核在其内部数据结构中记录的每个进程属性。
https://unix.stackexchange.com/questions/503130
复制相似问题