powerpc/jump_label: Annotate jump label assembly
[linux/fpc-iii.git] / kernel / uid16.c
blobd58cc4d8f0d1fa95c7ec0120cb408a9b4ad859e5
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 return sys_chown(filename, low2highuid(user), low2highgid(group));
24 SYSCALL_DEFINE3(lchown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
26 return sys_lchown(filename, low2highuid(user), low2highgid(group));
29 SYSCALL_DEFINE3(fchown16, unsigned int, fd, old_uid_t, user, old_gid_t, group)
31 return sys_fchown(fd, low2highuid(user), low2highgid(group));
34 SYSCALL_DEFINE2(setregid16, old_gid_t, rgid, old_gid_t, egid)
36 return sys_setregid(low2highgid(rgid), low2highgid(egid));
39 SYSCALL_DEFINE1(setgid16, old_gid_t, gid)
41 return sys_setgid(low2highgid(gid));
44 SYSCALL_DEFINE2(setreuid16, old_uid_t, ruid, old_uid_t, euid)
46 return sys_setreuid(low2highuid(ruid), low2highuid(euid));
49 SYSCALL_DEFINE1(setuid16, old_uid_t, uid)
51 return sys_setuid(low2highuid(uid));
54 SYSCALL_DEFINE3(setresuid16, old_uid_t, ruid, old_uid_t, euid, old_uid_t, suid)
56 return sys_setresuid(low2highuid(ruid), low2highuid(euid),
57 low2highuid(suid));
60 SYSCALL_DEFINE3(getresuid16, old_uid_t __user *, ruidp, old_uid_t __user *, euidp, old_uid_t __user *, suidp)
62 const struct cred *cred = current_cred();
63 int retval;
64 old_uid_t ruid, euid, suid;
66 ruid = high2lowuid(from_kuid_munged(cred->user_ns, cred->uid));
67 euid = high2lowuid(from_kuid_munged(cred->user_ns, cred->euid));
68 suid = high2lowuid(from_kuid_munged(cred->user_ns, cred->suid));
70 if (!(retval = put_user(ruid, ruidp)) &&
71 !(retval = put_user(euid, euidp)))
72 retval = put_user(suid, suidp);
74 return retval;
77 SYSCALL_DEFINE3(setresgid16, old_gid_t, rgid, old_gid_t, egid, old_gid_t, sgid)
79 return sys_setresgid(low2highgid(rgid), low2highgid(egid),
80 low2highgid(sgid));
84 SYSCALL_DEFINE3(getresgid16, old_gid_t __user *, rgidp, old_gid_t __user *, egidp, old_gid_t __user *, sgidp)
86 const struct cred *cred = current_cred();
87 int retval;
88 old_gid_t rgid, egid, sgid;
90 rgid = high2lowgid(from_kgid_munged(cred->user_ns, cred->gid));
91 egid = high2lowgid(from_kgid_munged(cred->user_ns, cred->egid));
92 sgid = high2lowgid(from_kgid_munged(cred->user_ns, cred->sgid));
94 if (!(retval = put_user(rgid, rgidp)) &&
95 !(retval = put_user(egid, egidp)))
96 retval = put_user(sgid, sgidp);
98 return retval;
101 SYSCALL_DEFINE1(setfsuid16, old_uid_t, uid)
103 return sys_setfsuid(low2highuid(uid));
106 SYSCALL_DEFINE1(setfsgid16, old_gid_t, gid)
108 return sys_setfsgid(low2highgid(gid));
111 static int groups16_to_user(old_gid_t __user *grouplist,
112 struct group_info *group_info)
114 struct user_namespace *user_ns = current_user_ns();
115 int i;
116 old_gid_t group;
117 kgid_t kgid;
119 for (i = 0; i < group_info->ngroups; i++) {
120 kgid = GROUP_AT(group_info, i);
121 group = high2lowgid(from_kgid_munged(user_ns, kgid));
122 if (put_user(group, grouplist+i))
123 return -EFAULT;
126 return 0;
129 static int groups16_from_user(struct group_info *group_info,
130 old_gid_t __user *grouplist)
132 struct user_namespace *user_ns = current_user_ns();
133 int i;
134 old_gid_t group;
135 kgid_t kgid;
137 for (i = 0; i < group_info->ngroups; i++) {
138 if (get_user(group, grouplist+i))
139 return -EFAULT;
141 kgid = make_kgid(user_ns, low2highgid(group));
142 if (!gid_valid(kgid))
143 return -EINVAL;
145 GROUP_AT(group_info, i) = kgid;
148 return 0;
151 SYSCALL_DEFINE2(getgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
153 const struct cred *cred = current_cred();
154 int i;
156 if (gidsetsize < 0)
157 return -EINVAL;
159 i = cred->group_info->ngroups;
160 if (gidsetsize) {
161 if (i > gidsetsize) {
162 i = -EINVAL;
163 goto out;
165 if (groups16_to_user(grouplist, cred->group_info)) {
166 i = -EFAULT;
167 goto out;
170 out:
171 return i;
174 SYSCALL_DEFINE2(setgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
176 struct group_info *group_info;
177 int retval;
179 if (!may_setgroups())
180 return -EPERM;
181 if ((unsigned)gidsetsize > NGROUPS_MAX)
182 return -EINVAL;
184 group_info = groups_alloc(gidsetsize);
185 if (!group_info)
186 return -ENOMEM;
187 retval = groups16_from_user(group_info, grouplist);
188 if (retval) {
189 put_group_info(group_info);
190 return retval;
193 retval = set_current_groups(group_info);
194 put_group_info(group_info);
196 return retval;
199 SYSCALL_DEFINE0(getuid16)
201 return high2lowuid(from_kuid_munged(current_user_ns(), current_uid()));
204 SYSCALL_DEFINE0(geteuid16)
206 return high2lowuid(from_kuid_munged(current_user_ns(), current_euid()));
209 SYSCALL_DEFINE0(getgid16)
211 return high2lowgid(from_kgid_munged(current_user_ns(), current_gid()));
214 SYSCALL_DEFINE0(getegid16)
216 return high2lowgid(from_kgid_munged(current_user_ns(), current_egid()));