staging:iio:max1363 use device_id instead of searching on name again
[zen-stable.git] / kernel / uid16.c
blob419209893d87b528488203ea258a39021fd70ad3
1 /*
2 * Wrapper functions for 16bit uid back compatibility. All nicely tied
3 * together in the faint hope we can take the out in five years time.
4 */
6 #include <linux/mm.h>
7 #include <linux/mman.h>
8 #include <linux/notifier.h>
9 #include <linux/reboot.h>
10 #include <linux/prctl.h>
11 #include <linux/capability.h>
12 #include <linux/init.h>
13 #include <linux/highuid.h>
14 #include <linux/security.h>
15 #include <linux/syscalls.h>
17 #include <asm/uaccess.h>
19 SYSCALL_DEFINE3(chown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
21 long ret = sys_chown(filename, low2highuid(user), low2highgid(group));
22 /* avoid REGPARM breakage on x86: */
23 asmlinkage_protect(3, ret, filename, user, group);
24 return ret;
27 SYSCALL_DEFINE3(lchown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
29 long ret = sys_lchown(filename, low2highuid(user), low2highgid(group));
30 /* avoid REGPARM breakage on x86: */
31 asmlinkage_protect(3, ret, filename, user, group);
32 return ret;
35 SYSCALL_DEFINE3(fchown16, unsigned int, fd, old_uid_t, user, old_gid_t, group)
37 long ret = sys_fchown(fd, low2highuid(user), low2highgid(group));
38 /* avoid REGPARM breakage on x86: */
39 asmlinkage_protect(3, ret, fd, user, group);
40 return ret;
43 SYSCALL_DEFINE2(setregid16, old_gid_t, rgid, old_gid_t, egid)
45 long ret = sys_setregid(low2highgid(rgid), low2highgid(egid));
46 /* avoid REGPARM breakage on x86: */
47 asmlinkage_protect(2, ret, rgid, egid);
48 return ret;
51 SYSCALL_DEFINE1(setgid16, old_gid_t, gid)
53 long ret = sys_setgid(low2highgid(gid));
54 /* avoid REGPARM breakage on x86: */
55 asmlinkage_protect(1, ret, gid);
56 return ret;
59 SYSCALL_DEFINE2(setreuid16, old_uid_t, ruid, old_uid_t, euid)
61 long ret = sys_setreuid(low2highuid(ruid), low2highuid(euid));
62 /* avoid REGPARM breakage on x86: */
63 asmlinkage_protect(2, ret, ruid, euid);
64 return ret;
67 SYSCALL_DEFINE1(setuid16, old_uid_t, uid)
69 long ret = sys_setuid(low2highuid(uid));
70 /* avoid REGPARM breakage on x86: */
71 asmlinkage_protect(1, ret, uid);
72 return ret;
75 SYSCALL_DEFINE3(setresuid16, old_uid_t, ruid, old_uid_t, euid, old_uid_t, suid)
77 long ret = sys_setresuid(low2highuid(ruid), low2highuid(euid),
78 low2highuid(suid));
79 /* avoid REGPARM breakage on x86: */
80 asmlinkage_protect(3, ret, ruid, euid, suid);
81 return ret;
84 SYSCALL_DEFINE3(getresuid16, old_uid_t __user *, ruid, old_uid_t __user *, euid, old_uid_t __user *, suid)
86 const struct cred *cred = current_cred();
87 int retval;
89 if (!(retval = put_user(high2lowuid(cred->uid), ruid)) &&
90 !(retval = put_user(high2lowuid(cred->euid), euid)))
91 retval = put_user(high2lowuid(cred->suid), suid);
93 return retval;
96 SYSCALL_DEFINE3(setresgid16, old_gid_t, rgid, old_gid_t, egid, old_gid_t, sgid)
98 long ret = sys_setresgid(low2highgid(rgid), low2highgid(egid),
99 low2highgid(sgid));
100 /* avoid REGPARM breakage on x86: */
101 asmlinkage_protect(3, ret, rgid, egid, sgid);
102 return ret;
106 SYSCALL_DEFINE3(getresgid16, old_gid_t __user *, rgid, old_gid_t __user *, egid, old_gid_t __user *, sgid)
108 const struct cred *cred = current_cred();
109 int retval;
111 if (!(retval = put_user(high2lowgid(cred->gid), rgid)) &&
112 !(retval = put_user(high2lowgid(cred->egid), egid)))
113 retval = put_user(high2lowgid(cred->sgid), sgid);
115 return retval;
118 SYSCALL_DEFINE1(setfsuid16, old_uid_t, uid)
120 long ret = sys_setfsuid(low2highuid(uid));
121 /* avoid REGPARM breakage on x86: */
122 asmlinkage_protect(1, ret, uid);
123 return ret;
126 SYSCALL_DEFINE1(setfsgid16, old_gid_t, gid)
128 long ret = sys_setfsgid(low2highgid(gid));
129 /* avoid REGPARM breakage on x86: */
130 asmlinkage_protect(1, ret, gid);
131 return ret;
134 static int groups16_to_user(old_gid_t __user *grouplist,
135 struct group_info *group_info)
137 int i;
138 old_gid_t group;
140 for (i = 0; i < group_info->ngroups; i++) {
141 group = high2lowgid(GROUP_AT(group_info, i));
142 if (put_user(group, grouplist+i))
143 return -EFAULT;
146 return 0;
149 static int groups16_from_user(struct group_info *group_info,
150 old_gid_t __user *grouplist)
152 int i;
153 old_gid_t group;
155 for (i = 0; i < group_info->ngroups; i++) {
156 if (get_user(group, grouplist+i))
157 return -EFAULT;
158 GROUP_AT(group_info, i) = low2highgid(group);
161 return 0;
164 SYSCALL_DEFINE2(getgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
166 const struct cred *cred = current_cred();
167 int i;
169 if (gidsetsize < 0)
170 return -EINVAL;
172 i = cred->group_info->ngroups;
173 if (gidsetsize) {
174 if (i > gidsetsize) {
175 i = -EINVAL;
176 goto out;
178 if (groups16_to_user(grouplist, cred->group_info)) {
179 i = -EFAULT;
180 goto out;
183 out:
184 return i;
187 SYSCALL_DEFINE2(setgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
189 struct group_info *group_info;
190 int retval;
192 if (!capable(CAP_SETGID))
193 return -EPERM;
194 if ((unsigned)gidsetsize > NGROUPS_MAX)
195 return -EINVAL;
197 group_info = groups_alloc(gidsetsize);
198 if (!group_info)
199 return -ENOMEM;
200 retval = groups16_from_user(group_info, grouplist);
201 if (retval) {
202 put_group_info(group_info);
203 return retval;
206 retval = set_current_groups(group_info);
207 put_group_info(group_info);
209 return retval;
212 SYSCALL_DEFINE0(getuid16)
214 return high2lowuid(current_uid());
217 SYSCALL_DEFINE0(geteuid16)
219 return high2lowuid(current_euid());
222 SYSCALL_DEFINE0(getgid16)
224 return high2lowgid(current_gid());
227 SYSCALL_DEFINE0(getegid16)
229 return high2lowgid(current_egid());