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/cred.h>
16 #include <linux/syscalls.h>
18 #include <linux/uaccess.h>
20 SYSCALL_DEFINE3(chown16
, const char __user
*, filename
, old_uid_t
, user
, old_gid_t
, group
)
22 return sys_chown(filename
, low2highuid(user
), low2highgid(group
));
25 SYSCALL_DEFINE3(lchown16
, const char __user
*, filename
, old_uid_t
, user
, old_gid_t
, group
)
27 return sys_lchown(filename
, low2highuid(user
), low2highgid(group
));
30 SYSCALL_DEFINE3(fchown16
, unsigned int, fd
, old_uid_t
, user
, old_gid_t
, group
)
32 return sys_fchown(fd
, low2highuid(user
), low2highgid(group
));
35 SYSCALL_DEFINE2(setregid16
, old_gid_t
, rgid
, old_gid_t
, egid
)
37 return sys_setregid(low2highgid(rgid
), low2highgid(egid
));
40 SYSCALL_DEFINE1(setgid16
, old_gid_t
, gid
)
42 return sys_setgid(low2highgid(gid
));
45 SYSCALL_DEFINE2(setreuid16
, old_uid_t
, ruid
, old_uid_t
, euid
)
47 return sys_setreuid(low2highuid(ruid
), low2highuid(euid
));
50 SYSCALL_DEFINE1(setuid16
, old_uid_t
, uid
)
52 return sys_setuid(low2highuid(uid
));
55 SYSCALL_DEFINE3(setresuid16
, old_uid_t
, ruid
, old_uid_t
, euid
, old_uid_t
, suid
)
57 return sys_setresuid(low2highuid(ruid
), low2highuid(euid
),
61 SYSCALL_DEFINE3(getresuid16
, old_uid_t __user
*, ruidp
, old_uid_t __user
*, euidp
, old_uid_t __user
*, suidp
)
63 const struct cred
*cred
= current_cred();
65 old_uid_t ruid
, euid
, suid
;
67 ruid
= high2lowuid(from_kuid_munged(cred
->user_ns
, cred
->uid
));
68 euid
= high2lowuid(from_kuid_munged(cred
->user_ns
, cred
->euid
));
69 suid
= high2lowuid(from_kuid_munged(cred
->user_ns
, cred
->suid
));
71 if (!(retval
= put_user(ruid
, ruidp
)) &&
72 !(retval
= put_user(euid
, euidp
)))
73 retval
= put_user(suid
, suidp
);
78 SYSCALL_DEFINE3(setresgid16
, old_gid_t
, rgid
, old_gid_t
, egid
, old_gid_t
, sgid
)
80 return sys_setresgid(low2highgid(rgid
), low2highgid(egid
),
85 SYSCALL_DEFINE3(getresgid16
, old_gid_t __user
*, rgidp
, old_gid_t __user
*, egidp
, old_gid_t __user
*, sgidp
)
87 const struct cred
*cred
= current_cred();
89 old_gid_t rgid
, egid
, sgid
;
91 rgid
= high2lowgid(from_kgid_munged(cred
->user_ns
, cred
->gid
));
92 egid
= high2lowgid(from_kgid_munged(cred
->user_ns
, cred
->egid
));
93 sgid
= high2lowgid(from_kgid_munged(cred
->user_ns
, cred
->sgid
));
95 if (!(retval
= put_user(rgid
, rgidp
)) &&
96 !(retval
= put_user(egid
, egidp
)))
97 retval
= put_user(sgid
, sgidp
);
102 SYSCALL_DEFINE1(setfsuid16
, old_uid_t
, uid
)
104 return sys_setfsuid(low2highuid(uid
));
107 SYSCALL_DEFINE1(setfsgid16
, old_gid_t
, gid
)
109 return sys_setfsgid(low2highgid(gid
));
112 static int groups16_to_user(old_gid_t __user
*grouplist
,
113 struct group_info
*group_info
)
115 struct user_namespace
*user_ns
= current_user_ns();
120 for (i
= 0; i
< group_info
->ngroups
; i
++) {
121 kgid
= group_info
->gid
[i
];
122 group
= high2lowgid(from_kgid_munged(user_ns
, kgid
));
123 if (put_user(group
, grouplist
+i
))
130 static int groups16_from_user(struct group_info
*group_info
,
131 old_gid_t __user
*grouplist
)
133 struct user_namespace
*user_ns
= current_user_ns();
138 for (i
= 0; i
< group_info
->ngroups
; i
++) {
139 if (get_user(group
, grouplist
+i
))
142 kgid
= make_kgid(user_ns
, low2highgid(group
));
143 if (!gid_valid(kgid
))
146 group_info
->gid
[i
] = kgid
;
152 SYSCALL_DEFINE2(getgroups16
, int, gidsetsize
, old_gid_t __user
*, grouplist
)
154 const struct cred
*cred
= current_cred();
160 i
= cred
->group_info
->ngroups
;
162 if (i
> gidsetsize
) {
166 if (groups16_to_user(grouplist
, cred
->group_info
)) {
175 SYSCALL_DEFINE2(setgroups16
, int, gidsetsize
, old_gid_t __user
*, grouplist
)
177 struct group_info
*group_info
;
180 if (!may_setgroups())
182 if ((unsigned)gidsetsize
> NGROUPS_MAX
)
185 group_info
= groups_alloc(gidsetsize
);
188 retval
= groups16_from_user(group_info
, grouplist
);
190 put_group_info(group_info
);
194 retval
= set_current_groups(group_info
);
195 put_group_info(group_info
);
200 SYSCALL_DEFINE0(getuid16
)
202 return high2lowuid(from_kuid_munged(current_user_ns(), current_uid()));
205 SYSCALL_DEFINE0(geteuid16
)
207 return high2lowuid(from_kuid_munged(current_user_ns(), current_euid()));
210 SYSCALL_DEFINE0(getgid16
)
212 return high2lowgid(from_kgid_munged(current_user_ns(), current_gid()));
215 SYSCALL_DEFINE0(getegid16
)
217 return high2lowgid(from_kgid_munged(current_user_ns(), current_egid()));