blob: 51c6e89e8619a56e28949d26f7f7053b5d32b5af [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/mman.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/notifier.h>
9#include <linux/reboot.h>
10#include <linux/prctl.h>
Randy.Dunlapc59ede72006-01-11 12:17:46 -080011#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
13#include <linux/highuid.h>
14#include <linux/security.h>
15#include <linux/syscalls.h>
16
17#include <asm/uaccess.h>
18
Heiko Carstensca013e92009-01-14 14:14:19 +010019SYSCALL_DEFINE3(chown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090021 long ret = sys_chown(filename, low2highuid(user), low2highgid(group));
22 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070023 asmlinkage_protect(3, ret, filename, user, group);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090024 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070025}
26
Heiko Carstensca013e92009-01-14 14:14:19 +010027SYSCALL_DEFINE3(lchown16, const char __user *, filename, old_uid_t, user, old_gid_t, group)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090029 long ret = sys_lchown(filename, low2highuid(user), low2highgid(group));
30 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070031 asmlinkage_protect(3, ret, filename, user, group);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090032 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033}
34
Heiko Carstensca013e92009-01-14 14:14:19 +010035SYSCALL_DEFINE3(fchown16, unsigned int, fd, old_uid_t, user, old_gid_t, group)
Linus Torvalds1da177e2005-04-16 15:20:36 -070036{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090037 long ret = sys_fchown(fd, low2highuid(user), low2highgid(group));
38 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070039 asmlinkage_protect(3, ret, fd, user, group);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090040 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041}
42
Heiko Carstensa6b42e82009-01-14 14:14:20 +010043SYSCALL_DEFINE2(setregid16, old_gid_t, rgid, old_gid_t, egid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090045 long ret = sys_setregid(low2highgid(rgid), low2highgid(egid));
46 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070047 asmlinkage_protect(2, ret, rgid, egid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090048 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Heiko Carstensa6b42e82009-01-14 14:14:20 +010051SYSCALL_DEFINE1(setgid16, old_gid_t, gid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090053 long ret = sys_setgid(low2highgid(gid));
54 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070055 asmlinkage_protect(1, ret, gid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090056 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
Heiko Carstensa6b42e82009-01-14 14:14:20 +010059SYSCALL_DEFINE2(setreuid16, old_uid_t, ruid, old_uid_t, euid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090061 long ret = sys_setreuid(low2highuid(ruid), low2highuid(euid));
62 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070063 asmlinkage_protect(2, ret, ruid, euid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090064 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Heiko Carstensa6b42e82009-01-14 14:14:20 +010067SYSCALL_DEFINE1(setuid16, old_uid_t, uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090069 long ret = sys_setuid(low2highuid(uid));
70 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070071 asmlinkage_protect(1, ret, uid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090072 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
74
Heiko Carstensa6b42e82009-01-14 14:14:20 +010075SYSCALL_DEFINE3(setresuid16, old_uid_t, ruid, old_uid_t, euid, old_uid_t, suid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090077 long ret = sys_setresuid(low2highuid(ruid), low2highuid(euid),
78 low2highuid(suid));
79 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -070080 asmlinkage_protect(3, ret, ruid, euid, suid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090081 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
83
Heiko Carstensa6b42e82009-01-14 14:14:20 +010084SYSCALL_DEFINE3(getresuid16, old_uid_t __user *, ruid, old_uid_t __user *, euid, old_uid_t __user *, suid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
David Howells86a264a2008-11-14 10:39:18 +110086 const struct cred *cred = current_cred();
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 int retval;
88
David Howells86a264a2008-11-14 10:39:18 +110089 if (!(retval = put_user(high2lowuid(cred->uid), ruid)) &&
90 !(retval = put_user(high2lowuid(cred->euid), euid)))
91 retval = put_user(high2lowuid(cred->suid), suid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93 return retval;
94}
95
Heiko Carstensa6b42e82009-01-14 14:14:20 +010096SYSCALL_DEFINE3(setresgid16, old_gid_t, rgid, old_gid_t, egid, old_gid_t, sgid)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +090098 long ret = sys_setresgid(low2highgid(rgid), low2highgid(egid),
99 low2highgid(sgid));
100 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -0700101 asmlinkage_protect(3, ret, rgid, egid, sgid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +0900102 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
Heiko Carstensa6b42e82009-01-14 14:14:20 +0100105
106SYSCALL_DEFINE3(getresgid16, old_gid_t __user *, rgid, old_gid_t __user *, egid, old_gid_t __user *, sgid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
David Howells86a264a2008-11-14 10:39:18 +1100108 const struct cred *cred = current_cred();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 int retval;
110
David Howells86a264a2008-11-14 10:39:18 +1100111 if (!(retval = put_user(high2lowgid(cred->gid), rgid)) &&
112 !(retval = put_user(high2lowgid(cred->egid), egid)))
113 retval = put_user(high2lowgid(cred->sgid), sgid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 return retval;
116}
117
Heiko Carstensa6b42e82009-01-14 14:14:20 +0100118SYSCALL_DEFINE1(setfsuid16, old_uid_t, uid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +0900120 long ret = sys_setfsuid(low2highuid(uid));
121 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -0700122 asmlinkage_protect(1, ret, uid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +0900123 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
Heiko Carstensa6b42e82009-01-14 14:14:20 +0100126SYSCALL_DEFINE1(setfsgid16, old_gid_t, gid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +0900128 long ret = sys_setfsgid(low2highgid(gid));
129 /* avoid REGPARM breakage on x86: */
Roland McGrath54a01512008-04-10 15:37:38 -0700130 asmlinkage_protect(1, ret, gid);
OGAWA Hirofumi5a7b46b2006-04-20 06:41:39 +0900131 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
134static int groups16_to_user(old_gid_t __user *grouplist,
135 struct group_info *group_info)
136{
137 int i;
138 old_gid_t group;
139
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;
144 }
145
146 return 0;
147}
148
149static int groups16_from_user(struct group_info *group_info,
150 old_gid_t __user *grouplist)
151{
152 int i;
153 old_gid_t group;
154
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);
159 }
160
161 return 0;
162}
163
Heiko Carstens003d7ab2009-01-14 14:14:21 +0100164SYSCALL_DEFINE2(getgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
David Howells86a264a2008-11-14 10:39:18 +1100166 const struct cred *cred = current_cred();
167 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 if (gidsetsize < 0)
170 return -EINVAL;
171
David Howells86a264a2008-11-14 10:39:18 +1100172 i = cred->group_info->ngroups;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 if (gidsetsize) {
174 if (i > gidsetsize) {
175 i = -EINVAL;
176 goto out;
177 }
David Howells86a264a2008-11-14 10:39:18 +1100178 if (groups16_to_user(grouplist, cred->group_info)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 i = -EFAULT;
180 goto out;
181 }
182 }
183out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 return i;
185}
186
Heiko Carstens003d7ab2009-01-14 14:14:21 +0100187SYSCALL_DEFINE2(setgroups16, int, gidsetsize, old_gid_t __user *, grouplist)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188{
189 struct group_info *group_info;
190 int retval;
191
Serge E. Hallynb0e77592011-03-23 16:43:24 -0700192 if (!nsown_capable(CAP_SETGID))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 return -EPERM;
194 if ((unsigned)gidsetsize > NGROUPS_MAX)
195 return -EINVAL;
196
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;
204 }
205
206 retval = set_current_groups(group_info);
207 put_group_info(group_info);
208
209 return retval;
210}
211
Heiko Carstens003d7ab2009-01-14 14:14:21 +0100212SYSCALL_DEFINE0(getuid16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
David Howells86a264a2008-11-14 10:39:18 +1100214 return high2lowuid(current_uid());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215}
216
Heiko Carstens003d7ab2009-01-14 14:14:21 +0100217SYSCALL_DEFINE0(geteuid16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
David Howells86a264a2008-11-14 10:39:18 +1100219 return high2lowuid(current_euid());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
221
Heiko Carstens003d7ab2009-01-14 14:14:21 +0100222SYSCALL_DEFINE0(getgid16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
David Howells86a264a2008-11-14 10:39:18 +1100224 return high2lowgid(current_gid());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225}
226
Heiko Carstens003d7ab2009-01-14 14:14:21 +0100227SYSCALL_DEFINE0(getegid16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228{
David Howells86a264a2008-11-14 10:39:18 +1100229 return high2lowgid(current_egid());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230}