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> |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 19 | #include <linux/nfs4_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/syscalls.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 21 | #include <linux/slab.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 22 | #include <linux/uaccess.h> |
David Howells | 07f3f05c | 2006-09-30 20:52:18 +0200 | [diff] [blame] | 23 | #include "internal.h" |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 24 | |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 25 | struct compat_nfs_string { |
| 26 | compat_uint_t len; |
David Howells | 5fc3e62 | 2005-04-27 15:39:03 -0700 | [diff] [blame] | 27 | compat_uptr_t data; |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | static inline void compat_nfs_string(struct nfs_string *dst, |
| 31 | struct compat_nfs_string *src) |
| 32 | { |
| 33 | dst->data = compat_ptr(src->data); |
| 34 | dst->len = src->len; |
| 35 | } |
| 36 | |
| 37 | struct compat_nfs4_mount_data_v1 { |
| 38 | compat_int_t version; |
| 39 | compat_int_t flags; |
| 40 | compat_int_t rsize; |
| 41 | compat_int_t wsize; |
| 42 | compat_int_t timeo; |
| 43 | compat_int_t retrans; |
| 44 | compat_int_t acregmin; |
| 45 | compat_int_t acregmax; |
| 46 | compat_int_t acdirmin; |
| 47 | compat_int_t acdirmax; |
| 48 | struct compat_nfs_string client_addr; |
| 49 | struct compat_nfs_string mnt_path; |
| 50 | struct compat_nfs_string hostname; |
| 51 | compat_uint_t host_addrlen; |
David Howells | 5fc3e62 | 2005-04-27 15:39:03 -0700 | [diff] [blame] | 52 | compat_uptr_t host_addr; |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 53 | compat_int_t proto; |
| 54 | compat_int_t auth_flavourlen; |
David Howells | 5fc3e62 | 2005-04-27 15:39:03 -0700 | [diff] [blame] | 55 | compat_uptr_t auth_flavours; |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | static int do_nfs4_super_data_conv(void *raw_data) |
| 59 | { |
| 60 | int version = *(compat_uint_t *) raw_data; |
| 61 | |
| 62 | if (version == 1) { |
| 63 | struct compat_nfs4_mount_data_v1 *raw = raw_data; |
| 64 | struct nfs4_mount_data *real = raw_data; |
| 65 | |
| 66 | /* copy the fields backwards */ |
| 67 | real->auth_flavours = compat_ptr(raw->auth_flavours); |
| 68 | real->auth_flavourlen = raw->auth_flavourlen; |
| 69 | real->proto = raw->proto; |
| 70 | real->host_addr = compat_ptr(raw->host_addr); |
| 71 | real->host_addrlen = raw->host_addrlen; |
| 72 | compat_nfs_string(&real->hostname, &raw->hostname); |
| 73 | compat_nfs_string(&real->mnt_path, &raw->mnt_path); |
| 74 | compat_nfs_string(&real->client_addr, &raw->client_addr); |
| 75 | real->acdirmax = raw->acdirmax; |
| 76 | real->acdirmin = raw->acdirmin; |
| 77 | real->acregmax = raw->acregmax; |
| 78 | real->acregmin = raw->acregmin; |
| 79 | real->retrans = raw->retrans; |
| 80 | real->timeo = raw->timeo; |
| 81 | real->wsize = raw->wsize; |
| 82 | real->rsize = raw->rsize; |
| 83 | real->flags = raw->flags; |
| 84 | real->version = raw->version; |
| 85 | } |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 90 | #define NFS4_NAME "nfs4" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Heiko Carstens | 932602e | 2014-03-04 16:07:52 +0100 | [diff] [blame] | 92 | COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name, |
| 93 | const char __user *, dir_name, |
| 94 | const char __user *, type, compat_ulong_t, flags, |
| 95 | const void __user *, data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
Vegard Nossum | eca6f53 | 2009-09-18 13:05:45 -0700 | [diff] [blame] | 97 | char *kernel_type; |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 98 | void *options; |
Vegard Nossum | eca6f53 | 2009-09-18 13:05:45 -0700 | [diff] [blame] | 99 | char *kernel_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | int retval; |
| 101 | |
Tim Gardner | b8850d1 | 2014-08-28 11:26:03 -0600 | [diff] [blame] | 102 | kernel_type = copy_mount_string(type); |
| 103 | retval = PTR_ERR(kernel_type); |
| 104 | if (IS_ERR(kernel_type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | goto out; |
| 106 | |
Tim Gardner | b8850d1 | 2014-08-28 11:26:03 -0600 | [diff] [blame] | 107 | kernel_dev = copy_mount_string(dev_name); |
| 108 | retval = PTR_ERR(kernel_dev); |
| 109 | if (IS_ERR(kernel_dev)) |
Seunghun Lee | 5e6123f | 2014-09-14 22:15:10 +0900 | [diff] [blame] | 110 | goto out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 112 | options = copy_mount_options(data); |
| 113 | retval = PTR_ERR(options); |
| 114 | if (IS_ERR(options)) |
Seunghun Lee | 5e6123f | 2014-09-14 22:15:10 +0900 | [diff] [blame] | 115 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 117 | if (kernel_type && options) { |
Greg Kroah-Hartman | f0ac2ab | 2018-06-01 20:35:10 +0200 | [diff] [blame] | 118 | if (!strcmp(kernel_type, NFS4_NAME)) { |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 119 | retval = -EINVAL; |
| 120 | if (do_nfs4_super_data_conv(options)) |
Seunghun Lee | 5e6123f | 2014-09-14 22:15:10 +0900 | [diff] [blame] | 121 | goto out3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 125 | retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | out3: |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 128 | kfree(options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | out2: |
Seunghun Lee | 5e6123f | 2014-09-14 22:15:10 +0900 | [diff] [blame] | 130 | kfree(kernel_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | out1: |
Vegard Nossum | eca6f53 | 2009-09-18 13:05:45 -0700 | [diff] [blame] | 132 | kfree(kernel_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | out: |
| 134 | return retval; |
| 135 | } |