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