aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2008-11-13 18:39:18 -0500
committerJames Morris <jmorris@namei.org>2008-11-13 18:39:18 -0500
commit86a264abe542cfececb4df129bc45a0338d8cdb9 (patch)
tree30152f04ba847f311028d5ca697f864c16c7ebb3 /kernel
parentf1752eec6145c97163dbce62d17cf5d928e28a27 (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')
-rw-r--r--kernel/sys.c59
-rw-r--r--kernel/uid16.c31
2 files changed, 45 insertions, 45 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
744asmlinkage long sys_getresuid(uid_t __user *ruid, uid_t __user *euid, uid_t __user *suid) 746asmlinkage 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
797asmlinkage long sys_getresgid(gid_t __user *rgid, gid_t __user *egid, gid_t __user *sgid) 799asmlinkage 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 */
1202int groups_search(struct group_info *group_info, gid_t grp) 1204int 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
1269asmlinkage long sys_getgroups(int gidsetsize, gid_t __user *grouplist) 1271asmlinkage 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 */
1331int in_group_p(gid_t grp) 1328int 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
1342int in_egroup_p(gid_t grp) 1340int 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;
diff --git a/kernel/uid16.c b/kernel/uid16.c
index 71f07fc39fea..2460c3199b5a 100644
--- a/kernel/uid16.c
+++ b/kernel/uid16.c
@@ -84,11 +84,12 @@ asmlinkage long sys_setresuid16(old_uid_t ruid, old_uid_t euid, old_uid_t suid)
84 84
85asmlinkage long sys_getresuid16(old_uid_t __user *ruid, old_uid_t __user *euid, old_uid_t __user *suid) 85asmlinkage long sys_getresuid16(old_uid_t __user *ruid, old_uid_t __user *euid, old_uid_t __user *suid)
86{ 86{
87 const struct cred *cred = current_cred();
87 int retval; 88 int retval;
88 89
89 if (!(retval = put_user(high2lowuid(current->cred->uid), ruid)) && 90 if (!(retval = put_user(high2lowuid(cred->uid), ruid)) &&
90 !(retval = put_user(high2lowuid(current->cred->euid), euid))) 91 !(retval = put_user(high2lowuid(cred->euid), euid)))
91 retval = put_user(high2lowuid(current->cred->suid), suid); 92 retval = put_user(high2lowuid(cred->suid), suid);
92 93
93 return retval; 94 return retval;
94} 95}
@@ -104,11 +105,12 @@ asmlinkage long sys_setresgid16(old_gid_t rgid, old_gid_t egid, old_gid_t sgid)
104 105
105asmlinkage long sys_getresgid16(old_gid_t __user *rgid, old_gid_t __user *egid, old_gid_t __user *sgid) 106asmlinkage long sys_getresgid16(old_gid_t __user *rgid, old_gid_t __user *egid, old_gid_t __user *sgid)
106{ 107{
108 const struct cred *cred = current_cred();
107 int retval; 109 int retval;
108 110
109 if (!(retval = put_user(high2lowgid(current->cred->gid), rgid)) && 111 if (!(retval = put_user(high2lowgid(cred->gid), rgid)) &&
110 !(retval = put_user(high2lowgid(current->cred->egid), egid))) 112 !(retval = put_user(high2lowgid(cred->egid), egid)))
111 retval = put_user(high2lowgid(current->cred->sgid), sgid); 113 retval = put_user(high2lowgid(cred->sgid), sgid);
112 114
113 return retval; 115 return retval;
114} 116}
@@ -161,25 +163,24 @@ static int groups16_from_user(struct group_info *group_info,
161 163
162asmlinkage long sys_getgroups16(int gidsetsize, old_gid_t __user *grouplist) 164asmlinkage long sys_getgroups16(int gidsetsize, old_gid_t __user *grouplist)
163{ 165{
164 int i = 0; 166 const struct cred *cred = current_cred();
167 int i;
165 168
166 if (gidsetsize < 0) 169 if (gidsetsize < 0)
167 return -EINVAL; 170 return -EINVAL;
168 171
169 get_group_info(current->cred->group_info); 172 i = cred->group_info->ngroups;
170 i = current->cred->group_info->ngroups;
171 if (gidsetsize) { 173 if (gidsetsize) {
172 if (i > gidsetsize) { 174 if (i > gidsetsize) {
173 i = -EINVAL; 175 i = -EINVAL;
174 goto out; 176 goto out;
175 } 177 }
176 if (groups16_to_user(grouplist, current->cred->group_info)) { 178 if (groups16_to_user(grouplist, cred->group_info)) {
177 i = -EFAULT; 179 i = -EFAULT;
178 goto out; 180 goto out;
179 } 181 }
180 } 182 }
181out: 183out:
182 put_group_info(current->cred->group_info);
183 return i; 184 return i;
184} 185}
185 186
@@ -210,20 +211,20 @@ asmlinkage long sys_setgroups16(int gidsetsize, old_gid_t __user *grouplist)
210 211
211asmlinkage long sys_getuid16(void) 212asmlinkage long sys_getuid16(void)
212{ 213{
213 return high2lowuid(current->cred->uid); 214 return high2lowuid(current_uid());
214} 215}
215 216
216asmlinkage long sys_geteuid16(void) 217asmlinkage long sys_geteuid16(void)
217{ 218{
218 return high2lowuid(current->cred->euid); 219 return high2lowuid(current_euid());
219} 220}
220 221
221asmlinkage long sys_getgid16(void) 222asmlinkage long sys_getgid16(void)
222{ 223{
223 return high2lowgid(current->cred->gid); 224 return high2lowgid(current_gid());
224} 225}
225 226
226asmlinkage long sys_getegid16(void) 227asmlinkage long sys_getegid16(void)
227{ 228{
228 return high2lowgid(current->cred->egid); 229 return high2lowgid(current_egid());
229} 230}