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