aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/credentials.txt3
-rw-r--r--include/linux/cred.h15
-rw-r--r--include/linux/sched.h1
3 files changed, 14 insertions, 5 deletions
diff --git a/Documentation/credentials.txt b/Documentation/credentials.txt
index a2db35287003..995baf379c07 100644
--- a/Documentation/credentials.txt
+++ b/Documentation/credentials.txt
@@ -417,6 +417,9 @@ reference on them using:
417This does all the RCU magic inside of it. The caller must call put_cred() on 417This does all the RCU magic inside of it. The caller must call put_cred() on
418the credentials so obtained when they're finished with. 418the credentials so obtained when they're finished with.
419 419
420 [*] Note: The result of __task_cred() should not be passed directly to
421 get_cred() as this may race with commit_cred().
422
420There are a couple of convenience functions to access bits of another task's 423There are a couple of convenience functions to access bits of another task's
421credentials, hiding the RCU magic from the caller: 424credentials, hiding the RCU magic from the caller:
422 425
diff --git a/include/linux/cred.h b/include/linux/cred.h
index ce40cbc791e2..4d2c39573f36 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -274,13 +274,18 @@ static inline void put_cred(const struct cred *_cred)
274 * @task: The task to query 274 * @task: The task to query
275 * 275 *
276 * Access the objective credentials of a task. The caller must hold the RCU 276 * Access the objective credentials of a task. The caller must hold the RCU
277 * readlock. 277 * readlock or the task must be dead and unable to change its own credentials.
278 * 278 *
279 * The caller must make sure task doesn't go away, either by holding a ref on 279 * The result of this function should not be passed directly to get_cred();
280 * task or by holding tasklist_lock to prevent it from being unlinked. 280 * rather get_task_cred() should be used instead.
281 */ 281 */
282#define __task_cred(task) \ 282#define __task_cred(task) \
283 ((const struct cred *)(rcu_dereference_check((task)->real_cred, rcu_read_lock_held() || lockdep_tasklist_lock_is_held()))) 283 ({ \
284 const struct task_struct *__t = (task); \
285 rcu_dereference_check(__t->real_cred, \
286 rcu_read_lock_held() || \
287 task_is_dead(__t)); \
288 })
284 289
285/** 290/**
286 * get_current_cred - Get the current task's subjective credentials 291 * get_current_cred - Get the current task's subjective credentials
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 747fcaedddb7..0478888c6899 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -214,6 +214,7 @@ extern char ___assert_task_state[1 - 2*!!(
214 214
215#define task_is_traced(task) ((task->state & __TASK_TRACED) != 0) 215#define task_is_traced(task) ((task->state & __TASK_TRACED) != 0)
216#define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0) 216#define task_is_stopped(task) ((task->state & __TASK_STOPPED) != 0)
217#define task_is_dead(task) ((task)->exit_state != 0)
217#define task_is_stopped_or_traced(task) \ 218#define task_is_stopped_or_traced(task) \
218 ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0) 219 ((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
219#define task_contributes_to_load(task) \ 220#define task_contributes_to_load(task) \