blob: 190b38b39d9ed74efa5816e437232f86ee7070d4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Macheka2531292010-07-18 14:27:13 +020011 * Copyright (C) 2003 Pavel Machek (pavel@ucw.cz)
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 *
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 Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/compat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/ncp_mount.h>
David Howells9a9947b2005-04-18 10:54:51 -070020#include <linux/nfs4_mount.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/syscalls.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080023#include <linux/uaccess.h>
David Howells07f3f05c2006-09-30 20:52:18 +020024#include "internal.h"
David Woodhouse9f729492006-01-18 17:44:05 -080025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026struct compat_ncp_mount_data {
27 compat_int_t version;
28 compat_uint_t ncp_fd;
Stephen Rothwell202e5972005-09-06 15:16:40 -070029 __compat_uid_t mounted_uid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 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 Rothwell202e5972005-09-06 15:16:40 -070035 __compat_uid_t uid;
36 __compat_gid_t gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
David Howells9a9947b2005-04-18 10:54:51 -070092struct compat_nfs_string {
93 compat_uint_t len;
David Howells5fc3e622005-04-27 15:39:03 -070094 compat_uptr_t data;
David Howells9a9947b2005-04-18 10:54:51 -070095};
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;
David Howells5fc3e622005-04-27 15:39:03 -0700119 compat_uptr_t host_addr;
David Howells9a9947b2005-04-18 10:54:51 -0700120 compat_int_t proto;
121 compat_int_t auth_flavourlen;
David Howells5fc3e622005-04-27 15:39:03 -0700122 compat_uptr_t auth_flavours;
David Howells9a9947b2005-04-18 10:54:51 -0700123};
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 }
David Howells9a9947b2005-04-18 10:54:51 -0700153
154 return 0;
155}
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157#define NCPFS_NAME "ncpfs"
David Howells9a9947b2005-04-18 10:54:51 -0700158#define NFS4_NAME "nfs4"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Heiko Carstens932602e2014-03-04 16:07:52 +0100160COMPAT_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 Torvalds1da177e2005-04-16 15:20:36 -0700164{
Vegard Nossumeca6f532009-09-18 13:05:45 -0700165 char *kernel_type;
Al Virob40ef862015-12-14 18:44:44 -0500166 void *options;
Vegard Nossumeca6f532009-09-18 13:05:45 -0700167 char *kernel_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 int retval;
169
Tim Gardnerb8850d12014-08-28 11:26:03 -0600170 kernel_type = copy_mount_string(type);
171 retval = PTR_ERR(kernel_type);
172 if (IS_ERR(kernel_type))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 goto out;
174
Tim Gardnerb8850d12014-08-28 11:26:03 -0600175 kernel_dev = copy_mount_string(dev_name);
176 retval = PTR_ERR(kernel_dev);
177 if (IS_ERR(kernel_dev))
Seunghun Lee5e6123f2014-09-14 22:15:10 +0900178 goto out1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Al Virob40ef862015-12-14 18:44:44 -0500180 options = copy_mount_options(data);
181 retval = PTR_ERR(options);
182 if (IS_ERR(options))
Seunghun Lee5e6123f2014-09-14 22:15:10 +0900183 goto out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Al Virob40ef862015-12-14 18:44:44 -0500185 if (kernel_type && options) {
Arnd Bergmann2116b7a2010-10-04 22:55:57 +0200186 if (!strcmp(kernel_type, NCPFS_NAME)) {
Al Virob40ef862015-12-14 18:44:44 -0500187 do_ncp_super_data_conv(options);
Vegard Nossumeca6f532009-09-18 13:05:45 -0700188 } else if (!strcmp(kernel_type, NFS4_NAME)) {
Al Virob40ef862015-12-14 18:44:44 -0500189 retval = -EINVAL;
190 if (do_nfs4_super_data_conv(options))
Seunghun Lee5e6123f2014-09-14 22:15:10 +0900191 goto out3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 }
193 }
194
Al Virob40ef862015-12-14 18:44:44 -0500195 retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 out3:
Al Virob40ef862015-12-14 18:44:44 -0500198 kfree(options);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 out2:
Seunghun Lee5e6123f2014-09-14 22:15:10 +0900200 kfree(kernel_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 out1:
Vegard Nossumeca6f532009-09-18 13:05:45 -0700202 kfree(kernel_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 out:
204 return retval;
205}