Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/compat.c |
| 4 | * |
| 5 | * Kernel compatibililty routines for e.g. 32 bit syscall support |
| 6 | * on 64 bit kernels. |
| 7 | * |
| 8 | * Copyright (C) 2002 Stephen Rothwell, IBM Corporation |
| 9 | * Copyright (C) 1997-2000 Jakub Jelinek (jakub@redhat.com) |
| 10 | * Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be) |
| 11 | * Copyright (C) 2001,2002 Andi Kleen, SuSE Labs |
Pavel Machek | a253129 | 2010-07-18 14:27:13 +0200 | [diff] [blame] | 12 | * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/compat.h> |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 16 | #include <linux/nfs4_mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/syscalls.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 19 | #include <linux/uaccess.h> |
David Howells | 07f3f05 | 2006-09-30 20:52:18 +0200 | [diff] [blame] | 20 | #include "internal.h" |
David Woodhouse | 9f72949 | 2006-01-18 17:44:05 -0800 | [diff] [blame] | 21 | |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 22 | struct compat_nfs_string { |
| 23 | compat_uint_t len; |
David Howells | 5fc3e62 | 2005-04-27 15:39:03 -0700 | [diff] [blame] | 24 | compat_uptr_t data; |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 25 | }; |
| 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 | |
| 34 | struct compat_nfs4_mount_data_v1 { |
| 35 | compat_int_t version; |
| 36 | compat_int_t flags; |
| 37 | compat_int_t rsize; |
| 38 | compat_int_t wsize; |
| 39 | compat_int_t timeo; |
| 40 | compat_int_t retrans; |
| 41 | compat_int_t acregmin; |
| 42 | compat_int_t acregmax; |
| 43 | compat_int_t acdirmin; |
| 44 | compat_int_t acdirmax; |
| 45 | struct compat_nfs_string client_addr; |
| 46 | struct compat_nfs_string mnt_path; |
| 47 | struct compat_nfs_string hostname; |
| 48 | compat_uint_t host_addrlen; |
David Howells | 5fc3e62 | 2005-04-27 15:39:03 -0700 | [diff] [blame] | 49 | compat_uptr_t host_addr; |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 50 | compat_int_t proto; |
| 51 | compat_int_t auth_flavourlen; |
David Howells | 5fc3e62 | 2005-04-27 15:39:03 -0700 | [diff] [blame] | 52 | compat_uptr_t auth_flavours; |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | static int do_nfs4_super_data_conv(void *raw_data) |
| 56 | { |
| 57 | int version = *(compat_uint_t *) raw_data; |
| 58 | |
| 59 | if (version == 1) { |
| 60 | struct compat_nfs4_mount_data_v1 *raw = raw_data; |
| 61 | struct nfs4_mount_data *real = raw_data; |
| 62 | |
| 63 | /* copy the fields backwards */ |
| 64 | real->auth_flavours = compat_ptr(raw->auth_flavours); |
| 65 | real->auth_flavourlen = raw->auth_flavourlen; |
| 66 | real->proto = raw->proto; |
| 67 | real->host_addr = compat_ptr(raw->host_addr); |
| 68 | real->host_addrlen = raw->host_addrlen; |
| 69 | compat_nfs_string(&real->hostname, &raw->hostname); |
| 70 | compat_nfs_string(&real->mnt_path, &raw->mnt_path); |
| 71 | compat_nfs_string(&real->client_addr, &raw->client_addr); |
| 72 | real->acdirmax = raw->acdirmax; |
| 73 | real->acdirmin = raw->acdirmin; |
| 74 | real->acregmax = raw->acregmax; |
| 75 | real->acregmin = raw->acregmin; |
| 76 | real->retrans = raw->retrans; |
| 77 | real->timeo = raw->timeo; |
| 78 | real->wsize = raw->wsize; |
| 79 | real->rsize = raw->rsize; |
| 80 | real->flags = raw->flags; |
| 81 | real->version = raw->version; |
| 82 | } |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |
David Howells | 9a9947b | 2005-04-18 10:54:51 -0700 | [diff] [blame] | 87 | #define NFS4_NAME "nfs4" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Heiko Carstens | 932602e | 2014-03-04 16:07:52 +0100 | [diff] [blame] | 89 | COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name, |
| 90 | const char __user *, dir_name, |
| 91 | const char __user *, type, compat_ulong_t, flags, |
| 92 | const void __user *, data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
Vegard Nossum | eca6f53 | 2009-09-18 13:05:45 -0700 | [diff] [blame] | 94 | char *kernel_type; |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 95 | void *options; |
Vegard Nossum | eca6f53 | 2009-09-18 13:05:45 -0700 | [diff] [blame] | 96 | char *kernel_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | int retval; |
| 98 | |
Tim Gardner | b8850d1 | 2014-08-28 11:26:03 -0600 | [diff] [blame] | 99 | kernel_type = copy_mount_string(type); |
| 100 | retval = PTR_ERR(kernel_type); |
| 101 | if (IS_ERR(kernel_type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | goto out; |
| 103 | |
Tim Gardner | b8850d1 | 2014-08-28 11:26:03 -0600 | [diff] [blame] | 104 | kernel_dev = copy_mount_string(dev_name); |
| 105 | retval = PTR_ERR(kernel_dev); |
| 106 | if (IS_ERR(kernel_dev)) |
Seunghun Lee | 5e6123f | 2014-09-14 22:15:10 +0900 | [diff] [blame] | 107 | goto out1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 109 | options = copy_mount_options(data); |
| 110 | retval = PTR_ERR(options); |
| 111 | if (IS_ERR(options)) |
Seunghun Lee | 5e6123f | 2014-09-14 22:15:10 +0900 | [diff] [blame] | 112 | goto out2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 114 | if (kernel_type && options) { |
Greg Kroah-Hartman | f0ac2ab | 2018-06-01 20:35:10 +0200 | [diff] [blame] | 115 | if (!strcmp(kernel_type, NFS4_NAME)) { |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 116 | retval = -EINVAL; |
| 117 | if (do_nfs4_super_data_conv(options)) |
Seunghun Lee | 5e6123f | 2014-09-14 22:15:10 +0900 | [diff] [blame] | 118 | goto out3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 122 | retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | out3: |
Al Viro | b40ef86 | 2015-12-14 18:44:44 -0500 | [diff] [blame] | 125 | kfree(options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | out2: |
Seunghun Lee | 5e6123f | 2014-09-14 22:15:10 +0900 | [diff] [blame] | 127 | kfree(kernel_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | out1: |
Vegard Nossum | eca6f53 | 2009-09-18 13:05:45 -0700 | [diff] [blame] | 129 | kfree(kernel_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | out: |
| 131 | return retval; |
| 132 | } |