Skip to content

Commit 3295514

Browse files
Al Virotorvalds
authored andcommitted
fix rcu annotations noise in cred.h
task->cred is declared as __rcu, and access to other tasks' ->cred is, indeed, protected. Access to current->cred does not need rcu_dereference() at all, since only the task itself can change its ->cred. sparse, of course, has no way of knowing that... Add force-cast in current_cred(), make current_fsuid() et.al. use it. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 7813b94 commit 3295514

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

include/linux/cred.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,11 @@ static inline void put_cred(const struct cred *_cred)
265265
/**
266266
* current_cred - Access the current task's subjective credentials
267267
*
268-
* Access the subjective credentials of the current task.
268+
* Access the subjective credentials of the current task. RCU-safe,
269+
* since nobody else can modify it.
269270
*/
270271
#define current_cred() \
271-
(current->cred)
272+
(*(__force struct cred **)&current->cred)
272273

273274
/**
274275
* __task_cred - Access a task's objective credentials
@@ -307,7 +308,7 @@ static inline void put_cred(const struct cred *_cred)
307308
({ \
308309
struct user_struct *__u; \
309310
struct cred *__cred; \
310-
__cred = (struct cred *) current_cred(); \
311+
__cred = current_cred(); \
311312
__u = get_uid(__cred->user); \
312313
__u; \
313314
})
@@ -322,7 +323,7 @@ static inline void put_cred(const struct cred *_cred)
322323
({ \
323324
struct group_info *__groups; \
324325
struct cred *__cred; \
325-
__cred = (struct cred *) current_cred(); \
326+
__cred = current_cred(); \
326327
__groups = get_group_info(__cred->group_info); \
327328
__groups; \
328329
})
@@ -341,7 +342,7 @@ static inline void put_cred(const struct cred *_cred)
341342

342343
#define current_cred_xxx(xxx) \
343344
({ \
344-
current->cred->xxx; \
345+
current_cred()->xxx; \
345346
})
346347

347348
#define current_uid() (current_cred_xxx(uid))

0 commit comments

Comments
 (0)