Commit a9482ebcdedbc5872ed34a266e6a45c35116f264
Committed by
Al Viro
1 parent
0e639bdeef
Exists in
master
and in
7 other branches
ncpfs: use memdup_user()
Remove open-coded memdup_user() Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Showing 1 changed file with 7 additions and 14 deletions Inline Diff
fs/ncpfs/ioctl.c
1 | /* | 1 | /* |
2 | * ioctl.c | 2 | * ioctl.c |
3 | * | 3 | * |
4 | * Copyright (C) 1995, 1996 by Volker Lendecke | 4 | * Copyright (C) 1995, 1996 by Volker Lendecke |
5 | * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache | 5 | * Modified 1997 Peter Waltenberg, Bill Hawes, David Woodhouse for 2.1 dcache |
6 | * Modified 1998, 1999 Wolfram Pienkoss for NLS | 6 | * Modified 1998, 1999 Wolfram Pienkoss for NLS |
7 | * | 7 | * |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <linux/capability.h> | 10 | #include <linux/capability.h> |
11 | #include <linux/compat.h> | 11 | #include <linux/compat.h> |
12 | #include <linux/errno.h> | 12 | #include <linux/errno.h> |
13 | #include <linux/fs.h> | 13 | #include <linux/fs.h> |
14 | #include <linux/ioctl.h> | 14 | #include <linux/ioctl.h> |
15 | #include <linux/time.h> | 15 | #include <linux/time.h> |
16 | #include <linux/mm.h> | 16 | #include <linux/mm.h> |
17 | #include <linux/mount.h> | 17 | #include <linux/mount.h> |
18 | #include <linux/highuid.h> | 18 | #include <linux/highuid.h> |
19 | #include <linux/smp_lock.h> | 19 | #include <linux/smp_lock.h> |
20 | #include <linux/vmalloc.h> | 20 | #include <linux/vmalloc.h> |
21 | #include <linux/sched.h> | 21 | #include <linux/sched.h> |
22 | 22 | ||
23 | #include <linux/ncp_fs.h> | 23 | #include <linux/ncp_fs.h> |
24 | 24 | ||
25 | #include <asm/uaccess.h> | 25 | #include <asm/uaccess.h> |
26 | 26 | ||
27 | #include "ncplib_kernel.h" | 27 | #include "ncplib_kernel.h" |
28 | 28 | ||
29 | /* maximum limit for ncp_objectname_ioctl */ | 29 | /* maximum limit for ncp_objectname_ioctl */ |
30 | #define NCP_OBJECT_NAME_MAX_LEN 4096 | 30 | #define NCP_OBJECT_NAME_MAX_LEN 4096 |
31 | /* maximum limit for ncp_privatedata_ioctl */ | 31 | /* maximum limit for ncp_privatedata_ioctl */ |
32 | #define NCP_PRIVATE_DATA_MAX_LEN 8192 | 32 | #define NCP_PRIVATE_DATA_MAX_LEN 8192 |
33 | /* maximum negotiable packet size */ | 33 | /* maximum negotiable packet size */ |
34 | #define NCP_PACKET_SIZE_INTERNAL 65536 | 34 | #define NCP_PACKET_SIZE_INTERNAL 65536 |
35 | 35 | ||
36 | static int | 36 | static int |
37 | ncp_get_fs_info(struct ncp_server * server, struct file *file, | 37 | ncp_get_fs_info(struct ncp_server * server, struct file *file, |
38 | struct ncp_fs_info __user *arg) | 38 | struct ncp_fs_info __user *arg) |
39 | { | 39 | { |
40 | struct inode *inode = file->f_path.dentry->d_inode; | 40 | struct inode *inode = file->f_path.dentry->d_inode; |
41 | struct ncp_fs_info info; | 41 | struct ncp_fs_info info; |
42 | 42 | ||
43 | if (file_permission(file, MAY_WRITE) != 0 | 43 | if (file_permission(file, MAY_WRITE) != 0 |
44 | && current_uid() != server->m.mounted_uid) | 44 | && current_uid() != server->m.mounted_uid) |
45 | return -EACCES; | 45 | return -EACCES; |
46 | 46 | ||
47 | if (copy_from_user(&info, arg, sizeof(info))) | 47 | if (copy_from_user(&info, arg, sizeof(info))) |
48 | return -EFAULT; | 48 | return -EFAULT; |
49 | 49 | ||
50 | if (info.version != NCP_GET_FS_INFO_VERSION) { | 50 | if (info.version != NCP_GET_FS_INFO_VERSION) { |
51 | DPRINTK("info.version invalid: %d\n", info.version); | 51 | DPRINTK("info.version invalid: %d\n", info.version); |
52 | return -EINVAL; | 52 | return -EINVAL; |
53 | } | 53 | } |
54 | /* TODO: info.addr = server->m.serv_addr; */ | 54 | /* TODO: info.addr = server->m.serv_addr; */ |
55 | SET_UID(info.mounted_uid, server->m.mounted_uid); | 55 | SET_UID(info.mounted_uid, server->m.mounted_uid); |
56 | info.connection = server->connection; | 56 | info.connection = server->connection; |
57 | info.buffer_size = server->buffer_size; | 57 | info.buffer_size = server->buffer_size; |
58 | info.volume_number = NCP_FINFO(inode)->volNumber; | 58 | info.volume_number = NCP_FINFO(inode)->volNumber; |
59 | info.directory_id = NCP_FINFO(inode)->DosDirNum; | 59 | info.directory_id = NCP_FINFO(inode)->DosDirNum; |
60 | 60 | ||
61 | if (copy_to_user(arg, &info, sizeof(info))) | 61 | if (copy_to_user(arg, &info, sizeof(info))) |
62 | return -EFAULT; | 62 | return -EFAULT; |
63 | return 0; | 63 | return 0; |
64 | } | 64 | } |
65 | 65 | ||
66 | static int | 66 | static int |
67 | ncp_get_fs_info_v2(struct ncp_server * server, struct file *file, | 67 | ncp_get_fs_info_v2(struct ncp_server * server, struct file *file, |
68 | struct ncp_fs_info_v2 __user * arg) | 68 | struct ncp_fs_info_v2 __user * arg) |
69 | { | 69 | { |
70 | struct inode *inode = file->f_path.dentry->d_inode; | 70 | struct inode *inode = file->f_path.dentry->d_inode; |
71 | struct ncp_fs_info_v2 info2; | 71 | struct ncp_fs_info_v2 info2; |
72 | 72 | ||
73 | if (file_permission(file, MAY_WRITE) != 0 | 73 | if (file_permission(file, MAY_WRITE) != 0 |
74 | && current_uid() != server->m.mounted_uid) | 74 | && current_uid() != server->m.mounted_uid) |
75 | return -EACCES; | 75 | return -EACCES; |
76 | 76 | ||
77 | if (copy_from_user(&info2, arg, sizeof(info2))) | 77 | if (copy_from_user(&info2, arg, sizeof(info2))) |
78 | return -EFAULT; | 78 | return -EFAULT; |
79 | 79 | ||
80 | if (info2.version != NCP_GET_FS_INFO_VERSION_V2) { | 80 | if (info2.version != NCP_GET_FS_INFO_VERSION_V2) { |
81 | DPRINTK("info.version invalid: %d\n", info2.version); | 81 | DPRINTK("info.version invalid: %d\n", info2.version); |
82 | return -EINVAL; | 82 | return -EINVAL; |
83 | } | 83 | } |
84 | info2.mounted_uid = server->m.mounted_uid; | 84 | info2.mounted_uid = server->m.mounted_uid; |
85 | info2.connection = server->connection; | 85 | info2.connection = server->connection; |
86 | info2.buffer_size = server->buffer_size; | 86 | info2.buffer_size = server->buffer_size; |
87 | info2.volume_number = NCP_FINFO(inode)->volNumber; | 87 | info2.volume_number = NCP_FINFO(inode)->volNumber; |
88 | info2.directory_id = NCP_FINFO(inode)->DosDirNum; | 88 | info2.directory_id = NCP_FINFO(inode)->DosDirNum; |
89 | info2.dummy1 = info2.dummy2 = info2.dummy3 = 0; | 89 | info2.dummy1 = info2.dummy2 = info2.dummy3 = 0; |
90 | 90 | ||
91 | if (copy_to_user(arg, &info2, sizeof(info2))) | 91 | if (copy_to_user(arg, &info2, sizeof(info2))) |
92 | return -EFAULT; | 92 | return -EFAULT; |
93 | return 0; | 93 | return 0; |
94 | } | 94 | } |
95 | 95 | ||
96 | #ifdef CONFIG_COMPAT | 96 | #ifdef CONFIG_COMPAT |
97 | struct compat_ncp_objectname_ioctl | 97 | struct compat_ncp_objectname_ioctl |
98 | { | 98 | { |
99 | s32 auth_type; | 99 | s32 auth_type; |
100 | u32 object_name_len; | 100 | u32 object_name_len; |
101 | compat_caddr_t object_name; /* a userspace data, in most cases user name */ | 101 | compat_caddr_t object_name; /* a userspace data, in most cases user name */ |
102 | }; | 102 | }; |
103 | 103 | ||
104 | struct compat_ncp_fs_info_v2 { | 104 | struct compat_ncp_fs_info_v2 { |
105 | s32 version; | 105 | s32 version; |
106 | u32 mounted_uid; | 106 | u32 mounted_uid; |
107 | u32 connection; | 107 | u32 connection; |
108 | u32 buffer_size; | 108 | u32 buffer_size; |
109 | 109 | ||
110 | u32 volume_number; | 110 | u32 volume_number; |
111 | u32 directory_id; | 111 | u32 directory_id; |
112 | 112 | ||
113 | u32 dummy1; | 113 | u32 dummy1; |
114 | u32 dummy2; | 114 | u32 dummy2; |
115 | u32 dummy3; | 115 | u32 dummy3; |
116 | }; | 116 | }; |
117 | 117 | ||
118 | struct compat_ncp_ioctl_request { | 118 | struct compat_ncp_ioctl_request { |
119 | u32 function; | 119 | u32 function; |
120 | u32 size; | 120 | u32 size; |
121 | compat_caddr_t data; | 121 | compat_caddr_t data; |
122 | }; | 122 | }; |
123 | 123 | ||
124 | struct compat_ncp_privatedata_ioctl | 124 | struct compat_ncp_privatedata_ioctl |
125 | { | 125 | { |
126 | u32 len; | 126 | u32 len; |
127 | compat_caddr_t data; /* ~1000 for NDS */ | 127 | compat_caddr_t data; /* ~1000 for NDS */ |
128 | }; | 128 | }; |
129 | 129 | ||
130 | #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct compat_ncp_fs_info_v2) | 130 | #define NCP_IOC_GET_FS_INFO_V2_32 _IOWR('n', 4, struct compat_ncp_fs_info_v2) |
131 | #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct compat_ncp_ioctl_request) | 131 | #define NCP_IOC_NCPREQUEST_32 _IOR('n', 1, struct compat_ncp_ioctl_request) |
132 | #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct compat_ncp_objectname_ioctl) | 132 | #define NCP_IOC_GETOBJECTNAME_32 _IOWR('n', 9, struct compat_ncp_objectname_ioctl) |
133 | #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct compat_ncp_objectname_ioctl) | 133 | #define NCP_IOC_SETOBJECTNAME_32 _IOR('n', 9, struct compat_ncp_objectname_ioctl) |
134 | #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct compat_ncp_privatedata_ioctl) | 134 | #define NCP_IOC_GETPRIVATEDATA_32 _IOWR('n', 10, struct compat_ncp_privatedata_ioctl) |
135 | #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct compat_ncp_privatedata_ioctl) | 135 | #define NCP_IOC_SETPRIVATEDATA_32 _IOR('n', 10, struct compat_ncp_privatedata_ioctl) |
136 | 136 | ||
137 | static int | 137 | static int |
138 | ncp_get_compat_fs_info_v2(struct ncp_server * server, struct file *file, | 138 | ncp_get_compat_fs_info_v2(struct ncp_server * server, struct file *file, |
139 | struct compat_ncp_fs_info_v2 __user * arg) | 139 | struct compat_ncp_fs_info_v2 __user * arg) |
140 | { | 140 | { |
141 | struct inode *inode = file->f_path.dentry->d_inode; | 141 | struct inode *inode = file->f_path.dentry->d_inode; |
142 | struct compat_ncp_fs_info_v2 info2; | 142 | struct compat_ncp_fs_info_v2 info2; |
143 | 143 | ||
144 | if (file_permission(file, MAY_WRITE) != 0 | 144 | if (file_permission(file, MAY_WRITE) != 0 |
145 | && current_uid() != server->m.mounted_uid) | 145 | && current_uid() != server->m.mounted_uid) |
146 | return -EACCES; | 146 | return -EACCES; |
147 | 147 | ||
148 | if (copy_from_user(&info2, arg, sizeof(info2))) | 148 | if (copy_from_user(&info2, arg, sizeof(info2))) |
149 | return -EFAULT; | 149 | return -EFAULT; |
150 | 150 | ||
151 | if (info2.version != NCP_GET_FS_INFO_VERSION_V2) { | 151 | if (info2.version != NCP_GET_FS_INFO_VERSION_V2) { |
152 | DPRINTK("info.version invalid: %d\n", info2.version); | 152 | DPRINTK("info.version invalid: %d\n", info2.version); |
153 | return -EINVAL; | 153 | return -EINVAL; |
154 | } | 154 | } |
155 | info2.mounted_uid = server->m.mounted_uid; | 155 | info2.mounted_uid = server->m.mounted_uid; |
156 | info2.connection = server->connection; | 156 | info2.connection = server->connection; |
157 | info2.buffer_size = server->buffer_size; | 157 | info2.buffer_size = server->buffer_size; |
158 | info2.volume_number = NCP_FINFO(inode)->volNumber; | 158 | info2.volume_number = NCP_FINFO(inode)->volNumber; |
159 | info2.directory_id = NCP_FINFO(inode)->DosDirNum; | 159 | info2.directory_id = NCP_FINFO(inode)->DosDirNum; |
160 | info2.dummy1 = info2.dummy2 = info2.dummy3 = 0; | 160 | info2.dummy1 = info2.dummy2 = info2.dummy3 = 0; |
161 | 161 | ||
162 | if (copy_to_user(arg, &info2, sizeof(info2))) | 162 | if (copy_to_user(arg, &info2, sizeof(info2))) |
163 | return -EFAULT; | 163 | return -EFAULT; |
164 | return 0; | 164 | return 0; |
165 | } | 165 | } |
166 | #endif | 166 | #endif |
167 | 167 | ||
168 | #define NCP_IOC_GETMOUNTUID16 _IOW('n', 2, u16) | 168 | #define NCP_IOC_GETMOUNTUID16 _IOW('n', 2, u16) |
169 | #define NCP_IOC_GETMOUNTUID32 _IOW('n', 2, u32) | 169 | #define NCP_IOC_GETMOUNTUID32 _IOW('n', 2, u32) |
170 | #define NCP_IOC_GETMOUNTUID64 _IOW('n', 2, u64) | 170 | #define NCP_IOC_GETMOUNTUID64 _IOW('n', 2, u64) |
171 | 171 | ||
172 | #ifdef CONFIG_NCPFS_NLS | 172 | #ifdef CONFIG_NCPFS_NLS |
173 | /* Here we are select the iocharset and the codepage for NLS. | 173 | /* Here we are select the iocharset and the codepage for NLS. |
174 | * Thanks Petr Vandrovec for idea and many hints. | 174 | * Thanks Petr Vandrovec for idea and many hints. |
175 | */ | 175 | */ |
176 | static int | 176 | static int |
177 | ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg) | 177 | ncp_set_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg) |
178 | { | 178 | { |
179 | struct ncp_nls_ioctl user; | 179 | struct ncp_nls_ioctl user; |
180 | struct nls_table *codepage; | 180 | struct nls_table *codepage; |
181 | struct nls_table *iocharset; | 181 | struct nls_table *iocharset; |
182 | struct nls_table *oldset_io; | 182 | struct nls_table *oldset_io; |
183 | struct nls_table *oldset_cp; | 183 | struct nls_table *oldset_cp; |
184 | 184 | ||
185 | if (!capable(CAP_SYS_ADMIN)) | 185 | if (!capable(CAP_SYS_ADMIN)) |
186 | return -EACCES; | 186 | return -EACCES; |
187 | if (server->root_setuped) | 187 | if (server->root_setuped) |
188 | return -EBUSY; | 188 | return -EBUSY; |
189 | 189 | ||
190 | if (copy_from_user(&user, arg, sizeof(user))) | 190 | if (copy_from_user(&user, arg, sizeof(user))) |
191 | return -EFAULT; | 191 | return -EFAULT; |
192 | 192 | ||
193 | codepage = NULL; | 193 | codepage = NULL; |
194 | user.codepage[NCP_IOCSNAME_LEN] = 0; | 194 | user.codepage[NCP_IOCSNAME_LEN] = 0; |
195 | if (!user.codepage[0] || !strcmp(user.codepage, "default")) | 195 | if (!user.codepage[0] || !strcmp(user.codepage, "default")) |
196 | codepage = load_nls_default(); | 196 | codepage = load_nls_default(); |
197 | else { | 197 | else { |
198 | codepage = load_nls(user.codepage); | 198 | codepage = load_nls(user.codepage); |
199 | if (!codepage) { | 199 | if (!codepage) { |
200 | return -EBADRQC; | 200 | return -EBADRQC; |
201 | } | 201 | } |
202 | } | 202 | } |
203 | 203 | ||
204 | iocharset = NULL; | 204 | iocharset = NULL; |
205 | user.iocharset[NCP_IOCSNAME_LEN] = 0; | 205 | user.iocharset[NCP_IOCSNAME_LEN] = 0; |
206 | if (!user.iocharset[0] || !strcmp(user.iocharset, "default")) { | 206 | if (!user.iocharset[0] || !strcmp(user.iocharset, "default")) { |
207 | iocharset = load_nls_default(); | 207 | iocharset = load_nls_default(); |
208 | NCP_CLR_FLAG(server, NCP_FLAG_UTF8); | 208 | NCP_CLR_FLAG(server, NCP_FLAG_UTF8); |
209 | } else if (!strcmp(user.iocharset, "utf8")) { | 209 | } else if (!strcmp(user.iocharset, "utf8")) { |
210 | iocharset = load_nls_default(); | 210 | iocharset = load_nls_default(); |
211 | NCP_SET_FLAG(server, NCP_FLAG_UTF8); | 211 | NCP_SET_FLAG(server, NCP_FLAG_UTF8); |
212 | } else { | 212 | } else { |
213 | iocharset = load_nls(user.iocharset); | 213 | iocharset = load_nls(user.iocharset); |
214 | if (!iocharset) { | 214 | if (!iocharset) { |
215 | unload_nls(codepage); | 215 | unload_nls(codepage); |
216 | return -EBADRQC; | 216 | return -EBADRQC; |
217 | } | 217 | } |
218 | NCP_CLR_FLAG(server, NCP_FLAG_UTF8); | 218 | NCP_CLR_FLAG(server, NCP_FLAG_UTF8); |
219 | } | 219 | } |
220 | 220 | ||
221 | oldset_cp = server->nls_vol; | 221 | oldset_cp = server->nls_vol; |
222 | server->nls_vol = codepage; | 222 | server->nls_vol = codepage; |
223 | oldset_io = server->nls_io; | 223 | oldset_io = server->nls_io; |
224 | server->nls_io = iocharset; | 224 | server->nls_io = iocharset; |
225 | 225 | ||
226 | if (oldset_cp) | 226 | if (oldset_cp) |
227 | unload_nls(oldset_cp); | 227 | unload_nls(oldset_cp); |
228 | if (oldset_io) | 228 | if (oldset_io) |
229 | unload_nls(oldset_io); | 229 | unload_nls(oldset_io); |
230 | 230 | ||
231 | return 0; | 231 | return 0; |
232 | } | 232 | } |
233 | 233 | ||
234 | static int | 234 | static int |
235 | ncp_get_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg) | 235 | ncp_get_charsets(struct ncp_server* server, struct ncp_nls_ioctl __user *arg) |
236 | { | 236 | { |
237 | struct ncp_nls_ioctl user; | 237 | struct ncp_nls_ioctl user; |
238 | int len; | 238 | int len; |
239 | 239 | ||
240 | memset(&user, 0, sizeof(user)); | 240 | memset(&user, 0, sizeof(user)); |
241 | if (server->nls_vol && server->nls_vol->charset) { | 241 | if (server->nls_vol && server->nls_vol->charset) { |
242 | len = strlen(server->nls_vol->charset); | 242 | len = strlen(server->nls_vol->charset); |
243 | if (len > NCP_IOCSNAME_LEN) | 243 | if (len > NCP_IOCSNAME_LEN) |
244 | len = NCP_IOCSNAME_LEN; | 244 | len = NCP_IOCSNAME_LEN; |
245 | strncpy(user.codepage, server->nls_vol->charset, len); | 245 | strncpy(user.codepage, server->nls_vol->charset, len); |
246 | user.codepage[len] = 0; | 246 | user.codepage[len] = 0; |
247 | } | 247 | } |
248 | 248 | ||
249 | if (NCP_IS_FLAG(server, NCP_FLAG_UTF8)) | 249 | if (NCP_IS_FLAG(server, NCP_FLAG_UTF8)) |
250 | strcpy(user.iocharset, "utf8"); | 250 | strcpy(user.iocharset, "utf8"); |
251 | else if (server->nls_io && server->nls_io->charset) { | 251 | else if (server->nls_io && server->nls_io->charset) { |
252 | len = strlen(server->nls_io->charset); | 252 | len = strlen(server->nls_io->charset); |
253 | if (len > NCP_IOCSNAME_LEN) | 253 | if (len > NCP_IOCSNAME_LEN) |
254 | len = NCP_IOCSNAME_LEN; | 254 | len = NCP_IOCSNAME_LEN; |
255 | strncpy(user.iocharset, server->nls_io->charset, len); | 255 | strncpy(user.iocharset, server->nls_io->charset, len); |
256 | user.iocharset[len] = 0; | 256 | user.iocharset[len] = 0; |
257 | } | 257 | } |
258 | 258 | ||
259 | if (copy_to_user(arg, &user, sizeof(user))) | 259 | if (copy_to_user(arg, &user, sizeof(user))) |
260 | return -EFAULT; | 260 | return -EFAULT; |
261 | return 0; | 261 | return 0; |
262 | } | 262 | } |
263 | #endif /* CONFIG_NCPFS_NLS */ | 263 | #endif /* CONFIG_NCPFS_NLS */ |
264 | 264 | ||
265 | static int __ncp_ioctl(struct inode *inode, struct file *filp, | 265 | static int __ncp_ioctl(struct inode *inode, struct file *filp, |
266 | unsigned int cmd, unsigned long arg) | 266 | unsigned int cmd, unsigned long arg) |
267 | { | 267 | { |
268 | struct ncp_server *server = NCP_SERVER(inode); | 268 | struct ncp_server *server = NCP_SERVER(inode); |
269 | int result; | 269 | int result; |
270 | struct ncp_ioctl_request request; | 270 | struct ncp_ioctl_request request; |
271 | char* bouncebuffer; | 271 | char* bouncebuffer; |
272 | void __user *argp = (void __user *)arg; | 272 | void __user *argp = (void __user *)arg; |
273 | uid_t uid = current_uid(); | 273 | uid_t uid = current_uid(); |
274 | 274 | ||
275 | switch (cmd) { | 275 | switch (cmd) { |
276 | #ifdef CONFIG_COMPAT | 276 | #ifdef CONFIG_COMPAT |
277 | case NCP_IOC_NCPREQUEST_32: | 277 | case NCP_IOC_NCPREQUEST_32: |
278 | #endif | 278 | #endif |
279 | case NCP_IOC_NCPREQUEST: | 279 | case NCP_IOC_NCPREQUEST: |
280 | if (file_permission(filp, MAY_WRITE) != 0 | 280 | if (file_permission(filp, MAY_WRITE) != 0 |
281 | && uid != server->m.mounted_uid) | 281 | && uid != server->m.mounted_uid) |
282 | return -EACCES; | 282 | return -EACCES; |
283 | 283 | ||
284 | #ifdef CONFIG_COMPAT | 284 | #ifdef CONFIG_COMPAT |
285 | if (cmd == NCP_IOC_NCPREQUEST_32) { | 285 | if (cmd == NCP_IOC_NCPREQUEST_32) { |
286 | struct compat_ncp_ioctl_request request32; | 286 | struct compat_ncp_ioctl_request request32; |
287 | if (copy_from_user(&request32, argp, sizeof(request32))) | 287 | if (copy_from_user(&request32, argp, sizeof(request32))) |
288 | return -EFAULT; | 288 | return -EFAULT; |
289 | request.function = request32.function; | 289 | request.function = request32.function; |
290 | request.size = request32.size; | 290 | request.size = request32.size; |
291 | request.data = compat_ptr(request32.data); | 291 | request.data = compat_ptr(request32.data); |
292 | } else | 292 | } else |
293 | #endif | 293 | #endif |
294 | if (copy_from_user(&request, argp, sizeof(request))) | 294 | if (copy_from_user(&request, argp, sizeof(request))) |
295 | return -EFAULT; | 295 | return -EFAULT; |
296 | 296 | ||
297 | if ((request.function > 255) | 297 | if ((request.function > 255) |
298 | || (request.size > | 298 | || (request.size > |
299 | NCP_PACKET_SIZE - sizeof(struct ncp_request_header))) { | 299 | NCP_PACKET_SIZE - sizeof(struct ncp_request_header))) { |
300 | return -EINVAL; | 300 | return -EINVAL; |
301 | } | 301 | } |
302 | bouncebuffer = vmalloc(NCP_PACKET_SIZE_INTERNAL); | 302 | bouncebuffer = vmalloc(NCP_PACKET_SIZE_INTERNAL); |
303 | if (!bouncebuffer) | 303 | if (!bouncebuffer) |
304 | return -ENOMEM; | 304 | return -ENOMEM; |
305 | if (copy_from_user(bouncebuffer, request.data, request.size)) { | 305 | if (copy_from_user(bouncebuffer, request.data, request.size)) { |
306 | vfree(bouncebuffer); | 306 | vfree(bouncebuffer); |
307 | return -EFAULT; | 307 | return -EFAULT; |
308 | } | 308 | } |
309 | ncp_lock_server(server); | 309 | ncp_lock_server(server); |
310 | 310 | ||
311 | /* FIXME: We hack around in the server's structures | 311 | /* FIXME: We hack around in the server's structures |
312 | here to be able to use ncp_request */ | 312 | here to be able to use ncp_request */ |
313 | 313 | ||
314 | server->has_subfunction = 0; | 314 | server->has_subfunction = 0; |
315 | server->current_size = request.size; | 315 | server->current_size = request.size; |
316 | memcpy(server->packet, bouncebuffer, request.size); | 316 | memcpy(server->packet, bouncebuffer, request.size); |
317 | 317 | ||
318 | result = ncp_request2(server, request.function, | 318 | result = ncp_request2(server, request.function, |
319 | bouncebuffer, NCP_PACKET_SIZE_INTERNAL); | 319 | bouncebuffer, NCP_PACKET_SIZE_INTERNAL); |
320 | if (result < 0) | 320 | if (result < 0) |
321 | result = -EIO; | 321 | result = -EIO; |
322 | else | 322 | else |
323 | result = server->reply_size; | 323 | result = server->reply_size; |
324 | ncp_unlock_server(server); | 324 | ncp_unlock_server(server); |
325 | DPRINTK("ncp_ioctl: copy %d bytes\n", | 325 | DPRINTK("ncp_ioctl: copy %d bytes\n", |
326 | result); | 326 | result); |
327 | if (result >= 0) | 327 | if (result >= 0) |
328 | if (copy_to_user(request.data, bouncebuffer, result)) | 328 | if (copy_to_user(request.data, bouncebuffer, result)) |
329 | result = -EFAULT; | 329 | result = -EFAULT; |
330 | vfree(bouncebuffer); | 330 | vfree(bouncebuffer); |
331 | return result; | 331 | return result; |
332 | 332 | ||
333 | case NCP_IOC_CONN_LOGGED_IN: | 333 | case NCP_IOC_CONN_LOGGED_IN: |
334 | 334 | ||
335 | if (!capable(CAP_SYS_ADMIN)) | 335 | if (!capable(CAP_SYS_ADMIN)) |
336 | return -EACCES; | 336 | return -EACCES; |
337 | if (!(server->m.int_flags & NCP_IMOUNT_LOGGEDIN_POSSIBLE)) | 337 | if (!(server->m.int_flags & NCP_IMOUNT_LOGGEDIN_POSSIBLE)) |
338 | return -EINVAL; | 338 | return -EINVAL; |
339 | if (server->root_setuped) | 339 | if (server->root_setuped) |
340 | return -EBUSY; | 340 | return -EBUSY; |
341 | server->root_setuped = 1; | 341 | server->root_setuped = 1; |
342 | return ncp_conn_logged_in(inode->i_sb); | 342 | return ncp_conn_logged_in(inode->i_sb); |
343 | 343 | ||
344 | case NCP_IOC_GET_FS_INFO: | 344 | case NCP_IOC_GET_FS_INFO: |
345 | return ncp_get_fs_info(server, filp, argp); | 345 | return ncp_get_fs_info(server, filp, argp); |
346 | 346 | ||
347 | case NCP_IOC_GET_FS_INFO_V2: | 347 | case NCP_IOC_GET_FS_INFO_V2: |
348 | return ncp_get_fs_info_v2(server, filp, argp); | 348 | return ncp_get_fs_info_v2(server, filp, argp); |
349 | 349 | ||
350 | #ifdef CONFIG_COMPAT | 350 | #ifdef CONFIG_COMPAT |
351 | case NCP_IOC_GET_FS_INFO_V2_32: | 351 | case NCP_IOC_GET_FS_INFO_V2_32: |
352 | return ncp_get_compat_fs_info_v2(server, filp, argp); | 352 | return ncp_get_compat_fs_info_v2(server, filp, argp); |
353 | #endif | 353 | #endif |
354 | /* we have too many combinations of CONFIG_COMPAT, | 354 | /* we have too many combinations of CONFIG_COMPAT, |
355 | * CONFIG_64BIT and CONFIG_UID16, so just handle | 355 | * CONFIG_64BIT and CONFIG_UID16, so just handle |
356 | * any of the possible ioctls */ | 356 | * any of the possible ioctls */ |
357 | case NCP_IOC_GETMOUNTUID16: | 357 | case NCP_IOC_GETMOUNTUID16: |
358 | case NCP_IOC_GETMOUNTUID32: | 358 | case NCP_IOC_GETMOUNTUID32: |
359 | case NCP_IOC_GETMOUNTUID64: | 359 | case NCP_IOC_GETMOUNTUID64: |
360 | if (file_permission(filp, MAY_READ) != 0 | 360 | if (file_permission(filp, MAY_READ) != 0 |
361 | && uid != server->m.mounted_uid) | 361 | && uid != server->m.mounted_uid) |
362 | return -EACCES; | 362 | return -EACCES; |
363 | 363 | ||
364 | if (cmd == NCP_IOC_GETMOUNTUID16) { | 364 | if (cmd == NCP_IOC_GETMOUNTUID16) { |
365 | u16 uid; | 365 | u16 uid; |
366 | SET_UID(uid, server->m.mounted_uid); | 366 | SET_UID(uid, server->m.mounted_uid); |
367 | if (put_user(uid, (u16 __user *)argp)) | 367 | if (put_user(uid, (u16 __user *)argp)) |
368 | return -EFAULT; | 368 | return -EFAULT; |
369 | } else if (cmd == NCP_IOC_GETMOUNTUID32) { | 369 | } else if (cmd == NCP_IOC_GETMOUNTUID32) { |
370 | if (put_user(server->m.mounted_uid, | 370 | if (put_user(server->m.mounted_uid, |
371 | (u32 __user *)argp)) | 371 | (u32 __user *)argp)) |
372 | return -EFAULT; | 372 | return -EFAULT; |
373 | } else { | 373 | } else { |
374 | if (put_user(server->m.mounted_uid, | 374 | if (put_user(server->m.mounted_uid, |
375 | (u64 __user *)argp)) | 375 | (u64 __user *)argp)) |
376 | return -EFAULT; | 376 | return -EFAULT; |
377 | } | 377 | } |
378 | return 0; | 378 | return 0; |
379 | 379 | ||
380 | case NCP_IOC_GETROOT: | 380 | case NCP_IOC_GETROOT: |
381 | { | 381 | { |
382 | struct ncp_setroot_ioctl sr; | 382 | struct ncp_setroot_ioctl sr; |
383 | 383 | ||
384 | if (file_permission(filp, MAY_READ) != 0 | 384 | if (file_permission(filp, MAY_READ) != 0 |
385 | && uid != server->m.mounted_uid) | 385 | && uid != server->m.mounted_uid) |
386 | return -EACCES; | 386 | return -EACCES; |
387 | 387 | ||
388 | if (server->m.mounted_vol[0]) { | 388 | if (server->m.mounted_vol[0]) { |
389 | struct dentry* dentry = inode->i_sb->s_root; | 389 | struct dentry* dentry = inode->i_sb->s_root; |
390 | 390 | ||
391 | if (dentry) { | 391 | if (dentry) { |
392 | struct inode* s_inode = dentry->d_inode; | 392 | struct inode* s_inode = dentry->d_inode; |
393 | 393 | ||
394 | if (s_inode) { | 394 | if (s_inode) { |
395 | sr.volNumber = NCP_FINFO(s_inode)->volNumber; | 395 | sr.volNumber = NCP_FINFO(s_inode)->volNumber; |
396 | sr.dirEntNum = NCP_FINFO(s_inode)->dirEntNum; | 396 | sr.dirEntNum = NCP_FINFO(s_inode)->dirEntNum; |
397 | sr.namespace = server->name_space[sr.volNumber]; | 397 | sr.namespace = server->name_space[sr.volNumber]; |
398 | } else | 398 | } else |
399 | DPRINTK("ncpfs: s_root->d_inode==NULL\n"); | 399 | DPRINTK("ncpfs: s_root->d_inode==NULL\n"); |
400 | } else | 400 | } else |
401 | DPRINTK("ncpfs: s_root==NULL\n"); | 401 | DPRINTK("ncpfs: s_root==NULL\n"); |
402 | } else { | 402 | } else { |
403 | sr.volNumber = -1; | 403 | sr.volNumber = -1; |
404 | sr.namespace = 0; | 404 | sr.namespace = 0; |
405 | sr.dirEntNum = 0; | 405 | sr.dirEntNum = 0; |
406 | } | 406 | } |
407 | if (copy_to_user(argp, &sr, sizeof(sr))) | 407 | if (copy_to_user(argp, &sr, sizeof(sr))) |
408 | return -EFAULT; | 408 | return -EFAULT; |
409 | return 0; | 409 | return 0; |
410 | } | 410 | } |
411 | 411 | ||
412 | case NCP_IOC_SETROOT: | 412 | case NCP_IOC_SETROOT: |
413 | { | 413 | { |
414 | struct ncp_setroot_ioctl sr; | 414 | struct ncp_setroot_ioctl sr; |
415 | __u32 vnum; | 415 | __u32 vnum; |
416 | __le32 de; | 416 | __le32 de; |
417 | __le32 dosde; | 417 | __le32 dosde; |
418 | struct dentry* dentry; | 418 | struct dentry* dentry; |
419 | 419 | ||
420 | if (!capable(CAP_SYS_ADMIN)) | 420 | if (!capable(CAP_SYS_ADMIN)) |
421 | { | 421 | { |
422 | return -EACCES; | 422 | return -EACCES; |
423 | } | 423 | } |
424 | if (server->root_setuped) return -EBUSY; | 424 | if (server->root_setuped) return -EBUSY; |
425 | if (copy_from_user(&sr, argp, sizeof(sr))) | 425 | if (copy_from_user(&sr, argp, sizeof(sr))) |
426 | return -EFAULT; | 426 | return -EFAULT; |
427 | if (sr.volNumber < 0) { | 427 | if (sr.volNumber < 0) { |
428 | server->m.mounted_vol[0] = 0; | 428 | server->m.mounted_vol[0] = 0; |
429 | vnum = NCP_NUMBER_OF_VOLUMES; | 429 | vnum = NCP_NUMBER_OF_VOLUMES; |
430 | de = 0; | 430 | de = 0; |
431 | dosde = 0; | 431 | dosde = 0; |
432 | } else if (sr.volNumber >= NCP_NUMBER_OF_VOLUMES) { | 432 | } else if (sr.volNumber >= NCP_NUMBER_OF_VOLUMES) { |
433 | return -EINVAL; | 433 | return -EINVAL; |
434 | } else if (ncp_mount_subdir(server, sr.volNumber, | 434 | } else if (ncp_mount_subdir(server, sr.volNumber, |
435 | sr.namespace, sr.dirEntNum, | 435 | sr.namespace, sr.dirEntNum, |
436 | &vnum, &de, &dosde)) { | 436 | &vnum, &de, &dosde)) { |
437 | return -ENOENT; | 437 | return -ENOENT; |
438 | } | 438 | } |
439 | 439 | ||
440 | dentry = inode->i_sb->s_root; | 440 | dentry = inode->i_sb->s_root; |
441 | server->root_setuped = 1; | 441 | server->root_setuped = 1; |
442 | if (dentry) { | 442 | if (dentry) { |
443 | struct inode* s_inode = dentry->d_inode; | 443 | struct inode* s_inode = dentry->d_inode; |
444 | 444 | ||
445 | if (inode) { | 445 | if (inode) { |
446 | NCP_FINFO(s_inode)->volNumber = vnum; | 446 | NCP_FINFO(s_inode)->volNumber = vnum; |
447 | NCP_FINFO(s_inode)->dirEntNum = de; | 447 | NCP_FINFO(s_inode)->dirEntNum = de; |
448 | NCP_FINFO(s_inode)->DosDirNum = dosde; | 448 | NCP_FINFO(s_inode)->DosDirNum = dosde; |
449 | } else | 449 | } else |
450 | DPRINTK("ncpfs: s_root->d_inode==NULL\n"); | 450 | DPRINTK("ncpfs: s_root->d_inode==NULL\n"); |
451 | } else | 451 | } else |
452 | DPRINTK("ncpfs: s_root==NULL\n"); | 452 | DPRINTK("ncpfs: s_root==NULL\n"); |
453 | 453 | ||
454 | return 0; | 454 | return 0; |
455 | } | 455 | } |
456 | 456 | ||
457 | #ifdef CONFIG_NCPFS_PACKET_SIGNING | 457 | #ifdef CONFIG_NCPFS_PACKET_SIGNING |
458 | case NCP_IOC_SIGN_INIT: | 458 | case NCP_IOC_SIGN_INIT: |
459 | if (file_permission(filp, MAY_WRITE) != 0 | 459 | if (file_permission(filp, MAY_WRITE) != 0 |
460 | && uid != server->m.mounted_uid) | 460 | && uid != server->m.mounted_uid) |
461 | return -EACCES; | 461 | return -EACCES; |
462 | 462 | ||
463 | if (argp) { | 463 | if (argp) { |
464 | if (server->sign_wanted) | 464 | if (server->sign_wanted) |
465 | { | 465 | { |
466 | struct ncp_sign_init sign; | 466 | struct ncp_sign_init sign; |
467 | 467 | ||
468 | if (copy_from_user(&sign, argp, sizeof(sign))) | 468 | if (copy_from_user(&sign, argp, sizeof(sign))) |
469 | return -EFAULT; | 469 | return -EFAULT; |
470 | memcpy(server->sign_root,sign.sign_root,8); | 470 | memcpy(server->sign_root,sign.sign_root,8); |
471 | memcpy(server->sign_last,sign.sign_last,16); | 471 | memcpy(server->sign_last,sign.sign_last,16); |
472 | server->sign_active = 1; | 472 | server->sign_active = 1; |
473 | } | 473 | } |
474 | /* ignore when signatures not wanted */ | 474 | /* ignore when signatures not wanted */ |
475 | } else { | 475 | } else { |
476 | server->sign_active = 0; | 476 | server->sign_active = 0; |
477 | } | 477 | } |
478 | return 0; | 478 | return 0; |
479 | 479 | ||
480 | case NCP_IOC_SIGN_WANTED: | 480 | case NCP_IOC_SIGN_WANTED: |
481 | if (file_permission(filp, MAY_READ) != 0 | 481 | if (file_permission(filp, MAY_READ) != 0 |
482 | && uid != server->m.mounted_uid) | 482 | && uid != server->m.mounted_uid) |
483 | return -EACCES; | 483 | return -EACCES; |
484 | 484 | ||
485 | if (put_user(server->sign_wanted, (int __user *)argp)) | 485 | if (put_user(server->sign_wanted, (int __user *)argp)) |
486 | return -EFAULT; | 486 | return -EFAULT; |
487 | return 0; | 487 | return 0; |
488 | 488 | ||
489 | case NCP_IOC_SET_SIGN_WANTED: | 489 | case NCP_IOC_SET_SIGN_WANTED: |
490 | { | 490 | { |
491 | int newstate; | 491 | int newstate; |
492 | 492 | ||
493 | if (file_permission(filp, MAY_WRITE) != 0 | 493 | if (file_permission(filp, MAY_WRITE) != 0 |
494 | && uid != server->m.mounted_uid) | 494 | && uid != server->m.mounted_uid) |
495 | return -EACCES; | 495 | return -EACCES; |
496 | 496 | ||
497 | /* get only low 8 bits... */ | 497 | /* get only low 8 bits... */ |
498 | if (get_user(newstate, (unsigned char __user *)argp)) | 498 | if (get_user(newstate, (unsigned char __user *)argp)) |
499 | return -EFAULT; | 499 | return -EFAULT; |
500 | if (server->sign_active) { | 500 | if (server->sign_active) { |
501 | /* cannot turn signatures OFF when active */ | 501 | /* cannot turn signatures OFF when active */ |
502 | if (!newstate) return -EINVAL; | 502 | if (!newstate) return -EINVAL; |
503 | } else { | 503 | } else { |
504 | server->sign_wanted = newstate != 0; | 504 | server->sign_wanted = newstate != 0; |
505 | } | 505 | } |
506 | return 0; | 506 | return 0; |
507 | } | 507 | } |
508 | 508 | ||
509 | #endif /* CONFIG_NCPFS_PACKET_SIGNING */ | 509 | #endif /* CONFIG_NCPFS_PACKET_SIGNING */ |
510 | 510 | ||
511 | #ifdef CONFIG_NCPFS_IOCTL_LOCKING | 511 | #ifdef CONFIG_NCPFS_IOCTL_LOCKING |
512 | case NCP_IOC_LOCKUNLOCK: | 512 | case NCP_IOC_LOCKUNLOCK: |
513 | if (file_permission(filp, MAY_WRITE) != 0 | 513 | if (file_permission(filp, MAY_WRITE) != 0 |
514 | && uid != server->m.mounted_uid) | 514 | && uid != server->m.mounted_uid) |
515 | return -EACCES; | 515 | return -EACCES; |
516 | 516 | ||
517 | { | 517 | { |
518 | struct ncp_lock_ioctl rqdata; | 518 | struct ncp_lock_ioctl rqdata; |
519 | 519 | ||
520 | if (copy_from_user(&rqdata, argp, sizeof(rqdata))) | 520 | if (copy_from_user(&rqdata, argp, sizeof(rqdata))) |
521 | return -EFAULT; | 521 | return -EFAULT; |
522 | if (rqdata.origin != 0) | 522 | if (rqdata.origin != 0) |
523 | return -EINVAL; | 523 | return -EINVAL; |
524 | /* check for cmd */ | 524 | /* check for cmd */ |
525 | switch (rqdata.cmd) { | 525 | switch (rqdata.cmd) { |
526 | case NCP_LOCK_EX: | 526 | case NCP_LOCK_EX: |
527 | case NCP_LOCK_SH: | 527 | case NCP_LOCK_SH: |
528 | if (rqdata.timeout == 0) | 528 | if (rqdata.timeout == 0) |
529 | rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT; | 529 | rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT; |
530 | else if (rqdata.timeout > NCP_LOCK_MAX_TIMEOUT) | 530 | else if (rqdata.timeout > NCP_LOCK_MAX_TIMEOUT) |
531 | rqdata.timeout = NCP_LOCK_MAX_TIMEOUT; | 531 | rqdata.timeout = NCP_LOCK_MAX_TIMEOUT; |
532 | break; | 532 | break; |
533 | case NCP_LOCK_LOG: | 533 | case NCP_LOCK_LOG: |
534 | rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT; /* has no effect */ | 534 | rqdata.timeout = NCP_LOCK_DEFAULT_TIMEOUT; /* has no effect */ |
535 | case NCP_LOCK_CLEAR: | 535 | case NCP_LOCK_CLEAR: |
536 | break; | 536 | break; |
537 | default: | 537 | default: |
538 | return -EINVAL; | 538 | return -EINVAL; |
539 | } | 539 | } |
540 | /* locking needs both read and write access */ | 540 | /* locking needs both read and write access */ |
541 | if ((result = ncp_make_open(inode, O_RDWR)) != 0) | 541 | if ((result = ncp_make_open(inode, O_RDWR)) != 0) |
542 | { | 542 | { |
543 | return result; | 543 | return result; |
544 | } | 544 | } |
545 | result = -EIO; | 545 | result = -EIO; |
546 | if (!ncp_conn_valid(server)) | 546 | if (!ncp_conn_valid(server)) |
547 | goto outrel; | 547 | goto outrel; |
548 | result = -EISDIR; | 548 | result = -EISDIR; |
549 | if (!S_ISREG(inode->i_mode)) | 549 | if (!S_ISREG(inode->i_mode)) |
550 | goto outrel; | 550 | goto outrel; |
551 | if (rqdata.cmd == NCP_LOCK_CLEAR) | 551 | if (rqdata.cmd == NCP_LOCK_CLEAR) |
552 | { | 552 | { |
553 | result = ncp_ClearPhysicalRecord(NCP_SERVER(inode), | 553 | result = ncp_ClearPhysicalRecord(NCP_SERVER(inode), |
554 | NCP_FINFO(inode)->file_handle, | 554 | NCP_FINFO(inode)->file_handle, |
555 | rqdata.offset, | 555 | rqdata.offset, |
556 | rqdata.length); | 556 | rqdata.length); |
557 | if (result > 0) result = 0; /* no such lock */ | 557 | if (result > 0) result = 0; /* no such lock */ |
558 | } | 558 | } |
559 | else | 559 | else |
560 | { | 560 | { |
561 | int lockcmd; | 561 | int lockcmd; |
562 | 562 | ||
563 | switch (rqdata.cmd) | 563 | switch (rqdata.cmd) |
564 | { | 564 | { |
565 | case NCP_LOCK_EX: lockcmd=1; break; | 565 | case NCP_LOCK_EX: lockcmd=1; break; |
566 | case NCP_LOCK_SH: lockcmd=3; break; | 566 | case NCP_LOCK_SH: lockcmd=3; break; |
567 | default: lockcmd=0; break; | 567 | default: lockcmd=0; break; |
568 | } | 568 | } |
569 | result = ncp_LogPhysicalRecord(NCP_SERVER(inode), | 569 | result = ncp_LogPhysicalRecord(NCP_SERVER(inode), |
570 | NCP_FINFO(inode)->file_handle, | 570 | NCP_FINFO(inode)->file_handle, |
571 | lockcmd, | 571 | lockcmd, |
572 | rqdata.offset, | 572 | rqdata.offset, |
573 | rqdata.length, | 573 | rqdata.length, |
574 | rqdata.timeout); | 574 | rqdata.timeout); |
575 | if (result > 0) result = -EAGAIN; | 575 | if (result > 0) result = -EAGAIN; |
576 | } | 576 | } |
577 | outrel: | 577 | outrel: |
578 | ncp_inode_close(inode); | 578 | ncp_inode_close(inode); |
579 | return result; | 579 | return result; |
580 | } | 580 | } |
581 | #endif /* CONFIG_NCPFS_IOCTL_LOCKING */ | 581 | #endif /* CONFIG_NCPFS_IOCTL_LOCKING */ |
582 | 582 | ||
583 | #ifdef CONFIG_COMPAT | 583 | #ifdef CONFIG_COMPAT |
584 | case NCP_IOC_GETOBJECTNAME_32: | 584 | case NCP_IOC_GETOBJECTNAME_32: |
585 | if (uid != server->m.mounted_uid) | 585 | if (uid != server->m.mounted_uid) |
586 | return -EACCES; | 586 | return -EACCES; |
587 | { | 587 | { |
588 | struct compat_ncp_objectname_ioctl user; | 588 | struct compat_ncp_objectname_ioctl user; |
589 | size_t outl; | 589 | size_t outl; |
590 | 590 | ||
591 | if (copy_from_user(&user, argp, sizeof(user))) | 591 | if (copy_from_user(&user, argp, sizeof(user))) |
592 | return -EFAULT; | 592 | return -EFAULT; |
593 | user.auth_type = server->auth.auth_type; | 593 | user.auth_type = server->auth.auth_type; |
594 | outl = user.object_name_len; | 594 | outl = user.object_name_len; |
595 | user.object_name_len = server->auth.object_name_len; | 595 | user.object_name_len = server->auth.object_name_len; |
596 | if (outl > user.object_name_len) | 596 | if (outl > user.object_name_len) |
597 | outl = user.object_name_len; | 597 | outl = user.object_name_len; |
598 | if (outl) { | 598 | if (outl) { |
599 | if (copy_to_user(compat_ptr(user.object_name), | 599 | if (copy_to_user(compat_ptr(user.object_name), |
600 | server->auth.object_name, | 600 | server->auth.object_name, |
601 | outl)) return -EFAULT; | 601 | outl)) return -EFAULT; |
602 | } | 602 | } |
603 | if (copy_to_user(argp, &user, sizeof(user))) | 603 | if (copy_to_user(argp, &user, sizeof(user))) |
604 | return -EFAULT; | 604 | return -EFAULT; |
605 | return 0; | 605 | return 0; |
606 | } | 606 | } |
607 | #endif | 607 | #endif |
608 | 608 | ||
609 | case NCP_IOC_GETOBJECTNAME: | 609 | case NCP_IOC_GETOBJECTNAME: |
610 | if (uid != server->m.mounted_uid) | 610 | if (uid != server->m.mounted_uid) |
611 | return -EACCES; | 611 | return -EACCES; |
612 | { | 612 | { |
613 | struct ncp_objectname_ioctl user; | 613 | struct ncp_objectname_ioctl user; |
614 | size_t outl; | 614 | size_t outl; |
615 | 615 | ||
616 | if (copy_from_user(&user, argp, sizeof(user))) | 616 | if (copy_from_user(&user, argp, sizeof(user))) |
617 | return -EFAULT; | 617 | return -EFAULT; |
618 | user.auth_type = server->auth.auth_type; | 618 | user.auth_type = server->auth.auth_type; |
619 | outl = user.object_name_len; | 619 | outl = user.object_name_len; |
620 | user.object_name_len = server->auth.object_name_len; | 620 | user.object_name_len = server->auth.object_name_len; |
621 | if (outl > user.object_name_len) | 621 | if (outl > user.object_name_len) |
622 | outl = user.object_name_len; | 622 | outl = user.object_name_len; |
623 | if (outl) { | 623 | if (outl) { |
624 | if (copy_to_user(user.object_name, | 624 | if (copy_to_user(user.object_name, |
625 | server->auth.object_name, | 625 | server->auth.object_name, |
626 | outl)) return -EFAULT; | 626 | outl)) return -EFAULT; |
627 | } | 627 | } |
628 | if (copy_to_user(argp, &user, sizeof(user))) | 628 | if (copy_to_user(argp, &user, sizeof(user))) |
629 | return -EFAULT; | 629 | return -EFAULT; |
630 | return 0; | 630 | return 0; |
631 | } | 631 | } |
632 | 632 | ||
633 | #ifdef CONFIG_COMPAT | 633 | #ifdef CONFIG_COMPAT |
634 | case NCP_IOC_SETOBJECTNAME_32: | 634 | case NCP_IOC_SETOBJECTNAME_32: |
635 | #endif | 635 | #endif |
636 | case NCP_IOC_SETOBJECTNAME: | 636 | case NCP_IOC_SETOBJECTNAME: |
637 | if (uid != server->m.mounted_uid) | 637 | if (uid != server->m.mounted_uid) |
638 | return -EACCES; | 638 | return -EACCES; |
639 | { | 639 | { |
640 | struct ncp_objectname_ioctl user; | 640 | struct ncp_objectname_ioctl user; |
641 | void* newname; | 641 | void* newname; |
642 | void* oldname; | 642 | void* oldname; |
643 | size_t oldnamelen; | 643 | size_t oldnamelen; |
644 | void* oldprivate; | 644 | void* oldprivate; |
645 | size_t oldprivatelen; | 645 | size_t oldprivatelen; |
646 | 646 | ||
647 | #ifdef CONFIG_COMPAT | 647 | #ifdef CONFIG_COMPAT |
648 | if (cmd == NCP_IOC_SETOBJECTNAME_32) { | 648 | if (cmd == NCP_IOC_SETOBJECTNAME_32) { |
649 | struct compat_ncp_objectname_ioctl user32; | 649 | struct compat_ncp_objectname_ioctl user32; |
650 | if (copy_from_user(&user32, argp, sizeof(user32))) | 650 | if (copy_from_user(&user32, argp, sizeof(user32))) |
651 | return -EFAULT; | 651 | return -EFAULT; |
652 | user.auth_type = user32.auth_type; | 652 | user.auth_type = user32.auth_type; |
653 | user.object_name_len = user32.object_name_len; | 653 | user.object_name_len = user32.object_name_len; |
654 | user.object_name = compat_ptr(user32.object_name); | 654 | user.object_name = compat_ptr(user32.object_name); |
655 | } else | 655 | } else |
656 | #endif | 656 | #endif |
657 | if (copy_from_user(&user, argp, sizeof(user))) | 657 | if (copy_from_user(&user, argp, sizeof(user))) |
658 | return -EFAULT; | 658 | return -EFAULT; |
659 | 659 | ||
660 | if (user.object_name_len > NCP_OBJECT_NAME_MAX_LEN) | 660 | if (user.object_name_len > NCP_OBJECT_NAME_MAX_LEN) |
661 | return -ENOMEM; | 661 | return -ENOMEM; |
662 | if (user.object_name_len) { | 662 | if (user.object_name_len) { |
663 | newname = kmalloc(user.object_name_len, GFP_USER); | 663 | newname = memdup_user(user.object_name, |
664 | if (!newname) | 664 | user.object_name_len); |
665 | return -ENOMEM; | 665 | if (IS_ERR(newname)) |
666 | if (copy_from_user(newname, user.object_name, user.object_name_len)) { | 666 | return PTR_ERR(newname); |
667 | kfree(newname); | ||
668 | return -EFAULT; | ||
669 | } | ||
670 | } else { | 667 | } else { |
671 | newname = NULL; | 668 | newname = NULL; |
672 | } | 669 | } |
673 | /* enter critical section */ | 670 | /* enter critical section */ |
674 | /* maybe that kfree can sleep so do that this way */ | 671 | /* maybe that kfree can sleep so do that this way */ |
675 | /* it is at least more SMP friendly (in future...) */ | 672 | /* it is at least more SMP friendly (in future...) */ |
676 | oldname = server->auth.object_name; | 673 | oldname = server->auth.object_name; |
677 | oldnamelen = server->auth.object_name_len; | 674 | oldnamelen = server->auth.object_name_len; |
678 | oldprivate = server->priv.data; | 675 | oldprivate = server->priv.data; |
679 | oldprivatelen = server->priv.len; | 676 | oldprivatelen = server->priv.len; |
680 | server->auth.auth_type = user.auth_type; | 677 | server->auth.auth_type = user.auth_type; |
681 | server->auth.object_name_len = user.object_name_len; | 678 | server->auth.object_name_len = user.object_name_len; |
682 | server->auth.object_name = newname; | 679 | server->auth.object_name = newname; |
683 | server->priv.len = 0; | 680 | server->priv.len = 0; |
684 | server->priv.data = NULL; | 681 | server->priv.data = NULL; |
685 | /* leave critical section */ | 682 | /* leave critical section */ |
686 | kfree(oldprivate); | 683 | kfree(oldprivate); |
687 | kfree(oldname); | 684 | kfree(oldname); |
688 | return 0; | 685 | return 0; |
689 | } | 686 | } |
690 | 687 | ||
691 | #ifdef CONFIG_COMPAT | 688 | #ifdef CONFIG_COMPAT |
692 | case NCP_IOC_GETPRIVATEDATA_32: | 689 | case NCP_IOC_GETPRIVATEDATA_32: |
693 | #endif | 690 | #endif |
694 | case NCP_IOC_GETPRIVATEDATA: | 691 | case NCP_IOC_GETPRIVATEDATA: |
695 | if (uid != server->m.mounted_uid) | 692 | if (uid != server->m.mounted_uid) |
696 | return -EACCES; | 693 | return -EACCES; |
697 | { | 694 | { |
698 | struct ncp_privatedata_ioctl user; | 695 | struct ncp_privatedata_ioctl user; |
699 | size_t outl; | 696 | size_t outl; |
700 | 697 | ||
701 | #ifdef CONFIG_COMPAT | 698 | #ifdef CONFIG_COMPAT |
702 | if (cmd == NCP_IOC_GETPRIVATEDATA_32) { | 699 | if (cmd == NCP_IOC_GETPRIVATEDATA_32) { |
703 | struct compat_ncp_privatedata_ioctl user32; | 700 | struct compat_ncp_privatedata_ioctl user32; |
704 | if (copy_from_user(&user32, argp, sizeof(user32))) | 701 | if (copy_from_user(&user32, argp, sizeof(user32))) |
705 | return -EFAULT; | 702 | return -EFAULT; |
706 | user.len = user32.len; | 703 | user.len = user32.len; |
707 | user.data = compat_ptr(user32.data); | 704 | user.data = compat_ptr(user32.data); |
708 | } else | 705 | } else |
709 | #endif | 706 | #endif |
710 | if (copy_from_user(&user, argp, sizeof(user))) | 707 | if (copy_from_user(&user, argp, sizeof(user))) |
711 | return -EFAULT; | 708 | return -EFAULT; |
712 | 709 | ||
713 | outl = user.len; | 710 | outl = user.len; |
714 | user.len = server->priv.len; | 711 | user.len = server->priv.len; |
715 | if (outl > user.len) outl = user.len; | 712 | if (outl > user.len) outl = user.len; |
716 | if (outl) { | 713 | if (outl) { |
717 | if (copy_to_user(user.data, | 714 | if (copy_to_user(user.data, |
718 | server->priv.data, | 715 | server->priv.data, |
719 | outl)) return -EFAULT; | 716 | outl)) return -EFAULT; |
720 | } | 717 | } |
721 | #ifdef CONFIG_COMPAT | 718 | #ifdef CONFIG_COMPAT |
722 | if (cmd == NCP_IOC_GETPRIVATEDATA_32) { | 719 | if (cmd == NCP_IOC_GETPRIVATEDATA_32) { |
723 | struct compat_ncp_privatedata_ioctl user32; | 720 | struct compat_ncp_privatedata_ioctl user32; |
724 | user32.len = user.len; | 721 | user32.len = user.len; |
725 | user32.data = (unsigned long) user.data; | 722 | user32.data = (unsigned long) user.data; |
726 | if (copy_to_user(argp, &user32, sizeof(user32))) | 723 | if (copy_to_user(argp, &user32, sizeof(user32))) |
727 | return -EFAULT; | 724 | return -EFAULT; |
728 | } else | 725 | } else |
729 | #endif | 726 | #endif |
730 | if (copy_to_user(argp, &user, sizeof(user))) | 727 | if (copy_to_user(argp, &user, sizeof(user))) |
731 | return -EFAULT; | 728 | return -EFAULT; |
732 | 729 | ||
733 | return 0; | 730 | return 0; |
734 | } | 731 | } |
735 | 732 | ||
736 | #ifdef CONFIG_COMPAT | 733 | #ifdef CONFIG_COMPAT |
737 | case NCP_IOC_SETPRIVATEDATA_32: | 734 | case NCP_IOC_SETPRIVATEDATA_32: |
738 | #endif | 735 | #endif |
739 | case NCP_IOC_SETPRIVATEDATA: | 736 | case NCP_IOC_SETPRIVATEDATA: |
740 | if (uid != server->m.mounted_uid) | 737 | if (uid != server->m.mounted_uid) |
741 | return -EACCES; | 738 | return -EACCES; |
742 | { | 739 | { |
743 | struct ncp_privatedata_ioctl user; | 740 | struct ncp_privatedata_ioctl user; |
744 | void* new; | 741 | void* new; |
745 | void* old; | 742 | void* old; |
746 | size_t oldlen; | 743 | size_t oldlen; |
747 | 744 | ||
748 | #ifdef CONFIG_COMPAT | 745 | #ifdef CONFIG_COMPAT |
749 | if (cmd == NCP_IOC_SETPRIVATEDATA_32) { | 746 | if (cmd == NCP_IOC_SETPRIVATEDATA_32) { |
750 | struct compat_ncp_privatedata_ioctl user32; | 747 | struct compat_ncp_privatedata_ioctl user32; |
751 | if (copy_from_user(&user32, argp, sizeof(user32))) | 748 | if (copy_from_user(&user32, argp, sizeof(user32))) |
752 | return -EFAULT; | 749 | return -EFAULT; |
753 | user.len = user32.len; | 750 | user.len = user32.len; |
754 | user.data = compat_ptr(user32.data); | 751 | user.data = compat_ptr(user32.data); |
755 | } else | 752 | } else |
756 | #endif | 753 | #endif |
757 | if (copy_from_user(&user, argp, sizeof(user))) | 754 | if (copy_from_user(&user, argp, sizeof(user))) |
758 | return -EFAULT; | 755 | return -EFAULT; |
759 | 756 | ||
760 | if (user.len > NCP_PRIVATE_DATA_MAX_LEN) | 757 | if (user.len > NCP_PRIVATE_DATA_MAX_LEN) |
761 | return -ENOMEM; | 758 | return -ENOMEM; |
762 | if (user.len) { | 759 | if (user.len) { |
763 | new = kmalloc(user.len, GFP_USER); | 760 | new = memdup_user(user.data, user.len); |
764 | if (!new) | 761 | if (IS_ERR(new)) |
765 | return -ENOMEM; | 762 | return PTR_ERR(new); |
766 | if (copy_from_user(new, user.data, user.len)) { | ||
767 | kfree(new); | ||
768 | return -EFAULT; | ||
769 | } | ||
770 | } else { | 763 | } else { |
771 | new = NULL; | 764 | new = NULL; |
772 | } | 765 | } |
773 | /* enter critical section */ | 766 | /* enter critical section */ |
774 | old = server->priv.data; | 767 | old = server->priv.data; |
775 | oldlen = server->priv.len; | 768 | oldlen = server->priv.len; |
776 | server->priv.len = user.len; | 769 | server->priv.len = user.len; |
777 | server->priv.data = new; | 770 | server->priv.data = new; |
778 | /* leave critical section */ | 771 | /* leave critical section */ |
779 | kfree(old); | 772 | kfree(old); |
780 | return 0; | 773 | return 0; |
781 | } | 774 | } |
782 | 775 | ||
783 | #ifdef CONFIG_NCPFS_NLS | 776 | #ifdef CONFIG_NCPFS_NLS |
784 | case NCP_IOC_SETCHARSETS: | 777 | case NCP_IOC_SETCHARSETS: |
785 | return ncp_set_charsets(server, argp); | 778 | return ncp_set_charsets(server, argp); |
786 | 779 | ||
787 | case NCP_IOC_GETCHARSETS: | 780 | case NCP_IOC_GETCHARSETS: |
788 | return ncp_get_charsets(server, argp); | 781 | return ncp_get_charsets(server, argp); |
789 | 782 | ||
790 | #endif /* CONFIG_NCPFS_NLS */ | 783 | #endif /* CONFIG_NCPFS_NLS */ |
791 | 784 | ||
792 | case NCP_IOC_SETDENTRYTTL: | 785 | case NCP_IOC_SETDENTRYTTL: |
793 | if (file_permission(filp, MAY_WRITE) != 0 && | 786 | if (file_permission(filp, MAY_WRITE) != 0 && |
794 | uid != server->m.mounted_uid) | 787 | uid != server->m.mounted_uid) |
795 | return -EACCES; | 788 | return -EACCES; |
796 | 789 | ||
797 | { | 790 | { |
798 | u_int32_t user; | 791 | u_int32_t user; |
799 | 792 | ||
800 | if (copy_from_user(&user, argp, sizeof(user))) | 793 | if (copy_from_user(&user, argp, sizeof(user))) |
801 | return -EFAULT; | 794 | return -EFAULT; |
802 | /* 20 secs at most... */ | 795 | /* 20 secs at most... */ |
803 | if (user > 20000) | 796 | if (user > 20000) |
804 | return -EINVAL; | 797 | return -EINVAL; |
805 | user = (user * HZ) / 1000; | 798 | user = (user * HZ) / 1000; |
806 | server->dentry_ttl = user; | 799 | server->dentry_ttl = user; |
807 | return 0; | 800 | return 0; |
808 | } | 801 | } |
809 | 802 | ||
810 | case NCP_IOC_GETDENTRYTTL: | 803 | case NCP_IOC_GETDENTRYTTL: |
811 | { | 804 | { |
812 | u_int32_t user = (server->dentry_ttl * 1000) / HZ; | 805 | u_int32_t user = (server->dentry_ttl * 1000) / HZ; |
813 | if (copy_to_user(argp, &user, sizeof(user))) | 806 | if (copy_to_user(argp, &user, sizeof(user))) |
814 | return -EFAULT; | 807 | return -EFAULT; |
815 | return 0; | 808 | return 0; |
816 | } | 809 | } |
817 | 810 | ||
818 | } | 811 | } |
819 | return -EINVAL; | 812 | return -EINVAL; |
820 | } | 813 | } |
821 | 814 | ||
822 | static int ncp_ioctl_need_write(unsigned int cmd) | 815 | static int ncp_ioctl_need_write(unsigned int cmd) |
823 | { | 816 | { |
824 | switch (cmd) { | 817 | switch (cmd) { |
825 | case NCP_IOC_GET_FS_INFO: | 818 | case NCP_IOC_GET_FS_INFO: |
826 | case NCP_IOC_GET_FS_INFO_V2: | 819 | case NCP_IOC_GET_FS_INFO_V2: |
827 | case NCP_IOC_NCPREQUEST: | 820 | case NCP_IOC_NCPREQUEST: |
828 | case NCP_IOC_SETDENTRYTTL: | 821 | case NCP_IOC_SETDENTRYTTL: |
829 | case NCP_IOC_SIGN_INIT: | 822 | case NCP_IOC_SIGN_INIT: |
830 | case NCP_IOC_LOCKUNLOCK: | 823 | case NCP_IOC_LOCKUNLOCK: |
831 | case NCP_IOC_SET_SIGN_WANTED: | 824 | case NCP_IOC_SET_SIGN_WANTED: |
832 | return 1; | 825 | return 1; |
833 | case NCP_IOC_GETOBJECTNAME: | 826 | case NCP_IOC_GETOBJECTNAME: |
834 | case NCP_IOC_SETOBJECTNAME: | 827 | case NCP_IOC_SETOBJECTNAME: |
835 | case NCP_IOC_GETPRIVATEDATA: | 828 | case NCP_IOC_GETPRIVATEDATA: |
836 | case NCP_IOC_SETPRIVATEDATA: | 829 | case NCP_IOC_SETPRIVATEDATA: |
837 | case NCP_IOC_SETCHARSETS: | 830 | case NCP_IOC_SETCHARSETS: |
838 | case NCP_IOC_GETCHARSETS: | 831 | case NCP_IOC_GETCHARSETS: |
839 | case NCP_IOC_CONN_LOGGED_IN: | 832 | case NCP_IOC_CONN_LOGGED_IN: |
840 | case NCP_IOC_GETDENTRYTTL: | 833 | case NCP_IOC_GETDENTRYTTL: |
841 | case NCP_IOC_GETMOUNTUID2: | 834 | case NCP_IOC_GETMOUNTUID2: |
842 | case NCP_IOC_SIGN_WANTED: | 835 | case NCP_IOC_SIGN_WANTED: |
843 | case NCP_IOC_GETROOT: | 836 | case NCP_IOC_GETROOT: |
844 | case NCP_IOC_SETROOT: | 837 | case NCP_IOC_SETROOT: |
845 | return 0; | 838 | return 0; |
846 | default: | 839 | default: |
847 | /* unkown IOCTL command, assume write */ | 840 | /* unkown IOCTL command, assume write */ |
848 | return 1; | 841 | return 1; |
849 | } | 842 | } |
850 | } | 843 | } |
851 | 844 | ||
852 | int ncp_ioctl(struct inode *inode, struct file *filp, | 845 | int ncp_ioctl(struct inode *inode, struct file *filp, |
853 | unsigned int cmd, unsigned long arg) | 846 | unsigned int cmd, unsigned long arg) |
854 | { | 847 | { |
855 | int ret; | 848 | int ret; |
856 | 849 | ||
857 | if (ncp_ioctl_need_write(cmd)) { | 850 | if (ncp_ioctl_need_write(cmd)) { |
858 | /* | 851 | /* |
859 | * inside the ioctl(), any failures which | 852 | * inside the ioctl(), any failures which |
860 | * are because of file_permission() are | 853 | * are because of file_permission() are |
861 | * -EACCESS, so it seems consistent to keep | 854 | * -EACCESS, so it seems consistent to keep |
862 | * that here. | 855 | * that here. |
863 | */ | 856 | */ |
864 | if (mnt_want_write(filp->f_path.mnt)) | 857 | if (mnt_want_write(filp->f_path.mnt)) |
865 | return -EACCES; | 858 | return -EACCES; |
866 | } | 859 | } |
867 | ret = __ncp_ioctl(inode, filp, cmd, arg); | 860 | ret = __ncp_ioctl(inode, filp, cmd, arg); |
868 | if (ncp_ioctl_need_write(cmd)) | 861 | if (ncp_ioctl_need_write(cmd)) |
869 | mnt_drop_write(filp->f_path.mnt); | 862 | mnt_drop_write(filp->f_path.mnt); |
870 | return ret; | 863 | return ret; |
871 | } | 864 | } |
872 | 865 | ||
873 | #ifdef CONFIG_COMPAT | 866 | #ifdef CONFIG_COMPAT |
874 | long ncp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | 867 | long ncp_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
875 | { | 868 | { |
876 | struct inode *inode = file->f_path.dentry->d_inode; | 869 | struct inode *inode = file->f_path.dentry->d_inode; |
877 | int ret; | 870 | int ret; |
878 | 871 | ||
879 | lock_kernel(); | 872 | lock_kernel(); |
880 | arg = (unsigned long) compat_ptr(arg); | 873 | arg = (unsigned long) compat_ptr(arg); |
881 | ret = ncp_ioctl(inode, file, cmd, arg); | 874 | ret = ncp_ioctl(inode, file, cmd, arg); |
882 | unlock_kernel(); | 875 | unlock_kernel(); |
883 | return ret; | 876 | return ret; |
884 | } | 877 | } |
885 | #endif | 878 | #endif |
886 | 879 |