diff options
author | David Howells <dhowells@redhat.com> | 2008-11-13 18:39:18 -0500 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2008-11-13 18:39:18 -0500 |
commit | 86a264abe542cfececb4df129bc45a0338d8cdb9 (patch) | |
tree | 30152f04ba847f311028d5ca697f864c16c7ebb3 /kernel/sys.c | |
parent | f1752eec6145c97163dbce62d17cf5d928e28a27 (diff) |
CRED: Wrap current->cred and a few other accessors
Wrap current->cred and a few other accessors to hide their actual
implementation.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: James Morris <jmorris@namei.org>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'kernel/sys.c')
-rw-r--r-- | kernel/sys.c | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/kernel/sys.c b/kernel/sys.c index 5d81f07c0150..c4d6b59553e9 100644 --- a/kernel/sys.c +++ b/kernel/sys.c | |||
@@ -143,6 +143,7 @@ asmlinkage long sys_setpriority(int which, int who, int niceval) | |||
143 | { | 143 | { |
144 | struct task_struct *g, *p; | 144 | struct task_struct *g, *p; |
145 | struct user_struct *user; | 145 | struct user_struct *user; |
146 | const struct cred *cred = current_cred(); | ||
146 | int error = -EINVAL; | 147 | int error = -EINVAL; |
147 | struct pid *pgrp; | 148 | struct pid *pgrp; |
148 | 149 | ||
@@ -176,18 +177,18 @@ asmlinkage long sys_setpriority(int which, int who, int niceval) | |||
176 | } while_each_pid_thread(pgrp, PIDTYPE_PGID, p); | 177 | } while_each_pid_thread(pgrp, PIDTYPE_PGID, p); |
177 | break; | 178 | break; |
178 | case PRIO_USER: | 179 | case PRIO_USER: |
179 | user = current->cred->user; | 180 | user = cred->user; |
180 | if (!who) | 181 | if (!who) |
181 | who = current_uid(); | 182 | who = cred->uid; |
182 | else | 183 | else if ((who != cred->uid) && |
183 | if (who != current_uid() && !(user = find_user(who))) | 184 | !(user = find_user(who))) |
184 | goto out_unlock; /* No processes for this user */ | 185 | goto out_unlock; /* No processes for this user */ |
185 | 186 | ||
186 | do_each_thread(g, p) | 187 | do_each_thread(g, p) |
187 | if (p->cred->uid == who) | 188 | if (__task_cred(p)->uid == who) |
188 | error = set_one_prio(p, niceval, error); | 189 | error = set_one_prio(p, niceval, error); |
189 | while_each_thread(g, p); | 190 | while_each_thread(g, p); |
190 | if (who != current_uid()) | 191 | if (who != cred->uid) |
191 | free_uid(user); /* For find_user() */ | 192 | free_uid(user); /* For find_user() */ |
192 | break; | 193 | break; |
193 | } | 194 | } |
@@ -207,6 +208,7 @@ asmlinkage long sys_getpriority(int which, int who) | |||
207 | { | 208 | { |
208 | struct task_struct *g, *p; | 209 | struct task_struct *g, *p; |
209 | struct user_struct *user; | 210 | struct user_struct *user; |
211 | const struct cred *cred = current_cred(); | ||
210 | long niceval, retval = -ESRCH; | 212 | long niceval, retval = -ESRCH; |
211 | struct pid *pgrp; | 213 | struct pid *pgrp; |
212 | 214 | ||
@@ -238,21 +240,21 @@ asmlinkage long sys_getpriority(int which, int who) | |||
238 | } while_each_pid_thread(pgrp, PIDTYPE_PGID, p); | 240 | } while_each_pid_thread(pgrp, PIDTYPE_PGID, p); |
239 | break; | 241 | break; |
240 | case PRIO_USER: | 242 | case PRIO_USER: |
241 | user = current->cred->user; | 243 | user = (struct user_struct *) cred->user; |
242 | if (!who) | 244 | if (!who) |
243 | who = current_uid(); | 245 | who = cred->uid; |
244 | else | 246 | else if ((who != cred->uid) && |
245 | if (who != current_uid() && !(user = find_user(who))) | 247 | !(user = find_user(who))) |
246 | goto out_unlock; /* No processes for this user */ | 248 | goto out_unlock; /* No processes for this user */ |
247 | 249 | ||
248 | do_each_thread(g, p) | 250 | do_each_thread(g, p) |
249 | if (p->cred->uid == who) { | 251 | if (__task_cred(p)->uid == who) { |
250 | niceval = 20 - task_nice(p); | 252 | niceval = 20 - task_nice(p); |
251 | if (niceval > retval) | 253 | if (niceval > retval) |
252 | retval = niceval; | 254 | retval = niceval; |
253 | } | 255 | } |
254 | while_each_thread(g, p); | 256 | while_each_thread(g, p); |
255 | if (who != current_uid()) | 257 | if (who != cred->uid) |
256 | free_uid(user); /* for find_user() */ | 258 | free_uid(user); /* for find_user() */ |
257 | break; | 259 | break; |
258 | } | 260 | } |
@@ -743,11 +745,11 @@ asmlinkage long sys_setresuid(uid_t ruid, uid_t euid, uid_t suid) | |||
743 | 745 | ||
744 | asmlinkage long sys_getresuid(uid_t __user *ruid, uid_t __user *euid, uid_t __user *suid) | 746 | asmlinkage long sys_getresuid(uid_t __user *ruid, uid_t __user *euid, uid_t __user *suid) |
745 | { | 747 | { |
746 | struct cred *cred = current->cred; | 748 | const struct cred *cred = current_cred(); |
747 | int retval; | 749 | int retval; |
748 | 750 | ||
749 | if (!(retval = put_user(cred->uid, ruid)) && | 751 | if (!(retval = put_user(cred->uid, ruid)) && |
750 | !(retval = put_user(cred->euid, euid))) | 752 | !(retval = put_user(cred->euid, euid))) |
751 | retval = put_user(cred->suid, suid); | 753 | retval = put_user(cred->suid, suid); |
752 | 754 | ||
753 | return retval; | 755 | return retval; |
@@ -796,11 +798,11 @@ asmlinkage long sys_setresgid(gid_t rgid, gid_t egid, gid_t sgid) | |||
796 | 798 | ||
797 | asmlinkage long sys_getresgid(gid_t __user *rgid, gid_t __user *egid, gid_t __user *sgid) | 799 | asmlinkage long sys_getresgid(gid_t __user *rgid, gid_t __user *egid, gid_t __user *sgid) |
798 | { | 800 | { |
799 | struct cred *cred = current->cred; | 801 | const struct cred *cred = current_cred(); |
800 | int retval; | 802 | int retval; |
801 | 803 | ||
802 | if (!(retval = put_user(cred->gid, rgid)) && | 804 | if (!(retval = put_user(cred->gid, rgid)) && |
803 | !(retval = put_user(cred->egid, egid))) | 805 | !(retval = put_user(cred->egid, egid))) |
804 | retval = put_user(cred->sgid, sgid); | 806 | retval = put_user(cred->sgid, sgid); |
805 | 807 | ||
806 | return retval; | 808 | return retval; |
@@ -1199,7 +1201,7 @@ static void groups_sort(struct group_info *group_info) | |||
1199 | } | 1201 | } |
1200 | 1202 | ||
1201 | /* a simple bsearch */ | 1203 | /* a simple bsearch */ |
1202 | int groups_search(struct group_info *group_info, gid_t grp) | 1204 | int groups_search(const struct group_info *group_info, gid_t grp) |
1203 | { | 1205 | { |
1204 | unsigned int left, right; | 1206 | unsigned int left, right; |
1205 | 1207 | ||
@@ -1268,13 +1270,8 @@ EXPORT_SYMBOL(set_current_groups); | |||
1268 | 1270 | ||
1269 | asmlinkage long sys_getgroups(int gidsetsize, gid_t __user *grouplist) | 1271 | asmlinkage long sys_getgroups(int gidsetsize, gid_t __user *grouplist) |
1270 | { | 1272 | { |
1271 | struct cred *cred = current->cred; | 1273 | const struct cred *cred = current_cred(); |
1272 | int i = 0; | 1274 | int i; |
1273 | |||
1274 | /* | ||
1275 | * SMP: Nobody else can change our grouplist. Thus we are | ||
1276 | * safe. | ||
1277 | */ | ||
1278 | 1275 | ||
1279 | if (gidsetsize < 0) | 1276 | if (gidsetsize < 0) |
1280 | return -EINVAL; | 1277 | return -EINVAL; |
@@ -1330,8 +1327,9 @@ asmlinkage long sys_setgroups(int gidsetsize, gid_t __user *grouplist) | |||
1330 | */ | 1327 | */ |
1331 | int in_group_p(gid_t grp) | 1328 | int in_group_p(gid_t grp) |
1332 | { | 1329 | { |
1333 | struct cred *cred = current->cred; | 1330 | const struct cred *cred = current_cred(); |
1334 | int retval = 1; | 1331 | int retval = 1; |
1332 | |||
1335 | if (grp != cred->fsgid) | 1333 | if (grp != cred->fsgid) |
1336 | retval = groups_search(cred->group_info, grp); | 1334 | retval = groups_search(cred->group_info, grp); |
1337 | return retval; | 1335 | return retval; |
@@ -1341,8 +1339,9 @@ EXPORT_SYMBOL(in_group_p); | |||
1341 | 1339 | ||
1342 | int in_egroup_p(gid_t grp) | 1340 | int in_egroup_p(gid_t grp) |
1343 | { | 1341 | { |
1344 | struct cred *cred = current->cred; | 1342 | const struct cred *cred = current_cred(); |
1345 | int retval = 1; | 1343 | int retval = 1; |
1344 | |||
1346 | if (grp != cred->egid) | 1345 | if (grp != cred->egid) |
1347 | retval = groups_search(cred->group_info, grp); | 1346 | retval = groups_search(cred->group_info, grp); |
1348 | return retval; | 1347 | return retval; |