compat.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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/nfs4_mount.h>
  19. #include <linux/syscalls.h>
  20. #include <linux/slab.h>
  21. #include <linux/uaccess.h>
  22. #include "internal.h"
  23. struct compat_nfs_string {
  24. compat_uint_t len;
  25. compat_uptr_t data;
  26. };
  27. static inline void compat_nfs_string(struct nfs_string *dst,
  28. struct compat_nfs_string *src)
  29. {
  30. dst->data = compat_ptr(src->data);
  31. dst->len = src->len;
  32. }
  33. struct compat_nfs4_mount_data_v1 {
  34. compat_int_t version;
  35. compat_int_t flags;
  36. compat_int_t rsize;
  37. compat_int_t wsize;
  38. compat_int_t timeo;
  39. compat_int_t retrans;
  40. compat_int_t acregmin;
  41. compat_int_t acregmax;
  42. compat_int_t acdirmin;
  43. compat_int_t acdirmax;
  44. struct compat_nfs_string client_addr;
  45. struct compat_nfs_string mnt_path;
  46. struct compat_nfs_string hostname;
  47. compat_uint_t host_addrlen;
  48. compat_uptr_t host_addr;
  49. compat_int_t proto;
  50. compat_int_t auth_flavourlen;
  51. compat_uptr_t auth_flavours;
  52. };
  53. static int do_nfs4_super_data_conv(void *raw_data)
  54. {
  55. int version = *(compat_uint_t *) raw_data;
  56. if (version == 1) {
  57. struct compat_nfs4_mount_data_v1 *raw = raw_data;
  58. struct nfs4_mount_data *real = raw_data;
  59. /* copy the fields backwards */
  60. real->auth_flavours = compat_ptr(raw->auth_flavours);
  61. real->auth_flavourlen = raw->auth_flavourlen;
  62. real->proto = raw->proto;
  63. real->host_addr = compat_ptr(raw->host_addr);
  64. real->host_addrlen = raw->host_addrlen;
  65. compat_nfs_string(&real->hostname, &raw->hostname);
  66. compat_nfs_string(&real->mnt_path, &raw->mnt_path);
  67. compat_nfs_string(&real->client_addr, &raw->client_addr);
  68. real->acdirmax = raw->acdirmax;
  69. real->acdirmin = raw->acdirmin;
  70. real->acregmax = raw->acregmax;
  71. real->acregmin = raw->acregmin;
  72. real->retrans = raw->retrans;
  73. real->timeo = raw->timeo;
  74. real->wsize = raw->wsize;
  75. real->rsize = raw->rsize;
  76. real->flags = raw->flags;
  77. real->version = raw->version;
  78. }
  79. return 0;
  80. }
  81. #define NFS4_NAME "nfs4"
  82. COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name,
  83. const char __user *, dir_name,
  84. const char __user *, type, compat_ulong_t, flags,
  85. const void __user *, data)
  86. {
  87. char *kernel_type;
  88. void *options;
  89. char *kernel_dev;
  90. int retval;
  91. kernel_type = copy_mount_string(type);
  92. retval = PTR_ERR(kernel_type);
  93. if (IS_ERR(kernel_type))
  94. goto out;
  95. kernel_dev = copy_mount_string(dev_name);
  96. retval = PTR_ERR(kernel_dev);
  97. if (IS_ERR(kernel_dev))
  98. goto out1;
  99. options = copy_mount_options(data);
  100. retval = PTR_ERR(options);
  101. if (IS_ERR(options))
  102. goto out2;
  103. if (kernel_type && options) {
  104. if (!strcmp(kernel_type, NFS4_NAME)) {
  105. retval = -EINVAL;
  106. if (do_nfs4_super_data_conv(options))
  107. goto out3;
  108. }
  109. }
  110. retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options);
  111. out3:
  112. kfree(options);
  113. out2:
  114. kfree(kernel_dev);
  115. out1:
  116. kfree(kernel_type);
  117. out:
  118. return retval;
  119. }