当前位置: 首页 > news >正文

Linux内核进程管理子系统有什么第三十九回 —— 进程主结构详解(35)

接前一篇文章:Linux内核进程管理子系统有什么第三十八回 —— 进程主结构详解(34)

本文内容参考:

Linux内核进程管理专题报告_linux rseq-CSDN博客

《趣谈Linux操作系统 核心原理篇:第三部分 进程管理》—— 刘超

《图解Linux内核 基于6.x》 —— 姜亚华 机械工业出版社

特此致谢!

进程管理核心结构 —— task_struct

8. 进程权限相关成员

进程权限相关成员包括以下几个:

	/* Process credentials: *//* Tracer's credentials at attach: */const struct cred __rcu		*ptracer_cred;/* Objective and real subjective task credentials (COW): */const struct cred __rcu		*real_cred;/* Effective (overridable) subjective task credentials (COW): */const struct cred __rcu		*cred;

这几个字段的描述如下:

上一回对于进程权限相关的字段进行了解析,本回对于这3个字段的共同类型struct cred进行详细解析。

struct cred的定义在include/linux/cred.h中,如下:

/** The security context of a task** The parts of the context break down into two categories:**  (1) The objective context of a task.  These parts are used when some other*	task is attempting to affect this one.**  (2) The subjective context.  These details are used when the task is acting*	upon another object, be that a file, a task, a key or whatever.** Note that some members of this structure belong to both categories - the* LSM security pointer for instance.** A task has two security pointers.  task->real_cred points to the objective* context that defines that task's actual details.  The objective part of this* context is used whenever that task is acted upon.** task->cred points to the subjective context that defines the details of how* that task is going to act upon another object.  This may be overridden* temporarily to point to another security context, but normally points to the* same context as task->real_cred.*/
struct cred {atomic_t	usage;
#ifdef CONFIG_DEBUG_CREDENTIALSatomic_t	subscribers;	/* number of processes subscribed */void		*put_addr;unsigned	magic;
#define CRED_MAGIC	0x43736564
#define CRED_MAGIC_DEAD	0x44656144
#endifkuid_t		uid;		/* real UID of the task */kgid_t		gid;		/* real GID of the task */kuid_t		suid;		/* saved UID of the task */kgid_t		sgid;		/* saved GID of the task */kuid_t		euid;		/* effective UID of the task */kgid_t		egid;		/* effective GID of the task */kuid_t		fsuid;		/* UID for VFS ops */kgid_t		fsgid;		/* GID for VFS ops */unsigned	securebits;	/* SUID-less security management */kernel_cap_t	cap_inheritable; /* caps our children can inherit */kernel_cap_t	cap_permitted;	/* caps we're permitted */kernel_cap_t	cap_effective;	/* caps we can actually use */kernel_cap_t	cap_bset;	/* capability bounding set */kernel_cap_t	cap_ambient;	/* Ambient capability set */
#ifdef CONFIG_KEYSunsigned char	jit_keyring;	/* default keyring to attach requested* keys to */struct key	*session_keyring; /* keyring inherited over fork */struct key	*process_keyring; /* keyring private to this process */struct key	*thread_keyring; /* keyring private to this thread */struct key	*request_key_auth; /* assumed request_key authority */
#endif
#ifdef CONFIG_SECURITYvoid		*security;	/* LSM security */
#endifstruct user_struct *user;	/* real user ID subscription */struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */struct ucounts *ucounts;struct group_info *group_info;	/* supplementary groups for euid/fsgid *//* RCU deletion */union {int non_rcu;			/* Can we skip RCU deletion? */struct rcu_head	rcu;		/* RCU deletion hook */};
} __randomize_layout;

先来仔细研读一下Linux内核对于struct cred的注释:

struct cred —— (一个)任务的安全上下文

上下文的各个部分分为两类:

(1) 任务的客体上下文

当其它任务试图影响此任务时,会使用这些部分。

(2) 主体上下文

当任务作用于另一个对象时,无论是文件、任务、密钥还是其它任何对象,都会使用这些详部分。

注意:struct cred的一些成员属于这两个类别,例如LSM安全指针。

一个任务有两个安全指针:task->real_cred和task->cred。

  • task->real_cred指向定义该任务实际细节的客体上下文。每当执行该任务时,都会使用此上下文的客体部分。
  • task->cred指向主体上下文,该上下文定义了任务将如何作用于另一个对象的细节。这可能会被临时覆盖以指向另一个安全上下文,但通常会指向与task->real_cred相同的上下文。

从struct cred的定义可以看出,大部分是关于用户和用户所属的用户组信息。

  • 第1组 —— kuid_t uid和kgid_t gid

uid和pid的注释分别是real UID/PID of the task。

一般情况下,谁启动的进程,就是谁的ID。但是权限审核的时候,往往不比较这两个,也就是说不大起作用。

  • 第2组 —— kuid_t euid和kgid_t egid

euid和egid的注释分别是effective UID/GID of the task。

一看这个名字effective,就知道这个是起实际作用的。当这个进程要操作消息队列、共享内存、信号量等对象的时候,其实就是在比较这个用户和组是否有权限。

  • 第3组 —— kuid_t fsuid和kgid_t fsgid

fsuid和fsgid的注释分别是UID/GID for VFS ops。实际上就是filesystem UID/GID。

这是对文件操作会审核的权限。

更多内容请看下回。

http://www.xdnf.cn/news/1423567.html

相关文章:

  • 算法练习——169.多数元素
  • 教育项目管理工具新趋势:可视化与自动化如何提升效率?
  • XGBoost学习笔记
  • 故障排查指南:理解与解决 “No route to host“ 错误
  • 【科普向-第七篇】Git全家桶介绍:Git/Gitlab/GitHub/TortoiseGit/Sourcetree
  • std::map::try_emplace完全详解
  • 从 Oracle 到 TiDB,通过ETL工具,高效实现数据拉通
  • 并发 -- JUC(java.util.concurrent) 包的简单介绍
  • NebulaAI V2.7.0发布:MCP广场正式上线!
  • FFMPEG 10BIT下 Intel b570 qsv 硬解AV1,H265视频编码测试
  • 【项目思维】贪吃蛇(嵌入式进阶方向)
  • 光学神经网络与人工智能应用
  • 【XR技术概念科普】详解6DoF:为什么它是沉浸感的关键?
  • 贝叶斯向量自回归模型 (BVAR)
  • 【Java】Redis(中间件)
  • 从API调用到效果呈现:面具特效功能在直播美颜SDK中的应用实践
  • Redis 八股
  • 中国家具百强「库斯家居」携手 企企通:启动 SRM 项目,构筑采购数字化新生态
  • Android/Java 中创建类实例的各种模式
  • nestjs 发起请求 axios
  • 3-6〔OSCP ◈ 研记〕❘ WEB应用攻击▸WEB应用枚举B
  • 【STM32】状态机(State Machine)
  • 证明与激励:Walrus 可编程数据如何通过激励可用性证明获得安全性
  • SpringBoot学习日记 Day9:响应式编程新世界探索
  • 【跨境知识】密文面单
  • Linux常用命令行大全:14个核心指令详解+实战案例
  • 多线程——线程的休眠、中断和等待
  • Markdown 语法全面指南
  • Win10系统获取网络上行流量的三种方法
  • 五、导入现有模型