uid16.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. */
  5. #include <linux/mm.h>
  6. #include <linux/utsname.h>
  7. #include <linux/mman.h>
  8. #include <linux/smp_lock.h>
  9. #include <linux/notifier.h>
  10. #include <linux/reboot.h>
  11. #include <linux/prctl.h>
  12. #include <linux/capability.h>
  13. #include <linux/init.h>
  14. #include <linux/highuid.h>
  15. #include <linux/security.h>
  16. #include <linux/syscalls.h>
  17. #include <asm/uaccess.h>
  18. asmlinkage long sys_chown16(const char __user * filename, old_uid_t user, old_gid_t group)
  19. {
  20. long ret = sys_chown(filename, low2highuid(user), low2highgid(group));
  21. /* avoid REGPARM breakage on x86: */
  22. prevent_tail_call(ret);
  23. return ret;
  24. }
  25. asmlinkage long sys_lchown16(const char __user * filename, old_uid_t user, old_gid_t group)
  26. {
  27. long ret = sys_lchown(filename, low2highuid(user), low2highgid(group));
  28. /* avoid REGPARM breakage on x86: */
  29. prevent_tail_call(ret);
  30. return ret;
  31. }
  32. asmlinkage long sys_fchown16(unsigned int fd, old_uid_t user, old_gid_t group)
  33. {
  34. long ret = sys_fchown(fd, low2highuid(user), low2highgid(group));
  35. /* avoid REGPARM breakage on x86: */
  36. prevent_tail_call(ret);
  37. return ret;
  38. }
  39. asmlinkage long sys_setregid16(old_gid_t rgid, old_gid_t egid)
  40. {
  41. long ret = sys_setregid(low2highgid(rgid), low2highgid(egid));
  42. /* avoid REGPARM breakage on x86: */
  43. prevent_tail_call(ret);
  44. return ret;
  45. }
  46. asmlinkage long sys_setgid16(old_gid_t gid)
  47. {
  48. long ret = sys_setgid(low2highgid(gid));
  49. /* avoid REGPARM breakage on x86: */
  50. prevent_tail_call(ret);
  51. return ret;
  52. }
  53. asmlinkage long sys_setreuid16(old_uid_t ruid, old_uid_t euid)
  54. {
  55. long ret = sys_setreuid(low2highuid(ruid), low2highuid(euid));
  56. /* avoid REGPARM breakage on x86: */
  57. prevent_tail_call(ret);
  58. return ret;
  59. }
  60. asmlinkage long sys_setuid16(old_uid_t uid)
  61. {
  62. long ret = sys_setuid(low2highuid(uid));
  63. /* avoid REGPARM breakage on x86: */
  64. prevent_tail_call(ret);
  65. return ret;
  66. }
  67. asmlinkage long sys_setresuid16(old_uid_t ruid, old_uid_t euid, old_uid_t suid)
  68. {
  69. long ret = sys_setresuid(low2highuid(ruid), low2highuid(euid),
  70. low2highuid(suid));
  71. /* avoid REGPARM breakage on x86: */
  72. prevent_tail_call(ret);
  73. return ret;
  74. }
  75. asmlinkage long sys_getresuid16(old_uid_t __user *ruid, old_uid_t __user *euid, old_uid_t __user *suid)
  76. {
  77. int retval;
  78. if (!(retval = put_user(high2lowuid(current->uid), ruid)) &&
  79. !(retval = put_user(high2lowuid(current->euid), euid)))
  80. retval = put_user(high2lowuid(current->suid), suid);
  81. return retval;
  82. }
  83. asmlinkage long sys_setresgid16(old_gid_t rgid, old_gid_t egid, old_gid_t sgid)
  84. {
  85. long ret = sys_setresgid(low2highgid(rgid), low2highgid(egid),
  86. low2highgid(sgid));
  87. /* avoid REGPARM breakage on x86: */
  88. prevent_tail_call(ret);
  89. return ret;
  90. }
  91. asmlinkage long sys_getresgid16(old_gid_t __user *rgid, old_gid_t __user *egid, old_gid_t __user *sgid)
  92. {
  93. int retval;
  94. if (!(retval = put_user(high2lowgid(current->gid), rgid)) &&
  95. !(retval = put_user(high2lowgid(current->egid), egid)))
  96. retval = put_user(high2lowgid(current->sgid), sgid);
  97. return retval;
  98. }
  99. asmlinkage long sys_setfsuid16(old_uid_t uid)
  100. {
  101. long ret = sys_setfsuid(low2highuid(uid));
  102. /* avoid REGPARM breakage on x86: */
  103. prevent_tail_call(ret);
  104. return ret;
  105. }
  106. asmlinkage long sys_setfsgid16(old_gid_t gid)
  107. {
  108. long ret = sys_setfsgid(low2highgid(gid));
  109. /* avoid REGPARM breakage on x86: */
  110. prevent_tail_call(ret);
  111. return ret;
  112. }
  113. static int groups16_to_user(old_gid_t __user *grouplist,
  114. struct group_info *group_info)
  115. {
  116. int i;
  117. old_gid_t group;
  118. for (i = 0; i < group_info->ngroups; i++) {
  119. group = high2lowgid(GROUP_AT(group_info, i));
  120. if (put_user(group, grouplist+i))
  121. return -EFAULT;
  122. }
  123. return 0;
  124. }
  125. static int groups16_from_user(struct group_info *group_info,
  126. old_gid_t __user *grouplist)
  127. {
  128. int i;
  129. old_gid_t group;
  130. for (i = 0; i < group_info->ngroups; i++) {
  131. if (get_user(group, grouplist+i))
  132. return -EFAULT;
  133. GROUP_AT(group_info, i) = low2highgid(group);
  134. }
  135. return 0;
  136. }
  137. asmlinkage long sys_getgroups16(int gidsetsize, old_gid_t __user *grouplist)
  138. {
  139. int i = 0;
  140. if (gidsetsize < 0)
  141. return -EINVAL;
  142. get_group_info(current->group_info);
  143. i = current->group_info->ngroups;
  144. if (gidsetsize) {
  145. if (i > gidsetsize) {
  146. i = -EINVAL;
  147. goto out;
  148. }
  149. if (groups16_to_user(grouplist, current->group_info)) {
  150. i = -EFAULT;
  151. goto out;
  152. }
  153. }
  154. out:
  155. put_group_info(current->group_info);
  156. return i;
  157. }
  158. asmlinkage long sys_setgroups16(int gidsetsize, old_gid_t __user *grouplist)
  159. {
  160. struct group_info *group_info;
  161. int retval;
  162. if (!capable(CAP_SETGID))
  163. return -EPERM;
  164. if ((unsigned)gidsetsize > NGROUPS_MAX)
  165. return -EINVAL;
  166. group_info = groups_alloc(gidsetsize);
  167. if (!group_info)
  168. return -ENOMEM;
  169. retval = groups16_from_user(group_info, grouplist);
  170. if (retval) {
  171. put_group_info(group_info);
  172. return retval;
  173. }
  174. retval = set_current_groups(group_info);
  175. put_group_info(group_info);
  176. return retval;
  177. }
  178. asmlinkage long sys_getuid16(void)
  179. {
  180. return high2lowuid(current->uid);
  181. }
  182. asmlinkage long sys_geteuid16(void)
  183. {
  184. return high2lowuid(current->euid);
  185. }
  186. asmlinkage long sys_getgid16(void)
  187. {
  188. return high2lowgid(current->gid);
  189. }
  190. asmlinkage long sys_getegid16(void)
  191. {
  192. return high2lowgid(current->egid);
  193. }