blob: 0314501688b9745f7601793fe17c0a14d7e1e147 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 */
5
6#include <linux/mm.h>
7#include <linux/utsname.h>
8#include <linux/mman.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/notifier.h>
10#include <linux/reboot.h>
11#include <linux/prctl.h>
Randy.Dunlapc59ede72006-01-11 12:17:46 -080012#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/init.h>
14#include <linux/highuid.h>
15#include <linux/security.h>
16#include <linux/syscalls.h>
17
18#include <asm/uaccess.h>
19
Heiko Carstensca013e92009-01-14 14:14:19 +010020SYSCALL_DEFINE3(chown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090022 long ret = sys_chown(filename, low2highuid(user), low2highgid(group));
23 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070024 asmlinkage_protect(3, ret, filename, user, group);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090025 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026}
27
Heiko Carstensca013e92009-01-14 14:14:19 +010028SYSCALL_DEFINE3(lchown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090030 long ret = sys_lchown(filename, low2highuid(user), low2highgid(group));
31 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070032 asmlinkage_protect(3, ret, filename, user, group);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090033 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070034}
35
Heiko Carstensca013e92009-01-14 14:14:19 +010036SYSCALL_DEFINE3(fchown16, unsigned int, fd, old_uid_t, user, old_gid_t, group)
Linus Torvalds1da177e2005-04-16 15:20:36 -070037{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090038 long ret = sys_fchown(fd, low2highuid(user), low2highgid(group));
39 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070040 asmlinkage_protect(3, ret, fd, user, group);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090041 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042}
43
Heiko Carstensa6b42e82009-01-14 14:14:20 +010044SYSCALL_DEFINE2(setregid16, old_gid_t, rgid, old_gid_t, egid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090046 long ret = sys_setregid(low2highgid(rgid), low2highgid(egid));
47 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070048 asmlinkage_protect(2, ret, rgid, egid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090049 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050}
51
Heiko Carstensa6b42e82009-01-14 14:14:20 +010052SYSCALL_DEFINE1(setgid16, old_gid_t, gid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090054 long ret = sys_setgid(low2highgid(gid));
55 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070056 asmlinkage_protect(1, ret, gid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090057 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058}
59
Heiko Carstensa6b42e82009-01-14 14:14:20 +010060SYSCALL_DEFINE2(setreuid16, old_uid_t, ruid, old_uid_t, euid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090062 long ret = sys_setreuid(low2highuid(ruid), low2highuid(euid));
63 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070064 asmlinkage_protect(2, ret, ruid, euid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090065 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
Heiko Carstensa6b42e82009-01-14 14:14:20 +010068SYSCALL_DEFINE1(setuid16, old_uid_t, uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090070 long ret = sys_setuid(low2highuid(uid));
71 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070072 asmlinkage_protect(1, ret, uid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090073 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074}
75
Heiko Carstensa6b42e82009-01-14 14:14:20 +010076SYSCALL_DEFINE3(setresuid16, old_uid_t, ruid, old_uid_t, euid, old_uid_t, suid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070077{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090078 long ret = sys_setresuid(low2highuid(ruid), low2highuid(euid),
79 low2highuid(suid));
80 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070081 asmlinkage_protect(3, ret, ruid, euid, suid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090082 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083}
84
Heiko Carstensa6b42e82009-01-14 14:14:20 +010085SYSCALL_DEFINE3(getresuid16, old_uid_t __user *, ruid, old_uid_t __user *, euid, old_uid_t __user *, suid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
David Howells86a264a2008-11-14 10:39:18 +110087 const struct cred *cred = current_cred();
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 int retval;
89
David Howells86a264a2008-11-14 10:39:18 +110090 if (!(retval = put_user(high2lowuid(cred->uid), ruid)) &&
91 !(retval = put_user(high2lowuid(cred->euid), euid)))
92 retval = put_user(high2lowuid(cred->suid), suid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 return retval;
95}
96
Heiko Carstensa6b42e82009-01-14 14:14:20 +010097SYSCALL_DEFINE3(setresgid16, old_gid_t, rgid, old_gid_t, egid, old_gid_t, sgid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070098{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090099 long ret = sys_setresgid(low2highgid(rgid), low2highgid(egid),
100 low2highgid(sgid));
101 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -0700102 asmlinkage_protect(3, ret, rgid, egid, sgid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +0900103 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
Heiko Carstensa6b42e82009-01-14 14:14:20 +0100106
107SYSCALL_DEFINE3(getresgid16, old_gid_t __user *, rgid, old_gid_t __user *, egid, old_gid_t __user *, sgid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
David Howells86a264a2008-11-14 10:39:18 +1100109 const struct cred *cred = current_cred();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 int retval;
111
David Howells86a264a2008-11-14 10:39:18 +1100112 if (!(retval = put_user(high2lowgid(cred->gid), rgid)) &&
113 !(retval = put_user(high2lowgid(cred->egid), egid)))
114 retval = put_user(high2lowgid(cred->sgid), sgid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116 return retval;
117}
118
Heiko Carstensa6b42e82009-01-14 14:14:20 +0100119SYSCALL_DEFINE1(setfsuid16, old_uid_t, uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +0900121 long ret = sys_setfsuid(low2highuid(uid));
122 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -0700123 asmlinkage_protect(1, ret, uid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +0900124 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}
126
Heiko Carstensa6b42e82009-01-14 14:14:20 +0100127SYSCALL_DEFINE1(setfsgid16, old_gid_t, gid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +0900129 long ret = sys_setfsgid(low2highgid(gid));
130 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -0700131 asmlinkage_protect(1, ret, gid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +0900132 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133}
134
135static int groups16_to_user(old_gid_t __user *grouplist,
136 struct group_info *group_info)
137{
138 int i;
139 old_gid_t group;
140
141 for (i = 0; i < group_info->ngroups; i++) {
142 group = high2lowgid(GROUP_AT(group_info, i));
143 if (put_user(group, grouplist+i))
144 return -EFAULT;
145 }
146
147 return 0;
148}
149
150static int groups16_from_user(struct group_info *group_info,
151 old_gid_t __user *grouplist)
152{
153 int i;
154 old_gid_t group;
155
156 for (i = 0; i < group_info->ngroups; i++) {
157 if (get_user(group, grouplist+i))
158 return -EFAULT;
159 GROUP_AT(group_info, i) = low2highgid(group);
160 }
161
162 return 0;
163}
164
Heiko Carstens003d7ab2009-01-14 14:14:21 +0100165SYSCALL_DEFINE2(getgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
David Howells86a264a2008-11-14 10:39:18 +1100167 const struct cred *cred = current_cred();
168 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 if (gidsetsize < 0)
171 return -EINVAL;
172
David Howells86a264a2008-11-14 10:39:18 +1100173 i = cred->group_info->ngroups;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 if (gidsetsize) {
175 if (i > gidsetsize) {
176 i = -EINVAL;
177 goto out;
178 }
David Howells86a264a2008-11-14 10:39:18 +1100179 if (groups16_to_user(grouplist, cred->group_info)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 i = -EFAULT;
181 goto out;
182 }
183 }
184out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return i;
186}
187
Heiko Carstens003d7ab2009-01-14 14:14:21 +0100188SYSCALL_DEFINE2(setgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
190 struct group_info *group_info;
191 int retval;
192
193 if (!capable(CAP_SETGID))
194 return -EPERM;
195 if ((unsigned)gidsetsize > NGROUPS_MAX)
196 return -EINVAL;
197
198 group_info = groups_alloc(gidsetsize);
199 if (!group_info)
200 return -ENOMEM;
201 retval = groups16_from_user(group_info, grouplist);
202 if (retval) {
203 put_group_info(group_info);
204 return retval;
205 }
206
207 retval = set_current_groups(group_info);
208 put_group_info(group_info);
209
210 return retval;
211}
212
Heiko Carstens003d7ab2009-01-14 14:14:21 +0100213SYSCALL_DEFINE0(getuid16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214{
David Howells86a264a2008-11-14 10:39:18 +1100215 return high2lowuid(current_uid());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
217
Heiko Carstens003d7ab2009-01-14 14:14:21 +0100218SYSCALL_DEFINE0(geteuid16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219{
David Howells86a264a2008-11-14 10:39:18 +1100220 return high2lowuid(current_euid());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
222
Heiko Carstens003d7ab2009-01-14 14:14:21 +0100223SYSCALL_DEFINE0(getgid16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224{
David Howells86a264a2008-11-14 10:39:18 +1100225 return high2lowgid(current_gid());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
Heiko Carstens003d7ab2009-01-14 14:14:21 +0100228SYSCALL_DEFINE0(getegid16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
David Howells86a264a2008-11-14 10:39:18 +1100230 return high2lowgid(current_egid());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}