compat.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. * linux/fs/compat.c
  3. *
  4. * Kernel compatibililty routines for e.g. 32 bit syscall support
  5. * on 64 bit kernels.
  6. *
  7. * Copyright (C) 2002 Stephen Rothwell, IBM Corporation
  8. * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com)
  9. * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
  10. * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs
  11. * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz)
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2 as
  15. * published by the Free Software Foundation.
  16. */
  17. #include <linux/compat.h>
  18. #include <linux/ncp_mount.h>
  19. #include <linux/nfs4_mount.h>
  20. #include <linux/syscalls.h>
  21. #include <linux/slab.h>
  22. #include <linux/uaccess.h>
  23. #include "internal.h"
  24. struct compat_ncp_mount_data {
  25. compat_int_t version;
  26. compat_uint_t ncp_fd;
  27. __compat_uid_t mounted_uid;
  28. compat_pid_t wdog_pid;
  29. unsigned char mounted_vol[NCP_VOLNAME_LEN + 1];
  30. compat_uint_t time_out;
  31. compat_uint_t retry_count;
  32. compat_uint_t flags;
  33. __compat_uid_t uid;
  34. __compat_gid_t gid;
  35. compat_mode_t file_mode;
  36. compat_mode_t dir_mode;
  37. };
  38. struct compat_ncp_mount_data_v4 {
  39. compat_int_t version;
  40. compat_ulong_t flags;
  41. compat_ulong_t mounted_uid;
  42. compat_long_t wdog_pid;
  43. compat_uint_t ncp_fd;
  44. compat_uint_t time_out;
  45. compat_uint_t retry_count;
  46. compat_ulong_t uid;
  47. compat_ulong_t gid;
  48. compat_ulong_t file_mode;
  49. compat_ulong_t dir_mode;
  50. };
  51. static void *do_ncp_super_data_conv(void *raw_data)
  52. {
  53. int version = *(unsigned int *)raw_data;
  54. if (version == 3) {
  55. struct compat_ncp_mount_data *c_n = raw_data;
  56. struct ncp_mount_data *n = raw_data;
  57. n->dir_mode = c_n->dir_mode;
  58. n->file_mode = c_n->file_mode;
  59. n->gid = c_n->gid;
  60. n->uid = c_n->uid;
  61. memmove (n->mounted_vol, c_n->mounted_vol, (sizeof (c_n->mounted_vol) + 3 * sizeof (unsigned int)));
  62. n->wdog_pid = c_n->wdog_pid;
  63. n->mounted_uid = c_n->mounted_uid;
  64. } else if (version == 4) {
  65. struct compat_ncp_mount_data_v4 *c_n = raw_data;
  66. struct ncp_mount_data_v4 *n = raw_data;
  67. n->dir_mode = c_n->dir_mode;
  68. n->file_mode = c_n->file_mode;
  69. n->gid = c_n->gid;
  70. n->uid = c_n->uid;
  71. n->retry_count = c_n->retry_count;
  72. n->time_out = c_n->time_out;
  73. n->ncp_fd = c_n->ncp_fd;
  74. n->wdog_pid = c_n->wdog_pid;
  75. n->mounted_uid = c_n->mounted_uid;
  76. n->flags = c_n->flags;
  77. } else if (version != 5) {
  78. return NULL;
  79. }
  80. return raw_data;
  81. }
  82. struct compat_nfs_string {
  83. compat_uint_t len;
  84. compat_uptr_t data;
  85. };
  86. static inline void compat_nfs_string(struct nfs_string *dst,
  87. struct compat_nfs_string *src)
  88. {
  89. dst->data = compat_ptr(src->data);
  90. dst->len = src->len;
  91. }
  92. struct compat_nfs4_mount_data_v1 {
  93. compat_int_t version;
  94. compat_int_t flags;
  95. compat_int_t rsize;
  96. compat_int_t wsize;
  97. compat_int_t timeo;
  98. compat_int_t retrans;
  99. compat_int_t acregmin;
  100. compat_int_t acregmax;
  101. compat_int_t acdirmin;
  102. compat_int_t acdirmax;
  103. struct compat_nfs_string client_addr;
  104. struct compat_nfs_string mnt_path;
  105. struct compat_nfs_string hostname;
  106. compat_uint_t host_addrlen;
  107. compat_uptr_t host_addr;
  108. compat_int_t proto;
  109. compat_int_t auth_flavourlen;
  110. compat_uptr_t auth_flavours;
  111. };
  112. static int do_nfs4_super_data_conv(void *raw_data)
  113. {
  114. int version = *(compat_uint_t *) raw_data;
  115. if (version == 1) {
  116. struct compat_nfs4_mount_data_v1 *raw = raw_data;
  117. struct nfs4_mount_data *real = raw_data;
  118. /* copy the fields backwards */
  119. real->auth_flavours = compat_ptr(raw->auth_flavours);
  120. real->auth_flavourlen = raw->auth_flavourlen;
  121. real->proto = raw->proto;
  122. real->host_addr = compat_ptr(raw->host_addr);
  123. real->host_addrlen = raw->host_addrlen;
  124. compat_nfs_string(&real->hostname, &raw->hostname);
  125. compat_nfs_string(&real->mnt_path, &raw->mnt_path);
  126. compat_nfs_string(&real->client_addr, &raw->client_addr);
  127. real->acdirmax = raw->acdirmax;
  128. real->acdirmin = raw->acdirmin;
  129. real->acregmax = raw->acregmax;
  130. real->acregmin = raw->acregmin;
  131. real->retrans = raw->retrans;
  132. real->timeo = raw->timeo;
  133. real->wsize = raw->wsize;
  134. real->rsize = raw->rsize;
  135. real->flags = raw->flags;
  136. real->version = raw->version;
  137. }
  138. return 0;
  139. }
  140. #define NCPFS_NAME "ncpfs"
  141. #define NFS4_NAME "nfs4"
  142. COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name,
  143. const char __user *, dir_name,
  144. const char __user *, type, compat_ulong_t, flags,
  145. const void __user *, data)
  146. {
  147. char *kernel_type;
  148. void *options;
  149. char *kernel_dev;
  150. int retval;
  151. kernel_type = copy_mount_string(type);
  152. retval = PTR_ERR(kernel_type);
  153. if (IS_ERR(kernel_type))
  154. goto out;
  155. kernel_dev = copy_mount_string(dev_name);
  156. retval = PTR_ERR(kernel_dev);
  157. if (IS_ERR(kernel_dev))
  158. goto out1;
  159. options = copy_mount_options(data);
  160. retval = PTR_ERR(options);
  161. if (IS_ERR(options))
  162. goto out2;
  163. if (kernel_type && options) {
  164. if (!strcmp(kernel_type, NCPFS_NAME)) {
  165. do_ncp_super_data_conv(options);
  166. } else if (!strcmp(kernel_type, NFS4_NAME)) {
  167. retval = -EINVAL;
  168. if (do_nfs4_super_data_conv(options))
  169. goto out3;
  170. }
  171. }
  172. retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options);
  173. out3:
  174. kfree(options);
  175. out2:
  176. kfree(kernel_dev);
  177. out1:
  178. kfree(kernel_type);
  179. out:
  180. return retval;
  181. }