4 * Kernel compatibililty routines for e.g. 32 bit syscall support
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)
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.
18 #include <linux/stddef.h>
19 #include <linux/kernel.h>
20 #include <linux/linkage.h>
21 #include <linux/compat.h>
22 #include <linux/errno.h>
23 #include <linux/time.h>
24 #include <linux/cred.h>
26 #include <linux/fcntl.h>
27 #include <linux/namei.h>
28 #include <linux/file.h>
29 #include <linux/fdtable.h>
30 #include <linux/vfs.h>
31 #include <linux/ioctl.h>
32 #include <linux/init.h>
33 #include <linux/ncp_mount.h>
34 #include <linux/nfs4_mount.h>
35 #include <linux/syscalls.h>
36 #include <linux/ctype.h>
37 #include <linux/dirent.h>
38 #include <linux/fsnotify.h>
39 #include <linux/highuid.h>
40 #include <linux/personality.h>
41 #include <linux/rwsem.h>
42 #include <linux/tsacct_kern.h>
43 #include <linux/security.h>
44 #include <linux/highmem.h>
45 #include <linux/signal.h>
47 #include <linux/fs_struct.h>
48 #include <linux/slab.h>
49 #include <linux/pagemap.h>
50 #include <linux/aio.h>
52 #include <linux/uaccess.h>
53 #include <asm/mmu_context.h>
54 #include <asm/ioctls.h>
57 /* A write operation does a read from user space and vice versa */
58 #define vrfy_dir(type) ((type) == READ ? VERIFY_WRITE : VERIFY_READ)
60 ssize_t compat_rw_copy_check_uvector(int type,
61 const struct compat_iovec __user *uvector, unsigned long nr_segs,
62 unsigned long fast_segs, struct iovec *fast_pointer,
63 struct iovec **ret_pointer)
65 compat_ssize_t tot_len;
66 struct iovec *iov = *ret_pointer = fast_pointer;
71 * SuS says "The readv() function *may* fail if the iovcnt argument
72 * was less than or equal to 0, or greater than {IOV_MAX}. Linux has
73 * traditionally returned zero for zero segments, so...
79 if (nr_segs > UIO_MAXIOV)
81 if (nr_segs > fast_segs) {
83 iov = kmalloc(nr_segs*sizeof(struct iovec), GFP_KERNEL);
90 if (!access_ok(VERIFY_READ, uvector, nr_segs*sizeof(*uvector)))
94 * Single unix specification:
95 * We should -EINVAL if an element length is not >= 0 and fitting an
98 * In Linux, the total length is limited to MAX_RW_COUNT, there is
99 * no overflow possibility.
103 for (seg = 0; seg < nr_segs; seg++) {
107 if (__get_user(len, &uvector->iov_len) ||
108 __get_user(buf, &uvector->iov_base)) {
112 if (len < 0) /* size_t not fitting in compat_ssize_t .. */
115 !access_ok(vrfy_dir(type), compat_ptr(buf), len)) {
119 if (len > MAX_RW_COUNT - tot_len)
120 len = MAX_RW_COUNT - tot_len;
122 iov->iov_base = compat_ptr(buf);
123 iov->iov_len = (compat_size_t) len;
133 struct compat_ncp_mount_data {
134 compat_int_t version;
135 compat_uint_t ncp_fd;
136 __compat_uid_t mounted_uid;
137 compat_pid_t wdog_pid;
138 unsigned char mounted_vol[NCP_VOLNAME_LEN + 1];
139 compat_uint_t time_out;
140 compat_uint_t retry_count;
144 compat_mode_t file_mode;
145 compat_mode_t dir_mode;
148 struct compat_ncp_mount_data_v4 {
149 compat_int_t version;
150 compat_ulong_t flags;
151 compat_ulong_t mounted_uid;
152 compat_long_t wdog_pid;
153 compat_uint_t ncp_fd;
154 compat_uint_t time_out;
155 compat_uint_t retry_count;
158 compat_ulong_t file_mode;
159 compat_ulong_t dir_mode;
162 static void *do_ncp_super_data_conv(void *raw_data)
164 int version = *(unsigned int *)raw_data;
167 struct compat_ncp_mount_data *c_n = raw_data;
168 struct ncp_mount_data *n = raw_data;
170 n->dir_mode = c_n->dir_mode;
171 n->file_mode = c_n->file_mode;
174 memmove (n->mounted_vol, c_n->mounted_vol, (sizeof (c_n->mounted_vol) + 3 * sizeof (unsigned int)));
175 n->wdog_pid = c_n->wdog_pid;
176 n->mounted_uid = c_n->mounted_uid;
177 } else if (version == 4) {
178 struct compat_ncp_mount_data_v4 *c_n = raw_data;
179 struct ncp_mount_data_v4 *n = raw_data;
181 n->dir_mode = c_n->dir_mode;
182 n->file_mode = c_n->file_mode;
185 n->retry_count = c_n->retry_count;
186 n->time_out = c_n->time_out;
187 n->ncp_fd = c_n->ncp_fd;
188 n->wdog_pid = c_n->wdog_pid;
189 n->mounted_uid = c_n->mounted_uid;
190 n->flags = c_n->flags;
191 } else if (version != 5) {
199 struct compat_nfs_string {
204 static inline void compat_nfs_string(struct nfs_string *dst,
205 struct compat_nfs_string *src)
207 dst->data = compat_ptr(src->data);
211 struct compat_nfs4_mount_data_v1 {
212 compat_int_t version;
217 compat_int_t retrans;
218 compat_int_t acregmin;
219 compat_int_t acregmax;
220 compat_int_t acdirmin;
221 compat_int_t acdirmax;
222 struct compat_nfs_string client_addr;
223 struct compat_nfs_string mnt_path;
224 struct compat_nfs_string hostname;
225 compat_uint_t host_addrlen;
226 compat_uptr_t host_addr;
228 compat_int_t auth_flavourlen;
229 compat_uptr_t auth_flavours;
232 static int do_nfs4_super_data_conv(void *raw_data)
234 int version = *(compat_uint_t *) raw_data;
237 struct compat_nfs4_mount_data_v1 *raw = raw_data;
238 struct nfs4_mount_data *real = raw_data;
240 /* copy the fields backwards */
241 real->auth_flavours = compat_ptr(raw->auth_flavours);
242 real->auth_flavourlen = raw->auth_flavourlen;
243 real->proto = raw->proto;
244 real->host_addr = compat_ptr(raw->host_addr);
245 real->host_addrlen = raw->host_addrlen;
246 compat_nfs_string(&real->hostname, &raw->hostname);
247 compat_nfs_string(&real->mnt_path, &raw->mnt_path);
248 compat_nfs_string(&real->client_addr, &raw->client_addr);
249 real->acdirmax = raw->acdirmax;
250 real->acdirmin = raw->acdirmin;
251 real->acregmax = raw->acregmax;
252 real->acregmin = raw->acregmin;
253 real->retrans = raw->retrans;
254 real->timeo = raw->timeo;
255 real->wsize = raw->wsize;
256 real->rsize = raw->rsize;
257 real->flags = raw->flags;
258 real->version = raw->version;
264 #define NCPFS_NAME "ncpfs"
265 #define NFS4_NAME "nfs4"
267 COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name,
268 const char __user *, dir_name,
269 const char __user *, type, compat_ulong_t, flags,
270 const void __user *, data)
277 kernel_type = copy_mount_string(type);
278 retval = PTR_ERR(kernel_type);
279 if (IS_ERR(kernel_type))
282 kernel_dev = copy_mount_string(dev_name);
283 retval = PTR_ERR(kernel_dev);
284 if (IS_ERR(kernel_dev))
287 options = copy_mount_options(data);
288 retval = PTR_ERR(options);
292 if (kernel_type && options) {
293 if (!strcmp(kernel_type, NCPFS_NAME)) {
294 do_ncp_super_data_conv(options);
295 } else if (!strcmp(kernel_type, NFS4_NAME)) {
297 if (do_nfs4_super_data_conv(options))
302 retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options);
314 #ifdef CONFIG_FHANDLE
316 * Exactly like fs/open.c:sys_open_by_handle_at(), except that it
317 * doesn't set the O_LARGEFILE flag.
319 COMPAT_SYSCALL_DEFINE3(open_by_handle_at, int, mountdirfd,
320 struct file_handle __user *, handle, int, flags)
322 return do_handle_open(mountdirfd, handle, flags);