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

你可能感兴趣的:(linux内核态real,cred)