diff options
author | David Howells <dhowells@redhat.com> | 2008-11-13 18:39:26 -0500 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2008-11-13 18:39:26 -0500 |
commit | 3b11a1decef07c19443d24ae926982bc8ec9f4c0 (patch) | |
tree | b6555f0e5b07f4b2badd332a0a900b974920c49d /include/linux | |
parent | 98870ab0a5a3f1822aee681d2997017e1c87d026 (diff) |
CRED: Differentiate objective and effective subjective credentials on a task
Differentiate the objective and real subjective credentials from the effective
subjective credentials on a task by introducing a second credentials pointer
into the task_struct.
task_struct::real_cred then refers to the objective and apparent real
subjective credentials of a task, as perceived by the other tasks in the
system.
task_struct::cred then refers to the effective subjective credentials of a
task, as used by that task when it's actually running. These are not visible
to the other tasks in the system.
__task_cred(task) then refers to the objective/real credentials of the task in
question.
current_cred() refers to the effective subjective credentials of the current
task.
prepare_creds() uses the objective creds as a base and commit_creds() changes
both pointers in the task_struct (indeed commit_creds() requires them to be the
same).
override_creds() and revert_creds() change the subjective creds pointer only,
and the former returns the old subjective creds. These are used by NFSD,
faccessat() and do_coredump(), and will by used by CacheFiles.
In SELinux, current_has_perm() is provided as an alternative to
task_has_perm(). This uses the effective subjective context of current,
whereas task_has_perm() uses the objective/real context of the subject.
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/cred.h | 29 | ||||
-rw-r--r-- | include/linux/init_task.h | 1 | ||||
-rw-r--r-- | include/linux/sched.h | 5 |
3 files changed, 20 insertions, 15 deletions
diff --git a/include/linux/cred.h b/include/linux/cred.h index 794aab5c66e5..55a9c995d694 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h | |||
@@ -146,8 +146,8 @@ extern struct cred *prepare_exec_creds(void); | |||
146 | extern struct cred *prepare_usermodehelper_creds(void); | 146 | extern struct cred *prepare_usermodehelper_creds(void); |
147 | extern int commit_creds(struct cred *); | 147 | extern int commit_creds(struct cred *); |
148 | extern void abort_creds(struct cred *); | 148 | extern void abort_creds(struct cred *); |
149 | extern const struct cred *override_creds(const struct cred *) __deprecated; | 149 | extern const struct cred *override_creds(const struct cred *); |
150 | extern void revert_creds(const struct cred *) __deprecated; | 150 | extern void revert_creds(const struct cred *); |
151 | extern void __init cred_init(void); | 151 | extern void __init cred_init(void); |
152 | 152 | ||
153 | /** | 153 | /** |
@@ -202,32 +202,32 @@ static inline void put_cred(const struct cred *_cred) | |||
202 | } | 202 | } |
203 | 203 | ||
204 | /** | 204 | /** |
205 | * current_cred - Access the current task's credentials | 205 | * current_cred - Access the current task's subjective credentials |
206 | * | 206 | * |
207 | * Access the credentials of the current task. | 207 | * Access the subjective credentials of the current task. |
208 | */ | 208 | */ |
209 | #define current_cred() \ | 209 | #define current_cred() \ |
210 | (current->cred) | 210 | (current->cred) |
211 | 211 | ||
212 | /** | 212 | /** |
213 | * __task_cred - Access another task's credentials | 213 | * __task_cred - Access a task's objective credentials |
214 | * @task: The task to query | 214 | * @task: The task to query |
215 | * | 215 | * |
216 | * Access the credentials of another task. The caller must hold the | 216 | * Access the objective credentials of a task. The caller must hold the RCU |
217 | * RCU readlock. | 217 | * readlock. |
218 | * | 218 | * |
219 | * The caller must make sure task doesn't go away, either by holding a ref on | 219 | * The caller must make sure task doesn't go away, either by holding a ref on |
220 | * task or by holding tasklist_lock to prevent it from being unlinked. | 220 | * task or by holding tasklist_lock to prevent it from being unlinked. |
221 | */ | 221 | */ |
222 | #define __task_cred(task) \ | 222 | #define __task_cred(task) \ |
223 | ((const struct cred *)(rcu_dereference((task)->cred))) | 223 | ((const struct cred *)(rcu_dereference((task)->real_cred))) |
224 | 224 | ||
225 | /** | 225 | /** |
226 | * get_task_cred - Get another task's credentials | 226 | * get_task_cred - Get another task's objective credentials |
227 | * @task: The task to query | 227 | * @task: The task to query |
228 | * | 228 | * |
229 | * Get the credentials of a task, pinning them so that they can't go away. | 229 | * Get the objective credentials of a task, pinning them so that they can't go |
230 | * Accessing a task's credentials directly is not permitted. | 230 | * away. Accessing a task's credentials directly is not permitted. |
231 | * | 231 | * |
232 | * The caller must make sure task doesn't go away, either by holding a ref on | 232 | * The caller must make sure task doesn't go away, either by holding a ref on |
233 | * task or by holding tasklist_lock to prevent it from being unlinked. | 233 | * task or by holding tasklist_lock to prevent it from being unlinked. |
@@ -243,10 +243,11 @@ static inline void put_cred(const struct cred *_cred) | |||
243 | }) | 243 | }) |
244 | 244 | ||
245 | /** | 245 | /** |
246 | * get_current_cred - Get the current task's credentials | 246 | * get_current_cred - Get the current task's subjective credentials |
247 | * | 247 | * |
248 | * Get the credentials of the current task, pinning them so that they can't go | 248 | * Get the subjective credentials of the current task, pinning them so that |
249 | * away. Accessing the current task's credentials directly is not permitted. | 249 | * they can't go away. Accessing the current task's credentials directly is |
250 | * not permitted. | ||
250 | */ | 251 | */ |
251 | #define get_current_cred() \ | 252 | #define get_current_cred() \ |
252 | (get_cred(current_cred())) | 253 | (get_cred(current_cred())) |
diff --git a/include/linux/init_task.h b/include/linux/init_task.h index 08c3b24ad9a8..2597858035cd 100644 --- a/include/linux/init_task.h +++ b/include/linux/init_task.h | |||
@@ -149,6 +149,7 @@ extern struct cred init_cred; | |||
149 | .children = LIST_HEAD_INIT(tsk.children), \ | 149 | .children = LIST_HEAD_INIT(tsk.children), \ |
150 | .sibling = LIST_HEAD_INIT(tsk.sibling), \ | 150 | .sibling = LIST_HEAD_INIT(tsk.sibling), \ |
151 | .group_leader = &tsk, \ | 151 | .group_leader = &tsk, \ |
152 | .real_cred = &init_cred, \ | ||
152 | .cred = &init_cred, \ | 153 | .cred = &init_cred, \ |
153 | .cred_exec_mutex = \ | 154 | .cred_exec_mutex = \ |
154 | __MUTEX_INITIALIZER(tsk.cred_exec_mutex), \ | 155 | __MUTEX_INITIALIZER(tsk.cred_exec_mutex), \ |
diff --git a/include/linux/sched.h b/include/linux/sched.h index 121d655e460d..3443123b0709 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -1145,7 +1145,10 @@ struct task_struct { | |||
1145 | struct list_head cpu_timers[3]; | 1145 | struct list_head cpu_timers[3]; |
1146 | 1146 | ||
1147 | /* process credentials */ | 1147 | /* process credentials */ |
1148 | const struct cred *cred; /* actual/objective task credentials (COW) */ | 1148 | const struct cred *real_cred; /* objective and real subjective task |
1149 | * credentials (COW) */ | ||
1150 | const struct cred *cred; /* effective (overridable) subjective task | ||
1151 | * credentials (COW) */ | ||
1149 | struct mutex cred_exec_mutex; /* execve vs ptrace cred calculation mutex */ | 1152 | struct mutex cred_exec_mutex; /* execve vs ptrace cred calculation mutex */ |
1150 | 1153 | ||
1151 | char comm[TASK_COMM_LEN]; /* executable name excluding path | 1154 | char comm[TASK_COMM_LEN]; /* executable name excluding path |