diff options
Diffstat (limited to 'include/linux/cred.h')
-rw-r--r-- | include/linux/cred.h | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/include/linux/cred.h b/include/linux/cred.h index 62b9e532422d..eaf6fa695a04 100644 --- a/include/linux/cred.h +++ b/include/linux/cred.h | |||
@@ -84,6 +84,8 @@ struct thread_group_cred { | |||
84 | struct key *process_keyring; /* keyring private to this process */ | 84 | struct key *process_keyring; /* keyring private to this process */ |
85 | struct rcu_head rcu; /* RCU deletion hook */ | 85 | struct rcu_head rcu; /* RCU deletion hook */ |
86 | }; | 86 | }; |
87 | |||
88 | extern void release_tgcred(struct cred *cred); | ||
87 | #endif | 89 | #endif |
88 | 90 | ||
89 | /* | 91 | /* |
@@ -137,11 +139,30 @@ struct cred { | |||
137 | struct user_struct *user; /* real user ID subscription */ | 139 | struct user_struct *user; /* real user ID subscription */ |
138 | struct group_info *group_info; /* supplementary groups for euid/fsgid */ | 140 | struct group_info *group_info; /* supplementary groups for euid/fsgid */ |
139 | struct rcu_head rcu; /* RCU deletion hook */ | 141 | struct rcu_head rcu; /* RCU deletion hook */ |
140 | spinlock_t lock; /* lock for pointer changes */ | ||
141 | }; | 142 | }; |
142 | 143 | ||
143 | extern void __put_cred(struct cred *); | 144 | extern void __put_cred(struct cred *); |
144 | extern int copy_creds(struct task_struct *, unsigned long); | 145 | extern int copy_creds(struct task_struct *, unsigned long); |
146 | extern struct cred *prepare_creds(void); | ||
147 | extern struct cred *prepare_usermodehelper_creds(void); | ||
148 | extern int commit_creds(struct cred *); | ||
149 | extern void abort_creds(struct cred *); | ||
150 | extern const struct cred *override_creds(const struct cred *) __deprecated; | ||
151 | extern void revert_creds(const struct cred *) __deprecated; | ||
152 | extern void __init cred_init(void); | ||
153 | |||
154 | /** | ||
155 | * get_new_cred - Get a reference on a new set of credentials | ||
156 | * @cred: The new credentials to reference | ||
157 | * | ||
158 | * Get a reference on the specified set of new credentials. The caller must | ||
159 | * release the reference. | ||
160 | */ | ||
161 | static inline struct cred *get_new_cred(struct cred *cred) | ||
162 | { | ||
163 | atomic_inc(&cred->usage); | ||
164 | return cred; | ||
165 | } | ||
145 | 166 | ||
146 | /** | 167 | /** |
147 | * get_cred - Get a reference on a set of credentials | 168 | * get_cred - Get a reference on a set of credentials |
@@ -150,10 +171,9 @@ extern int copy_creds(struct task_struct *, unsigned long); | |||
150 | * Get a reference on the specified set of credentials. The caller must | 171 | * Get a reference on the specified set of credentials. The caller must |
151 | * release the reference. | 172 | * release the reference. |
152 | */ | 173 | */ |
153 | static inline struct cred *get_cred(struct cred *cred) | 174 | static inline const struct cred *get_cred(const struct cred *cred) |
154 | { | 175 | { |
155 | atomic_inc(&cred->usage); | 176 | return get_new_cred((struct cred *) cred); |
156 | return cred; | ||
157 | } | 177 | } |
158 | 178 | ||
159 | /** | 179 | /** |
@@ -166,6 +186,8 @@ static inline struct cred *get_cred(struct cred *cred) | |||
166 | static inline void put_cred(const struct cred *_cred) | 186 | static inline void put_cred(const struct cred *_cred) |
167 | { | 187 | { |
168 | struct cred *cred = (struct cred *) _cred; | 188 | struct cred *cred = (struct cred *) _cred; |
189 | |||
190 | BUG_ON(atomic_read(&(cred)->usage) <= 0); | ||
169 | if (atomic_dec_and_test(&(cred)->usage)) | 191 | if (atomic_dec_and_test(&(cred)->usage)) |
170 | __put_cred(cred); | 192 | __put_cred(cred); |
171 | } | 193 | } |
@@ -250,13 +272,13 @@ static inline void put_cred(const struct cred *_cred) | |||
250 | __groups; \ | 272 | __groups; \ |
251 | }) | 273 | }) |
252 | 274 | ||
253 | #define task_cred_xxx(task, xxx) \ | 275 | #define task_cred_xxx(task, xxx) \ |
254 | ({ \ | 276 | ({ \ |
255 | __typeof__(task->cred->xxx) ___val; \ | 277 | __typeof__(((struct cred *)NULL)->xxx) ___val; \ |
256 | rcu_read_lock(); \ | 278 | rcu_read_lock(); \ |
257 | ___val = __task_cred((task))->xxx; \ | 279 | ___val = __task_cred((task))->xxx; \ |
258 | rcu_read_unlock(); \ | 280 | rcu_read_unlock(); \ |
259 | ___val; \ | 281 | ___val; \ |
260 | }) | 282 | }) |
261 | 283 | ||
262 | #define task_uid(task) (task_cred_xxx((task), uid)) | 284 | #define task_uid(task) (task_cred_xxx((task), uid)) |