linux内核态real cred,Linux内核源码分析 -- 更新当前进程的 cred -- commit_creds

浅析一下用来修改当前进程 cred 的函数 commit_creds

源码版本:Linux kernel 5.9.9

首先来看 cred 结构

/*

* 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_tusage;

#ifdef CONFIG_DEBUG_CREDENTIALS

atomic_tsubscribers;/* number of processes subscribed 使用这个 cred 的进程数*/

void*put_addr;

unsignedmagic;

#define CRED_MAGIC0x43736564

#define CRED_MAGIC_DEAD0x44656144

#endif

kuid_tuid;/* real UID of the task 创建进程的用户的 id ,不是创建可执行程序的用户 id*/

kgid_tgid;/* real GID of the task */

kuid_tsuid;/* saved UID of the task 保存的 euid 切换之前的 id,用于 euid 切换回来*/

kgid_tsgid;/* saved GID of the task */

kuid_teuid;/* effective UID of the task euid 是进程运行过程中实时的 id*/

kgid_tegid;/* effective GID of the task */

kuid_tfsuid;/* UID for VFS ops */

kgid_tfsgid;/* GID for VFS ops */

unsignedsecurebits;/* SUID-less security management */

kernel_cap_tcap_inheritable; /* caps our children can inherit */

kernel_cap_tcap_permitted;/* caps we're permitted */

kernel_cap_tcap_effective;/* caps we can actually use */

kernel_cap_tcap_bset;/* capability bounding set */

kernel_cap_tcap_ambient;/* Ambient capability set */

#ifdef CONFIG_KEYS

unsigned charjit_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_SECURITY

void*security;/* subjective LSM security */

#endif

struct user_struct *user;/* real user ID subscription 创建进程的用户的 id 描述符*/

struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */

struct group_info *group_info;/* supplementary groups for euid/fsgid */

/* RCU deletion */

union {

int non_rcu;/* Can we skip RCU deletion? */

struct rcu_headrcu;/* RCU deletion hook */

};

} __randomize_layout;

commit_creds

/**

* commit_creds - Install new cred

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值