Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Pavel Machek | a253129 | 2010-07-18 14:27:13 +0200 | [diff] [blame] | 11 | * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/compat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/ncp_mount.h> |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 20 | #include <linux/nfs4_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/syscalls.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 23 | #include <linux/uaccess.h> |
David Howells | 07f3f05c | 2006-09-30 20:52:18 +0200 | [diff] [blame] | 24 | #include "internal.h" |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | struct compat_ncp_mount_data { |
| 27 | compat_int_t version; |
| 28 | compat_uint_t ncp_fd; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 29 | __compat_uid_t mounted_uid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | compat_pid_t wdog_pid; |
| 31 | unsigned char mounted_vol[NCP_VOLNAME_LEN + 1]; |
| 32 | compat_uint_t time_out; |
| 33 | compat_uint_t retry_count; |
| 34 | compat_uint_t flags; |
Stephen Rothwell | 202e597 | 2005-09-06 15:16:40 -0700 | [diff] [blame] | 35 | __compat_uid_t uid; |
| 36 | __compat_gid_t gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | compat_mode_t file_mode; |
| 38 | compat_mode_t dir_mode; |
| 39 | }; |
| 40 | |
| 41 | struct compat_ncp_mount_data_v4 { |
| 42 | compat_int_t version; |
| 43 | compat_ulong_t flags; |
| 44 | compat_ulong_t mounted_uid; |
| 45 | compat_long_t wdog_pid; |
| 46 | compat_uint_t ncp_fd; |
| 47 | compat_uint_t time_out; |
| 48 | compat_uint_t retry_count; |
| 49 | compat_ulong_t uid; |
| 50 | compat_ulong_t gid; |
| 51 | compat_ulong_t file_mode; |
| 52 | compat_ulong_t dir_mode; |
| 53 | }; |
| 54 | |
| 55 | static void *do_ncp_super_data_conv(void *raw_data) |
| 56 | { |
| 57 | int version = *(unsigned int *)raw_data; |
| 58 | |
| 59 | if (version == 3) { |
| 60 | struct compat_ncp_mount_data *c_n = raw_data; |
| 61 | struct ncp_mount_data *n = raw_data; |
| 62 | |
| 63 | n->dir_mode = c_n->dir_mode; |
| 64 | n->file_mode = c_n->file_mode; |
| 65 | n->gid = c_n->gid; |
| 66 | n->uid = c_n->uid; |
| 67 | memmove (n->mounted_vol, c_n->mounted_vol, (sizeof (c_n->mounted_vol) + 3 * sizeof (unsigned int))); |
| 68 | n->wdog_pid = c_n->wdog_pid; |
| 69 | n->mounted_uid = c_n->mounted_uid; |
| 70 | } else if (version == 4) { |
| 71 | struct compat_ncp_mount_data_v4 *c_n = raw_data; |
| 72 | struct ncp_mount_data_v4 *n = raw_data; |
| 73 | |
| 74 | n->dir_mode = c_n->dir_mode; |
| 75 | n->file_mode = c_n->file_mode; |
| 76 | n->gid = c_n->gid; |
| 77 | n->uid = c_n->uid; |
| 78 | n->retry_count = c_n->retry_count; |
| 79 | n->time_out = c_n->time_out; |
| 80 | n->ncp_fd = c_n->ncp_fd; |
| 81 | n->wdog_pid = c_n->wdog_pid; |
| 82 | n->mounted_uid = c_n->mounted_uid; |
| 83 | n->flags = c_n->flags; |
| 84 | } else if (version != 5) { |
| 85 | return NULL; |
| 86 | } |
| 87 | |
| 88 | return raw_data; |
| 89 | } |
| 90 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 92 | struct compat_nfs_string { |
| 93 | compat_uint_t len; |
David Howells | 5fc3e62 | 2005-04-27 15:39:03 -0700 | [diff] [blame] | 94 | compat_uptr_t data; |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | static inline void compat_nfs_string(struct nfs_string *dst, |
| 98 | struct compat_nfs_string *src) |
| 99 | { |
| 100 | dst->data = compat_ptr(src->data); |
| 101 | dst->len = src->len; |
| 102 | } |
| 103 | |
| 104 | struct compat_nfs4_mount_data_v1 { |
| 105 | compat_int_t version; |
| 106 | compat_int_t flags; |
| 107 | compat_int_t rsize; |
| 108 | compat_int_t wsize; |
| 109 | compat_int_t timeo; |
| 110 | compat_int_t retrans; |
| 111 | compat_int_t acregmin; |
| 112 | compat_int_t acregmax; |
| 113 | compat_int_t acdirmin; |
| 114 | compat_int_t acdirmax; |
| 115 | struct compat_nfs_string client_addr; |
| 116 | struct compat_nfs_string mnt_path; |
| 117 | struct compat_nfs_string hostname; |
| 118 | compat_uint_t host_addrlen; |
David Howells | 5fc3e62 | 2005-04-27 15:39:03 -0700 | [diff] [blame] | 119 | compat_uptr_t host_addr; |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 120 | compat_int_t proto; |
| 121 | compat_int_t auth_flavourlen; |
David Howells | 5fc3e62 | 2005-04-27 15:39:03 -0700 | [diff] [blame] | 122 | compat_uptr_t auth_flavours; |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | static int do_nfs4_super_data_conv(void *raw_data) |
| 126 | { |
| 127 | int version = *(compat_uint_t *) raw_data; |
| 128 | |
| 129 | if (version == 1) { |
| 130 | struct compat_nfs4_mount_data_v1 *raw = raw_data; |
| 131 | struct nfs4_mount_data *real = raw_data; |
| 132 | |
| 133 | /* copy the fields backwards */ |
| 134 | real->auth_flavours = compat_ptr(raw->auth_flavours); |
| 135 | real->auth_flavourlen = raw->auth_flavourlen; |
| 136 | real->proto = raw->proto; |
| 137 | real->host_addr = compat_ptr(raw->host_addr); |
| 138 | real->host_addrlen = raw->host_addrlen; |
| 139 | compat_nfs_string(&real->hostname, &raw->hostname); |
| 140 | compat_nfs_string(&real->mnt_path, &raw->mnt_path); |
| 141 | compat_nfs_string(&real->client_addr, &raw->client_addr); |
| 142 | real->acdirmax = raw->acdirmax; |
| 143 | real->acdirmin = raw->acdirmin; |
| 144 | real->acregmax = raw->acregmax; |
| 145 | real->acregmin = raw->acregmin; |
| 146 | real->retrans = raw->retrans; |
| 147 | real->timeo = raw->timeo; |
| 148 | real->wsize = raw->wsize; |
| 149 | real->rsize = raw->rsize; |
| 150 | real->flags = raw->flags; |
| 151 | real->version = raw->version; |
| 152 | } |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 153 | |
| 154 | return 0; |
| 155 | } |
| 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | #define NCPFS_NAME "ncpfs" |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 158 | #define NFS4_NAME "nfs4" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Heiko Carstens | 932602e | 2014-03-04 16:07:52 +0100 | [diff] [blame] | 160 | COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name, |
| 161 | const char __user *, dir_name, |
| 162 | const char __user *, type, compat_ulong_t, flags, |
| 163 | const void __user *, data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | { |
Vegard Nossum | eca6f53 | 2009-09-18 13:05:45 -0700 | [diff] [blame] | 165 | char *kernel_type; |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 166 | void *options; |
Vegard Nossum | eca6f53 | 2009-09-18 13:05:45 -0700 | [diff] [blame] | 167 | char *kernel_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | int retval; |
| 169 | |
Tim Gardner | b8850d1 | 2014-08-28 11:26:03 -0600 | [diff] [blame] | 170 | kernel_type = copy_mount_string(type); |
| 171 | retval = PTR_ERR(kernel_type); |
| 172 | if (IS_ERR(kernel_type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | goto out; |
| 174 | |
Tim Gardner | b8850d1 | 2014-08-28 11:26:03 -0600 | [diff] [blame] | 175 | kernel_dev = copy_mount_string(dev_name); |
| 176 | retval = PTR_ERR(kernel_dev); |
| 177 | if (IS_ERR(kernel_dev)) |
Seunghun Lee | 5e6123f | 2014-09-14 22:15:10 +0900 | [diff] [blame] | 178 | goto out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 180 | options = copy_mount_options(data); |
| 181 | retval = PTR_ERR(options); |
| 182 | if (IS_ERR(options)) |
Seunghun Lee | 5e6123f | 2014-09-14 22:15:10 +0900 | [diff] [blame] | 183 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 185 | if (kernel_type && options) { |
Arnd Bergmann | 2116b7a | 2010-10-04 22:55:57 +0200 | [diff] [blame] | 186 | if (!strcmp(kernel_type, NCPFS_NAME)) { |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 187 | do_ncp_super_data_conv(options); |
Vegard Nossum | eca6f53 | 2009-09-18 13:05:45 -0700 | [diff] [blame] | 188 | } else if (!strcmp(kernel_type, NFS4_NAME)) { |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 189 | retval = -EINVAL; |
| 190 | if (do_nfs4_super_data_conv(options)) |
Seunghun Lee | 5e6123f | 2014-09-14 22:15:10 +0900 | [diff] [blame] | 191 | goto out3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 195 | retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | out3: |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 198 | kfree(options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | out2: |
Seunghun Lee | 5e6123f | 2014-09-14 22:15:10 +0900 | [diff] [blame] | 200 | kfree(kernel_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | out1: |
Vegard Nossum | eca6f53 | 2009-09-18 13:05:45 -0700 | [diff] [blame] | 202 | kfree(kernel_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | out: |
| 204 | return retval; |
| 205 | } |