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.
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),
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();
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);
77 SYSCALL_DEFINE3(setresgid16, old_gid_t, rgid, old_gid_t, egid, old_gid_t, sgid)
79 return sys_setresgid(low2highgid(rgid), low2highgid(egid),
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();
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);
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();
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))
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();
137 for (i = 0; i < group_info->ngroups; i++) {
138 if (get_user(group, grouplist+i))
141 kgid = make_kgid(user_ns, low2highgid(group));
142 if (!gid_valid(kgid))
145 GROUP_AT(group_info, i) = kgid;
151 SYSCALL_DEFINE2(getgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
153 const struct cred *cred = current_cred();
159 i = cred->group_info->ngroups;
161 if (i > gidsetsize) {
165 if (groups16_to_user(grouplist, cred->group_info)) {
174 SYSCALL_DEFINE2(setgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
176 struct group_info *group_info;
179 if (!may_setgroups())
181 if ((unsigned)gidsetsize > NGROUPS_MAX)
184 group_info = groups_alloc(gidsetsize);
187 retval = groups16_from_user(group_info, grouplist);
189 put_group_info(group_info);
193 retval = set_current_groups(group_info);
194 put_group_info(group_info);
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()));