Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/callback_xdr.c |
| 3 | * |
| 4 | * Copyright (C) 2004 Trond Myklebust |
| 5 | * |
| 6 | * NFSv4 callback encode/decode procedures |
| 7 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/kernel.h> |
| 9 | #include <linux/sunrpc/svc.h> |
| 10 | #include <linux/nfs4.h> |
| 11 | #include <linux/nfs_fs.h> |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 12 | #include <linux/ratelimit.h> |
| 13 | #include <linux/printk.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 15 | #include <linux/sunrpc/bc_xprt.h> |
Trond Myklebust | 4ce7971 | 2005-06-22 17:16:21 +0000 | [diff] [blame] | 16 | #include "nfs4_fs.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include "callback.h" |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 18 | #include "internal.h" |
Trond Myklebust | 76e697b | 2012-11-26 14:20:49 -0500 | [diff] [blame] | 19 | #include "nfs4session.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Kinglong Mee | 45724e8 | 2015-09-24 20:57:58 +0800 | [diff] [blame] | 21 | #define CB_OP_TAGLEN_MAXSZ (512) |
| 22 | #define CB_OP_HDR_RES_MAXSZ (2 * 4) // opcode, status |
| 23 | #define CB_OP_GETATTR_BITMAP_MAXSZ (4 * 4) // bitmap length, 3 bitmaps |
| 24 | #define CB_OP_GETATTR_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \ |
| 25 | CB_OP_GETATTR_BITMAP_MAXSZ + \ |
| 26 | /* change, size, ctime, mtime */\ |
| 27 | (2 + 2 + 3 + 3) * 4) |
| 28 | #define CB_OP_RECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 30 | #if defined(CONFIG_NFS_V4_1) |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 31 | #define CB_OP_LAYOUTRECALL_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
Marc Eshel | 1be5683 | 2011-05-22 19:47:09 +0300 | [diff] [blame] | 32 | #define CB_OP_DEVICENOTIFY_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 33 | #define CB_OP_SEQUENCE_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ + \ |
Kinglong Mee | 45724e8 | 2015-09-24 20:57:58 +0800 | [diff] [blame] | 34 | NFS4_MAX_SESSIONID_LEN + \ |
| 35 | (1 + 3) * 4) // seqid, 3 slotids |
Alexandros Batsakis | 31f0960 | 2009-12-05 13:27:02 -0500 | [diff] [blame] | 36 | #define CB_OP_RECALLANY_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 37 | #define CB_OP_RECALLSLOT_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
Jeff Layton | db78368 | 2016-09-17 18:17:36 -0400 | [diff] [blame] | 38 | #define CB_OP_NOTIFY_LOCK_RES_MAXSZ (CB_OP_HDR_RES_MAXSZ) |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 39 | #endif /* CONFIG_NFS_V4_1 */ |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define NFSDBG_FACILITY NFSDBG_CALLBACK |
| 42 | |
Andy Adamson | 31d2b43 | 2010-01-14 17:45:04 -0500 | [diff] [blame] | 43 | /* Internal error code */ |
| 44 | #define NFS4ERR_RESOURCE_HDR 11050 |
| 45 | |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 46 | typedef __be32 (*callback_process_op_t)(void *, void *, |
| 47 | struct cb_process_state *); |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 48 | typedef __be32 (*callback_decode_arg_t)(struct svc_rqst *, struct xdr_stream *, void *); |
| 49 | typedef __be32 (*callback_encode_res_t)(struct svc_rqst *, struct xdr_stream *, void *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | |
| 52 | struct callback_op { |
| 53 | callback_process_op_t process_op; |
| 54 | callback_decode_arg_t decode_args; |
| 55 | callback_encode_res_t encode_res; |
| 56 | long res_maxsize; |
| 57 | }; |
| 58 | |
| 59 | static struct callback_op callback_ops[]; |
| 60 | |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 61 | static __be32 nfs4_callback_null(struct svc_rqst *rqstp, void *argp, void *resp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
| 63 | return htonl(NFS4_OK); |
| 64 | } |
| 65 | |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 66 | static int nfs4_decode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | { |
| 68 | return xdr_argsize_check(rqstp, p); |
| 69 | } |
| 70 | |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 71 | static int nfs4_encode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { |
| 73 | return xdr_ressize_check(rqstp, p); |
| 74 | } |
| 75 | |
Jeff Layton | b60475c | 2016-09-17 18:17:31 -0400 | [diff] [blame] | 76 | static __be32 *read_buf(struct xdr_stream *xdr, size_t nbytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 78 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | p = xdr_inline_decode(xdr, nbytes); |
| 81 | if (unlikely(p == NULL)) |
Trond Myklebust | 756b9b3 | 2015-12-07 12:52:23 -0800 | [diff] [blame] | 82 | printk(KERN_WARNING "NFS: NFSv4 callback reply buffer overflowed!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | return p; |
| 84 | } |
| 85 | |
Trond Myklebust | c065eee | 2017-02-19 16:08:28 -0500 | [diff] [blame] | 86 | static __be32 decode_string(struct xdr_stream *xdr, unsigned int *len, |
| 87 | const char **str, size_t maxlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | { |
Trond Myklebust | c065eee | 2017-02-19 16:08:28 -0500 | [diff] [blame] | 89 | ssize_t err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Trond Myklebust | c065eee | 2017-02-19 16:08:28 -0500 | [diff] [blame] | 91 | err = xdr_stream_decode_opaque_inline(xdr, (void **)str, maxlen); |
| 92 | if (err < 0) |
| 93 | return cpu_to_be32(NFS4ERR_RESOURCE); |
| 94 | *len = err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | return 0; |
| 96 | } |
| 97 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 98 | static __be32 decode_fh(struct xdr_stream *xdr, struct nfs_fh *fh) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 100 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | p = read_buf(xdr, 4); |
| 103 | if (unlikely(p == NULL)) |
| 104 | return htonl(NFS4ERR_RESOURCE); |
| 105 | fh->size = ntohl(*p); |
| 106 | if (fh->size > NFS4_FHSIZE) |
| 107 | return htonl(NFS4ERR_BADHANDLE); |
| 108 | p = read_buf(xdr, fh->size); |
| 109 | if (unlikely(p == NULL)) |
| 110 | return htonl(NFS4ERR_RESOURCE); |
| 111 | memcpy(&fh->data[0], p, fh->size); |
| 112 | memset(&fh->data[fh->size], 0, sizeof(fh->data) - fh->size); |
| 113 | return 0; |
| 114 | } |
| 115 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 116 | static __be32 decode_bitmap(struct xdr_stream *xdr, uint32_t *bitmap) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 118 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | unsigned int attrlen; |
| 120 | |
| 121 | p = read_buf(xdr, 4); |
| 122 | if (unlikely(p == NULL)) |
| 123 | return htonl(NFS4ERR_RESOURCE); |
| 124 | attrlen = ntohl(*p); |
| 125 | p = read_buf(xdr, attrlen << 2); |
| 126 | if (unlikely(p == NULL)) |
| 127 | return htonl(NFS4ERR_RESOURCE); |
| 128 | if (likely(attrlen > 0)) |
| 129 | bitmap[0] = ntohl(*p++); |
| 130 | if (attrlen > 1) |
| 131 | bitmap[1] = ntohl(*p); |
| 132 | return 0; |
| 133 | } |
| 134 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 135 | static __be32 decode_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 137 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Trond Myklebust | 2d2f24a | 2012-03-04 18:13:57 -0500 | [diff] [blame] | 139 | p = read_buf(xdr, NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | if (unlikely(p == NULL)) |
| 141 | return htonl(NFS4ERR_RESOURCE); |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 142 | memcpy(stateid->data, p, NFS4_STATEID_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 146 | static __be32 decode_delegation_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) |
| 147 | { |
| 148 | stateid->type = NFS4_DELEGATION_STATEID_TYPE; |
| 149 | return decode_stateid(xdr, stateid); |
| 150 | } |
| 151 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 152 | static __be32 decode_compound_hdr_arg(struct xdr_stream *xdr, struct cb_compound_hdr_arg *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 154 | __be32 *p; |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 155 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Trond Myklebust | c065eee | 2017-02-19 16:08:28 -0500 | [diff] [blame] | 157 | status = decode_string(xdr, &hdr->taglen, &hdr->tag, CB_OP_TAGLEN_MAXSZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | if (unlikely(status != 0)) |
| 159 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | p = read_buf(xdr, 12); |
| 161 | if (unlikely(p == NULL)) |
| 162 | return htonl(NFS4ERR_RESOURCE); |
Benny Halevy | b8f2ef8 | 2009-04-01 09:23:19 -0400 | [diff] [blame] | 163 | hdr->minorversion = ntohl(*p++); |
Bryan Schumaker | 459de2e | 2013-06-05 11:15:01 -0400 | [diff] [blame] | 164 | /* Check for minor version support */ |
| 165 | if (hdr->minorversion <= NFS4_MAX_MINOR_VERSION) { |
Steve Dickson | 42c2c42 | 2013-05-22 12:50:38 -0400 | [diff] [blame] | 166 | hdr->cb_ident = ntohl(*p++); /* ignored by v4.1 and v4.2 */ |
Benny Halevy | 48a9e2d | 2009-04-01 09:23:20 -0400 | [diff] [blame] | 167 | } else { |
Trond Myklebust | 9a3ba43 | 2012-03-12 18:01:48 -0400 | [diff] [blame] | 168 | pr_warn_ratelimited("NFS: %s: NFSv4 server callback with " |
Benny Halevy | b8f2ef8 | 2009-04-01 09:23:19 -0400 | [diff] [blame] | 169 | "illegal minor version %u!\n", |
| 170 | __func__, hdr->minorversion); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); |
| 172 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | hdr->nops = ntohl(*p); |
Benny Halevy | b8f2ef8 | 2009-04-01 09:23:19 -0400 | [diff] [blame] | 174 | dprintk("%s: minorversion %d nops %d\n", __func__, |
| 175 | hdr->minorversion, hdr->nops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 179 | static __be32 decode_op_hdr(struct xdr_stream *xdr, unsigned int *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 181 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | p = read_buf(xdr, 4); |
| 183 | if (unlikely(p == NULL)) |
Andy Adamson | 31d2b43 | 2010-01-14 17:45:04 -0500 | [diff] [blame] | 184 | return htonl(NFS4ERR_RESOURCE_HDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | *op = ntohl(*p); |
| 186 | return 0; |
| 187 | } |
| 188 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 189 | static __be32 decode_getattr_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_getattrargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 191 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | status = decode_fh(xdr, &args->fh); |
| 194 | if (unlikely(status != 0)) |
Anna Schumaker | 56938bb | 2017-04-07 14:14:58 -0400 | [diff] [blame] | 195 | return status; |
| 196 | return decode_bitmap(xdr, args->bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 199 | static __be32 decode_recall_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_recallargs *args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 201 | __be32 *p; |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 202 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 204 | status = decode_delegation_stateid(xdr, &args->stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | if (unlikely(status != 0)) |
Anna Schumaker | 135a4ea | 2017-04-07 14:14:59 -0400 | [diff] [blame] | 206 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | p = read_buf(xdr, 4); |
Anna Schumaker | 135a4ea | 2017-04-07 14:14:59 -0400 | [diff] [blame] | 208 | if (unlikely(p == NULL)) |
| 209 | return htonl(NFS4ERR_RESOURCE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | args->truncate = ntohl(*p); |
Anna Schumaker | 135a4ea | 2017-04-07 14:14:59 -0400 | [diff] [blame] | 211 | return decode_fh(xdr, &args->fh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 214 | #if defined(CONFIG_NFS_V4_1) |
Trond Myklebust | 93b717f | 2016-05-16 17:42:43 -0400 | [diff] [blame] | 215 | static __be32 decode_layout_stateid(struct xdr_stream *xdr, nfs4_stateid *stateid) |
| 216 | { |
| 217 | stateid->type = NFS4_LAYOUT_STATEID_TYPE; |
| 218 | return decode_stateid(xdr, stateid); |
| 219 | } |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 220 | |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 221 | static __be32 decode_layoutrecall_args(struct svc_rqst *rqstp, |
| 222 | struct xdr_stream *xdr, |
| 223 | struct cb_layoutrecallargs *args) |
| 224 | { |
| 225 | __be32 *p; |
| 226 | __be32 status = 0; |
| 227 | uint32_t iomode; |
| 228 | |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 229 | p = read_buf(xdr, 4 * sizeof(uint32_t)); |
Anna Schumaker | c79d56d | 2017-04-07 14:15:00 -0400 | [diff] [blame] | 230 | if (unlikely(p == NULL)) |
| 231 | return htonl(NFS4ERR_BADXDR); |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 232 | |
| 233 | args->cbl_layout_type = ntohl(*p++); |
| 234 | /* Depite the spec's xdr, iomode really belongs in the FILE switch, |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 235 | * as it is unusable and ignored with the other types. |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 236 | */ |
| 237 | iomode = ntohl(*p++); |
| 238 | args->cbl_layoutchanged = ntohl(*p++); |
| 239 | args->cbl_recall_type = ntohl(*p++); |
| 240 | |
| 241 | if (args->cbl_recall_type == RETURN_FILE) { |
| 242 | args->cbl_range.iomode = iomode; |
| 243 | status = decode_fh(xdr, &args->cbl_fh); |
| 244 | if (unlikely(status != 0)) |
Anna Schumaker | c79d56d | 2017-04-07 14:15:00 -0400 | [diff] [blame] | 245 | return status; |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 246 | |
| 247 | p = read_buf(xdr, 2 * sizeof(uint64_t)); |
Anna Schumaker | c79d56d | 2017-04-07 14:15:00 -0400 | [diff] [blame] | 248 | if (unlikely(p == NULL)) |
| 249 | return htonl(NFS4ERR_BADXDR); |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 250 | p = xdr_decode_hyper(p, &args->cbl_range.offset); |
| 251 | p = xdr_decode_hyper(p, &args->cbl_range.length); |
Anna Schumaker | c79d56d | 2017-04-07 14:15:00 -0400 | [diff] [blame] | 252 | return decode_layout_stateid(xdr, &args->cbl_stateid); |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 253 | } else if (args->cbl_recall_type == RETURN_FSID) { |
| 254 | p = read_buf(xdr, 2 * sizeof(uint64_t)); |
Anna Schumaker | c79d56d | 2017-04-07 14:15:00 -0400 | [diff] [blame] | 255 | if (unlikely(p == NULL)) |
| 256 | return htonl(NFS4ERR_BADXDR); |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 257 | p = xdr_decode_hyper(p, &args->cbl_fsid.major); |
| 258 | p = xdr_decode_hyper(p, &args->cbl_fsid.minor); |
Anna Schumaker | c79d56d | 2017-04-07 14:15:00 -0400 | [diff] [blame] | 259 | } else if (args->cbl_recall_type != RETURN_ALL) |
| 260 | return htonl(NFS4ERR_BADXDR); |
| 261 | return 0; |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Marc Eshel | 1be5683 | 2011-05-22 19:47:09 +0300 | [diff] [blame] | 264 | static |
| 265 | __be32 decode_devicenotify_args(struct svc_rqst *rqstp, |
| 266 | struct xdr_stream *xdr, |
| 267 | struct cb_devicenotifyargs *args) |
| 268 | { |
| 269 | __be32 *p; |
| 270 | __be32 status = 0; |
| 271 | u32 tmp; |
| 272 | int n, i; |
| 273 | args->ndevs = 0; |
| 274 | |
| 275 | /* Num of device notifications */ |
| 276 | p = read_buf(xdr, sizeof(uint32_t)); |
| 277 | if (unlikely(p == NULL)) { |
| 278 | status = htonl(NFS4ERR_BADXDR); |
| 279 | goto out; |
| 280 | } |
| 281 | n = ntohl(*p++); |
| 282 | if (n <= 0) |
| 283 | goto out; |
Dan Carpenter | 363e0df0 | 2012-01-12 10:16:14 +0300 | [diff] [blame] | 284 | if (n > ULONG_MAX / sizeof(*args->devs)) { |
| 285 | status = htonl(NFS4ERR_BADXDR); |
| 286 | goto out; |
| 287 | } |
Marc Eshel | 1be5683 | 2011-05-22 19:47:09 +0300 | [diff] [blame] | 288 | |
Trond Myklebust | a4f743a | 2015-02-11 17:49:13 -0500 | [diff] [blame] | 289 | args->devs = kmalloc_array(n, sizeof(*args->devs), GFP_KERNEL); |
Marc Eshel | 1be5683 | 2011-05-22 19:47:09 +0300 | [diff] [blame] | 290 | if (!args->devs) { |
| 291 | status = htonl(NFS4ERR_DELAY); |
| 292 | goto out; |
| 293 | } |
| 294 | |
| 295 | /* Decode each dev notification */ |
| 296 | for (i = 0; i < n; i++) { |
| 297 | struct cb_devicenotifyitem *dev = &args->devs[i]; |
| 298 | |
| 299 | p = read_buf(xdr, (4 * sizeof(uint32_t)) + NFS4_DEVICEID4_SIZE); |
| 300 | if (unlikely(p == NULL)) { |
| 301 | status = htonl(NFS4ERR_BADXDR); |
| 302 | goto err; |
| 303 | } |
| 304 | |
| 305 | tmp = ntohl(*p++); /* bitmap size */ |
| 306 | if (tmp != 1) { |
| 307 | status = htonl(NFS4ERR_INVAL); |
| 308 | goto err; |
| 309 | } |
| 310 | dev->cbd_notify_type = ntohl(*p++); |
| 311 | if (dev->cbd_notify_type != NOTIFY_DEVICEID4_CHANGE && |
| 312 | dev->cbd_notify_type != NOTIFY_DEVICEID4_DELETE) { |
| 313 | status = htonl(NFS4ERR_INVAL); |
| 314 | goto err; |
| 315 | } |
| 316 | |
| 317 | tmp = ntohl(*p++); /* opaque size */ |
| 318 | if (((dev->cbd_notify_type == NOTIFY_DEVICEID4_CHANGE) && |
| 319 | (tmp != NFS4_DEVICEID4_SIZE + 8)) || |
| 320 | ((dev->cbd_notify_type == NOTIFY_DEVICEID4_DELETE) && |
| 321 | (tmp != NFS4_DEVICEID4_SIZE + 4))) { |
| 322 | status = htonl(NFS4ERR_INVAL); |
| 323 | goto err; |
| 324 | } |
| 325 | dev->cbd_layout_type = ntohl(*p++); |
| 326 | memcpy(dev->cbd_dev_id.data, p, NFS4_DEVICEID4_SIZE); |
| 327 | p += XDR_QUADLEN(NFS4_DEVICEID4_SIZE); |
| 328 | |
| 329 | if (dev->cbd_layout_type == NOTIFY_DEVICEID4_CHANGE) { |
| 330 | p = read_buf(xdr, sizeof(uint32_t)); |
| 331 | if (unlikely(p == NULL)) { |
| 332 | status = htonl(NFS4ERR_BADXDR); |
| 333 | goto err; |
| 334 | } |
| 335 | dev->cbd_immediate = ntohl(*p++); |
| 336 | } else { |
| 337 | dev->cbd_immediate = 0; |
| 338 | } |
| 339 | |
| 340 | args->ndevs++; |
| 341 | |
| 342 | dprintk("%s: type %d layout 0x%x immediate %d\n", |
| 343 | __func__, dev->cbd_notify_type, dev->cbd_layout_type, |
| 344 | dev->cbd_immediate); |
| 345 | } |
| 346 | out: |
| 347 | dprintk("%s: status %d ndevs %d\n", |
| 348 | __func__, ntohl(status), args->ndevs); |
| 349 | return status; |
| 350 | err: |
| 351 | kfree(args->devs); |
| 352 | goto out; |
| 353 | } |
| 354 | |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 355 | static __be32 decode_sessionid(struct xdr_stream *xdr, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 356 | struct nfs4_sessionid *sid) |
| 357 | { |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 358 | __be32 *p; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 359 | |
Kinglong Mee | 590184a | 2015-09-24 20:57:37 +0800 | [diff] [blame] | 360 | p = read_buf(xdr, NFS4_MAX_SESSIONID_LEN); |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 361 | if (unlikely(p == NULL)) |
Joe Perches | a419aef | 2009-08-18 11:18:35 -0700 | [diff] [blame] | 362 | return htonl(NFS4ERR_RESOURCE); |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 363 | |
Kinglong Mee | 590184a | 2015-09-24 20:57:37 +0800 | [diff] [blame] | 364 | memcpy(sid->data, p, NFS4_MAX_SESSIONID_LEN); |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 365 | return 0; |
| 366 | } |
| 367 | |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 368 | static __be32 decode_rc_list(struct xdr_stream *xdr, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 369 | struct referring_call_list *rc_list) |
| 370 | { |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 371 | __be32 *p; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 372 | int i; |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 373 | __be32 status; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 374 | |
| 375 | status = decode_sessionid(xdr, &rc_list->rcl_sessionid); |
| 376 | if (status) |
| 377 | goto out; |
| 378 | |
| 379 | status = htonl(NFS4ERR_RESOURCE); |
| 380 | p = read_buf(xdr, sizeof(uint32_t)); |
| 381 | if (unlikely(p == NULL)) |
| 382 | goto out; |
| 383 | |
| 384 | rc_list->rcl_nrefcalls = ntohl(*p++); |
| 385 | if (rc_list->rcl_nrefcalls) { |
| 386 | p = read_buf(xdr, |
| 387 | rc_list->rcl_nrefcalls * 2 * sizeof(uint32_t)); |
| 388 | if (unlikely(p == NULL)) |
| 389 | goto out; |
Trond Myklebust | a4f743a | 2015-02-11 17:49:13 -0500 | [diff] [blame] | 390 | rc_list->rcl_refcalls = kmalloc_array(rc_list->rcl_nrefcalls, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 391 | sizeof(*rc_list->rcl_refcalls), |
| 392 | GFP_KERNEL); |
| 393 | if (unlikely(rc_list->rcl_refcalls == NULL)) |
| 394 | goto out; |
| 395 | for (i = 0; i < rc_list->rcl_nrefcalls; i++) { |
| 396 | rc_list->rcl_refcalls[i].rc_sequenceid = ntohl(*p++); |
| 397 | rc_list->rcl_refcalls[i].rc_slotid = ntohl(*p++); |
| 398 | } |
| 399 | } |
| 400 | status = 0; |
| 401 | |
| 402 | out: |
| 403 | return status; |
| 404 | } |
| 405 | |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 406 | static __be32 decode_cb_sequence_args(struct svc_rqst *rqstp, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 407 | struct xdr_stream *xdr, |
| 408 | struct cb_sequenceargs *args) |
| 409 | { |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 410 | __be32 *p; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 411 | int i; |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 412 | __be32 status; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 413 | |
| 414 | status = decode_sessionid(xdr, &args->csa_sessionid); |
| 415 | if (status) |
Anna Schumaker | 1796549 | 2017-04-07 14:15:01 -0400 | [diff] [blame^] | 416 | return status; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 417 | |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 418 | p = read_buf(xdr, 5 * sizeof(uint32_t)); |
| 419 | if (unlikely(p == NULL)) |
Anna Schumaker | 1796549 | 2017-04-07 14:15:01 -0400 | [diff] [blame^] | 420 | return htonl(NFS4ERR_RESOURCE); |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 421 | |
Ricardo Labiaga | 65fc64e | 2009-04-01 09:23:30 -0400 | [diff] [blame] | 422 | args->csa_addr = svc_addr(rqstp); |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 423 | args->csa_sequenceid = ntohl(*p++); |
| 424 | args->csa_slotid = ntohl(*p++); |
| 425 | args->csa_highestslotid = ntohl(*p++); |
| 426 | args->csa_cachethis = ntohl(*p++); |
| 427 | args->csa_nrclists = ntohl(*p++); |
| 428 | args->csa_rclists = NULL; |
| 429 | if (args->csa_nrclists) { |
Dan Carpenter | 0439f31 | 2012-06-12 10:37:08 +0300 | [diff] [blame] | 430 | args->csa_rclists = kmalloc_array(args->csa_nrclists, |
| 431 | sizeof(*args->csa_rclists), |
| 432 | GFP_KERNEL); |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 433 | if (unlikely(args->csa_rclists == NULL)) |
Anna Schumaker | 1796549 | 2017-04-07 14:15:01 -0400 | [diff] [blame^] | 434 | return htonl(NFS4ERR_RESOURCE); |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 435 | |
| 436 | for (i = 0; i < args->csa_nrclists; i++) { |
| 437 | status = decode_rc_list(xdr, &args->csa_rclists[i]); |
Trond Myklebust | d8ba1f9 | 2015-02-11 17:27:55 -0500 | [diff] [blame] | 438 | if (status) { |
| 439 | args->csa_nrclists = i; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 440 | goto out_free; |
Trond Myklebust | d8ba1f9 | 2015-02-11 17:27:55 -0500 | [diff] [blame] | 441 | } |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 442 | } |
| 443 | } |
Anna Schumaker | 1796549 | 2017-04-07 14:15:01 -0400 | [diff] [blame^] | 444 | return 0; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 445 | |
| 446 | out_free: |
| 447 | for (i = 0; i < args->csa_nrclists; i++) |
| 448 | kfree(args->csa_rclists[i].rcl_refcalls); |
| 449 | kfree(args->csa_rclists); |
Anna Schumaker | 1796549 | 2017-04-07 14:15:01 -0400 | [diff] [blame^] | 450 | return status; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 451 | } |
| 452 | |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 453 | static __be32 decode_recallany_args(struct svc_rqst *rqstp, |
Alexandros Batsakis | 31f0960 | 2009-12-05 13:27:02 -0500 | [diff] [blame] | 454 | struct xdr_stream *xdr, |
| 455 | struct cb_recallanyargs *args) |
| 456 | { |
Peng Tao | d743c3c | 2011-10-23 20:22:38 -0700 | [diff] [blame] | 457 | uint32_t bitmap[2]; |
| 458 | __be32 *p, status; |
Alexandros Batsakis | 31f0960 | 2009-12-05 13:27:02 -0500 | [diff] [blame] | 459 | |
Alexandros Batsakis | 31f0960 | 2009-12-05 13:27:02 -0500 | [diff] [blame] | 460 | p = read_buf(xdr, 4); |
| 461 | if (unlikely(p == NULL)) |
| 462 | return htonl(NFS4ERR_BADXDR); |
| 463 | args->craa_objs_to_keep = ntohl(*p++); |
Peng Tao | d743c3c | 2011-10-23 20:22:38 -0700 | [diff] [blame] | 464 | status = decode_bitmap(xdr, bitmap); |
| 465 | if (unlikely(status)) |
| 466 | return status; |
| 467 | args->craa_type_mask = bitmap[0]; |
Alexandros Batsakis | 31f0960 | 2009-12-05 13:27:02 -0500 | [diff] [blame] | 468 | |
| 469 | return 0; |
| 470 | } |
| 471 | |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 472 | static __be32 decode_recallslot_args(struct svc_rqst *rqstp, |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 473 | struct xdr_stream *xdr, |
| 474 | struct cb_recallslotargs *args) |
| 475 | { |
| 476 | __be32 *p; |
| 477 | |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 478 | p = read_buf(xdr, 4); |
| 479 | if (unlikely(p == NULL)) |
| 480 | return htonl(NFS4ERR_BADXDR); |
Trond Myklebust | d5fb4ce | 2012-11-20 20:24:02 -0500 | [diff] [blame] | 481 | args->crsa_target_highest_slotid = ntohl(*p++); |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 482 | return 0; |
| 483 | } |
| 484 | |
Jeff Layton | db78368 | 2016-09-17 18:17:36 -0400 | [diff] [blame] | 485 | static __be32 decode_lockowner(struct xdr_stream *xdr, struct cb_notify_lock_args *args) |
| 486 | { |
| 487 | __be32 *p; |
| 488 | unsigned int len; |
| 489 | |
| 490 | p = read_buf(xdr, 12); |
| 491 | if (unlikely(p == NULL)) |
| 492 | return htonl(NFS4ERR_BADXDR); |
| 493 | |
| 494 | p = xdr_decode_hyper(p, &args->cbnl_owner.clientid); |
| 495 | len = be32_to_cpu(*p); |
| 496 | |
| 497 | p = read_buf(xdr, len); |
| 498 | if (unlikely(p == NULL)) |
| 499 | return htonl(NFS4ERR_BADXDR); |
| 500 | |
| 501 | /* Only try to decode if the length is right */ |
| 502 | if (len == 20) { |
| 503 | p += 2; /* skip "lock id:" */ |
| 504 | args->cbnl_owner.s_dev = be32_to_cpu(*p++); |
| 505 | xdr_decode_hyper(p, &args->cbnl_owner.id); |
| 506 | args->cbnl_valid = true; |
| 507 | } else { |
| 508 | args->cbnl_owner.s_dev = 0; |
| 509 | args->cbnl_owner.id = 0; |
| 510 | args->cbnl_valid = false; |
| 511 | } |
| 512 | return 0; |
| 513 | } |
| 514 | |
| 515 | static __be32 decode_notify_lock_args(struct svc_rqst *rqstp, struct xdr_stream *xdr, struct cb_notify_lock_args *args) |
| 516 | { |
| 517 | __be32 status; |
| 518 | |
| 519 | status = decode_fh(xdr, &args->cbnl_fh); |
| 520 | if (unlikely(status != 0)) |
| 521 | goto out; |
| 522 | status = decode_lockowner(xdr, args); |
| 523 | out: |
| 524 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); |
| 525 | return status; |
| 526 | } |
| 527 | |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 528 | #endif /* CONFIG_NFS_V4_1 */ |
| 529 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 530 | static __be32 encode_string(struct xdr_stream *xdr, unsigned int len, const char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | { |
Trond Myklebust | ab6e9aa | 2017-02-19 16:08:26 -0500 | [diff] [blame] | 532 | if (unlikely(xdr_stream_encode_opaque(xdr, str, len) < 0)) |
| 533 | return cpu_to_be32(NFS4ERR_RESOURCE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | #define CB_SUPPORTED_ATTR0 (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) |
| 538 | #define CB_SUPPORTED_ATTR1 (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 539 | static __be32 encode_attr_bitmap(struct xdr_stream *xdr, const uint32_t *bitmap, __be32 **savep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 541 | __be32 bm[2]; |
| 542 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
| 544 | bm[0] = htonl(bitmap[0] & CB_SUPPORTED_ATTR0); |
| 545 | bm[1] = htonl(bitmap[1] & CB_SUPPORTED_ATTR1); |
| 546 | if (bm[1] != 0) { |
| 547 | p = xdr_reserve_space(xdr, 16); |
| 548 | if (unlikely(p == NULL)) |
| 549 | return htonl(NFS4ERR_RESOURCE); |
| 550 | *p++ = htonl(2); |
| 551 | *p++ = bm[0]; |
| 552 | *p++ = bm[1]; |
| 553 | } else if (bm[0] != 0) { |
| 554 | p = xdr_reserve_space(xdr, 12); |
| 555 | if (unlikely(p == NULL)) |
| 556 | return htonl(NFS4ERR_RESOURCE); |
| 557 | *p++ = htonl(1); |
| 558 | *p++ = bm[0]; |
| 559 | } else { |
| 560 | p = xdr_reserve_space(xdr, 8); |
| 561 | if (unlikely(p == NULL)) |
| 562 | return htonl(NFS4ERR_RESOURCE); |
| 563 | *p++ = htonl(0); |
| 564 | } |
| 565 | *savep = p; |
| 566 | return 0; |
| 567 | } |
| 568 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 569 | static __be32 encode_attr_change(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t change) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 571 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
| 573 | if (!(bitmap[0] & FATTR4_WORD0_CHANGE)) |
| 574 | return 0; |
| 575 | p = xdr_reserve_space(xdr, 8); |
Harvey Harrison | 90dc7d2 | 2008-02-20 13:03:05 -0800 | [diff] [blame] | 576 | if (unlikely(!p)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | return htonl(NFS4ERR_RESOURCE); |
| 578 | p = xdr_encode_hyper(p, change); |
| 579 | return 0; |
| 580 | } |
| 581 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 582 | static __be32 encode_attr_size(struct xdr_stream *xdr, const uint32_t *bitmap, uint64_t size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 584 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
| 586 | if (!(bitmap[0] & FATTR4_WORD0_SIZE)) |
| 587 | return 0; |
| 588 | p = xdr_reserve_space(xdr, 8); |
Harvey Harrison | 90dc7d2 | 2008-02-20 13:03:05 -0800 | [diff] [blame] | 589 | if (unlikely(!p)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | return htonl(NFS4ERR_RESOURCE); |
| 591 | p = xdr_encode_hyper(p, size); |
| 592 | return 0; |
| 593 | } |
| 594 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 595 | static __be32 encode_attr_time(struct xdr_stream *xdr, const struct timespec *time) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 597 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
| 599 | p = xdr_reserve_space(xdr, 12); |
Harvey Harrison | 90dc7d2 | 2008-02-20 13:03:05 -0800 | [diff] [blame] | 600 | if (unlikely(!p)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | return htonl(NFS4ERR_RESOURCE); |
| 602 | p = xdr_encode_hyper(p, time->tv_sec); |
| 603 | *p = htonl(time->tv_nsec); |
| 604 | return 0; |
| 605 | } |
| 606 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 607 | static __be32 encode_attr_ctime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | { |
| 609 | if (!(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) |
| 610 | return 0; |
| 611 | return encode_attr_time(xdr,time); |
| 612 | } |
| 613 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 614 | static __be32 encode_attr_mtime(struct xdr_stream *xdr, const uint32_t *bitmap, const struct timespec *time) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | { |
| 616 | if (!(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) |
| 617 | return 0; |
| 618 | return encode_attr_time(xdr,time); |
| 619 | } |
| 620 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 621 | static __be32 encode_compound_hdr_res(struct xdr_stream *xdr, struct cb_compound_hdr_res *hdr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 623 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | hdr->status = xdr_reserve_space(xdr, 4); |
| 626 | if (unlikely(hdr->status == NULL)) |
| 627 | return htonl(NFS4ERR_RESOURCE); |
| 628 | status = encode_string(xdr, hdr->taglen, hdr->tag); |
| 629 | if (unlikely(status != 0)) |
| 630 | return status; |
| 631 | hdr->nops = xdr_reserve_space(xdr, 4); |
| 632 | if (unlikely(hdr->nops == NULL)) |
| 633 | return htonl(NFS4ERR_RESOURCE); |
| 634 | return 0; |
| 635 | } |
| 636 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 637 | static __be32 encode_op_hdr(struct xdr_stream *xdr, uint32_t op, __be32 res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 639 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
| 641 | p = xdr_reserve_space(xdr, 8); |
| 642 | if (unlikely(p == NULL)) |
Andy Adamson | 31d2b43 | 2010-01-14 17:45:04 -0500 | [diff] [blame] | 643 | return htonl(NFS4ERR_RESOURCE_HDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | *p++ = htonl(op); |
| 645 | *p = res; |
| 646 | return 0; |
| 647 | } |
| 648 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 649 | static __be32 encode_getattr_res(struct svc_rqst *rqstp, struct xdr_stream *xdr, const struct cb_getattrres *res) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 651 | __be32 *savep = NULL; |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 652 | __be32 status = res->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
| 654 | if (unlikely(status != 0)) |
| 655 | goto out; |
| 656 | status = encode_attr_bitmap(xdr, res->bitmap, &savep); |
| 657 | if (unlikely(status != 0)) |
| 658 | goto out; |
| 659 | status = encode_attr_change(xdr, res->bitmap, res->change_attr); |
| 660 | if (unlikely(status != 0)) |
| 661 | goto out; |
| 662 | status = encode_attr_size(xdr, res->bitmap, res->size); |
| 663 | if (unlikely(status != 0)) |
| 664 | goto out; |
| 665 | status = encode_attr_ctime(xdr, res->bitmap, &res->ctime); |
| 666 | if (unlikely(status != 0)) |
| 667 | goto out; |
| 668 | status = encode_attr_mtime(xdr, res->bitmap, &res->mtime); |
| 669 | *savep = htonl((unsigned int)((char *)xdr->p - (char *)(savep+1))); |
| 670 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 671 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | return status; |
| 673 | } |
| 674 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 675 | #if defined(CONFIG_NFS_V4_1) |
| 676 | |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 677 | static __be32 encode_sessionid(struct xdr_stream *xdr, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 678 | const struct nfs4_sessionid *sid) |
| 679 | { |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 680 | __be32 *p; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 681 | |
Kinglong Mee | 590184a | 2015-09-24 20:57:37 +0800 | [diff] [blame] | 682 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN); |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 683 | if (unlikely(p == NULL)) |
| 684 | return htonl(NFS4ERR_RESOURCE); |
| 685 | |
Kinglong Mee | 590184a | 2015-09-24 20:57:37 +0800 | [diff] [blame] | 686 | memcpy(p, sid, NFS4_MAX_SESSIONID_LEN); |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 687 | return 0; |
| 688 | } |
| 689 | |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 690 | static __be32 encode_cb_sequence_res(struct svc_rqst *rqstp, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 691 | struct xdr_stream *xdr, |
| 692 | const struct cb_sequenceres *res) |
| 693 | { |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 694 | __be32 *p; |
Dan Carpenter | e216c8c | 2012-06-12 10:37:39 +0300 | [diff] [blame] | 695 | __be32 status = res->csr_status; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 696 | |
| 697 | if (unlikely(status != 0)) |
| 698 | goto out; |
| 699 | |
Kinglong Mee | e0a63c0 | 2015-09-24 20:58:38 +0800 | [diff] [blame] | 700 | status = encode_sessionid(xdr, &res->csr_sessionid); |
| 701 | if (status) |
| 702 | goto out; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 703 | |
| 704 | p = xdr_reserve_space(xdr, 4 * sizeof(uint32_t)); |
| 705 | if (unlikely(p == NULL)) |
| 706 | return htonl(NFS4ERR_RESOURCE); |
| 707 | |
| 708 | *p++ = htonl(res->csr_sequenceid); |
| 709 | *p++ = htonl(res->csr_slotid); |
| 710 | *p++ = htonl(res->csr_highestslotid); |
| 711 | *p++ = htonl(res->csr_target_highestslotid); |
| 712 | out: |
| 713 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); |
| 714 | return status; |
| 715 | } |
| 716 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 717 | static __be32 |
| 718 | preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) |
| 719 | { |
Benny Halevy | 281fe15 | 2009-04-01 09:23:27 -0400 | [diff] [blame] | 720 | if (op_nr == OP_CB_SEQUENCE) { |
| 721 | if (nop != 0) |
| 722 | return htonl(NFS4ERR_SEQUENCE_POS); |
| 723 | } else { |
| 724 | if (nop == 0) |
| 725 | return htonl(NFS4ERR_OP_NOT_IN_SESSION); |
| 726 | } |
| 727 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 728 | switch (op_nr) { |
| 729 | case OP_CB_GETATTR: |
| 730 | case OP_CB_RECALL: |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 731 | case OP_CB_SEQUENCE: |
Alexandros Batsakis | 31f0960 | 2009-12-05 13:27:02 -0500 | [diff] [blame] | 732 | case OP_CB_RECALL_ANY: |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 733 | case OP_CB_RECALL_SLOT: |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 734 | case OP_CB_LAYOUTRECALL: |
Marc Eshel | 1be5683 | 2011-05-22 19:47:09 +0300 | [diff] [blame] | 735 | case OP_CB_NOTIFY_DEVICEID: |
Jeff Layton | db78368 | 2016-09-17 18:17:36 -0400 | [diff] [blame] | 736 | case OP_CB_NOTIFY_LOCK: |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 737 | *op = &callback_ops[op_nr]; |
| 738 | break; |
| 739 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 740 | case OP_CB_NOTIFY: |
| 741 | case OP_CB_PUSH_DELEG: |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 742 | case OP_CB_RECALLABLE_OBJ_AVAIL: |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 743 | case OP_CB_WANTS_CANCELLED: |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 744 | return htonl(NFS4ERR_NOTSUPP); |
| 745 | |
| 746 | default: |
| 747 | return htonl(NFS4ERR_OP_ILLEGAL); |
| 748 | } |
| 749 | |
| 750 | return htonl(NFS_OK); |
| 751 | } |
| 752 | |
Trond Myklebust | 810d82e | 2016-01-23 15:18:18 -0500 | [diff] [blame] | 753 | static void nfs4_callback_free_slot(struct nfs4_session *session, |
| 754 | struct nfs4_slot *slot) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 755 | { |
| 756 | struct nfs4_slot_table *tbl = &session->bc_slot_table; |
| 757 | |
| 758 | spin_lock(&tbl->slot_tbl_lock); |
| 759 | /* |
| 760 | * Let the state manager know callback processing done. |
| 761 | * A single slot, so highest used slotid is either 0 or -1 |
| 762 | */ |
Trond Myklebust | 810d82e | 2016-01-23 15:18:18 -0500 | [diff] [blame] | 763 | nfs4_free_slot(tbl, slot); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 764 | nfs4_slot_tbl_drain_complete(tbl); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 765 | spin_unlock(&tbl->slot_tbl_lock); |
| 766 | } |
| 767 | |
Trond Myklebust | 55a6739 | 2011-08-02 14:46:29 -0400 | [diff] [blame] | 768 | static void nfs4_cb_free_slot(struct cb_process_state *cps) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 769 | { |
Trond Myklebust | 810d82e | 2016-01-23 15:18:18 -0500 | [diff] [blame] | 770 | if (cps->slot) { |
| 771 | nfs4_callback_free_slot(cps->clp->cl_session, cps->slot); |
| 772 | cps->slot = NULL; |
| 773 | } |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 774 | } |
| 775 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 776 | #else /* CONFIG_NFS_V4_1 */ |
| 777 | |
| 778 | static __be32 |
| 779 | preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) |
| 780 | { |
| 781 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); |
| 782 | } |
| 783 | |
Trond Myklebust | 55a6739 | 2011-08-02 14:46:29 -0400 | [diff] [blame] | 784 | static void nfs4_cb_free_slot(struct cb_process_state *cps) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 785 | { |
| 786 | } |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 787 | #endif /* CONFIG_NFS_V4_1 */ |
| 788 | |
Bryan Schumaker | 6b140b8 | 2013-06-05 11:15:02 -0400 | [diff] [blame] | 789 | #ifdef CONFIG_NFS_V4_2 |
| 790 | static __be32 |
| 791 | preprocess_nfs42_op(int nop, unsigned int op_nr, struct callback_op **op) |
| 792 | { |
| 793 | __be32 status = preprocess_nfs41_op(nop, op_nr, op); |
| 794 | if (status != htonl(NFS4ERR_OP_ILLEGAL)) |
| 795 | return status; |
| 796 | |
| 797 | if (op_nr == OP_CB_OFFLOAD) |
| 798 | return htonl(NFS4ERR_NOTSUPP); |
| 799 | return htonl(NFS4ERR_OP_ILLEGAL); |
| 800 | } |
| 801 | #else /* CONFIG_NFS_V4_2 */ |
| 802 | static __be32 |
| 803 | preprocess_nfs42_op(int nop, unsigned int op_nr, struct callback_op **op) |
| 804 | { |
| 805 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); |
| 806 | } |
| 807 | #endif /* CONFIG_NFS_V4_2 */ |
| 808 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 809 | static __be32 |
| 810 | preprocess_nfs4_op(unsigned int op_nr, struct callback_op **op) |
| 811 | { |
| 812 | switch (op_nr) { |
| 813 | case OP_CB_GETATTR: |
| 814 | case OP_CB_RECALL: |
| 815 | *op = &callback_ops[op_nr]; |
| 816 | break; |
| 817 | default: |
| 818 | return htonl(NFS4ERR_OP_ILLEGAL); |
| 819 | } |
| 820 | |
| 821 | return htonl(NFS_OK); |
| 822 | } |
| 823 | |
Bryan Schumaker | 459de2e | 2013-06-05 11:15:01 -0400 | [diff] [blame] | 824 | static __be32 process_op(int nop, struct svc_rqst *rqstp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | struct xdr_stream *xdr_in, void *argp, |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 826 | struct xdr_stream *xdr_out, void *resp, |
| 827 | struct cb_process_state *cps) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | { |
Trond Myklebust | a162a6b | 2006-03-20 13:44:10 -0500 | [diff] [blame] | 829 | struct callback_op *op = &callback_ops[0]; |
Andy Adamson | 31d2b43 | 2010-01-14 17:45:04 -0500 | [diff] [blame] | 830 | unsigned int op_nr; |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 831 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | long maxlen; |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 833 | __be32 res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 835 | dprintk("%s: start\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | status = decode_op_hdr(xdr_in, &op_nr); |
Andy Adamson | 31d2b43 | 2010-01-14 17:45:04 -0500 | [diff] [blame] | 837 | if (unlikely(status)) |
| 838 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 840 | dprintk("%s: minorversion=%d nop=%d op_nr=%u\n", |
Bryan Schumaker | 459de2e | 2013-06-05 11:15:01 -0400 | [diff] [blame] | 841 | __func__, cps->minorversion, nop, op_nr); |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 842 | |
Bryan Schumaker | 6b140b8 | 2013-06-05 11:15:02 -0400 | [diff] [blame] | 843 | switch (cps->minorversion) { |
| 844 | case 0: |
| 845 | status = preprocess_nfs4_op(op_nr, &op); |
| 846 | break; |
| 847 | case 1: |
| 848 | status = preprocess_nfs41_op(nop, op_nr, &op); |
| 849 | break; |
| 850 | case 2: |
| 851 | status = preprocess_nfs42_op(nop, op_nr, &op); |
| 852 | break; |
| 853 | default: |
| 854 | status = htonl(NFS4ERR_MINOR_VERS_MISMATCH); |
| 855 | } |
| 856 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 857 | if (status == htonl(NFS4ERR_OP_ILLEGAL)) |
| 858 | op_nr = OP_CB_ILLEGAL; |
Andy Adamson | b92b301 | 2010-01-14 17:45:05 -0500 | [diff] [blame] | 859 | if (status) |
| 860 | goto encode_hdr; |
Andy Adamson | 31d2b43 | 2010-01-14 17:45:04 -0500 | [diff] [blame] | 861 | |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 862 | if (cps->drc_status) { |
| 863 | status = cps->drc_status; |
Andy Adamson | 4911096 | 2010-01-14 17:45:08 -0500 | [diff] [blame] | 864 | goto encode_hdr; |
| 865 | } |
| 866 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | maxlen = xdr_out->end - xdr_out->p; |
| 868 | if (maxlen > 0 && maxlen < PAGE_SIZE) { |
Andy Adamson | e95e60d | 2010-01-14 17:45:06 -0500 | [diff] [blame] | 869 | status = op->decode_args(rqstp, xdr_in, argp); |
| 870 | if (likely(status == 0)) |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 871 | status = op->process_op(argp, resp, cps); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } else |
| 873 | status = htonl(NFS4ERR_RESOURCE); |
| 874 | |
Andy Adamson | b92b301 | 2010-01-14 17:45:05 -0500 | [diff] [blame] | 875 | encode_hdr: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | res = encode_op_hdr(xdr_out, op_nr, status); |
Andy Adamson | 31d2b43 | 2010-01-14 17:45:04 -0500 | [diff] [blame] | 877 | if (unlikely(res)) |
| 878 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | if (op->encode_res != NULL && status == 0) |
| 880 | status = op->encode_res(rqstp, xdr_out, resp); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 881 | dprintk("%s: done, status = %d\n", __func__, ntohl(status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | return status; |
| 883 | } |
| 884 | |
| 885 | /* |
| 886 | * Decode, process and encode a COMPOUND |
| 887 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 888 | static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *resp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | { |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 890 | struct cb_compound_hdr_arg hdr_arg = { 0 }; |
| 891 | struct cb_compound_hdr_res hdr_res = { NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | struct xdr_stream xdr_in, xdr_out; |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 893 | __be32 *p, status; |
| 894 | struct cb_process_state cps = { |
| 895 | .drc_status = 0, |
| 896 | .clp = NULL, |
Stanislav Kinsbursky | 9695c70 | 2012-07-25 16:57:06 +0400 | [diff] [blame] | 897 | .net = SVC_NET(rqstp), |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 898 | }; |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 899 | unsigned int nops = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 901 | dprintk("%s: start\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
Trond Myklebust | 756b9b3 | 2015-12-07 12:52:23 -0800 | [diff] [blame] | 903 | xdr_init_decode(&xdr_in, &rqstp->rq_arg, rqstp->rq_arg.head[0].iov_base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 905 | p = (__be32*)((char *)rqstp->rq_res.head[0].iov_base + rqstp->rq_res.head[0].iov_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | xdr_init_encode(&xdr_out, &rqstp->rq_res, p); |
| 907 | |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 908 | status = decode_compound_hdr_arg(&xdr_in, &hdr_arg); |
Vaishali Thakkar | 4ed0d83 | 2015-06-10 20:15:29 +0530 | [diff] [blame] | 909 | if (status == htonl(NFS4ERR_RESOURCE)) |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 910 | return rpc_garbage_args; |
| 911 | |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 912 | if (hdr_arg.minorversion == 0) { |
Stanislav Kinsbursky | 9695c70 | 2012-07-25 16:57:06 +0400 | [diff] [blame] | 913 | cps.clp = nfs4_find_client_ident(SVC_NET(rqstp), hdr_arg.cb_ident); |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 914 | if (!cps.clp || !check_gss_callback_principal(cps.clp, rqstp)) |
Chuck Lever | a4e187d | 2016-06-29 13:55:22 -0400 | [diff] [blame] | 915 | goto out_invalidcred; |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 916 | } |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 917 | |
Bryan Schumaker | 459de2e | 2013-06-05 11:15:01 -0400 | [diff] [blame] | 918 | cps.minorversion = hdr_arg.minorversion; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | hdr_res.taglen = hdr_arg.taglen; |
| 920 | hdr_res.tag = hdr_arg.tag; |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 921 | if (encode_compound_hdr_res(&xdr_out, &hdr_res) != 0) |
| 922 | return rpc_system_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 924 | while (status == 0 && nops != hdr_arg.nops) { |
Bryan Schumaker | 459de2e | 2013-06-05 11:15:01 -0400 | [diff] [blame] | 925 | status = process_op(nops, rqstp, &xdr_in, |
| 926 | argp, &xdr_out, resp, &cps); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | nops++; |
| 928 | } |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 929 | |
Andy Adamson | 31d2b43 | 2010-01-14 17:45:04 -0500 | [diff] [blame] | 930 | /* Buffer overflow in decode_ops_hdr or encode_ops_hdr. Return |
| 931 | * resource error in cb_compound status without returning op */ |
| 932 | if (unlikely(status == htonl(NFS4ERR_RESOURCE_HDR))) { |
| 933 | status = htonl(NFS4ERR_RESOURCE); |
| 934 | nops--; |
| 935 | } |
| 936 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | *hdr_res.status = status; |
| 938 | *hdr_res.nops = htonl(nops); |
Trond Myklebust | 55a6739 | 2011-08-02 14:46:29 -0400 | [diff] [blame] | 939 | nfs4_cb_free_slot(&cps); |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 940 | nfs_put_client(cps.clp); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 941 | dprintk("%s: done, status = %u\n", __func__, ntohl(status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | return rpc_success; |
Chuck Lever | a4e187d | 2016-06-29 13:55:22 -0400 | [diff] [blame] | 943 | |
| 944 | out_invalidcred: |
| 945 | pr_warn_ratelimited("NFS: NFSv4 callback contains invalid cred\n"); |
| 946 | return rpc_autherr_badcred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | /* |
| 950 | * Define NFS4 callback COMPOUND ops. |
| 951 | */ |
| 952 | static struct callback_op callback_ops[] = { |
| 953 | [0] = { |
| 954 | .res_maxsize = CB_OP_HDR_RES_MAXSZ, |
| 955 | }, |
| 956 | [OP_CB_GETATTR] = { |
| 957 | .process_op = (callback_process_op_t)nfs4_callback_getattr, |
| 958 | .decode_args = (callback_decode_arg_t)decode_getattr_args, |
| 959 | .encode_res = (callback_encode_res_t)encode_getattr_res, |
| 960 | .res_maxsize = CB_OP_GETATTR_RES_MAXSZ, |
| 961 | }, |
| 962 | [OP_CB_RECALL] = { |
| 963 | .process_op = (callback_process_op_t)nfs4_callback_recall, |
| 964 | .decode_args = (callback_decode_arg_t)decode_recall_args, |
| 965 | .res_maxsize = CB_OP_RECALL_RES_MAXSZ, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 966 | }, |
| 967 | #if defined(CONFIG_NFS_V4_1) |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 968 | [OP_CB_LAYOUTRECALL] = { |
| 969 | .process_op = (callback_process_op_t)nfs4_callback_layoutrecall, |
| 970 | .decode_args = |
| 971 | (callback_decode_arg_t)decode_layoutrecall_args, |
| 972 | .res_maxsize = CB_OP_LAYOUTRECALL_RES_MAXSZ, |
| 973 | }, |
Marc Eshel | 1be5683 | 2011-05-22 19:47:09 +0300 | [diff] [blame] | 974 | [OP_CB_NOTIFY_DEVICEID] = { |
| 975 | .process_op = (callback_process_op_t)nfs4_callback_devicenotify, |
| 976 | .decode_args = |
| 977 | (callback_decode_arg_t)decode_devicenotify_args, |
| 978 | .res_maxsize = CB_OP_DEVICENOTIFY_RES_MAXSZ, |
| 979 | }, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 980 | [OP_CB_SEQUENCE] = { |
| 981 | .process_op = (callback_process_op_t)nfs4_callback_sequence, |
| 982 | .decode_args = (callback_decode_arg_t)decode_cb_sequence_args, |
| 983 | .encode_res = (callback_encode_res_t)encode_cb_sequence_res, |
| 984 | .res_maxsize = CB_OP_SEQUENCE_RES_MAXSZ, |
| 985 | }, |
Alexandros Batsakis | 31f0960 | 2009-12-05 13:27:02 -0500 | [diff] [blame] | 986 | [OP_CB_RECALL_ANY] = { |
| 987 | .process_op = (callback_process_op_t)nfs4_callback_recallany, |
| 988 | .decode_args = (callback_decode_arg_t)decode_recallany_args, |
| 989 | .res_maxsize = CB_OP_RECALLANY_RES_MAXSZ, |
| 990 | }, |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 991 | [OP_CB_RECALL_SLOT] = { |
| 992 | .process_op = (callback_process_op_t)nfs4_callback_recallslot, |
| 993 | .decode_args = (callback_decode_arg_t)decode_recallslot_args, |
| 994 | .res_maxsize = CB_OP_RECALLSLOT_RES_MAXSZ, |
| 995 | }, |
Jeff Layton | db78368 | 2016-09-17 18:17:36 -0400 | [diff] [blame] | 996 | [OP_CB_NOTIFY_LOCK] = { |
| 997 | .process_op = (callback_process_op_t)nfs4_callback_notify_lock, |
| 998 | .decode_args = (callback_decode_arg_t)decode_notify_lock_args, |
| 999 | .res_maxsize = CB_OP_NOTIFY_LOCK_RES_MAXSZ, |
| 1000 | }, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 1001 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | }; |
| 1003 | |
| 1004 | /* |
| 1005 | * Define NFS4 callback procedures |
| 1006 | */ |
| 1007 | static struct svc_procedure nfs4_callback_procedures1[] = { |
| 1008 | [CB_NULL] = { |
| 1009 | .pc_func = nfs4_callback_null, |
| 1010 | .pc_decode = (kxdrproc_t)nfs4_decode_void, |
| 1011 | .pc_encode = (kxdrproc_t)nfs4_encode_void, |
| 1012 | .pc_xdrressize = 1, |
| 1013 | }, |
| 1014 | [CB_COMPOUND] = { |
| 1015 | .pc_func = nfs4_callback_compound, |
| 1016 | .pc_encode = (kxdrproc_t)nfs4_encode_void, |
| 1017 | .pc_argsize = 256, |
| 1018 | .pc_ressize = 256, |
| 1019 | .pc_xdrressize = NFS4_CALLBACK_BUFSIZE, |
| 1020 | } |
| 1021 | }; |
| 1022 | |
| 1023 | struct svc_version nfs4_callback_version1 = { |
| 1024 | .vs_vers = 1, |
| 1025 | .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1), |
| 1026 | .vs_proc = nfs4_callback_procedures1, |
| 1027 | .vs_xdrsize = NFS4_CALLBACK_XDRSIZE, |
| 1028 | .vs_dispatch = NULL, |
Jeff Layton | 05a45a2 | 2017-02-24 13:25:22 -0500 | [diff] [blame] | 1029 | .vs_hidden = true, |
Jeff Layton | 5283b03 | 2017-02-24 13:25:24 -0500 | [diff] [blame] | 1030 | .vs_need_cong_ctrl = true, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | }; |
| 1032 | |
Alexandros Batsakis | 07bccc2 | 2009-12-05 13:19:01 -0500 | [diff] [blame] | 1033 | struct svc_version nfs4_callback_version4 = { |
| 1034 | .vs_vers = 4, |
| 1035 | .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1), |
| 1036 | .vs_proc = nfs4_callback_procedures1, |
| 1037 | .vs_xdrsize = NFS4_CALLBACK_XDRSIZE, |
| 1038 | .vs_dispatch = NULL, |
Jeff Layton | 05a45a2 | 2017-02-24 13:25:22 -0500 | [diff] [blame] | 1039 | .vs_hidden = true, |
Jeff Layton | 5283b03 | 2017-02-24 13:25:24 -0500 | [diff] [blame] | 1040 | .vs_need_cong_ctrl = true, |
Alexandros Batsakis | 07bccc2 | 2009-12-05 13:19:01 -0500 | [diff] [blame] | 1041 | }; |