Blame view

fs/compat.c 3.21 KB
d2912cb15   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
  /*
   *  linux/fs/compat.c
   *
   *  Kernel compatibililty routines for e.g. 32 bit syscall support
   *  on 64 bit kernels.
   *
   *  Copyright (C) 2002       Stephen Rothwell, IBM Corporation
   *  Copyright (C) 1997-2000  Jakub Jelinek  (jakub@redhat.com)
   *  Copyright (C) 1998       Eddie C. Dost  (ecd@skynet.be)
   *  Copyright (C) 2001,2002  Andi Kleen, SuSE Labs 
a2531293d   Pavel Machek   update email address
12
   *  Copyright (C) 2003       Pavel Machek (pavel@ucw.cz)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14
  #include <linux/compat.h>
9a9947bf7   David Howells   [PATCH] Add 32-bi...
15
  #include <linux/nfs4_mount.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
  #include <linux/syscalls.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
17
  #include <linux/slab.h>
7c0f6ba68   Linus Torvalds   Replace <asm/uacc...
18
  #include <linux/uaccess.h>
07f3f05c1   David Howells   [PATCH] BLOCK: Mo...
19
  #include "internal.h"
9f72949f6   David Woodhouse   [PATCH] Add psele...
20

9a9947bf7   David Howells   [PATCH] Add 32-bi...
21
22
  struct compat_nfs_string {
  	compat_uint_t len;
5fc3e624a   David Howells   [PATCH] NFS4: Don...
23
  	compat_uptr_t data;
9a9947bf7   David Howells   [PATCH] Add 32-bi...
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  };
  
  static inline void compat_nfs_string(struct nfs_string *dst,
  				     struct compat_nfs_string *src)
  {
  	dst->data = compat_ptr(src->data);
  	dst->len = src->len;
  }
  
  struct compat_nfs4_mount_data_v1 {
  	compat_int_t version;
  	compat_int_t flags;
  	compat_int_t rsize;
  	compat_int_t wsize;
  	compat_int_t timeo;
  	compat_int_t retrans;
  	compat_int_t acregmin;
  	compat_int_t acregmax;
  	compat_int_t acdirmin;
  	compat_int_t acdirmax;
  	struct compat_nfs_string client_addr;
  	struct compat_nfs_string mnt_path;
  	struct compat_nfs_string hostname;
  	compat_uint_t host_addrlen;
5fc3e624a   David Howells   [PATCH] NFS4: Don...
48
  	compat_uptr_t host_addr;
9a9947bf7   David Howells   [PATCH] Add 32-bi...
49
50
  	compat_int_t proto;
  	compat_int_t auth_flavourlen;
5fc3e624a   David Howells   [PATCH] NFS4: Don...
51
  	compat_uptr_t auth_flavours;
9a9947bf7   David Howells   [PATCH] Add 32-bi...
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  };
  
  static int do_nfs4_super_data_conv(void *raw_data)
  {
  	int version = *(compat_uint_t *) raw_data;
  
  	if (version == 1) {
  		struct compat_nfs4_mount_data_v1 *raw = raw_data;
  		struct nfs4_mount_data *real = raw_data;
  
  		/* copy the fields backwards */
  		real->auth_flavours = compat_ptr(raw->auth_flavours);
  		real->auth_flavourlen = raw->auth_flavourlen;
  		real->proto = raw->proto;
  		real->host_addr = compat_ptr(raw->host_addr);
  		real->host_addrlen = raw->host_addrlen;
  		compat_nfs_string(&real->hostname, &raw->hostname);
  		compat_nfs_string(&real->mnt_path, &raw->mnt_path);
  		compat_nfs_string(&real->client_addr, &raw->client_addr);
  		real->acdirmax = raw->acdirmax;
  		real->acdirmin = raw->acdirmin;
  		real->acregmax = raw->acregmax;
  		real->acregmin = raw->acregmin;
  		real->retrans = raw->retrans;
  		real->timeo = raw->timeo;
  		real->wsize = raw->wsize;
  		real->rsize = raw->rsize;
  		real->flags = raw->flags;
  		real->version = raw->version;
  	}
9a9947bf7   David Howells   [PATCH] Add 32-bi...
82
83
84
  
  	return 0;
  }
9a9947bf7   David Howells   [PATCH] Add 32-bi...
85
  #define NFS4_NAME	"nfs4"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86

932602e23   Heiko Carstens   fs/compat: conver...
87
88
89
90
  COMPAT_SYSCALL_DEFINE5(mount, const char __user *, dev_name,
  		       const char __user *, dir_name,
  		       const char __user *, type, compat_ulong_t, flags,
  		       const void __user *, data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91
  {
eca6f534e   Vegard Nossum   fs: fix overflow ...
92
  	char *kernel_type;
b40ef8696   Al Viro   saner calling con...
93
  	void *options;
eca6f534e   Vegard Nossum   fs: fix overflow ...
94
  	char *kernel_dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95
  	int retval;
b8850d1fa   Tim Gardner   fs: namespace: su...
96
97
98
  	kernel_type = copy_mount_string(type);
  	retval = PTR_ERR(kernel_type);
  	if (IS_ERR(kernel_type))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99
  		goto out;
b8850d1fa   Tim Gardner   fs: namespace: su...
100
101
102
  	kernel_dev = copy_mount_string(dev_name);
  	retval = PTR_ERR(kernel_dev);
  	if (IS_ERR(kernel_dev))
5e6123f34   Seunghun Lee   vfs: move getname...
103
  		goto out1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104

b40ef8696   Al Viro   saner calling con...
105
106
107
  	options = copy_mount_options(data);
  	retval = PTR_ERR(options);
  	if (IS_ERR(options))
5e6123f34   Seunghun Lee   vfs: move getname...
108
  		goto out2;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109

b40ef8696   Al Viro   saner calling con...
110
  	if (kernel_type && options) {
f0ac2abcc   Greg Kroah-Hartman   ncpfs: remove com...
111
  		if (!strcmp(kernel_type, NFS4_NAME)) {
b40ef8696   Al Viro   saner calling con...
112
113
  			retval = -EINVAL;
  			if (do_nfs4_super_data_conv(options))
5e6123f34   Seunghun Lee   vfs: move getname...
114
  				goto out3;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
116
  		}
  	}
b40ef8696   Al Viro   saner calling con...
117
  	retval = do_mount(kernel_dev, dir_name, kernel_type, flags, options);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
   out3:
b40ef8696   Al Viro   saner calling con...
120
  	kfree(options);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
   out2:
5e6123f34   Seunghun Lee   vfs: move getname...
122
  	kfree(kernel_dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
   out1:
eca6f534e   Vegard Nossum   fs: fix overflow ...
124
  	kfree(kernel_type);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
126
127
   out:
  	return retval;
  }