Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
1da177e4 LT |
2 | /* |
3 | * linux/fs/nfs/callback_xdr.c | |
4 | * | |
5 | * Copyright (C) 2004 Trond Myklebust | |
6 | * | |
7 | * NFSv4 callback encode/decode procedures | |
8 | */ | |
1da177e4 LT |
9 | #include <linux/kernel.h> |
10 | #include <linux/sunrpc/svc.h> | |
11 | #include <linux/nfs4.h> | |
12 | #include <linux/nfs_fs.h> | |
9a3ba432 TM |
13 | #include <linux/ratelimit.h> |
14 | #include <linux/printk.h> | |
5a0e3ad6 | 15 | #include <linux/slab.h> |
c36fca52 | 16 | #include <linux/sunrpc/bc_xprt.h> |
4ce79717 | 17 | #include "nfs4_fs.h" |
1da177e4 | 18 | #include "callback.h" |
c36fca52 | 19 | #include "internal.h" |
76e697ba | 20 | #include "nfs4session.h" |
2bb50aab | 21 | #include "nfs4trace.h" |
1da177e4 | 22 | |
45724e8a KM |
23 | #define CB_OP_TAGLEN_MAXSZ (512) |
24 | #define CB_OP_HDR_RES_MAXSZ (2 * 4) // opcode, status | |
25 | #define CB_OP_GETATTR_BITMAP_MAXSZ (4 * 4) // bitmap length, 3 bitmaps | |
26 | #define CB_OP_GETATTR_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \ | |
27 | CB_OP_GETATTR_BITMAP_MAXSZ + \ | |
43df7110 TM |
28 | /* change, size, atime, ctime, |
29 | * mtime, deleg_atime, deleg_mtime */\ | |
30 | (2 + 2 + 3 + 3 + 3 + 3 + 3) * 4) | |
45724e8a | 31 | #define CB_OP_RECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
1da177e4 | 32 | |
4aece6a1 | 33 | #if defined(CONFIG_NFS_V4_1) |
f2a62561 | 34 | #define CB_OP_LAYOUTRECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
1be5683b | 35 | #define CB_OP_DEVICENOTIFY_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
4aece6a1 | 36 | #define CB_OP_SEQUENCE_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \ |
45724e8a KM |
37 | NFS4_MAX_SESSIONID_LEN + \ |
38 | (1 + 3) * 4) // seqid, 3 slotids | |
31f09607 | 39 | #define CB_OP_RECALLANY_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
b9efa1b2 | 40 | #define CB_OP_RECALLSLOT_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
db783688 | 41 | #define CB_OP_NOTIFY_LOCK_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
4aece6a1 | 42 | #endif /* CONFIG_NFS_V4_1 */ |
5178a125 OK |
43 | #ifdef CONFIG_NFS_V4_2 |
44 | #define CB_OP_OFFLOAD_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) | |
45 | #endif /* CONFIG_NFS_V4_2 */ | |
4aece6a1 | 46 | |
1da177e4 LT |
47 | #define NFSDBG_FACILITY NFSDBG_CALLBACK |
48 | ||
31d2b435 AA |
49 | /* Internal error code */ |
50 | #define NFS4ERR_RESOURCE_HDR 11050 | |
51 | ||
1da177e4 | 52 | struct callback_op { |
f4dac4ad CH |
53 | __be32 (*process_op)(void *, void *, struct cb_process_state *); |
54 | __be32 (*decode_args)(struct svc_rqst *, struct xdr_stream *, void *); | |
55 | __be32 (*encode_res)(struct svc_rqst *, struct xdr_stream *, | |
56 | const void *); | |
1da177e4 LT |
57 | long res_maxsize; |
58 | }; | |
59 | ||
60 | static struct callback_op callback_ops[]; | |
61 | ||
a6beb732 | 62 | static __be32 nfs4_callback_null(struct svc_rqst *rqstp) |
1da177e4 LT |
63 | { |
64 | return htonl(NFS4_OK); | |
65 | } | |
66 | ||
c35a810c CL |
67 | /* |
68 | * svc_process_common() looks for an XDR encoder to know when | |
69 | * not to drop a Reply. | |
70 | */ | |
130e2054 | 71 | static bool nfs4_encode_void(struct svc_rqst *rqstp, struct xdr_stream *xdr) |
1da177e4 | 72 | { |
130e2054 | 73 | return true; |
1da177e4 LT |
74 | } |
75 | ||
c065eeea TM |
76 | static __be32 decode_string(struct xdr_stream *xdr, unsigned int *len, |
77 | const char **str, size_t maxlen) | |
1da177e4 | 78 | { |
c065eeea | 79 | ssize_t err; |
1da177e4 | 80 | |
c065eeea TM |
81 | err = xdr_stream_decode_opaque_inline(xdr, (void **)str, maxlen); |
82 | if (err < 0) | |
83 | return cpu_to_be32(NFS4ERR_RESOURCE); | |
84 | *len = err; | |
1da177e4 LT |
85 | return 0; |
86 | } | |
87 | ||
e6f684f6 | 88 | static __be32 decode_fh(struct xdr_stream *xdr, struct nfs_fh *fh) |
1da177e4 | 89 | { |
5704fdeb | 90 | __be32 *p; |
1da177e4 | 91 | |
eb72f484 | 92 | p = xdr_inline_decode(xdr, 4); |
1da177e4 LT |
93 | if (unlikely(p == NULL)) |
94 | return htonl(NFS4ERR_RESOURCE); | |
95 | fh->size = ntohl(*p); | |
96 | if (fh->size > NFS4_FHSIZE) | |
97 | return htonl(NFS4ERR_BADHANDLE); | |
eb72f484 | 98 | p = xdr_inline_decode(xdr, fh->size); |
1da177e4 LT |
99 | if (unlikely(p == NULL)) |
100 | return htonl(NFS4ERR_RESOURCE); | |
101 | memcpy(&fh->data[0], p, fh->size); | |
102 | memset(&fh->data[fh->size], 0, sizeof(fh->data) - fh->size); | |
103 | return 0; | |
104 | } | |
105 | ||
e6f684f6 | 106 | static __be32 decode_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) |
1da177e4 | 107 | { |
5704fdeb | 108 | __be32 *p; |
1da177e4 LT |
109 | unsigned int attrlen; |
110 | ||
eb72f484 | 111 | p = xdr_inline_decode(xdr, 4); |
1da177e4 LT |
112 | if (unlikely(p == NULL)) |
113 | return htonl(NFS4ERR_RESOURCE); | |
114 | attrlen = ntohl(*p); | |
eb72f484 | 115 | p = xdr_inline_decode(xdr, attrlen << 2); |
1da177e4 LT |
116 | if (unlikely(p == NULL)) |
117 | return htonl(NFS4ERR_RESOURCE); | |
118 | if (likely(attrlen > 0)) | |
119 | bitmap[0] = ntohl(*p++); | |
120 | if (attrlen > 1) | |
95832998 JL |
121 | bitmap[1] = ntohl(*p++); |
122 | if (attrlen > 2) | |
123 | bitmap[2] = ntohl(*p); | |
1da177e4 LT |
124 | return 0; |
125 | } | |
126 | ||
e6f684f6 | 127 | static __be32 decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) |
1da177e4 | 128 | { |
5704fdeb | 129 | __be32 *p; |
1da177e4 | 130 | |
eb72f484 | 131 | p = xdr_inline_decode(xdr, NFS4_STATEID_SIZE); |
1da177e4 LT |
132 | if (unlikely(p == NULL)) |
133 | return htonl(NFS4ERR_RESOURCE); | |
93b717fd | 134 | memcpy(stateid->data, p, NFS4_STATEID_SIZE); |
1da177e4 LT |
135 | return 0; |
136 | } | |
137 | ||
93b717fd TM |
138 | static __be32 decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) |
139 | { | |
140 | stateid->type = NFS4_DELEGATION_STATEID_TYPE; | |
141 | return decode_stateid(xdr, stateid); | |
142 | } | |
143 | ||
e6f684f6 | 144 | static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr) |
1da177e4 | 145 | { |
5704fdeb | 146 | __be32 *p; |
e6f684f6 | 147 | __be32 status; |
1da177e4 | 148 | |
c065eeea | 149 | status = decode_string(xdr, &hdr->taglen, &hdr->tag, CB_OP_TAGLEN_MAXSZ); |
1da177e4 LT |
150 | if (unlikely(status != 0)) |
151 | return status; | |
eb72f484 | 152 | p = xdr_inline_decode(xdr, 12); |
1da177e4 LT |
153 | if (unlikely(p == NULL)) |
154 | return htonl(NFS4ERR_RESOURCE); | |
b8f2ef84 | 155 | hdr->minorversion = ntohl(*p++); |
459de2ed BS |
156 | /* Check for minor version support */ |
157 | if (hdr->minorversion <= NFS4_MAX_MINOR_VERSION) { | |
42c2c424 | 158 | hdr->cb_ident = ntohl(*p++); /* ignored by v4.1 and v4.2 */ |
48a9e2d2 | 159 | } else { |
9a3ba432 | 160 | pr_warn_ratelimited("NFS: %s: NFSv4 server callback with " |
b8f2ef84 BH |
161 | "illegal minor version %u!\n", |
162 | __func__, hdr->minorversion); | |
1da177e4 LT |
163 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); |
164 | } | |
1da177e4 LT |
165 | hdr->nops = ntohl(*p); |
166 | return 0; | |
167 | } | |
168 | ||
e6f684f6 | 169 | static __be32 decode_op_hdr(struct xdr_stream *xdr, unsigned int *op) |
1da177e4 | 170 | { |
5704fdeb | 171 | __be32 *p; |
eb72f484 | 172 | p = xdr_inline_decode(xdr, 4); |
1da177e4 | 173 | if (unlikely(p == NULL)) |
31d2b435 | 174 | return htonl(NFS4ERR_RESOURCE_HDR); |
1da177e4 LT |
175 | *op = ntohl(*p); |
176 | return 0; | |
177 | } | |
178 | ||
f4dac4ad CH |
179 | static __be32 decode_getattr_args(struct svc_rqst *rqstp, |
180 | struct xdr_stream *xdr, void *argp) | |
1da177e4 | 181 | { |
f4dac4ad | 182 | struct cb_getattrargs *args = argp; |
e6f684f6 | 183 | __be32 status; |
1da177e4 LT |
184 | |
185 | status = decode_fh(xdr, &args->fh); | |
186 | if (unlikely(status != 0)) | |
56938bb7 AS |
187 | return status; |
188 | return decode_bitmap(xdr, args->bitmap); | |
1da177e4 LT |
189 | } |
190 | ||
f4dac4ad CH |
191 | static __be32 decode_recall_args(struct svc_rqst *rqstp, |
192 | struct xdr_stream *xdr, void *argp) | |
1da177e4 | 193 | { |
f4dac4ad | 194 | struct cb_recallargs *args = argp; |
5704fdeb | 195 | __be32 *p; |
e6f684f6 | 196 | __be32 status; |
1da177e4 | 197 | |
93b717fd | 198 | status = decode_delegation_stateid(xdr, &args->stateid); |
1da177e4 | 199 | if (unlikely(status != 0)) |
135a4ea0 | 200 | return status; |
eb72f484 | 201 | p = xdr_inline_decode(xdr, 4); |
135a4ea0 AS |
202 | if (unlikely(p == NULL)) |
203 | return htonl(NFS4ERR_RESOURCE); | |
1da177e4 | 204 | args->truncate = ntohl(*p); |
135a4ea0 | 205 | return decode_fh(xdr, &args->fh); |
1da177e4 LT |
206 | } |
207 | ||
4aece6a1 | 208 | #if defined(CONFIG_NFS_V4_1) |
93b717fd TM |
209 | static __be32 decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) |
210 | { | |
211 | stateid->type = NFS4_LAYOUT_STATEID_TYPE; | |
212 | return decode_stateid(xdr, stateid); | |
213 | } | |
4aece6a1 | 214 | |
f2a62561 | 215 | static __be32 decode_layoutrecall_args(struct svc_rqst *rqstp, |
f4dac4ad | 216 | struct xdr_stream *xdr, void *argp) |
f2a62561 | 217 | { |
f4dac4ad | 218 | struct cb_layoutrecallargs *args = argp; |
f2a62561 FI |
219 | __be32 *p; |
220 | __be32 status = 0; | |
221 | uint32_t iomode; | |
222 | ||
eb72f484 | 223 | p = xdr_inline_decode(xdr, 4 * sizeof(uint32_t)); |
c79d56d2 AS |
224 | if (unlikely(p == NULL)) |
225 | return htonl(NFS4ERR_BADXDR); | |
f2a62561 FI |
226 | |
227 | args->cbl_layout_type = ntohl(*p++); | |
228 | /* Depite the spec's xdr, iomode really belongs in the FILE switch, | |
25985edc | 229 | * as it is unusable and ignored with the other types. |
f2a62561 FI |
230 | */ |
231 | iomode = ntohl(*p++); | |
232 | args->cbl_layoutchanged = ntohl(*p++); | |
233 | args->cbl_recall_type = ntohl(*p++); | |
234 | ||
235 | if (args->cbl_recall_type == RETURN_FILE) { | |
236 | args->cbl_range.iomode = iomode; | |
237 | status = decode_fh(xdr, &args->cbl_fh); | |
238 | if (unlikely(status != 0)) | |
c79d56d2 | 239 | return status; |
f2a62561 | 240 | |
eb72f484 | 241 | p = xdr_inline_decode(xdr, 2 * sizeof(uint64_t)); |
c79d56d2 AS |
242 | if (unlikely(p == NULL)) |
243 | return htonl(NFS4ERR_BADXDR); | |
f2a62561 FI |
244 | p = xdr_decode_hyper(p, &args->cbl_range.offset); |
245 | p = xdr_decode_hyper(p, &args->cbl_range.length); | |
c79d56d2 | 246 | return decode_layout_stateid(xdr, &args->cbl_stateid); |
f2a62561 | 247 | } else if (args->cbl_recall_type == RETURN_FSID) { |
eb72f484 | 248 | p = xdr_inline_decode(xdr, 2 * sizeof(uint64_t)); |
c79d56d2 AS |
249 | if (unlikely(p == NULL)) |
250 | return htonl(NFS4ERR_BADXDR); | |
f2a62561 FI |
251 | p = xdr_decode_hyper(p, &args->cbl_fsid.major); |
252 | p = xdr_decode_hyper(p, &args->cbl_fsid.minor); | |
c79d56d2 AS |
253 | } else if (args->cbl_recall_type != RETURN_ALL) |
254 | return htonl(NFS4ERR_BADXDR); | |
255 | return 0; | |
f2a62561 FI |
256 | } |
257 | ||
1be5683b ME |
258 | static |
259 | __be32 decode_devicenotify_args(struct svc_rqst *rqstp, | |
260 | struct xdr_stream *xdr, | |
f4dac4ad | 261 | void *argp) |
1be5683b | 262 | { |
f4dac4ad | 263 | struct cb_devicenotifyargs *args = argp; |
b05bf5c6 | 264 | uint32_t tmp, n, i; |
1be5683b ME |
265 | __be32 *p; |
266 | __be32 status = 0; | |
1be5683b ME |
267 | |
268 | /* Num of device notifications */ | |
eb72f484 | 269 | p = xdr_inline_decode(xdr, sizeof(uint32_t)); |
1be5683b ME |
270 | if (unlikely(p == NULL)) { |
271 | status = htonl(NFS4ERR_BADXDR); | |
272 | goto out; | |
273 | } | |
274 | n = ntohl(*p++); | |
b05bf5c6 | 275 | if (n == 0) |
1be5683b ME |
276 | goto out; |
277 | ||
a4f743a6 | 278 | args->devs = kmalloc_array(n, sizeof(*args->devs), GFP_KERNEL); |
1be5683b ME |
279 | if (!args->devs) { |
280 | status = htonl(NFS4ERR_DELAY); | |
281 | goto out; | |
282 | } | |
283 | ||
284 | /* Decode each dev notification */ | |
285 | for (i = 0; i < n; i++) { | |
286 | struct cb_devicenotifyitem *dev = &args->devs[i]; | |
287 | ||
eb72f484 CL |
288 | p = xdr_inline_decode(xdr, (4 * sizeof(uint32_t)) + |
289 | NFS4_DEVICEID4_SIZE); | |
1be5683b ME |
290 | if (unlikely(p == NULL)) { |
291 | status = htonl(NFS4ERR_BADXDR); | |
292 | goto err; | |
293 | } | |
294 | ||
295 | tmp = ntohl(*p++); /* bitmap size */ | |
296 | if (tmp != 1) { | |
297 | status = htonl(NFS4ERR_INVAL); | |
298 | goto err; | |
299 | } | |
300 | dev->cbd_notify_type = ntohl(*p++); | |
301 | if (dev->cbd_notify_type != NOTIFY_DEVICEID4_CHANGE && | |
302 | dev->cbd_notify_type != NOTIFY_DEVICEID4_DELETE) { | |
303 | status = htonl(NFS4ERR_INVAL); | |
304 | goto err; | |
305 | } | |
306 | ||
307 | tmp = ntohl(*p++); /* opaque size */ | |
308 | if (((dev->cbd_notify_type == NOTIFY_DEVICEID4_CHANGE) && | |
309 | (tmp != NFS4_DEVICEID4_SIZE + 8)) || | |
310 | ((dev->cbd_notify_type == NOTIFY_DEVICEID4_DELETE) && | |
311 | (tmp != NFS4_DEVICEID4_SIZE + 4))) { | |
312 | status = htonl(NFS4ERR_INVAL); | |
313 | goto err; | |
314 | } | |
315 | dev->cbd_layout_type = ntohl(*p++); | |
316 | memcpy(dev->cbd_dev_id.data, p, NFS4_DEVICEID4_SIZE); | |
317 | p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE); | |
318 | ||
319 | if (dev->cbd_layout_type == NOTIFY_DEVICEID4_CHANGE) { | |
eb72f484 | 320 | p = xdr_inline_decode(xdr, sizeof(uint32_t)); |
1be5683b ME |
321 | if (unlikely(p == NULL)) { |
322 | status = htonl(NFS4ERR_BADXDR); | |
323 | goto err; | |
324 | } | |
325 | dev->cbd_immediate = ntohl(*p++); | |
326 | } else { | |
327 | dev->cbd_immediate = 0; | |
328 | } | |
329 | ||
1be5683b ME |
330 | dprintk("%s: type %d layout 0x%x immediate %d\n", |
331 | __func__, dev->cbd_notify_type, dev->cbd_layout_type, | |
332 | dev->cbd_immediate); | |
333 | } | |
b05bf5c6 TM |
334 | args->ndevs = n; |
335 | dprintk("%s: ndevs %d\n", __func__, args->ndevs); | |
336 | return 0; | |
337 | err: | |
338 | kfree(args->devs); | |
1be5683b | 339 | out: |
b05bf5c6 TM |
340 | args->devs = NULL; |
341 | args->ndevs = 0; | |
1be5683b ME |
342 | dprintk("%s: status %d ndevs %d\n", |
343 | __func__, ntohl(status), args->ndevs); | |
344 | return status; | |
1be5683b ME |
345 | } |
346 | ||
9733f0d9 | 347 | static __be32 decode_sessionid(struct xdr_stream *xdr, |
4aece6a1 BH |
348 | struct nfs4_sessionid *sid) |
349 | { | |
9733f0d9 | 350 | __be32 *p; |
4aece6a1 | 351 | |
eb72f484 | 352 | p = xdr_inline_decode(xdr, NFS4_MAX_SESSIONID_LEN); |
4aece6a1 | 353 | if (unlikely(p == NULL)) |
a419aef8 | 354 | return htonl(NFS4ERR_RESOURCE); |
4aece6a1 | 355 | |
590184a6 | 356 | memcpy(sid->data, p, NFS4_MAX_SESSIONID_LEN); |
4aece6a1 BH |
357 | return 0; |
358 | } | |
359 | ||
9733f0d9 | 360 | static __be32 decode_rc_list(struct xdr_stream *xdr, |
4aece6a1 BH |
361 | struct referring_call_list *rc_list) |
362 | { | |
9733f0d9 | 363 | __be32 *p; |
4aece6a1 | 364 | int i; |
9733f0d9 | 365 | __be32 status; |
4aece6a1 BH |
366 | |
367 | status = decode_sessionid(xdr, &rc_list->rcl_sessionid); | |
368 | if (status) | |
369 | goto out; | |
370 | ||
371 | status = htonl(NFS4ERR_RESOURCE); | |
eb72f484 | 372 | p = xdr_inline_decode(xdr, sizeof(uint32_t)); |
4aece6a1 BH |
373 | if (unlikely(p == NULL)) |
374 | goto out; | |
375 | ||
376 | rc_list->rcl_nrefcalls = ntohl(*p++); | |
377 | if (rc_list->rcl_nrefcalls) { | |
6dbf1f34 DC |
378 | if (unlikely(rc_list->rcl_nrefcalls > xdr->buf->len)) |
379 | goto out; | |
eb72f484 | 380 | p = xdr_inline_decode(xdr, |
4aece6a1 BH |
381 | rc_list->rcl_nrefcalls * 2 * sizeof(uint32_t)); |
382 | if (unlikely(p == NULL)) | |
383 | goto out; | |
a4f743a6 | 384 | rc_list->rcl_refcalls = kmalloc_array(rc_list->rcl_nrefcalls, |
4aece6a1 BH |
385 | sizeof(*rc_list->rcl_refcalls), |
386 | GFP_KERNEL); | |
387 | if (unlikely(rc_list->rcl_refcalls == NULL)) | |
388 | goto out; | |
389 | for (i = 0; i < rc_list->rcl_nrefcalls; i++) { | |
390 | rc_list->rcl_refcalls[i].rc_sequenceid = ntohl(*p++); | |
391 | rc_list->rcl_refcalls[i].rc_slotid = ntohl(*p++); | |
392 | } | |
393 | } | |
394 | status = 0; | |
395 | ||
396 | out: | |
397 | return status; | |
398 | } | |
399 | ||
9733f0d9 | 400 | static __be32 decode_cb_sequence_args(struct svc_rqst *rqstp, |
4aece6a1 | 401 | struct xdr_stream *xdr, |
f4dac4ad | 402 | void *argp) |
4aece6a1 | 403 | { |
f4dac4ad | 404 | struct cb_sequenceargs *args = argp; |
9733f0d9 | 405 | __be32 *p; |
4aece6a1 | 406 | int i; |
9733f0d9 | 407 | __be32 status; |
4aece6a1 BH |
408 | |
409 | status = decode_sessionid(xdr, &args->csa_sessionid); | |
410 | if (status) | |
1796549a | 411 | return status; |
4aece6a1 | 412 | |
eb72f484 | 413 | p = xdr_inline_decode(xdr, 5 * sizeof(uint32_t)); |
4aece6a1 | 414 | if (unlikely(p == NULL)) |
1796549a | 415 | return htonl(NFS4ERR_RESOURCE); |
4aece6a1 | 416 | |
65fc64e5 | 417 | args->csa_addr = svc_addr(rqstp); |
4aece6a1 BH |
418 | args->csa_sequenceid = ntohl(*p++); |
419 | args->csa_slotid = ntohl(*p++); | |
420 | args->csa_highestslotid = ntohl(*p++); | |
421 | args->csa_cachethis = ntohl(*p++); | |
422 | args->csa_nrclists = ntohl(*p++); | |
423 | args->csa_rclists = NULL; | |
424 | if (args->csa_nrclists) { | |
0439f31c DC |
425 | args->csa_rclists = kmalloc_array(args->csa_nrclists, |
426 | sizeof(*args->csa_rclists), | |
427 | GFP_KERNEL); | |
4aece6a1 | 428 | if (unlikely(args->csa_rclists == NULL)) |
1796549a | 429 | return htonl(NFS4ERR_RESOURCE); |
4aece6a1 BH |
430 | |
431 | for (i = 0; i < args->csa_nrclists; i++) { | |
432 | status = decode_rc_list(xdr, &args->csa_rclists[i]); | |
d8ba1f97 TM |
433 | if (status) { |
434 | args->csa_nrclists = i; | |
4aece6a1 | 435 | goto out_free; |
d8ba1f97 | 436 | } |
4aece6a1 BH |
437 | } |
438 | } | |
1796549a | 439 | return 0; |
4aece6a1 BH |
440 | |
441 | out_free: | |
442 | for (i = 0; i < args->csa_nrclists; i++) | |
443 | kfree(args->csa_rclists[i].rcl_refcalls); | |
444 | kfree(args->csa_rclists); | |
1796549a | 445 | return status; |
4aece6a1 BH |
446 | } |
447 | ||
9733f0d9 | 448 | static __be32 decode_recallany_args(struct svc_rqst *rqstp, |
31f09607 | 449 | struct xdr_stream *xdr, |
f4dac4ad | 450 | void *argp) |
31f09607 | 451 | { |
f4dac4ad | 452 | struct cb_recallanyargs *args = argp; |
95832998 | 453 | uint32_t bitmap[3]; |
d743c3c9 | 454 | __be32 *p, status; |
31f09607 | 455 | |
eb72f484 | 456 | p = xdr_inline_decode(xdr, 4); |
31f09607 AB |
457 | if (unlikely(p == NULL)) |
458 | return htonl(NFS4ERR_BADXDR); | |
459 | args->craa_objs_to_keep = ntohl(*p++); | |
d743c3c9 PT |
460 | status = decode_bitmap(xdr, bitmap); |
461 | if (unlikely(status)) | |
462 | return status; | |
463 | args->craa_type_mask = bitmap[0]; | |
31f09607 AB |
464 | |
465 | return 0; | |
466 | } | |
467 | ||
9733f0d9 | 468 | static __be32 decode_recallslot_args(struct svc_rqst *rqstp, |
b9efa1b2 | 469 | struct xdr_stream *xdr, |
f4dac4ad | 470 | void *argp) |
b9efa1b2 | 471 | { |
f4dac4ad | 472 | struct cb_recallslotargs *args = argp; |
b9efa1b2 AA |
473 | __be32 *p; |
474 | ||
eb72f484 | 475 | p = xdr_inline_decode(xdr, 4); |
b9efa1b2 AA |
476 | if (unlikely(p == NULL)) |
477 | return htonl(NFS4ERR_BADXDR); | |
d5fb4ce3 | 478 | args->crsa_target_highest_slotid = ntohl(*p++); |
b9efa1b2 AA |
479 | return 0; |
480 | } | |
481 | ||
db783688 JL |
482 | static __be32 decode_lockowner(struct xdr_stream *xdr, struct cb_notify_lock_args *args) |
483 | { | |
484 | __be32 *p; | |
485 | unsigned int len; | |
486 | ||
eb72f484 | 487 | p = xdr_inline_decode(xdr, 12); |
db783688 JL |
488 | if (unlikely(p == NULL)) |
489 | return htonl(NFS4ERR_BADXDR); | |
490 | ||
491 | p = xdr_decode_hyper(p, &args->cbnl_owner.clientid); | |
492 | len = be32_to_cpu(*p); | |
493 | ||
eb72f484 | 494 | p = xdr_inline_decode(xdr, len); |
db783688 JL |
495 | if (unlikely(p == NULL)) |
496 | return htonl(NFS4ERR_BADXDR); | |
497 | ||
498 | /* Only try to decode if the length is right */ | |
499 | if (len == 20) { | |
500 | p += 2; /* skip "lock id:" */ | |
501 | args->cbnl_owner.s_dev = be32_to_cpu(*p++); | |
502 | xdr_decode_hyper(p, &args->cbnl_owner.id); | |
503 | args->cbnl_valid = true; | |
504 | } else { | |
505 | args->cbnl_owner.s_dev = 0; | |
506 | args->cbnl_owner.id = 0; | |
507 | args->cbnl_valid = false; | |
508 | } | |
509 | return 0; | |
510 | } | |
511 | ||
f4dac4ad CH |
512 | static __be32 decode_notify_lock_args(struct svc_rqst *rqstp, |
513 | struct xdr_stream *xdr, void *argp) | |
db783688 | 514 | { |
f4dac4ad | 515 | struct cb_notify_lock_args *args = argp; |
db783688 JL |
516 | __be32 status; |
517 | ||
518 | status = decode_fh(xdr, &args->cbnl_fh); | |
519 | if (unlikely(status != 0)) | |
535ece2b AS |
520 | return status; |
521 | return decode_lockowner(xdr, args); | |
db783688 JL |
522 | } |
523 | ||
4aece6a1 | 524 | #endif /* CONFIG_NFS_V4_1 */ |
5178a125 OK |
525 | #ifdef CONFIG_NFS_V4_2 |
526 | static __be32 decode_write_response(struct xdr_stream *xdr, | |
527 | struct cb_offloadargs *args) | |
528 | { | |
529 | __be32 *p; | |
530 | ||
531 | /* skip the always zero field */ | |
eb72f484 | 532 | p = xdr_inline_decode(xdr, 4); |
5178a125 OK |
533 | if (unlikely(!p)) |
534 | goto out; | |
535 | p++; | |
536 | ||
537 | /* decode count, stable_how, verifier */ | |
538 | p = xdr_inline_decode(xdr, 8 + 4); | |
539 | if (unlikely(!p)) | |
540 | goto out; | |
541 | p = xdr_decode_hyper(p, &args->wr_count); | |
542 | args->wr_writeverf.committed = be32_to_cpup(p); | |
543 | p = xdr_inline_decode(xdr, NFS4_VERIFIER_SIZE); | |
544 | if (likely(p)) { | |
545 | memcpy(&args->wr_writeverf.verifier.data[0], p, | |
546 | NFS4_VERIFIER_SIZE); | |
547 | return 0; | |
548 | } | |
549 | out: | |
550 | return htonl(NFS4ERR_RESOURCE); | |
551 | } | |
552 | ||
553 | static __be32 decode_offload_args(struct svc_rqst *rqstp, | |
554 | struct xdr_stream *xdr, | |
555 | void *data) | |
556 | { | |
557 | struct cb_offloadargs *args = data; | |
558 | __be32 *p; | |
559 | __be32 status; | |
560 | ||
561 | /* decode fh */ | |
562 | status = decode_fh(xdr, &args->coa_fh); | |
563 | if (unlikely(status != 0)) | |
564 | return status; | |
565 | ||
566 | /* decode stateid */ | |
567 | status = decode_stateid(xdr, &args->coa_stateid); | |
568 | if (unlikely(status != 0)) | |
569 | return status; | |
4aece6a1 | 570 | |
5178a125 | 571 | /* decode status */ |
eb72f484 | 572 | p = xdr_inline_decode(xdr, 4); |
5178a125 OK |
573 | if (unlikely(!p)) |
574 | goto out; | |
575 | args->error = ntohl(*p++); | |
576 | if (!args->error) { | |
577 | status = decode_write_response(xdr, args); | |
578 | if (unlikely(status != 0)) | |
579 | return status; | |
580 | } else { | |
581 | p = xdr_inline_decode(xdr, 8); | |
582 | if (unlikely(!p)) | |
583 | goto out; | |
584 | p = xdr_decode_hyper(p, &args->wr_count); | |
585 | } | |
586 | return 0; | |
587 | out: | |
588 | return htonl(NFS4ERR_RESOURCE); | |
589 | } | |
590 | #endif /* CONFIG_NFS_V4_2 */ | |
e6f684f6 | 591 | static __be32 encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) |
1da177e4 | 592 | { |
ab6e9aaf TM |
593 | if (unlikely(xdr_stream_encode_opaque(xdr, str, len) < 0)) |
594 | return cpu_to_be32(NFS4ERR_RESOURCE); | |
1da177e4 LT |
595 | return 0; |
596 | } | |
597 | ||
8b064946 | 598 | static __be32 encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitmap, size_t sz) |
1da177e4 | 599 | { |
8b064946 TM |
600 | if (xdr_stream_encode_uint32_array(xdr, bitmap, sz) < 0) |
601 | return cpu_to_be32(NFS4ERR_RESOURCE); | |
1da177e4 LT |
602 | return 0; |
603 | } | |
604 | ||
e6f684f6 | 605 | static __be32 encode_attr_change(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t change) |
1da177e4 | 606 | { |
5704fdeb | 607 | __be32 *p; |
1da177e4 LT |
608 | |
609 | if (!(bitmap[0] & FATTR4_WORD0_CHANGE)) | |
610 | return 0; | |
611 | p = xdr_reserve_space(xdr, 8); | |
90dc7d27 | 612 | if (unlikely(!p)) |
1da177e4 LT |
613 | return htonl(NFS4ERR_RESOURCE); |
614 | p = xdr_encode_hyper(p, change); | |
615 | return 0; | |
616 | } | |
617 | ||
e6f684f6 | 618 | static __be32 encode_attr_size(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t size) |
1da177e4 | 619 | { |
5704fdeb | 620 | __be32 *p; |
1da177e4 LT |
621 | |
622 | if (!(bitmap[0] & FATTR4_WORD0_SIZE)) | |
623 | return 0; | |
624 | p = xdr_reserve_space(xdr, 8); | |
90dc7d27 | 625 | if (unlikely(!p)) |
1da177e4 LT |
626 | return htonl(NFS4ERR_RESOURCE); |
627 | p = xdr_encode_hyper(p, size); | |
628 | return 0; | |
629 | } | |
630 | ||
7d34ff51 | 631 | static __be32 encode_attr_time(struct xdr_stream *xdr, const struct timespec64 *time) |
1da177e4 | 632 | { |
5704fdeb | 633 | __be32 *p; |
1da177e4 LT |
634 | |
635 | p = xdr_reserve_space(xdr, 12); | |
90dc7d27 | 636 | if (unlikely(!p)) |
1da177e4 LT |
637 | return htonl(NFS4ERR_RESOURCE); |
638 | p = xdr_encode_hyper(p, time->tv_sec); | |
639 | *p = htonl(time->tv_nsec); | |
640 | return 0; | |
641 | } | |
642 | ||
43df7110 TM |
643 | static __be32 encode_attr_atime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec64 *time) |
644 | { | |
645 | if (!(bitmap[1] & FATTR4_WORD1_TIME_ACCESS)) | |
646 | return 0; | |
647 | return encode_attr_time(xdr,time); | |
648 | } | |
649 | ||
7d34ff51 | 650 | static __be32 encode_attr_ctime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec64 *time) |
1da177e4 LT |
651 | { |
652 | if (!(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) | |
653 | return 0; | |
654 | return encode_attr_time(xdr,time); | |
655 | } | |
656 | ||
7d34ff51 | 657 | static __be32 encode_attr_mtime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec64 *time) |
1da177e4 LT |
658 | { |
659 | if (!(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) | |
660 | return 0; | |
661 | return encode_attr_time(xdr,time); | |
662 | } | |
663 | ||
43df7110 TM |
664 | static __be32 encode_attr_delegatime(struct xdr_stream *xdr, |
665 | const uint32_t *bitmap, | |
666 | const struct timespec64 *time) | |
667 | { | |
668 | if (!(bitmap[2] & FATTR4_WORD2_TIME_DELEG_ACCESS)) | |
669 | return 0; | |
670 | return encode_attr_time(xdr,time); | |
671 | } | |
672 | ||
673 | static __be32 encode_attr_delegmtime(struct xdr_stream *xdr, | |
674 | const uint32_t *bitmap, | |
675 | const struct timespec64 *time) | |
676 | { | |
677 | if (!(bitmap[2] & FATTR4_WORD2_TIME_DELEG_MODIFY)) | |
678 | return 0; | |
679 | return encode_attr_time(xdr,time); | |
680 | } | |
681 | ||
e6f684f6 | 682 | static __be32 encode_compound_hdr_res(struct xdr_stream *xdr, struct cb_compound_hdr_res *hdr) |
1da177e4 | 683 | { |
e6f684f6 | 684 | __be32 status; |
1da177e4 LT |
685 | |
686 | hdr->status = xdr_reserve_space(xdr, 4); | |
687 | if (unlikely(hdr->status == NULL)) | |
688 | return htonl(NFS4ERR_RESOURCE); | |
689 | status = encode_string(xdr, hdr->taglen, hdr->tag); | |
690 | if (unlikely(status != 0)) | |
691 | return status; | |
692 | hdr->nops = xdr_reserve_space(xdr, 4); | |
693 | if (unlikely(hdr->nops == NULL)) | |
694 | return htonl(NFS4ERR_RESOURCE); | |
695 | return 0; | |
696 | } | |
697 | ||
e6f684f6 | 698 | static __be32 encode_op_hdr(struct xdr_stream *xdr, uint32_t op, __be32 res) |
1da177e4 | 699 | { |
5704fdeb | 700 | __be32 *p; |
1da177e4 LT |
701 | |
702 | p = xdr_reserve_space(xdr, 8); | |
703 | if (unlikely(p == NULL)) | |
31d2b435 | 704 | return htonl(NFS4ERR_RESOURCE_HDR); |
1da177e4 LT |
705 | *p++ = htonl(op); |
706 | *p = res; | |
707 | return 0; | |
708 | } | |
709 | ||
f4dac4ad CH |
710 | static __be32 encode_getattr_res(struct svc_rqst *rqstp, struct xdr_stream *xdr, |
711 | const void *resp) | |
1da177e4 | 712 | { |
f4dac4ad | 713 | const struct cb_getattrres *res = resp; |
5704fdeb | 714 | __be32 *savep = NULL; |
e6f684f6 | 715 | __be32 status = res->status; |
1da177e4 LT |
716 | |
717 | if (unlikely(status != 0)) | |
718 | goto out; | |
8b064946 | 719 | status = encode_attr_bitmap(xdr, res->bitmap, ARRAY_SIZE(res->bitmap)); |
1da177e4 LT |
720 | if (unlikely(status != 0)) |
721 | goto out; | |
8b064946 TM |
722 | status = cpu_to_be32(NFS4ERR_RESOURCE); |
723 | savep = xdr_reserve_space(xdr, sizeof(*savep)); | |
724 | if (unlikely(!savep)) | |
725 | goto out; | |
1da177e4 LT |
726 | status = encode_attr_change(xdr, res->bitmap, res->change_attr); |
727 | if (unlikely(status != 0)) | |
728 | goto out; | |
729 | status = encode_attr_size(xdr, res->bitmap, res->size); | |
43df7110 TM |
730 | if (unlikely(status != 0)) |
731 | goto out; | |
732 | status = encode_attr_atime(xdr, res->bitmap, &res->atime); | |
1da177e4 LT |
733 | if (unlikely(status != 0)) |
734 | goto out; | |
735 | status = encode_attr_ctime(xdr, res->bitmap, &res->ctime); | |
736 | if (unlikely(status != 0)) | |
737 | goto out; | |
738 | status = encode_attr_mtime(xdr, res->bitmap, &res->mtime); | |
43df7110 TM |
739 | if (unlikely(status != 0)) |
740 | goto out; | |
741 | status = encode_attr_delegatime(xdr, res->bitmap, &res->atime); | |
742 | if (unlikely(status != 0)) | |
743 | goto out; | |
744 | status = encode_attr_delegmtime(xdr, res->bitmap, &res->mtime); | |
1da177e4 LT |
745 | *savep = htonl((unsigned int)((char *)xdr->p - (char *)(savep+1))); |
746 | out: | |
1da177e4 LT |
747 | return status; |
748 | } | |
749 | ||
34bc47c9 BH |
750 | #if defined(CONFIG_NFS_V4_1) |
751 | ||
9733f0d9 | 752 | static __be32 encode_sessionid(struct xdr_stream *xdr, |
4aece6a1 BH |
753 | const struct nfs4_sessionid *sid) |
754 | { | |
9733f0d9 | 755 | __be32 *p; |
4aece6a1 | 756 | |
590184a6 | 757 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN); |
4aece6a1 BH |
758 | if (unlikely(p == NULL)) |
759 | return htonl(NFS4ERR_RESOURCE); | |
760 | ||
590184a6 | 761 | memcpy(p, sid, NFS4_MAX_SESSIONID_LEN); |
4aece6a1 BH |
762 | return 0; |
763 | } | |
764 | ||
9733f0d9 | 765 | static __be32 encode_cb_sequence_res(struct svc_rqst *rqstp, |
4aece6a1 | 766 | struct xdr_stream *xdr, |
f4dac4ad | 767 | const void *resp) |
4aece6a1 | 768 | { |
f4dac4ad | 769 | const struct cb_sequenceres *res = resp; |
9733f0d9 | 770 | __be32 *p; |
e216c8c7 | 771 | __be32 status = res->csr_status; |
4aece6a1 BH |
772 | |
773 | if (unlikely(status != 0)) | |
3d0bfaa6 | 774 | return status; |
4aece6a1 | 775 | |
e0a63c0b KM |
776 | status = encode_sessionid(xdr, &res->csr_sessionid); |
777 | if (status) | |
3d0bfaa6 | 778 | return status; |
4aece6a1 BH |
779 | |
780 | p = xdr_reserve_space(xdr, 4 * sizeof(uint32_t)); | |
781 | if (unlikely(p == NULL)) | |
782 | return htonl(NFS4ERR_RESOURCE); | |
783 | ||
784 | *p++ = htonl(res->csr_sequenceid); | |
785 | *p++ = htonl(res->csr_slotid); | |
786 | *p++ = htonl(res->csr_highestslotid); | |
787 | *p++ = htonl(res->csr_target_highestslotid); | |
3d0bfaa6 | 788 | return 0; |
4aece6a1 BH |
789 | } |
790 | ||
34bc47c9 BH |
791 | static __be32 |
792 | preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) | |
793 | { | |
281fe15d BH |
794 | if (op_nr == OP_CB_SEQUENCE) { |
795 | if (nop != 0) | |
796 | return htonl(NFS4ERR_SEQUENCE_POS); | |
797 | } else { | |
798 | if (nop == 0) | |
799 | return htonl(NFS4ERR_OP_NOT_IN_SESSION); | |
800 | } | |
801 | ||
34bc47c9 BH |
802 | switch (op_nr) { |
803 | case OP_CB_GETATTR: | |
804 | case OP_CB_RECALL: | |
4aece6a1 | 805 | case OP_CB_SEQUENCE: |
31f09607 | 806 | case OP_CB_RECALL_ANY: |
b9efa1b2 | 807 | case OP_CB_RECALL_SLOT: |
f2a62561 | 808 | case OP_CB_LAYOUTRECALL: |
1be5683b | 809 | case OP_CB_NOTIFY_DEVICEID: |
db783688 | 810 | case OP_CB_NOTIFY_LOCK: |
34bc47c9 BH |
811 | *op = &callback_ops[op_nr]; |
812 | break; | |
813 | ||
34bc47c9 BH |
814 | case OP_CB_NOTIFY: |
815 | case OP_CB_PUSH_DELEG: | |
34bc47c9 | 816 | case OP_CB_RECALLABLE_OBJ_AVAIL: |
34bc47c9 | 817 | case OP_CB_WANTS_CANCELLED: |
34bc47c9 BH |
818 | return htonl(NFS4ERR_NOTSUPP); |
819 | ||
820 | default: | |
821 | return htonl(NFS4ERR_OP_ILLEGAL); | |
822 | } | |
823 | ||
824 | return htonl(NFS_OK); | |
825 | } | |
826 | ||
810d82e6 TM |
827 | static void nfs4_callback_free_slot(struct nfs4_session *session, |
828 | struct nfs4_slot *slot) | |
42acd021 AA |
829 | { |
830 | struct nfs4_slot_table *tbl = &session->bc_slot_table; | |
831 | ||
832 | spin_lock(&tbl->slot_tbl_lock); | |
833 | /* | |
834 | * Let the state manager know callback processing done. | |
835 | * A single slot, so highest used slotid is either 0 or -1 | |
836 | */ | |
810d82e6 | 837 | nfs4_free_slot(tbl, slot); |
42acd021 AA |
838 | spin_unlock(&tbl->slot_tbl_lock); |
839 | } | |
840 | ||
55a67399 | 841 | static void nfs4_cb_free_slot(struct cb_process_state *cps) |
42acd021 | 842 | { |
810d82e6 TM |
843 | if (cps->slot) { |
844 | nfs4_callback_free_slot(cps->clp->cl_session, cps->slot); | |
845 | cps->slot = NULL; | |
846 | } | |
42acd021 AA |
847 | } |
848 | ||
34bc47c9 BH |
849 | #else /* CONFIG_NFS_V4_1 */ |
850 | ||
851 | static __be32 | |
852 | preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) | |
853 | { | |
854 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); | |
855 | } | |
856 | ||
55a67399 | 857 | static void nfs4_cb_free_slot(struct cb_process_state *cps) |
42acd021 AA |
858 | { |
859 | } | |
34bc47c9 BH |
860 | #endif /* CONFIG_NFS_V4_1 */ |
861 | ||
6b140b85 BS |
862 | #ifdef CONFIG_NFS_V4_2 |
863 | static __be32 | |
864 | preprocess_nfs42_op(int nop, unsigned int op_nr, struct callback_op **op) | |
865 | { | |
866 | __be32 status = preprocess_nfs41_op(nop, op_nr, op); | |
867 | if (status != htonl(NFS4ERR_OP_ILLEGAL)) | |
868 | return status; | |
869 | ||
5178a125 OK |
870 | if (op_nr == OP_CB_OFFLOAD) { |
871 | *op = &callback_ops[op_nr]; | |
872 | return htonl(NFS_OK); | |
873 | } else | |
6b140b85 BS |
874 | return htonl(NFS4ERR_NOTSUPP); |
875 | return htonl(NFS4ERR_OP_ILLEGAL); | |
876 | } | |
877 | #else /* CONFIG_NFS_V4_2 */ | |
878 | static __be32 | |
879 | preprocess_nfs42_op(int nop, unsigned int op_nr, struct callback_op **op) | |
880 | { | |
881 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); | |
882 | } | |
883 | #endif /* CONFIG_NFS_V4_2 */ | |
884 | ||
34bc47c9 BH |
885 | static __be32 |
886 | preprocess_nfs4_op(unsigned int op_nr, struct callback_op **op) | |
887 | { | |
888 | switch (op_nr) { | |
889 | case OP_CB_GETATTR: | |
890 | case OP_CB_RECALL: | |
891 | *op = &callback_ops[op_nr]; | |
892 | break; | |
893 | default: | |
894 | return htonl(NFS4ERR_OP_ILLEGAL); | |
895 | } | |
896 | ||
897 | return htonl(NFS_OK); | |
898 | } | |
899 | ||
459de2ed | 900 | static __be32 process_op(int nop, struct svc_rqst *rqstp, |
9eff97ab | 901 | struct cb_process_state *cps) |
1da177e4 | 902 | { |
9eff97ab | 903 | struct xdr_stream *xdr_out = &rqstp->rq_res_stream; |
a162a6b8 | 904 | struct callback_op *op = &callback_ops[0]; |
31d2b435 | 905 | unsigned int op_nr; |
34bc47c9 | 906 | __be32 status; |
1da177e4 | 907 | long maxlen; |
e6f684f6 | 908 | __be32 res; |
1da177e4 | 909 | |
9eff97ab | 910 | status = decode_op_hdr(&rqstp->rq_arg_stream, &op_nr); |
31d2b435 AA |
911 | if (unlikely(status)) |
912 | return status; | |
1da177e4 | 913 | |
6b140b85 BS |
914 | switch (cps->minorversion) { |
915 | case 0: | |
916 | status = preprocess_nfs4_op(op_nr, &op); | |
917 | break; | |
918 | case 1: | |
919 | status = preprocess_nfs41_op(nop, op_nr, &op); | |
920 | break; | |
921 | case 2: | |
922 | status = preprocess_nfs42_op(nop, op_nr, &op); | |
923 | break; | |
924 | default: | |
925 | status = htonl(NFS4ERR_MINOR_VERS_MISMATCH); | |
926 | } | |
34bc47c9 | 927 | |
34bc47c9 BH |
928 | if (status == htonl(NFS4ERR_OP_ILLEGAL)) |
929 | op_nr = OP_CB_ILLEGAL; | |
b92b3019 AA |
930 | if (status) |
931 | goto encode_hdr; | |
31d2b435 | 932 | |
c36fca52 AA |
933 | if (cps->drc_status) { |
934 | status = cps->drc_status; | |
4911096f AA |
935 | goto encode_hdr; |
936 | } | |
937 | ||
1da177e4 LT |
938 | maxlen = xdr_out->end - xdr_out->p; |
939 | if (maxlen > 0 && maxlen < PAGE_SIZE) { | |
9eff97ab CL |
940 | status = op->decode_args(rqstp, &rqstp->rq_arg_stream, |
941 | rqstp->rq_argp); | |
e95e60da | 942 | if (likely(status == 0)) |
9eff97ab CL |
943 | status = op->process_op(rqstp->rq_argp, rqstp->rq_resp, |
944 | cps); | |
1da177e4 LT |
945 | } else |
946 | status = htonl(NFS4ERR_RESOURCE); | |
947 | ||
b92b3019 | 948 | encode_hdr: |
1da177e4 | 949 | res = encode_op_hdr(xdr_out, op_nr, status); |
31d2b435 AA |
950 | if (unlikely(res)) |
951 | return res; | |
1da177e4 | 952 | if (op->encode_res != NULL && status == 0) |
9eff97ab | 953 | status = op->encode_res(rqstp, xdr_out, rqstp->rq_resp); |
1da177e4 LT |
954 | return status; |
955 | } | |
956 | ||
957 | /* | |
958 | * Decode, process and encode a COMPOUND | |
959 | */ | |
a6beb732 | 960 | static __be32 nfs4_callback_compound(struct svc_rqst *rqstp) |
1da177e4 | 961 | { |
3a6258e1 TM |
962 | struct cb_compound_hdr_arg hdr_arg = { 0 }; |
963 | struct cb_compound_hdr_res hdr_res = { NULL }; | |
c36fca52 AA |
964 | struct cb_process_state cps = { |
965 | .drc_status = 0, | |
966 | .clp = NULL, | |
9695c705 | 967 | .net = SVC_NET(rqstp), |
c36fca52 | 968 | }; |
3a6258e1 | 969 | unsigned int nops = 0; |
89ef17b6 | 970 | __be32 status; |
1da177e4 | 971 | |
89ef17b6 | 972 | status = decode_compound_hdr_arg(&rqstp->rq_arg_stream, &hdr_arg); |
4ed0d83d | 973 | if (status == htonl(NFS4ERR_RESOURCE)) |
3a6258e1 TM |
974 | return rpc_garbage_args; |
975 | ||
c36fca52 | 976 | if (hdr_arg.minorversion == 0) { |
9695c705 | 977 | cps.clp = nfs4_find_client_ident(SVC_NET(rqstp), hdr_arg.cb_ident); |
2bb50aab CL |
978 | if (!cps.clp) { |
979 | trace_nfs_cb_no_clp(rqstp->rq_xid, hdr_arg.cb_ident); | |
980 | goto out_invalidcred; | |
981 | } | |
982 | if (!check_gss_callback_principal(cps.clp, rqstp)) { | |
983 | trace_nfs_cb_badprinc(rqstp->rq_xid, hdr_arg.cb_ident); | |
984 | nfs_put_client(cps.clp); | |
a4e187d8 | 985 | goto out_invalidcred; |
32cd3ee5 | 986 | } |
eccbbc7c | 987 | svc_xprt_set_valid(rqstp->rq_xprt); |
778be232 | 988 | } |
c36fca52 | 989 | |
459de2ed | 990 | cps.minorversion = hdr_arg.minorversion; |
1da177e4 LT |
991 | hdr_res.taglen = hdr_arg.taglen; |
992 | hdr_res.tag = hdr_arg.tag; | |
89ef17b6 | 993 | if (encode_compound_hdr_res(&rqstp->rq_res_stream, &hdr_res) != 0) { |
32cd3ee5 OK |
994 | if (cps.clp) |
995 | nfs_put_client(cps.clp); | |
3a6258e1 | 996 | return rpc_system_err; |
32cd3ee5 | 997 | } |
3a6258e1 | 998 | while (status == 0 && nops != hdr_arg.nops) { |
9eff97ab | 999 | status = process_op(nops, rqstp, &cps); |
1da177e4 LT |
1000 | nops++; |
1001 | } | |
3a6258e1 | 1002 | |
31d2b435 AA |
1003 | /* Buffer overflow in decode_ops_hdr or encode_ops_hdr. Return |
1004 | * resource error in cb_compound status without returning op */ | |
1005 | if (unlikely(status == htonl(NFS4ERR_RESOURCE_HDR))) { | |
1006 | status = htonl(NFS4ERR_RESOURCE); | |
1007 | nops--; | |
1008 | } | |
1009 | ||
57331a59 BC |
1010 | if (svc_is_backchannel(rqstp) && cps.clp) { |
1011 | rqstp->bc_to_initval = cps.clp->cl_rpcclient->cl_timeout->to_initval; | |
1012 | rqstp->bc_to_retries = cps.clp->cl_rpcclient->cl_timeout->to_retries; | |
1013 | } | |
1014 | ||
1da177e4 LT |
1015 | *hdr_res.status = status; |
1016 | *hdr_res.nops = htonl(nops); | |
55a67399 | 1017 | nfs4_cb_free_slot(&cps); |
c36fca52 | 1018 | nfs_put_client(cps.clp); |
1da177e4 | 1019 | return rpc_success; |
a4e187d8 CL |
1020 | |
1021 | out_invalidcred: | |
1022 | pr_warn_ratelimited("NFS: NFSv4 callback contains invalid cred\n"); | |
9082e1d9 CL |
1023 | rqstp->rq_auth_stat = rpc_autherr_badcred; |
1024 | return rpc_success; | |
1da177e4 LT |
1025 | } |
1026 | ||
7d34c962 | 1027 | static int |
cee4db19 | 1028 | nfs_callback_dispatch(struct svc_rqst *rqstp) |
7d34c962 CL |
1029 | { |
1030 | const struct svc_procedure *procp = rqstp->rq_procinfo; | |
1031 | ||
cee4db19 | 1032 | *rqstp->rq_accept_statp = procp->pc_func(rqstp); |
7d34c962 CL |
1033 | return 1; |
1034 | } | |
1035 | ||
1da177e4 LT |
1036 | /* |
1037 | * Define NFS4 callback COMPOUND ops. | |
1038 | */ | |
1039 | static struct callback_op callback_ops[] = { | |
1040 | [0] = { | |
1041 | .res_maxsize = CB_OP_HDR_RES_MAXSZ, | |
1042 | }, | |
1043 | [OP_CB_GETATTR] = { | |
f4dac4ad CH |
1044 | .process_op = nfs4_callback_getattr, |
1045 | .decode_args = decode_getattr_args, | |
1046 | .encode_res = encode_getattr_res, | |
1da177e4 LT |
1047 | .res_maxsize = CB_OP_GETATTR_RES_MAXSZ, |
1048 | }, | |
1049 | [OP_CB_RECALL] = { | |
f4dac4ad CH |
1050 | .process_op = nfs4_callback_recall, |
1051 | .decode_args = decode_recall_args, | |
1da177e4 | 1052 | .res_maxsize = CB_OP_RECALL_RES_MAXSZ, |
4aece6a1 BH |
1053 | }, |
1054 | #if defined(CONFIG_NFS_V4_1) | |
f2a62561 | 1055 | [OP_CB_LAYOUTRECALL] = { |
f4dac4ad CH |
1056 | .process_op = nfs4_callback_layoutrecall, |
1057 | .decode_args = decode_layoutrecall_args, | |
f2a62561 FI |
1058 | .res_maxsize = CB_OP_LAYOUTRECALL_RES_MAXSZ, |
1059 | }, | |
1be5683b | 1060 | [OP_CB_NOTIFY_DEVICEID] = { |
f4dac4ad CH |
1061 | .process_op = nfs4_callback_devicenotify, |
1062 | .decode_args = decode_devicenotify_args, | |
1be5683b ME |
1063 | .res_maxsize = CB_OP_DEVICENOTIFY_RES_MAXSZ, |
1064 | }, | |
4aece6a1 | 1065 | [OP_CB_SEQUENCE] = { |
f4dac4ad CH |
1066 | .process_op = nfs4_callback_sequence, |
1067 | .decode_args = decode_cb_sequence_args, | |
1068 | .encode_res = encode_cb_sequence_res, | |
4aece6a1 BH |
1069 | .res_maxsize = CB_OP_SEQUENCE_RES_MAXSZ, |
1070 | }, | |
31f09607 | 1071 | [OP_CB_RECALL_ANY] = { |
f4dac4ad CH |
1072 | .process_op = nfs4_callback_recallany, |
1073 | .decode_args = decode_recallany_args, | |
31f09607 AB |
1074 | .res_maxsize = CB_OP_RECALLANY_RES_MAXSZ, |
1075 | }, | |
b9efa1b2 | 1076 | [OP_CB_RECALL_SLOT] = { |
f4dac4ad CH |
1077 | .process_op = nfs4_callback_recallslot, |
1078 | .decode_args = decode_recallslot_args, | |
b9efa1b2 AA |
1079 | .res_maxsize = CB_OP_RECALLSLOT_RES_MAXSZ, |
1080 | }, | |
db783688 | 1081 | [OP_CB_NOTIFY_LOCK] = { |
f4dac4ad CH |
1082 | .process_op = nfs4_callback_notify_lock, |
1083 | .decode_args = decode_notify_lock_args, | |
db783688 JL |
1084 | .res_maxsize = CB_OP_NOTIFY_LOCK_RES_MAXSZ, |
1085 | }, | |
4aece6a1 | 1086 | #endif /* CONFIG_NFS_V4_1 */ |
5178a125 OK |
1087 | #ifdef CONFIG_NFS_V4_2 |
1088 | [OP_CB_OFFLOAD] = { | |
1089 | .process_op = nfs4_callback_offload, | |
1090 | .decode_args = decode_offload_args, | |
1091 | .res_maxsize = CB_OP_OFFLOAD_RES_MAXSZ, | |
1092 | }, | |
1093 | #endif /* CONFIG_NFS_V4_2 */ | |
1da177e4 LT |
1094 | }; |
1095 | ||
1096 | /* | |
1097 | * Define NFS4 callback procedures | |
1098 | */ | |
860bda29 | 1099 | static const struct svc_procedure nfs4_callback_procedures1[] = { |
1da177e4 LT |
1100 | [CB_NULL] = { |
1101 | .pc_func = nfs4_callback_null, | |
63f8de37 | 1102 | .pc_encode = nfs4_encode_void, |
1da177e4 | 1103 | .pc_xdrressize = 1, |
2289e87b | 1104 | .pc_name = "NULL", |
1da177e4 LT |
1105 | }, |
1106 | [CB_COMPOUND] = { | |
1107 | .pc_func = nfs4_callback_compound, | |
63f8de37 | 1108 | .pc_encode = nfs4_encode_void, |
1da177e4 | 1109 | .pc_argsize = 256, |
103cc1fa | 1110 | .pc_argzero = 256, |
1da177e4 LT |
1111 | .pc_ressize = 256, |
1112 | .pc_xdrressize = NFS4_CALLBACK_BUFSIZE, | |
2289e87b | 1113 | .pc_name = "COMPOUND", |
1da177e4 LT |
1114 | } |
1115 | }; | |
1116 | ||
65ba3d24 CL |
1117 | static DEFINE_PER_CPU_ALIGNED(unsigned long, |
1118 | nfs4_callback_count1[ARRAY_SIZE(nfs4_callback_procedures1)]); | |
e9679189 | 1119 | const struct svc_version nfs4_callback_version1 = { |
1da177e4 LT |
1120 | .vs_vers = 1, |
1121 | .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1), | |
1122 | .vs_proc = nfs4_callback_procedures1, | |
7fd38af9 | 1123 | .vs_count = nfs4_callback_count1, |
1da177e4 | 1124 | .vs_xdrsize = NFS4_CALLBACK_XDRSIZE, |
7d34c962 | 1125 | .vs_dispatch = nfs_callback_dispatch, |
05a45a2d | 1126 | .vs_hidden = true, |
5283b03e | 1127 | .vs_need_cong_ctrl = true, |
1da177e4 LT |
1128 | }; |
1129 | ||
65ba3d24 CL |
1130 | static DEFINE_PER_CPU_ALIGNED(unsigned long, |
1131 | nfs4_callback_count4[ARRAY_SIZE(nfs4_callback_procedures1)]); | |
e9679189 | 1132 | const struct svc_version nfs4_callback_version4 = { |
07bccc2d AB |
1133 | .vs_vers = 4, |
1134 | .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1), | |
1135 | .vs_proc = nfs4_callback_procedures1, | |
7fd38af9 | 1136 | .vs_count = nfs4_callback_count4, |
07bccc2d | 1137 | .vs_xdrsize = NFS4_CALLBACK_XDRSIZE, |
7d34c962 | 1138 | .vs_dispatch = nfs_callback_dispatch, |
05a45a2d | 1139 | .vs_hidden = true, |
5283b03e | 1140 | .vs_need_cong_ctrl = true, |
07bccc2d | 1141 | }; |