]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - fs/compat.c
UBUNTU: Ubuntu-4.13.0-45.50
[mirror_ubuntu-artful-kernel.git] / fs / compat.c
CommitLineData
1da177e4
LT
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
a2531293 11 * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz)
1da177e4
LT
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
1da177e4 18#include <linux/compat.h>
1da177e4 19#include <linux/ncp_mount.h>
9a9947bf 20#include <linux/nfs4_mount.h>
1da177e4 21#include <linux/syscalls.h>
5a0e3ad6 22#include <linux/slab.h>
7c0f6ba6 23#include <linux/uaccess.h>
07f3f05c 24#include "internal.h"
9f72949f 25
1da177e4
LT
26struct compat_ncp_mount_data {
27 compat_int_t version;
28 compat_uint_t ncp_fd;
202e5979 29 __compat_uid_t mounted_uid;
1da177e4
LT
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;
202e5979
SR
35 __compat_uid_t uid;
36 __compat_gid_t gid;
1da177e4
LT
37 compat_mode_t file_mode;
38 compat_mode_t dir_mode;
39};
40
41struct 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
55static 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
1da177e4 91
9a9947bf
DH
92struct compat_nfs_string {
93 compat_uint_t len;
5fc3e624 94 compat_uptr_t data;
9a9947bf
DH
95};
96
97static 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
104struct 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;
5fc3e624 119 compat_uptr_t host_addr;
9a9947bf
DH
120 compat_int_t proto;
121 compat_int_t auth_flavourlen;
5fc3e624 122 compat_uptr_t auth_flavours;
9a9947bf
DH
123};
124
125static 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 }
9a9947bf
DH
153
154 return 0;
155}
156
1da177e4 157#define NCPFS_NAME "ncpfs"
9a9947bf 158#define NFS4_NAME "nfs4"
1da177e4 159
932602e2
HC
160COMPAT_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)
1da177e4 164{
eca6f534 165 char *kernel_type;
b40ef869 166 void *options;
eca6f534 167 char *kernel_dev;
1da177e4
LT
168 int retval;
169
b8850d1f
TG
170 kernel_type = copy_mount_string(type);
171 retval = PTR_ERR(kernel_type);
172 if (IS_ERR(kernel_type))
1da177e4
LT
173 goto out;
174
b8850d1f
TG
175 kernel_dev = copy_mount_string(dev_name);
176 retval = PTR_ERR(kernel_dev);
177 if (IS_ERR(kernel_dev))
5e6123f3 178 goto out1;
1da177e4 179
b40ef869
AV
180 options = copy_mount_options(data);
181 retval = PTR_ERR(options);
182 if (IS_ERR(options))
5e6123f3 183 goto out2;
1da177e4 184
b40ef869 185 if (kernel_type && options) {
2116b7a4 186 if (!strcmp(kernel_type, NCPFS_NAME)) {
b40ef869 187 do_ncp_super_data_conv(options);
eca6f534 188 } else if (!strcmp(kernel_type, NFS4_NAME)) {
b40ef869
AV
189 retval = -EINVAL;
190 if (do_nfs4_super_data_conv(options))
5e6123f3 191 goto out3;
1da177e4
LT
192 }
193 }
194
b40ef869 195 retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options);
1da177e4 196
1da177e4 197 out3:
b40ef869 198 kfree(options);
1da177e4 199 out2:
5e6123f3 200 kfree(kernel_dev);
1da177e4 201 out1:
eca6f534 202 kfree(kernel_type);
1da177e4
LT
203 out:
204 return retval;
205}