]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - fs/compat.c
Merge branch 'core-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[mirror_ubuntu-eoan-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>
9a9947bf 19#include <linux/nfs4_mount.h>
1da177e4 20#include <linux/syscalls.h>
5a0e3ad6 21#include <linux/slab.h>
7c0f6ba6 22#include <linux/uaccess.h>
07f3f05c 23#include "internal.h"
9f72949f 24
9a9947bf
DH
25struct compat_nfs_string {
26 compat_uint_t len;
5fc3e624 27 compat_uptr_t data;
9a9947bf
DH
28};
29
30static 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
37struct 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;
5fc3e624 52 compat_uptr_t host_addr;
9a9947bf
DH
53 compat_int_t proto;
54 compat_int_t auth_flavourlen;
5fc3e624 55 compat_uptr_t auth_flavours;
9a9947bf
DH
56};
57
58static 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 }
9a9947bf
DH
86
87 return 0;
88}
89
9a9947bf 90#define NFS4_NAME "nfs4"
1da177e4 91
932602e2
HC
92COMPAT_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)
1da177e4 96{
eca6f534 97 char *kernel_type;
b40ef869 98 void *options;
eca6f534 99 char *kernel_dev;
1da177e4
LT
100 int retval;
101
b8850d1f
TG
102 kernel_type = copy_mount_string(type);
103 retval = PTR_ERR(kernel_type);
104 if (IS_ERR(kernel_type))
1da177e4
LT
105 goto out;
106
b8850d1f
TG
107 kernel_dev = copy_mount_string(dev_name);
108 retval = PTR_ERR(kernel_dev);
109 if (IS_ERR(kernel_dev))
5e6123f3 110 goto out1;
1da177e4 111
b40ef869
AV
112 options = copy_mount_options(data);
113 retval = PTR_ERR(options);
114 if (IS_ERR(options))
5e6123f3 115 goto out2;
1da177e4 116
b40ef869 117 if (kernel_type && options) {
f0ac2abc 118 if (!strcmp(kernel_type, NFS4_NAME)) {
b40ef869
AV
119 retval = -EINVAL;
120 if (do_nfs4_super_data_conv(options))
5e6123f3 121 goto out3;
1da177e4
LT
122 }
123 }
124
b40ef869 125 retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options);
1da177e4 126
1da177e4 127 out3:
b40ef869 128 kfree(options);
1da177e4 129 out2:
5e6123f3 130 kfree(kernel_dev);
1da177e4 131 out1:
eca6f534 132 kfree(kernel_type);
1da177e4
LT
133 out:
134 return retval;
135}