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)) |
Anna Schumaker | 535ece2 | 2017-04-07 14:15:02 -0400 | [diff] [blame] | 521 | return status; |
| 522 | return decode_lockowner(xdr, args); |
Jeff Layton | db78368 | 2016-09-17 18:17:36 -0400 | [diff] [blame] | 523 | } |
| 524 | |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 525 | #endif /* CONFIG_NFS_V4_1 */ |
| 526 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 527 | 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] | 528 | { |
Trond Myklebust | ab6e9aa | 2017-02-19 16:08:26 -0500 | [diff] [blame] | 529 | if (unlikely(xdr_stream_encode_opaque(xdr, str, len) < 0)) |
| 530 | return cpu_to_be32(NFS4ERR_RESOURCE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | #define CB_SUPPORTED_ATTR0 (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) |
| 535 | #define CB_SUPPORTED_ATTR1 (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 536 | 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] | 537 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 538 | __be32 bm[2]; |
| 539 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
| 541 | bm[0] = htonl(bitmap[0] & CB_SUPPORTED_ATTR0); |
| 542 | bm[1] = htonl(bitmap[1] & CB_SUPPORTED_ATTR1); |
| 543 | if (bm[1] != 0) { |
| 544 | p = xdr_reserve_space(xdr, 16); |
| 545 | if (unlikely(p == NULL)) |
| 546 | return htonl(NFS4ERR_RESOURCE); |
| 547 | *p++ = htonl(2); |
| 548 | *p++ = bm[0]; |
| 549 | *p++ = bm[1]; |
| 550 | } else if (bm[0] != 0) { |
| 551 | p = xdr_reserve_space(xdr, 12); |
| 552 | if (unlikely(p == NULL)) |
| 553 | return htonl(NFS4ERR_RESOURCE); |
| 554 | *p++ = htonl(1); |
| 555 | *p++ = bm[0]; |
| 556 | } else { |
| 557 | p = xdr_reserve_space(xdr, 8); |
| 558 | if (unlikely(p == NULL)) |
| 559 | return htonl(NFS4ERR_RESOURCE); |
| 560 | *p++ = htonl(0); |
| 561 | } |
| 562 | *savep = p; |
| 563 | return 0; |
| 564 | } |
| 565 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 566 | 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] | 567 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 568 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
| 570 | if (!(bitmap[0] & FATTR4_WORD0_CHANGE)) |
| 571 | return 0; |
| 572 | p = xdr_reserve_space(xdr, 8); |
Harvey Harrison | 90dc7d2 | 2008-02-20 13:03:05 -0800 | [diff] [blame] | 573 | if (unlikely(!p)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | return htonl(NFS4ERR_RESOURCE); |
| 575 | p = xdr_encode_hyper(p, change); |
| 576 | return 0; |
| 577 | } |
| 578 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 579 | 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] | 580 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 581 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
| 583 | if (!(bitmap[0] & FATTR4_WORD0_SIZE)) |
| 584 | return 0; |
| 585 | p = xdr_reserve_space(xdr, 8); |
Harvey Harrison | 90dc7d2 | 2008-02-20 13:03:05 -0800 | [diff] [blame] | 586 | if (unlikely(!p)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | return htonl(NFS4ERR_RESOURCE); |
| 588 | p = xdr_encode_hyper(p, size); |
| 589 | return 0; |
| 590 | } |
| 591 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 592 | 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] | 593 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 594 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
| 596 | p = xdr_reserve_space(xdr, 12); |
Harvey Harrison | 90dc7d2 | 2008-02-20 13:03:05 -0800 | [diff] [blame] | 597 | if (unlikely(!p)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | return htonl(NFS4ERR_RESOURCE); |
| 599 | p = xdr_encode_hyper(p, time->tv_sec); |
| 600 | *p = htonl(time->tv_nsec); |
| 601 | return 0; |
| 602 | } |
| 603 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 604 | 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] | 605 | { |
| 606 | if (!(bitmap[1] & FATTR4_WORD1_TIME_METADATA)) |
| 607 | return 0; |
| 608 | return encode_attr_time(xdr,time); |
| 609 | } |
| 610 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 611 | 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] | 612 | { |
| 613 | if (!(bitmap[1] & FATTR4_WORD1_TIME_MODIFY)) |
| 614 | return 0; |
| 615 | return encode_attr_time(xdr,time); |
| 616 | } |
| 617 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 618 | 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] | 619 | { |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 620 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
| 622 | hdr->status = xdr_reserve_space(xdr, 4); |
| 623 | if (unlikely(hdr->status == NULL)) |
| 624 | return htonl(NFS4ERR_RESOURCE); |
| 625 | status = encode_string(xdr, hdr->taglen, hdr->tag); |
| 626 | if (unlikely(status != 0)) |
| 627 | return status; |
| 628 | hdr->nops = xdr_reserve_space(xdr, 4); |
| 629 | if (unlikely(hdr->nops == NULL)) |
| 630 | return htonl(NFS4ERR_RESOURCE); |
| 631 | return 0; |
| 632 | } |
| 633 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 634 | 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] | 635 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 636 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
| 638 | p = xdr_reserve_space(xdr, 8); |
| 639 | if (unlikely(p == NULL)) |
Andy Adamson | 31d2b43 | 2010-01-14 17:45:04 -0500 | [diff] [blame] | 640 | return htonl(NFS4ERR_RESOURCE_HDR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | *p++ = htonl(op); |
| 642 | *p = res; |
| 643 | return 0; |
| 644 | } |
| 645 | |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 646 | 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] | 647 | { |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 648 | __be32 *savep = NULL; |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 649 | __be32 status = res->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
| 651 | if (unlikely(status != 0)) |
| 652 | goto out; |
| 653 | status = encode_attr_bitmap(xdr, res->bitmap, &savep); |
| 654 | if (unlikely(status != 0)) |
| 655 | goto out; |
| 656 | status = encode_attr_change(xdr, res->bitmap, res->change_attr); |
| 657 | if (unlikely(status != 0)) |
| 658 | goto out; |
| 659 | status = encode_attr_size(xdr, res->bitmap, res->size); |
| 660 | if (unlikely(status != 0)) |
| 661 | goto out; |
| 662 | status = encode_attr_ctime(xdr, res->bitmap, &res->ctime); |
| 663 | if (unlikely(status != 0)) |
| 664 | goto out; |
| 665 | status = encode_attr_mtime(xdr, res->bitmap, &res->mtime); |
| 666 | *savep = htonl((unsigned int)((char *)xdr->p - (char *)(savep+1))); |
| 667 | out: |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 668 | dprintk("%s: exit with status = %d\n", __func__, ntohl(status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | return status; |
| 670 | } |
| 671 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 672 | #if defined(CONFIG_NFS_V4_1) |
| 673 | |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 674 | static __be32 encode_sessionid(struct xdr_stream *xdr, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 675 | const struct nfs4_sessionid *sid) |
| 676 | { |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 677 | __be32 *p; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 678 | |
Kinglong Mee | 590184a | 2015-09-24 20:57:37 +0800 | [diff] [blame] | 679 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN); |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 680 | if (unlikely(p == NULL)) |
| 681 | return htonl(NFS4ERR_RESOURCE); |
| 682 | |
Kinglong Mee | 590184a | 2015-09-24 20:57:37 +0800 | [diff] [blame] | 683 | memcpy(p, sid, NFS4_MAX_SESSIONID_LEN); |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 687 | static __be32 encode_cb_sequence_res(struct svc_rqst *rqstp, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 688 | struct xdr_stream *xdr, |
| 689 | const struct cb_sequenceres *res) |
| 690 | { |
Andy Adamson | 9733f0d | 2010-01-22 12:03:08 -0500 | [diff] [blame] | 691 | __be32 *p; |
Dan Carpenter | e216c8c | 2012-06-12 10:37:39 +0300 | [diff] [blame] | 692 | __be32 status = res->csr_status; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 693 | |
| 694 | if (unlikely(status != 0)) |
Anna Schumaker | 3d0bfaa | 2017-04-07 14:15:03 -0400 | [diff] [blame^] | 695 | return status; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 696 | |
Kinglong Mee | e0a63c0 | 2015-09-24 20:58:38 +0800 | [diff] [blame] | 697 | status = encode_sessionid(xdr, &res->csr_sessionid); |
| 698 | if (status) |
Anna Schumaker | 3d0bfaa | 2017-04-07 14:15:03 -0400 | [diff] [blame^] | 699 | return status; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 700 | |
| 701 | p = xdr_reserve_space(xdr, 4 * sizeof(uint32_t)); |
| 702 | if (unlikely(p == NULL)) |
| 703 | return htonl(NFS4ERR_RESOURCE); |
| 704 | |
| 705 | *p++ = htonl(res->csr_sequenceid); |
| 706 | *p++ = htonl(res->csr_slotid); |
| 707 | *p++ = htonl(res->csr_highestslotid); |
| 708 | *p++ = htonl(res->csr_target_highestslotid); |
Anna Schumaker | 3d0bfaa | 2017-04-07 14:15:03 -0400 | [diff] [blame^] | 709 | return 0; |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 710 | } |
| 711 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 712 | static __be32 |
| 713 | preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) |
| 714 | { |
Benny Halevy | 281fe15 | 2009-04-01 09:23:27 -0400 | [diff] [blame] | 715 | if (op_nr == OP_CB_SEQUENCE) { |
| 716 | if (nop != 0) |
| 717 | return htonl(NFS4ERR_SEQUENCE_POS); |
| 718 | } else { |
| 719 | if (nop == 0) |
| 720 | return htonl(NFS4ERR_OP_NOT_IN_SESSION); |
| 721 | } |
| 722 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 723 | switch (op_nr) { |
| 724 | case OP_CB_GETATTR: |
| 725 | case OP_CB_RECALL: |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 726 | case OP_CB_SEQUENCE: |
Alexandros Batsakis | 31f0960 | 2009-12-05 13:27:02 -0500 | [diff] [blame] | 727 | case OP_CB_RECALL_ANY: |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 728 | case OP_CB_RECALL_SLOT: |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 729 | case OP_CB_LAYOUTRECALL: |
Marc Eshel | 1be5683 | 2011-05-22 19:47:09 +0300 | [diff] [blame] | 730 | case OP_CB_NOTIFY_DEVICEID: |
Jeff Layton | db78368 | 2016-09-17 18:17:36 -0400 | [diff] [blame] | 731 | case OP_CB_NOTIFY_LOCK: |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 732 | *op = &callback_ops[op_nr]; |
| 733 | break; |
| 734 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 735 | case OP_CB_NOTIFY: |
| 736 | case OP_CB_PUSH_DELEG: |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 737 | case OP_CB_RECALLABLE_OBJ_AVAIL: |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 738 | case OP_CB_WANTS_CANCELLED: |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 739 | return htonl(NFS4ERR_NOTSUPP); |
| 740 | |
| 741 | default: |
| 742 | return htonl(NFS4ERR_OP_ILLEGAL); |
| 743 | } |
| 744 | |
| 745 | return htonl(NFS_OK); |
| 746 | } |
| 747 | |
Trond Myklebust | 810d82e | 2016-01-23 15:18:18 -0500 | [diff] [blame] | 748 | static void nfs4_callback_free_slot(struct nfs4_session *session, |
| 749 | struct nfs4_slot *slot) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 750 | { |
| 751 | struct nfs4_slot_table *tbl = &session->bc_slot_table; |
| 752 | |
| 753 | spin_lock(&tbl->slot_tbl_lock); |
| 754 | /* |
| 755 | * Let the state manager know callback processing done. |
| 756 | * A single slot, so highest used slotid is either 0 or -1 |
| 757 | */ |
Trond Myklebust | 810d82e | 2016-01-23 15:18:18 -0500 | [diff] [blame] | 758 | nfs4_free_slot(tbl, slot); |
Andy Adamson | 774d5f1 | 2013-05-20 14:13:50 -0400 | [diff] [blame] | 759 | nfs4_slot_tbl_drain_complete(tbl); |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 760 | spin_unlock(&tbl->slot_tbl_lock); |
| 761 | } |
| 762 | |
Trond Myklebust | 55a6739 | 2011-08-02 14:46:29 -0400 | [diff] [blame] | 763 | static void nfs4_cb_free_slot(struct cb_process_state *cps) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 764 | { |
Trond Myklebust | 810d82e | 2016-01-23 15:18:18 -0500 | [diff] [blame] | 765 | if (cps->slot) { |
| 766 | nfs4_callback_free_slot(cps->clp->cl_session, cps->slot); |
| 767 | cps->slot = NULL; |
| 768 | } |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 771 | #else /* CONFIG_NFS_V4_1 */ |
| 772 | |
| 773 | static __be32 |
| 774 | preprocess_nfs41_op(int nop, unsigned int op_nr, struct callback_op **op) |
| 775 | { |
| 776 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); |
| 777 | } |
| 778 | |
Trond Myklebust | 55a6739 | 2011-08-02 14:46:29 -0400 | [diff] [blame] | 779 | static void nfs4_cb_free_slot(struct cb_process_state *cps) |
Andy Adamson | 42acd02 | 2011-01-06 02:04:34 +0000 | [diff] [blame] | 780 | { |
| 781 | } |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 782 | #endif /* CONFIG_NFS_V4_1 */ |
| 783 | |
Bryan Schumaker | 6b140b8 | 2013-06-05 11:15:02 -0400 | [diff] [blame] | 784 | #ifdef CONFIG_NFS_V4_2 |
| 785 | static __be32 |
| 786 | preprocess_nfs42_op(int nop, unsigned int op_nr, struct callback_op **op) |
| 787 | { |
| 788 | __be32 status = preprocess_nfs41_op(nop, op_nr, op); |
| 789 | if (status != htonl(NFS4ERR_OP_ILLEGAL)) |
| 790 | return status; |
| 791 | |
| 792 | if (op_nr == OP_CB_OFFLOAD) |
| 793 | return htonl(NFS4ERR_NOTSUPP); |
| 794 | return htonl(NFS4ERR_OP_ILLEGAL); |
| 795 | } |
| 796 | #else /* CONFIG_NFS_V4_2 */ |
| 797 | static __be32 |
| 798 | preprocess_nfs42_op(int nop, unsigned int op_nr, struct callback_op **op) |
| 799 | { |
| 800 | return htonl(NFS4ERR_MINOR_VERS_MISMATCH); |
| 801 | } |
| 802 | #endif /* CONFIG_NFS_V4_2 */ |
| 803 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 804 | static __be32 |
| 805 | preprocess_nfs4_op(unsigned int op_nr, struct callback_op **op) |
| 806 | { |
| 807 | switch (op_nr) { |
| 808 | case OP_CB_GETATTR: |
| 809 | case OP_CB_RECALL: |
| 810 | *op = &callback_ops[op_nr]; |
| 811 | break; |
| 812 | default: |
| 813 | return htonl(NFS4ERR_OP_ILLEGAL); |
| 814 | } |
| 815 | |
| 816 | return htonl(NFS_OK); |
| 817 | } |
| 818 | |
Bryan Schumaker | 459de2e | 2013-06-05 11:15:01 -0400 | [diff] [blame] | 819 | static __be32 process_op(int nop, struct svc_rqst *rqstp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | struct xdr_stream *xdr_in, void *argp, |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 821 | struct xdr_stream *xdr_out, void *resp, |
| 822 | struct cb_process_state *cps) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | { |
Trond Myklebust | a162a6b | 2006-03-20 13:44:10 -0500 | [diff] [blame] | 824 | struct callback_op *op = &callback_ops[0]; |
Andy Adamson | 31d2b43 | 2010-01-14 17:45:04 -0500 | [diff] [blame] | 825 | unsigned int op_nr; |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 826 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | long maxlen; |
Al Viro | e6f684f | 2006-10-19 23:28:50 -0700 | [diff] [blame] | 828 | __be32 res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 830 | dprintk("%s: start\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | status = decode_op_hdr(xdr_in, &op_nr); |
Andy Adamson | 31d2b43 | 2010-01-14 17:45:04 -0500 | [diff] [blame] | 832 | if (unlikely(status)) |
| 833 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [diff] [blame] | 835 | dprintk("%s: minorversion=%d nop=%d op_nr=%u\n", |
Bryan Schumaker | 459de2e | 2013-06-05 11:15:01 -0400 | [diff] [blame] | 836 | __func__, cps->minorversion, nop, op_nr); |
Benny Halevy | 34bc47c9 | 2009-04-01 09:23:22 -0400 | [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); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 876 | dprintk("%s: done, status = %d\n", __func__, ntohl(status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | return status; |
| 878 | } |
| 879 | |
| 880 | /* |
| 881 | * Decode, process and encode a COMPOUND |
| 882 | */ |
Al Viro | 7111c66 | 2006-10-19 23:28:45 -0700 | [diff] [blame] | 883 | 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] | 884 | { |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 885 | struct cb_compound_hdr_arg hdr_arg = { 0 }; |
| 886 | struct cb_compound_hdr_res hdr_res = { NULL }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | struct xdr_stream xdr_in, xdr_out; |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 888 | __be32 *p, status; |
| 889 | struct cb_process_state cps = { |
| 890 | .drc_status = 0, |
| 891 | .clp = NULL, |
Stanislav Kinsbursky | 9695c70 | 2012-07-25 16:57:06 +0400 | [diff] [blame] | 892 | .net = SVC_NET(rqstp), |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 893 | }; |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 894 | unsigned int nops = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 896 | dprintk("%s: start\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | |
Trond Myklebust | 756b9b3 | 2015-12-07 12:52:23 -0800 | [diff] [blame] | 898 | 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] | 899 | |
Al Viro | 5704fde | 2006-10-19 23:28:51 -0700 | [diff] [blame] | 900 | 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] | 901 | xdr_init_encode(&xdr_out, &rqstp->rq_res, p); |
| 902 | |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 903 | status = decode_compound_hdr_arg(&xdr_in, &hdr_arg); |
Vaishali Thakkar | 4ed0d83 | 2015-06-10 20:15:29 +0530 | [diff] [blame] | 904 | if (status == htonl(NFS4ERR_RESOURCE)) |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 905 | return rpc_garbage_args; |
| 906 | |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 907 | if (hdr_arg.minorversion == 0) { |
Stanislav Kinsbursky | 9695c70 | 2012-07-25 16:57:06 +0400 | [diff] [blame] | 908 | 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] | 909 | if (!cps.clp || !check_gss_callback_principal(cps.clp, rqstp)) |
Chuck Lever | a4e187d | 2016-06-29 13:55:22 -0400 | [diff] [blame] | 910 | goto out_invalidcred; |
Andy Adamson | 778be23 | 2011-01-25 15:38:01 +0000 | [diff] [blame] | 911 | } |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 912 | |
Bryan Schumaker | 459de2e | 2013-06-05 11:15:01 -0400 | [diff] [blame] | 913 | cps.minorversion = hdr_arg.minorversion; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | hdr_res.taglen = hdr_arg.taglen; |
| 915 | hdr_res.tag = hdr_arg.tag; |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 916 | if (encode_compound_hdr_res(&xdr_out, &hdr_res) != 0) |
| 917 | return rpc_system_err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 919 | while (status == 0 && nops != hdr_arg.nops) { |
Bryan Schumaker | 459de2e | 2013-06-05 11:15:01 -0400 | [diff] [blame] | 920 | status = process_op(nops, rqstp, &xdr_in, |
| 921 | argp, &xdr_out, resp, &cps); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | nops++; |
| 923 | } |
Trond Myklebust | 3a6258e | 2008-05-06 13:32:40 -0400 | [diff] [blame] | 924 | |
Andy Adamson | 31d2b43 | 2010-01-14 17:45:04 -0500 | [diff] [blame] | 925 | /* Buffer overflow in decode_ops_hdr or encode_ops_hdr. Return |
| 926 | * resource error in cb_compound status without returning op */ |
| 927 | if (unlikely(status == htonl(NFS4ERR_RESOURCE_HDR))) { |
| 928 | status = htonl(NFS4ERR_RESOURCE); |
| 929 | nops--; |
| 930 | } |
| 931 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | *hdr_res.status = status; |
| 933 | *hdr_res.nops = htonl(nops); |
Trond Myklebust | 55a6739 | 2011-08-02 14:46:29 -0400 | [diff] [blame] | 934 | nfs4_cb_free_slot(&cps); |
Andy Adamson | c36fca5 | 2011-01-06 02:04:32 +0000 | [diff] [blame] | 935 | nfs_put_client(cps.clp); |
Harvey Harrison | 3110ff8 | 2008-05-02 13:42:44 -0700 | [diff] [blame] | 936 | dprintk("%s: done, status = %u\n", __func__, ntohl(status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | return rpc_success; |
Chuck Lever | a4e187d | 2016-06-29 13:55:22 -0400 | [diff] [blame] | 938 | |
| 939 | out_invalidcred: |
| 940 | pr_warn_ratelimited("NFS: NFSv4 callback contains invalid cred\n"); |
| 941 | return rpc_autherr_badcred; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | /* |
| 945 | * Define NFS4 callback COMPOUND ops. |
| 946 | */ |
| 947 | static struct callback_op callback_ops[] = { |
| 948 | [0] = { |
| 949 | .res_maxsize = CB_OP_HDR_RES_MAXSZ, |
| 950 | }, |
| 951 | [OP_CB_GETATTR] = { |
| 952 | .process_op = (callback_process_op_t)nfs4_callback_getattr, |
| 953 | .decode_args = (callback_decode_arg_t)decode_getattr_args, |
| 954 | .encode_res = (callback_encode_res_t)encode_getattr_res, |
| 955 | .res_maxsize = CB_OP_GETATTR_RES_MAXSZ, |
| 956 | }, |
| 957 | [OP_CB_RECALL] = { |
| 958 | .process_op = (callback_process_op_t)nfs4_callback_recall, |
| 959 | .decode_args = (callback_decode_arg_t)decode_recall_args, |
| 960 | .res_maxsize = CB_OP_RECALL_RES_MAXSZ, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 961 | }, |
| 962 | #if defined(CONFIG_NFS_V4_1) |
Fred Isaman | f2a6256 | 2011-01-06 11:36:29 +0000 | [diff] [blame] | 963 | [OP_CB_LAYOUTRECALL] = { |
| 964 | .process_op = (callback_process_op_t)nfs4_callback_layoutrecall, |
| 965 | .decode_args = |
| 966 | (callback_decode_arg_t)decode_layoutrecall_args, |
| 967 | .res_maxsize = CB_OP_LAYOUTRECALL_RES_MAXSZ, |
| 968 | }, |
Marc Eshel | 1be5683 | 2011-05-22 19:47:09 +0300 | [diff] [blame] | 969 | [OP_CB_NOTIFY_DEVICEID] = { |
| 970 | .process_op = (callback_process_op_t)nfs4_callback_devicenotify, |
| 971 | .decode_args = |
| 972 | (callback_decode_arg_t)decode_devicenotify_args, |
| 973 | .res_maxsize = CB_OP_DEVICENOTIFY_RES_MAXSZ, |
| 974 | }, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 975 | [OP_CB_SEQUENCE] = { |
| 976 | .process_op = (callback_process_op_t)nfs4_callback_sequence, |
| 977 | .decode_args = (callback_decode_arg_t)decode_cb_sequence_args, |
| 978 | .encode_res = (callback_encode_res_t)encode_cb_sequence_res, |
| 979 | .res_maxsize = CB_OP_SEQUENCE_RES_MAXSZ, |
| 980 | }, |
Alexandros Batsakis | 31f0960 | 2009-12-05 13:27:02 -0500 | [diff] [blame] | 981 | [OP_CB_RECALL_ANY] = { |
| 982 | .process_op = (callback_process_op_t)nfs4_callback_recallany, |
| 983 | .decode_args = (callback_decode_arg_t)decode_recallany_args, |
| 984 | .res_maxsize = CB_OP_RECALLANY_RES_MAXSZ, |
| 985 | }, |
Andy Adamson | b9efa1b | 2010-01-20 16:06:27 -0500 | [diff] [blame] | 986 | [OP_CB_RECALL_SLOT] = { |
| 987 | .process_op = (callback_process_op_t)nfs4_callback_recallslot, |
| 988 | .decode_args = (callback_decode_arg_t)decode_recallslot_args, |
| 989 | .res_maxsize = CB_OP_RECALLSLOT_RES_MAXSZ, |
| 990 | }, |
Jeff Layton | db78368 | 2016-09-17 18:17:36 -0400 | [diff] [blame] | 991 | [OP_CB_NOTIFY_LOCK] = { |
| 992 | .process_op = (callback_process_op_t)nfs4_callback_notify_lock, |
| 993 | .decode_args = (callback_decode_arg_t)decode_notify_lock_args, |
| 994 | .res_maxsize = CB_OP_NOTIFY_LOCK_RES_MAXSZ, |
| 995 | }, |
Benny Halevy | 4aece6a | 2009-04-01 09:23:26 -0400 | [diff] [blame] | 996 | #endif /* CONFIG_NFS_V4_1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | }; |
| 998 | |
| 999 | /* |
| 1000 | * Define NFS4 callback procedures |
| 1001 | */ |
| 1002 | static struct svc_procedure nfs4_callback_procedures1[] = { |
| 1003 | [CB_NULL] = { |
| 1004 | .pc_func = nfs4_callback_null, |
| 1005 | .pc_decode = (kxdrproc_t)nfs4_decode_void, |
| 1006 | .pc_encode = (kxdrproc_t)nfs4_encode_void, |
| 1007 | .pc_xdrressize = 1, |
| 1008 | }, |
| 1009 | [CB_COMPOUND] = { |
| 1010 | .pc_func = nfs4_callback_compound, |
| 1011 | .pc_encode = (kxdrproc_t)nfs4_encode_void, |
| 1012 | .pc_argsize = 256, |
| 1013 | .pc_ressize = 256, |
| 1014 | .pc_xdrressize = NFS4_CALLBACK_BUFSIZE, |
| 1015 | } |
| 1016 | }; |
| 1017 | |
| 1018 | struct svc_version nfs4_callback_version1 = { |
| 1019 | .vs_vers = 1, |
| 1020 | .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1), |
| 1021 | .vs_proc = nfs4_callback_procedures1, |
| 1022 | .vs_xdrsize = NFS4_CALLBACK_XDRSIZE, |
| 1023 | .vs_dispatch = NULL, |
Jeff Layton | 05a45a2 | 2017-02-24 13:25:22 -0500 | [diff] [blame] | 1024 | .vs_hidden = true, |
Jeff Layton | 5283b03 | 2017-02-24 13:25:24 -0500 | [diff] [blame] | 1025 | .vs_need_cong_ctrl = true, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | }; |
| 1027 | |
Alexandros Batsakis | 07bccc2 | 2009-12-05 13:19:01 -0500 | [diff] [blame] | 1028 | struct svc_version nfs4_callback_version4 = { |
| 1029 | .vs_vers = 4, |
| 1030 | .vs_nproc = ARRAY_SIZE(nfs4_callback_procedures1), |
| 1031 | .vs_proc = nfs4_callback_procedures1, |
| 1032 | .vs_xdrsize = NFS4_CALLBACK_XDRSIZE, |
| 1033 | .vs_dispatch = NULL, |
Jeff Layton | 05a45a2 | 2017-02-24 13:25:22 -0500 | [diff] [blame] | 1034 | .vs_hidden = true, |
Jeff Layton | 5283b03 | 2017-02-24 13:25:24 -0500 | [diff] [blame] | 1035 | .vs_need_cong_ctrl = true, |
Alexandros Batsakis | 07bccc2 | 2009-12-05 13:19:01 -0500 | [diff] [blame] | 1036 | }; |