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