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