Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Server-side XDR for NFSv4 |
| 3 | * |
| 4 | * Copyright (c) 2002 The Regents of the University of Michigan. |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Kendrick Smith <kmsmith@umich.edu> |
| 8 | * Andy Adamson <andros@umich.edu> |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions |
| 12 | * are met: |
| 13 | * |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
| 18 | * documentation and/or other materials provided with the distribution. |
| 19 | * 3. Neither the name of the University nor the names of its |
| 20 | * contributors may be used to endorse or promote products derived |
| 21 | * from this software without specific prior written permission. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 24 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 25 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 26 | * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 30 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | */ |
| 35 | |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 36 | #include <linux/file.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/namei.h> |
Boaz Harrosh | 341eb18 | 2009-12-03 20:29:12 +0200 | [diff] [blame] | 39 | #include <linux/statfs.h> |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 40 | #include <linux/utsname.h> |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 41 | #include <linux/pagemap.h> |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 42 | #include <linux/sunrpc/svcauth_gss.h> |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 43 | #include <linux/sunrpc/addr.h> |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 44 | #include <linux/xattr.h> |
| 45 | #include <uapi/linux/xattr.h> |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 46 | |
J. Bruce Fields | 2ca72e1 | 2011-01-04 17:37:15 -0500 | [diff] [blame] | 47 | #include "idmap.h" |
| 48 | #include "acl.h" |
Boaz Harrosh | 9a74af2 | 2009-12-03 20:30:56 +0200 | [diff] [blame] | 49 | #include "xdr4.h" |
J. Bruce Fields | 0a3adad | 2009-11-04 18:12:35 -0500 | [diff] [blame] | 50 | #include "vfs.h" |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 51 | #include "state.h" |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 52 | #include "cache.h" |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 53 | #include "netns.h" |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 54 | #include "pnfs.h" |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 55 | #include "filecache.h" |
J. Bruce Fields | 2ca72e1 | 2011-01-04 17:37:15 -0500 | [diff] [blame] | 56 | |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 57 | #include "trace.h" |
| 58 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 59 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
| 60 | #include <linux/security.h> |
| 61 | #endif |
| 62 | |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #define NFSDDBG_FACILITY NFSDDBG_XDR |
| 65 | |
J. Bruce Fields | 5cf23db | 2017-01-11 20:40:36 -0500 | [diff] [blame] | 66 | const u32 nfsd_suppattrs[3][3] = { |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 67 | {NFSD4_SUPPORTED_ATTRS_WORD0, |
| 68 | NFSD4_SUPPORTED_ATTRS_WORD1, |
| 69 | NFSD4_SUPPORTED_ATTRS_WORD2}, |
| 70 | |
| 71 | {NFSD4_1_SUPPORTED_ATTRS_WORD0, |
| 72 | NFSD4_1_SUPPORTED_ATTRS_WORD1, |
| 73 | NFSD4_1_SUPPORTED_ATTRS_WORD2}, |
| 74 | |
| 75 | {NFSD4_1_SUPPORTED_ATTRS_WORD0, |
| 76 | NFSD4_1_SUPPORTED_ATTRS_WORD1, |
| 77 | NFSD4_2_SUPPORTED_ATTRS_WORD2}, |
| 78 | }; |
| 79 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 80 | /* |
| 81 | * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing |
| 82 | * directory in order to indicate to the client that a filesystem boundary is present |
| 83 | * We use a fixed fsid for a referral |
| 84 | */ |
| 85 | #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL |
| 86 | #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL |
| 87 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 88 | static __be32 |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 89 | check_filename(char *str, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
| 91 | int i; |
| 92 | |
| 93 | if (len == 0) |
| 94 | return nfserr_inval; |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 95 | if (len > NFS4_MAXNAMLEN) |
| 96 | return nfserr_nametoolong; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | if (isdotent(str, len)) |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 98 | return nfserr_badname; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | for (i = 0; i < len; i++) |
| 100 | if (str[i] == '/') |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 101 | return nfserr_badname; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | #define DECODE_HEAD \ |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 106 | __be32 *p; \ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 107 | __be32 status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | #define DECODE_TAIL \ |
| 109 | status = 0; \ |
| 110 | out: \ |
| 111 | return status; \ |
| 112 | xdr_error: \ |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 113 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
| 114 | __FILE__, __LINE__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | status = nfserr_bad_xdr; \ |
| 116 | goto out |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #define READMEM(x,nbytes) do { \ |
| 119 | x = (char *)p; \ |
| 120 | p += XDR_QUADLEN(nbytes); \ |
| 121 | } while (0) |
| 122 | #define SAVEMEM(x,nbytes) do { \ |
| 123 | if (!(x = (p==argp->tmp || p == argp->tmpp) ? \ |
| 124 | savemem(argp, p, nbytes) : \ |
| 125 | (char *)p)) { \ |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 126 | dprintk("NFSD: xdr error (%s:%d)\n", \ |
| 127 | __FILE__, __LINE__); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | goto xdr_error; \ |
| 129 | } \ |
| 130 | p += XDR_QUADLEN(nbytes); \ |
| 131 | } while (0) |
| 132 | #define COPYMEM(x,nbytes) do { \ |
| 133 | memcpy((x), p, nbytes); \ |
| 134 | p += XDR_QUADLEN(nbytes); \ |
| 135 | } while (0) |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 136 | #define READ_BUF(nbytes) \ |
| 137 | do { \ |
| 138 | p = xdr_inline_decode(argp->xdr,\ |
| 139 | nbytes); \ |
| 140 | if (!p) \ |
| 141 | goto xdr_error; \ |
| 142 | } while (0) |
J. Bruce Fields | 2b86e3a | 2019-08-28 21:13:45 -0400 | [diff] [blame] | 143 | |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 144 | static int zero_clientid(clientid_t *clid) |
| 145 | { |
| 146 | return (clid->cl_boot == 0) && (clid->cl_id == 0); |
| 147 | } |
| 148 | |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 149 | /** |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 150 | * svcxdr_tmpalloc - allocate memory to be freed after compound processing |
J. Bruce Fields | ce043ac | 2014-06-24 16:51:12 -0400 | [diff] [blame] | 151 | * @argp: NFSv4 compound argument structure |
Trond Myklebust | ed99275 | 2019-08-18 14:18:59 -0400 | [diff] [blame] | 152 | * @len: length of buffer to allocate |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 153 | * |
Trond Myklebust | ed99275 | 2019-08-18 14:18:59 -0400 | [diff] [blame] | 154 | * Allocates a buffer of size @len to be freed when processing the compound |
| 155 | * operation described in @argp finishes. |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 156 | */ |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 157 | static void * |
| 158 | svcxdr_tmpalloc(struct nfsd4_compoundargs *argp, u32 len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 160 | struct svcxdr_tmpbuf *tb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 162 | tb = kmalloc(sizeof(*tb) + len, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | if (!tb) |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 164 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | tb->next = argp->to_free; |
| 166 | argp->to_free = tb; |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 167 | return tb->buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
| 169 | |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 170 | /* |
| 171 | * For xdr strings that need to be passed to other kernel api's |
| 172 | * as null-terminated strings. |
| 173 | * |
| 174 | * Note null-terminating in place usually isn't safe since the |
| 175 | * buffer might end on a page boundary. |
| 176 | */ |
| 177 | static char * |
| 178 | svcxdr_dupstr(struct nfsd4_compoundargs *argp, void *buf, u32 len) |
| 179 | { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 180 | char *p = svcxdr_tmpalloc(argp, len + 1); |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 181 | |
| 182 | if (!p) |
| 183 | return NULL; |
| 184 | memcpy(p, buf, len); |
| 185 | p[len] = '\0'; |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 186 | return p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Christoph Hellwig | 2d8498d | 2013-11-20 00:24:11 -0800 | [diff] [blame] | 189 | /** |
| 190 | * savemem - duplicate a chunk of memory for later processing |
| 191 | * @argp: NFSv4 compound argument structure to be freed with |
| 192 | * @p: pointer to be duplicated |
| 193 | * @nbytes: length to be duplicated |
| 194 | * |
| 195 | * Returns a pointer to a copy of @nbytes bytes of memory at @p |
| 196 | * that are preserved until processing of the NFSv4 compound |
| 197 | * operation described by @argp finishes. |
| 198 | */ |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 199 | static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 201 | void *ret; |
| 202 | |
| 203 | ret = svcxdr_tmpalloc(argp, nbytes); |
| 204 | if (!ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | return NULL; |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 206 | memcpy(ret, p, nbytes); |
| 207 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Chuck Lever | 5dcbfab | 2020-11-04 11:41:55 -0500 | [diff] [blame] | 210 | |
| 211 | /* |
| 212 | * NFSv4 basic data type decoders |
| 213 | */ |
| 214 | |
| 215 | static __be32 |
| 216 | nfsd4_decode_opaque(struct nfsd4_compoundargs *argp, struct xdr_netobj *o) |
| 217 | { |
| 218 | __be32 *p; |
| 219 | u32 len; |
| 220 | |
| 221 | if (xdr_stream_decode_u32(argp->xdr, &len) < 0) |
| 222 | return nfserr_bad_xdr; |
| 223 | if (len == 0 || len > NFS4_OPAQUE_LIMIT) |
| 224 | return nfserr_bad_xdr; |
| 225 | p = xdr_inline_decode(argp->xdr, len); |
| 226 | if (!p) |
| 227 | return nfserr_bad_xdr; |
| 228 | o->data = svcxdr_tmpalloc(argp, len); |
| 229 | if (!o->data) |
| 230 | return nfserr_jukebox; |
| 231 | o->len = len; |
| 232 | memcpy(o->data, p, len); |
| 233 | |
| 234 | return nfs_ok; |
| 235 | } |
| 236 | |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 237 | static __be32 |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 238 | nfsd4_decode_component4(struct nfsd4_compoundargs *argp, char **namp, u32 *lenp) |
| 239 | { |
| 240 | __be32 *p, status; |
| 241 | |
| 242 | if (xdr_stream_decode_u32(argp->xdr, lenp) < 0) |
| 243 | return nfserr_bad_xdr; |
| 244 | p = xdr_inline_decode(argp->xdr, *lenp); |
| 245 | if (!p) |
| 246 | return nfserr_bad_xdr; |
| 247 | status = check_filename((char *)p, *lenp); |
| 248 | if (status) |
| 249 | return status; |
| 250 | *namp = svcxdr_tmpalloc(argp, *lenp); |
| 251 | if (!*namp) |
| 252 | return nfserr_jukebox; |
| 253 | memcpy(*namp, p, *lenp); |
| 254 | |
| 255 | return nfs_ok; |
| 256 | } |
| 257 | |
| 258 | static __be32 |
J. Bruce Fields | bdba536 | 2019-06-05 14:17:42 -0400 | [diff] [blame] | 259 | nfsd4_decode_time(struct nfsd4_compoundargs *argp, struct timespec64 *tv) |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 260 | { |
| 261 | DECODE_HEAD; |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 262 | |
| 263 | READ_BUF(12); |
J. Bruce Fields | bdba536 | 2019-06-05 14:17:42 -0400 | [diff] [blame] | 264 | p = xdr_decode_hyper(p, &tv->tv_sec); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 265 | tv->tv_nsec = be32_to_cpup(p++); |
| 266 | if (tv->tv_nsec >= (u32)1000000000) |
| 267 | return nfserr_inval; |
| 268 | |
| 269 | DECODE_TAIL; |
| 270 | } |
| 271 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 272 | static __be32 |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 273 | nfsd4_decode_nfstime4(struct nfsd4_compoundargs *argp, struct timespec64 *tv) |
| 274 | { |
| 275 | __be32 *p; |
| 276 | |
| 277 | p = xdr_inline_decode(argp->xdr, XDR_UNIT * 3); |
| 278 | if (!p) |
| 279 | return nfserr_bad_xdr; |
| 280 | p = xdr_decode_hyper(p, &tv->tv_sec); |
| 281 | tv->tv_nsec = be32_to_cpup(p++); |
| 282 | if (tv->tv_nsec >= (u32)1000000000) |
| 283 | return nfserr_inval; |
| 284 | return nfs_ok; |
| 285 | } |
| 286 | |
| 287 | static __be32 |
Chuck Lever | 796dd1c | 2020-11-16 17:34:01 -0500 | [diff] [blame] | 288 | nfsd4_decode_verifier4(struct nfsd4_compoundargs *argp, nfs4_verifier *verf) |
| 289 | { |
| 290 | __be32 *p; |
| 291 | |
| 292 | p = xdr_inline_decode(argp->xdr, NFS4_VERIFIER_SIZE); |
| 293 | if (!p) |
| 294 | return nfserr_bad_xdr; |
| 295 | memcpy(verf->data, p, sizeof(verf->data)); |
| 296 | return nfs_ok; |
| 297 | } |
| 298 | |
| 299 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval) |
| 301 | { |
| 302 | u32 bmlen; |
| 303 | DECODE_HEAD; |
| 304 | |
| 305 | bmval[0] = 0; |
| 306 | bmval[1] = 0; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 307 | bmval[2] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
| 309 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 310 | bmlen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | if (bmlen > 1000) |
| 312 | goto xdr_error; |
| 313 | |
| 314 | READ_BUF(bmlen << 2); |
| 315 | if (bmlen > 0) |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 316 | bmval[0] = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | if (bmlen > 1) |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 318 | bmval[1] = be32_to_cpup(p++); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 319 | if (bmlen > 2) |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 320 | bmval[2] = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
| 322 | DECODE_TAIL; |
| 323 | } |
| 324 | |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 325 | /** |
| 326 | * nfsd4_decode_bitmap4 - Decode an NFSv4 bitmap4 |
| 327 | * @argp: NFSv4 compound argument structure |
| 328 | * @bmval: pointer to an array of u32's to decode into |
| 329 | * @bmlen: size of the @bmval array |
| 330 | * |
| 331 | * The server needs to return nfs_ok rather than nfserr_bad_xdr when |
| 332 | * encountering bitmaps containing bits it does not recognize. This |
| 333 | * includes bits in bitmap words past WORDn, where WORDn is the last |
| 334 | * bitmap WORD the implementation currently supports. Thus we are |
| 335 | * careful here to simply ignore bits in bitmap words that this |
| 336 | * implementation has yet to support explicitly. |
| 337 | * |
| 338 | * Return values: |
| 339 | * %nfs_ok: @bmval populated successfully |
| 340 | * %nfserr_bad_xdr: the encoded bitmap was invalid |
| 341 | */ |
| 342 | static __be32 |
| 343 | nfsd4_decode_bitmap4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen) |
| 344 | { |
| 345 | u32 i, count; |
| 346 | __be32 *p; |
| 347 | |
| 348 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 349 | return nfserr_bad_xdr; |
| 350 | /* request sanity */ |
| 351 | if (count > 1000) |
| 352 | return nfserr_bad_xdr; |
| 353 | p = xdr_inline_decode(argp->xdr, count << 2); |
| 354 | if (!p) |
| 355 | return nfserr_bad_xdr; |
| 356 | i = 0; |
| 357 | while (i < count) |
| 358 | bmval[i++] = be32_to_cpup(p++); |
| 359 | while (i < bmlen) |
| 360 | bmval[i++] = 0; |
| 361 | |
| 362 | return nfs_ok; |
| 363 | } |
| 364 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 365 | static __be32 |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 366 | nfsd4_decode_nfsace4(struct nfsd4_compoundargs *argp, struct nfs4_ace *ace) |
| 367 | { |
| 368 | __be32 *p, status; |
| 369 | u32 length; |
| 370 | |
| 371 | if (xdr_stream_decode_u32(argp->xdr, &ace->type) < 0) |
| 372 | return nfserr_bad_xdr; |
| 373 | if (xdr_stream_decode_u32(argp->xdr, &ace->flag) < 0) |
| 374 | return nfserr_bad_xdr; |
| 375 | if (xdr_stream_decode_u32(argp->xdr, &ace->access_mask) < 0) |
| 376 | return nfserr_bad_xdr; |
| 377 | |
| 378 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 379 | return nfserr_bad_xdr; |
| 380 | p = xdr_inline_decode(argp->xdr, length); |
| 381 | if (!p) |
| 382 | return nfserr_bad_xdr; |
| 383 | ace->whotype = nfs4_acl_get_whotype((char *)p, length); |
| 384 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
| 385 | status = nfs_ok; |
| 386 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
| 387 | status = nfsd_map_name_to_gid(argp->rqstp, |
| 388 | (char *)p, length, &ace->who_gid); |
| 389 | else |
| 390 | status = nfsd_map_name_to_uid(argp->rqstp, |
| 391 | (char *)p, length, &ace->who_uid); |
| 392 | |
| 393 | return status; |
| 394 | } |
| 395 | |
| 396 | /* A counted array of nfsace4's */ |
| 397 | static noinline __be32 |
| 398 | nfsd4_decode_acl(struct nfsd4_compoundargs *argp, struct nfs4_acl **acl) |
| 399 | { |
| 400 | struct nfs4_ace *ace; |
| 401 | __be32 status; |
| 402 | u32 count; |
| 403 | |
| 404 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 405 | return nfserr_bad_xdr; |
| 406 | |
| 407 | if (count > xdr_stream_remaining(argp->xdr) / 20) |
| 408 | /* |
| 409 | * Even with 4-byte names there wouldn't be |
| 410 | * space for that many aces; something fishy is |
| 411 | * going on: |
| 412 | */ |
| 413 | return nfserr_fbig; |
| 414 | |
| 415 | *acl = svcxdr_tmpalloc(argp, nfs4_acl_bytes(count)); |
| 416 | if (*acl == NULL) |
| 417 | return nfserr_jukebox; |
| 418 | |
| 419 | (*acl)->naces = count; |
| 420 | for (ace = (*acl)->aces; ace < (*acl)->aces + count; ace++) { |
| 421 | status = nfsd4_decode_nfsace4(argp, ace); |
| 422 | if (status) |
| 423 | return status; |
| 424 | } |
| 425 | |
| 426 | return nfs_ok; |
| 427 | } |
| 428 | |
Chuck Lever | dabe918 | 2020-11-19 14:05:51 -0500 | [diff] [blame] | 429 | static noinline __be32 |
| 430 | nfsd4_decode_security_label(struct nfsd4_compoundargs *argp, |
| 431 | struct xdr_netobj *label) |
| 432 | { |
| 433 | u32 lfs, pi, length; |
| 434 | __be32 *p; |
| 435 | |
| 436 | if (xdr_stream_decode_u32(argp->xdr, &lfs) < 0) |
| 437 | return nfserr_bad_xdr; |
| 438 | if (xdr_stream_decode_u32(argp->xdr, &pi) < 0) |
| 439 | return nfserr_bad_xdr; |
| 440 | |
| 441 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 442 | return nfserr_bad_xdr; |
| 443 | if (length > NFS4_MAXLABELLEN) |
| 444 | return nfserr_badlabel; |
| 445 | p = xdr_inline_decode(argp->xdr, length); |
| 446 | if (!p) |
| 447 | return nfserr_bad_xdr; |
| 448 | label->len = length; |
| 449 | label->data = svcxdr_dupstr(argp, p, length); |
| 450 | if (!label->data) |
| 451 | return nfserr_jukebox; |
| 452 | |
| 453 | return nfs_ok; |
| 454 | } |
| 455 | |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 456 | static __be32 |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 457 | nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen, |
| 458 | struct iattr *iattr, struct nfs4_acl **acl, |
| 459 | struct xdr_netobj *label, int *umask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | { |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 461 | unsigned int starting_pos; |
| 462 | u32 attrlist4_count; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 463 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | iattr->ia_valid = 0; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 466 | status = nfsd4_decode_bitmap4(argp, bmval, bmlen); |
| 467 | if (status) |
| 468 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
J. Bruce Fields | e864c18 | 2016-06-10 16:56:05 -0400 | [diff] [blame] | 470 | if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0 |
| 471 | || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1 |
| 472 | || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2) { |
| 473 | if (nfsd_attrs_supported(argp->minorversion, bmval)) |
| 474 | return nfserr_inval; |
| 475 | return nfserr_attrnotsupp; |
| 476 | } |
| 477 | |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 478 | if (xdr_stream_decode_u32(argp->xdr, &attrlist4_count) < 0) |
| 479 | return nfserr_bad_xdr; |
| 480 | starting_pos = xdr_stream_pos(argp->xdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
| 482 | if (bmval[0] & FATTR4_WORD0_SIZE) { |
Chuck Lever | 2ac1b9b | 2020-11-19 13:47:16 -0500 | [diff] [blame] | 483 | u64 size; |
| 484 | |
| 485 | if (xdr_stream_decode_u64(argp->xdr, &size) < 0) |
| 486 | return nfserr_bad_xdr; |
| 487 | iattr->ia_size = size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | iattr->ia_valid |= ATTR_SIZE; |
| 489 | } |
| 490 | if (bmval[0] & FATTR4_WORD0_ACL) { |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 491 | status = nfsd4_decode_acl(argp, acl); |
| 492 | if (status) |
| 493 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } else |
| 495 | *acl = NULL; |
| 496 | if (bmval[1] & FATTR4_WORD1_MODE) { |
Chuck Lever | 1c8f0ad | 2020-11-19 13:54:26 -0500 | [diff] [blame] | 497 | u32 mode; |
| 498 | |
| 499 | if (xdr_stream_decode_u32(argp->xdr, &mode) < 0) |
| 500 | return nfserr_bad_xdr; |
| 501 | iattr->ia_mode = mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | iattr->ia_mode &= (S_IFMT | S_IALLUGO); |
| 503 | iattr->ia_valid |= ATTR_MODE; |
| 504 | } |
| 505 | if (bmval[1] & FATTR4_WORD1_OWNER) { |
Chuck Lever | 9853a5a | 2020-11-19 13:56:42 -0500 | [diff] [blame] | 506 | u32 length; |
| 507 | |
| 508 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 509 | return nfserr_bad_xdr; |
| 510 | p = xdr_inline_decode(argp->xdr, length); |
| 511 | if (!p) |
| 512 | return nfserr_bad_xdr; |
| 513 | status = nfsd_map_name_to_uid(argp->rqstp, (char *)p, length, |
| 514 | &iattr->ia_uid); |
| 515 | if (status) |
NeilBrown | 47c8529 | 2011-02-16 13:08:35 +1100 | [diff] [blame] | 516 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | iattr->ia_valid |= ATTR_UID; |
| 518 | } |
| 519 | if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) { |
Chuck Lever | 393c31d | 2020-11-19 13:58:18 -0500 | [diff] [blame] | 520 | u32 length; |
| 521 | |
| 522 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 523 | return nfserr_bad_xdr; |
| 524 | p = xdr_inline_decode(argp->xdr, length); |
| 525 | if (!p) |
| 526 | return nfserr_bad_xdr; |
| 527 | status = nfsd_map_name_to_gid(argp->rqstp, (char *)p, length, |
| 528 | &iattr->ia_gid); |
| 529 | if (status) |
NeilBrown | 47c8529 | 2011-02-16 13:08:35 +1100 | [diff] [blame] | 530 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | iattr->ia_valid |= ATTR_GID; |
| 532 | } |
| 533 | if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 534 | u32 set_it; |
| 535 | |
| 536 | if (xdr_stream_decode_u32(argp->xdr, &set_it) < 0) |
| 537 | return nfserr_bad_xdr; |
| 538 | switch (set_it) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | case NFS4_SET_TO_CLIENT_TIME: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 540 | status = nfsd4_decode_nfstime4(argp, &iattr->ia_atime); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 541 | if (status) |
| 542 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET); |
| 544 | break; |
| 545 | case NFS4_SET_TO_SERVER_TIME: |
| 546 | iattr->ia_valid |= ATTR_ATIME; |
| 547 | break; |
| 548 | default: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 549 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | } |
| 551 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 553 | u32 set_it; |
| 554 | |
| 555 | if (xdr_stream_decode_u32(argp->xdr, &set_it) < 0) |
| 556 | return nfserr_bad_xdr; |
| 557 | switch (set_it) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | case NFS4_SET_TO_CLIENT_TIME: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 559 | status = nfsd4_decode_nfstime4(argp, &iattr->ia_mtime); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 560 | if (status) |
| 561 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET); |
| 563 | break; |
| 564 | case NFS4_SET_TO_SERVER_TIME: |
| 565 | iattr->ia_valid |= ATTR_MTIME; |
| 566 | break; |
| 567 | default: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 568 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | } |
| 570 | } |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 571 | label->len = 0; |
Arnd Bergmann | 2285ae7 | 2018-01-22 22:09:12 +0100 | [diff] [blame] | 572 | if (IS_ENABLED(CONFIG_NFSD_V4_SECURITY_LABEL) && |
| 573 | bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { |
Chuck Lever | dabe918 | 2020-11-19 14:05:51 -0500 | [diff] [blame] | 574 | status = nfsd4_decode_security_label(argp, label); |
| 575 | if (status) |
| 576 | return status; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 577 | } |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 578 | if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { |
Chuck Lever | 66f0476 | 2020-11-19 14:07:43 -0500 | [diff] [blame] | 579 | u32 mode, mask; |
| 580 | |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 581 | if (!umask) |
Chuck Lever | 66f0476 | 2020-11-19 14:07:43 -0500 | [diff] [blame] | 582 | return nfserr_bad_xdr; |
| 583 | if (xdr_stream_decode_u32(argp->xdr, &mode) < 0) |
| 584 | return nfserr_bad_xdr; |
| 585 | iattr->ia_mode = mode & (S_IFMT | S_IALLUGO); |
| 586 | if (xdr_stream_decode_u32(argp->xdr, &mask) < 0) |
| 587 | return nfserr_bad_xdr; |
| 588 | *umask = mask & S_IRWXUGO; |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 589 | iattr->ia_valid |= ATTR_MODE; |
| 590 | } |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 591 | |
| 592 | /* request sanity: did attrlist4 contain the expected number of words? */ |
| 593 | if (attrlist4_count != xdr_stream_pos(argp->xdr) - starting_pos) |
| 594 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 596 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 599 | static __be32 |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 600 | nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid) |
| 601 | { |
| 602 | DECODE_HEAD; |
| 603 | |
| 604 | READ_BUF(sizeof(stateid_t)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 605 | sid->si_generation = be32_to_cpup(p++); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 606 | COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t)); |
| 607 | |
| 608 | DECODE_TAIL; |
| 609 | } |
| 610 | |
Chuck Lever | d3d2f38 | 2020-11-03 13:18:23 -0500 | [diff] [blame] | 611 | static __be32 |
| 612 | nfsd4_decode_stateid4(struct nfsd4_compoundargs *argp, stateid_t *sid) |
| 613 | { |
| 614 | __be32 *p; |
| 615 | |
| 616 | p = xdr_inline_decode(argp->xdr, NFS4_STATEID_SIZE); |
| 617 | if (!p) |
| 618 | return nfserr_bad_xdr; |
| 619 | sid->si_generation = be32_to_cpup(p++); |
| 620 | memcpy(&sid->si_opaque, p, sizeof(sid->si_opaque)); |
| 621 | return nfs_ok; |
| 622 | } |
| 623 | |
Chuck Lever | 144e826 | 2020-11-16 17:25:02 -0500 | [diff] [blame] | 624 | static __be32 |
| 625 | nfsd4_decode_clientid4(struct nfsd4_compoundargs *argp, clientid_t *clientid) |
| 626 | { |
| 627 | __be32 *p; |
| 628 | |
| 629 | p = xdr_inline_decode(argp->xdr, sizeof(__be64)); |
| 630 | if (!p) |
| 631 | return nfserr_bad_xdr; |
| 632 | memcpy(clientid, p, sizeof(*clientid)); |
| 633 | return nfs_ok; |
| 634 | } |
| 635 | |
| 636 | static __be32 |
| 637 | nfsd4_decode_state_owner4(struct nfsd4_compoundargs *argp, |
| 638 | clientid_t *clientid, struct xdr_netobj *owner) |
| 639 | { |
| 640 | __be32 status; |
| 641 | |
| 642 | status = nfsd4_decode_clientid4(argp, clientid); |
| 643 | if (status) |
| 644 | return status; |
| 645 | return nfsd4_decode_opaque(argp, owner); |
| 646 | } |
| 647 | |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 648 | static __be32 nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_cb_sec *cbs) |
| 649 | { |
| 650 | DECODE_HEAD; |
Trond Myklebust | e45d1a1 | 2019-04-09 12:13:42 -0400 | [diff] [blame] | 651 | struct user_namespace *userns = nfsd_user_namespace(argp->rqstp); |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 652 | u32 dummy, uid, gid; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 653 | char *machine_name; |
| 654 | int i; |
| 655 | int nr_secflavs; |
| 656 | |
| 657 | /* callback_sec_params4 */ |
| 658 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 659 | nr_secflavs = be32_to_cpup(p++); |
J. Bruce Fields | 57569a7 | 2013-05-17 16:25:32 -0400 | [diff] [blame] | 660 | if (nr_secflavs) |
| 661 | cbs->flavor = (u32)(-1); |
| 662 | else |
| 663 | /* Is this legal? Be generous, take it to mean AUTH_NONE: */ |
| 664 | cbs->flavor = 0; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 665 | for (i = 0; i < nr_secflavs; ++i) { |
| 666 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 667 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 668 | switch (dummy) { |
| 669 | case RPC_AUTH_NULL: |
| 670 | /* Nothing to read */ |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 671 | if (cbs->flavor == (u32)(-1)) |
| 672 | cbs->flavor = RPC_AUTH_NULL; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 673 | break; |
| 674 | case RPC_AUTH_UNIX: |
| 675 | READ_BUF(8); |
| 676 | /* stamp */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 677 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 678 | |
| 679 | /* machine name */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 680 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 681 | READ_BUF(dummy); |
| 682 | SAVEMEM(machine_name, dummy); |
| 683 | |
| 684 | /* uid, gid */ |
| 685 | READ_BUF(8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 686 | uid = be32_to_cpup(p++); |
| 687 | gid = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 688 | |
| 689 | /* more gids */ |
| 690 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 691 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 692 | READ_BUF(dummy * 4); |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 693 | if (cbs->flavor == (u32)(-1)) { |
Trond Myklebust | e45d1a1 | 2019-04-09 12:13:42 -0400 | [diff] [blame] | 694 | kuid_t kuid = make_kuid(userns, uid); |
| 695 | kgid_t kgid = make_kgid(userns, gid); |
Eric W. Biederman | 03bc6d1 | 2013-02-02 06:24:49 -0800 | [diff] [blame] | 696 | if (uid_valid(kuid) && gid_valid(kgid)) { |
| 697 | cbs->uid = kuid; |
| 698 | cbs->gid = kgid; |
| 699 | cbs->flavor = RPC_AUTH_UNIX; |
| 700 | } else { |
| 701 | dprintk("RPC_AUTH_UNIX with invalid" |
| 702 | "uid or gid ignoring!\n"); |
| 703 | } |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 704 | } |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 705 | break; |
| 706 | case RPC_AUTH_GSS: |
| 707 | dprintk("RPC_AUTH_GSS callback secflavor " |
| 708 | "not supported!\n"); |
| 709 | READ_BUF(8); |
| 710 | /* gcbp_service */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 711 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 712 | /* gcbp_handle_from_server */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 713 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 714 | READ_BUF(dummy); |
| 715 | p += XDR_QUADLEN(dummy); |
| 716 | /* gcbp_handle_from_client */ |
| 717 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 718 | dummy = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 719 | READ_BUF(dummy); |
| 720 | break; |
| 721 | default: |
| 722 | dprintk("Illegal callback secflavor\n"); |
| 723 | return nfserr_inval; |
| 724 | } |
| 725 | } |
| 726 | DECODE_TAIL; |
| 727 | } |
| 728 | |
Chuck Lever | d169a6a | 2020-11-03 13:12:27 -0500 | [diff] [blame] | 729 | /* |
| 730 | * NFSv4 operation argument decoders |
| 731 | */ |
| 732 | |
| 733 | static __be32 |
| 734 | nfsd4_decode_access(struct nfsd4_compoundargs *argp, |
| 735 | struct nfsd4_access *access) |
| 736 | { |
| 737 | if (xdr_stream_decode_u32(argp->xdr, &access->ac_req_access) < 0) |
| 738 | return nfserr_bad_xdr; |
| 739 | return nfs_ok; |
| 740 | } |
| 741 | |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 742 | static __be32 nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs *argp, struct nfsd4_backchannel_ctl *bc) |
| 743 | { |
| 744 | DECODE_HEAD; |
| 745 | |
| 746 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 747 | bc->bc_cb_program = be32_to_cpup(p++); |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 748 | nfsd4_decode_cb_sec(argp, &bc->bc_cb_sec); |
| 749 | |
| 750 | DECODE_TAIL; |
| 751 | } |
| 752 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 753 | static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp, struct nfsd4_bind_conn_to_session *bcts) |
| 754 | { |
| 755 | DECODE_HEAD; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 756 | |
| 757 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 8); |
| 758 | COPYMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 759 | bcts->dir = be32_to_cpup(p++); |
Bryan Schumaker | 6ce2357 | 2011-04-27 15:47:16 -0400 | [diff] [blame] | 760 | /* XXX: skipping ctsa_use_conn_in_rdma_mode. Perhaps Tom Tucker |
| 761 | * could help us figure out we should be using it. */ |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 762 | DECODE_TAIL; |
| 763 | } |
| 764 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 765 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close) |
| 767 | { |
Chuck Lever | d3d2f38 | 2020-11-03 13:18:23 -0500 | [diff] [blame] | 768 | if (xdr_stream_decode_u32(argp->xdr, &close->cl_seqid) < 0) |
| 769 | return nfserr_bad_xdr; |
| 770 | return nfsd4_decode_stateid4(argp, &close->cl_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 774 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit) |
| 776 | { |
Chuck Lever | cbd9abb | 2020-11-03 13:19:51 -0500 | [diff] [blame] | 777 | if (xdr_stream_decode_u64(argp->xdr, &commit->co_offset) < 0) |
| 778 | return nfserr_bad_xdr; |
| 779 | if (xdr_stream_decode_u32(argp->xdr, &commit->co_count) < 0) |
| 780 | return nfserr_bad_xdr; |
| 781 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
| 783 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 784 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create) |
| 786 | { |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 787 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 789 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_type) < 0) |
| 790 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | switch (create->cr_type) { |
| 792 | case NF4LNK: |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 793 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_datalen) < 0) |
| 794 | return nfserr_bad_xdr; |
| 795 | p = xdr_inline_decode(argp->xdr, create->cr_datalen); |
| 796 | if (!p) |
| 797 | return nfserr_bad_xdr; |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 798 | create->cr_data = svcxdr_dupstr(argp, p, create->cr_datalen); |
J. Bruce Fields | 7fb8430 | 2014-06-24 15:06:41 -0400 | [diff] [blame] | 799 | if (!create->cr_data) |
J. Bruce Fields | 76f47128 | 2014-06-19 16:44:48 -0400 | [diff] [blame] | 800 | return nfserr_jukebox; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | break; |
| 802 | case NF4BLK: |
| 803 | case NF4CHR: |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 804 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata1) < 0) |
| 805 | return nfserr_bad_xdr; |
| 806 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata2) < 0) |
| 807 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | break; |
| 809 | case NF4SOCK: |
| 810 | case NF4FIFO: |
| 811 | case NF4DIR: |
| 812 | default: |
| 813 | break; |
| 814 | } |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 815 | status = nfsd4_decode_component4(argp, &create->cr_name, |
| 816 | &create->cr_namelen); |
| 817 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | return status; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 819 | status = nfsd4_decode_fattr4(argp, create->cr_bmval, |
| 820 | ARRAY_SIZE(create->cr_bmval), |
| 821 | &create->cr_iattr, &create->cr_acl, |
| 822 | &create->cr_label, &create->cr_umask); |
Benny Halevy | c0d6fc8 | 2009-04-03 08:29:05 +0300 | [diff] [blame] | 823 | if (status) |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 824 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 826 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 829 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr) |
| 831 | { |
Chuck Lever | 95e6482 | 2020-11-21 14:11:58 -0500 | [diff] [blame] | 832 | return nfsd4_decode_stateid4(argp, &dr->dr_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 835 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr) |
| 837 | { |
Chuck Lever | f759eff | 2020-11-19 14:40:20 -0500 | [diff] [blame] | 838 | return nfsd4_decode_bitmap4(argp, getattr->ga_bmval, |
| 839 | ARRAY_SIZE(getattr->ga_bmval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | } |
| 841 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 842 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link) |
| 844 | { |
Chuck Lever | 5c505d1 | 2020-11-04 15:01:24 -0500 | [diff] [blame] | 845 | return nfsd4_decode_component4(argp, &link->li_name, &link->li_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 848 | static __be32 |
Chuck Lever | 8918cc0 | 2020-11-16 17:16:52 -0500 | [diff] [blame] | 849 | nfsd4_decode_open_to_lock_owner4(struct nfsd4_compoundargs *argp, |
| 850 | struct nfsd4_lock *lock) |
| 851 | { |
| 852 | __be32 status; |
| 853 | |
| 854 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_new_open_seqid) < 0) |
| 855 | return nfserr_bad_xdr; |
| 856 | status = nfsd4_decode_stateid4(argp, &lock->lk_new_open_stateid); |
| 857 | if (status) |
| 858 | return status; |
| 859 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_new_lock_seqid) < 0) |
| 860 | return nfserr_bad_xdr; |
| 861 | return nfsd4_decode_state_owner4(argp, &lock->lk_new_clientid, |
| 862 | &lock->lk_new_owner); |
| 863 | } |
| 864 | |
| 865 | static __be32 |
| 866 | nfsd4_decode_exist_lock_owner4(struct nfsd4_compoundargs *argp, |
| 867 | struct nfsd4_lock *lock) |
| 868 | { |
| 869 | __be32 status; |
| 870 | |
| 871 | status = nfsd4_decode_stateid4(argp, &lock->lk_old_lock_stateid); |
| 872 | if (status) |
| 873 | return status; |
| 874 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_old_lock_seqid) < 0) |
| 875 | return nfserr_bad_xdr; |
| 876 | |
| 877 | return nfs_ok; |
| 878 | } |
| 879 | |
| 880 | static __be32 |
| 881 | nfsd4_decode_locker4(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) |
| 882 | { |
| 883 | if (xdr_stream_decode_bool(argp->xdr, &lock->lk_is_new) < 0) |
| 884 | return nfserr_bad_xdr; |
| 885 | if (lock->lk_is_new) |
| 886 | return nfsd4_decode_open_to_lock_owner4(argp, lock); |
| 887 | return nfsd4_decode_exist_lock_owner4(argp, lock); |
| 888 | } |
| 889 | |
| 890 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) |
| 892 | { |
Chuck Lever | 7c59dee | 2020-11-03 13:29:27 -0500 | [diff] [blame] | 893 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_type) < 0) |
| 894 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT)) |
Chuck Lever | 7c59dee | 2020-11-03 13:29:27 -0500 | [diff] [blame] | 896 | return nfserr_bad_xdr; |
| 897 | if (xdr_stream_decode_bool(argp->xdr, &lock->lk_reclaim) < 0) |
| 898 | return nfserr_bad_xdr; |
| 899 | if (xdr_stream_decode_u64(argp->xdr, &lock->lk_offset) < 0) |
| 900 | return nfserr_bad_xdr; |
| 901 | if (xdr_stream_decode_u64(argp->xdr, &lock->lk_length) < 0) |
| 902 | return nfserr_bad_xdr; |
| 903 | return nfsd4_decode_locker4(argp, lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | } |
| 905 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 906 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt) |
| 908 | { |
Chuck Lever | 0a146f0 | 2020-11-03 13:31:44 -0500 | [diff] [blame] | 909 | if (xdr_stream_decode_u32(argp->xdr, &lockt->lt_type) < 0) |
| 910 | return nfserr_bad_xdr; |
| 911 | if ((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT)) |
| 912 | return nfserr_bad_xdr; |
| 913 | if (xdr_stream_decode_u64(argp->xdr, &lockt->lt_offset) < 0) |
| 914 | return nfserr_bad_xdr; |
| 915 | if (xdr_stream_decode_u64(argp->xdr, &lockt->lt_length) < 0) |
| 916 | return nfserr_bad_xdr; |
| 917 | return nfsd4_decode_state_owner4(argp, &lockt->lt_clientid, |
| 918 | &lockt->lt_owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 921 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku) |
| 923 | { |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 924 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 926 | if (xdr_stream_decode_u32(argp->xdr, &locku->lu_type) < 0) |
| 927 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT)) |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 929 | return nfserr_bad_xdr; |
| 930 | if (xdr_stream_decode_u32(argp->xdr, &locku->lu_seqid) < 0) |
| 931 | return nfserr_bad_xdr; |
| 932 | status = nfsd4_decode_stateid4(argp, &locku->lu_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 933 | if (status) |
| 934 | return status; |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 935 | if (xdr_stream_decode_u64(argp->xdr, &locku->lu_offset) < 0) |
| 936 | return nfserr_bad_xdr; |
| 937 | if (xdr_stream_decode_u64(argp->xdr, &locku->lu_length) < 0) |
| 938 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 940 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | } |
| 942 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 943 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup) |
| 945 | { |
Chuck Lever | 3d5877e | 2020-11-04 15:02:40 -0500 | [diff] [blame] | 946 | return nfsd4_decode_component4(argp, &lookup->lo_name, &lookup->lo_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Chuck Lever | bf33bab | 2020-11-16 17:37:42 -0500 | [diff] [blame] | 949 | static __be32 |
| 950 | nfsd4_decode_createhow4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 951 | { |
| 952 | __be32 status; |
| 953 | |
| 954 | if (xdr_stream_decode_u32(argp->xdr, &open->op_createmode) < 0) |
| 955 | return nfserr_bad_xdr; |
| 956 | switch (open->op_createmode) { |
| 957 | case NFS4_CREATE_UNCHECKED: |
| 958 | case NFS4_CREATE_GUARDED: |
| 959 | status = nfsd4_decode_fattr4(argp, open->op_bmval, |
| 960 | ARRAY_SIZE(open->op_bmval), |
| 961 | &open->op_iattr, &open->op_acl, |
| 962 | &open->op_label, &open->op_umask); |
| 963 | if (status) |
| 964 | return status; |
| 965 | break; |
| 966 | case NFS4_CREATE_EXCLUSIVE: |
| 967 | status = nfsd4_decode_verifier4(argp, &open->op_verf); |
| 968 | if (status) |
| 969 | return status; |
| 970 | break; |
| 971 | case NFS4_CREATE_EXCLUSIVE4_1: |
| 972 | if (argp->minorversion < 1) |
| 973 | return nfserr_bad_xdr; |
| 974 | status = nfsd4_decode_verifier4(argp, &open->op_verf); |
| 975 | if (status) |
| 976 | return status; |
| 977 | status = nfsd4_decode_fattr4(argp, open->op_bmval, |
| 978 | ARRAY_SIZE(open->op_bmval), |
| 979 | &open->op_iattr, &open->op_acl, |
| 980 | &open->op_label, &open->op_umask); |
| 981 | if (status) |
| 982 | return status; |
| 983 | break; |
| 984 | default: |
| 985 | return nfserr_bad_xdr; |
| 986 | } |
| 987 | |
| 988 | return nfs_ok; |
| 989 | } |
| 990 | |
Chuck Lever | e6ec04b | 2020-11-16 17:41:21 -0500 | [diff] [blame] | 991 | static __be32 |
| 992 | nfsd4_decode_openflag4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 993 | { |
| 994 | __be32 status; |
| 995 | |
| 996 | if (xdr_stream_decode_u32(argp->xdr, &open->op_create) < 0) |
| 997 | return nfserr_bad_xdr; |
| 998 | switch (open->op_create) { |
| 999 | case NFS4_OPEN_NOCREATE: |
| 1000 | break; |
| 1001 | case NFS4_OPEN_CREATE: |
| 1002 | status = nfsd4_decode_createhow4(argp, open); |
| 1003 | if (status) |
| 1004 | return status; |
| 1005 | break; |
| 1006 | default: |
| 1007 | return nfserr_bad_xdr; |
| 1008 | } |
| 1009 | |
| 1010 | return nfs_ok; |
| 1011 | } |
| 1012 | |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1013 | static __be32 nfsd4_decode_share_access(struct nfsd4_compoundargs *argp, u32 *share_access, u32 *deleg_want, u32 *deleg_when) |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1014 | { |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1015 | u32 w; |
| 1016 | |
Chuck Lever | 9aa62f5 | 2020-11-16 17:54:48 -0500 | [diff] [blame] | 1017 | if (xdr_stream_decode_u32(argp->xdr, &w) < 0) |
| 1018 | return nfserr_bad_xdr; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1019 | *share_access = w & NFS4_SHARE_ACCESS_MASK; |
| 1020 | *deleg_want = w & NFS4_SHARE_WANT_MASK; |
| 1021 | if (deleg_when) |
| 1022 | *deleg_when = w & NFS4_SHARE_WHEN_MASK; |
| 1023 | |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1024 | switch (w & NFS4_SHARE_ACCESS_MASK) { |
| 1025 | case NFS4_SHARE_ACCESS_READ: |
| 1026 | case NFS4_SHARE_ACCESS_WRITE: |
| 1027 | case NFS4_SHARE_ACCESS_BOTH: |
| 1028 | break; |
| 1029 | default: |
| 1030 | return nfserr_bad_xdr; |
| 1031 | } |
Benny Halevy | fc0d14f | 2011-10-27 20:43:01 +0200 | [diff] [blame] | 1032 | w &= ~NFS4_SHARE_ACCESS_MASK; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1033 | if (!w) |
| 1034 | return nfs_ok; |
| 1035 | if (!argp->minorversion) |
| 1036 | return nfserr_bad_xdr; |
| 1037 | switch (w & NFS4_SHARE_WANT_MASK) { |
| 1038 | case NFS4_SHARE_WANT_NO_PREFERENCE: |
| 1039 | case NFS4_SHARE_WANT_READ_DELEG: |
| 1040 | case NFS4_SHARE_WANT_WRITE_DELEG: |
| 1041 | case NFS4_SHARE_WANT_ANY_DELEG: |
| 1042 | case NFS4_SHARE_WANT_NO_DELEG: |
| 1043 | case NFS4_SHARE_WANT_CANCEL: |
| 1044 | break; |
| 1045 | default: |
| 1046 | return nfserr_bad_xdr; |
| 1047 | } |
Benny Halevy | 92bac8c | 2011-10-19 19:13:29 -0700 | [diff] [blame] | 1048 | w &= ~NFS4_SHARE_WANT_MASK; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1049 | if (!w) |
| 1050 | return nfs_ok; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1051 | |
| 1052 | if (!deleg_when) /* open_downgrade */ |
| 1053 | return nfserr_inval; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1054 | switch (w) { |
| 1055 | case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL: |
| 1056 | case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED: |
Benny Halevy | c668fc6 | 2011-10-19 19:13:13 -0700 | [diff] [blame] | 1057 | case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL | |
| 1058 | NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED): |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1059 | return nfs_ok; |
| 1060 | } |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1061 | return nfserr_bad_xdr; |
| 1062 | } |
| 1063 | |
| 1064 | static __be32 nfsd4_decode_share_deny(struct nfsd4_compoundargs *argp, u32 *x) |
| 1065 | { |
Chuck Lever | b07bebd | 2020-11-16 17:56:17 -0500 | [diff] [blame] | 1066 | if (xdr_stream_decode_u32(argp->xdr, x) < 0) |
| 1067 | return nfserr_bad_xdr; |
| 1068 | /* Note: unlike access bits, deny bits may be zero. */ |
Dan Carpenter | 01cd4af | 2011-10-17 10:41:17 +0300 | [diff] [blame] | 1069 | if (*x & ~NFS4_SHARE_DENY_BOTH) |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1070 | return nfserr_bad_xdr; |
Chuck Lever | b07bebd | 2020-11-16 17:56:17 -0500 | [diff] [blame] | 1071 | |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1072 | return nfs_ok; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1075 | static __be32 |
Chuck Lever | 1708e50 | 2020-11-16 17:45:04 -0500 | [diff] [blame] | 1076 | nfsd4_decode_open_claim4(struct nfsd4_compoundargs *argp, |
| 1077 | struct nfsd4_open *open) |
| 1078 | { |
| 1079 | __be32 status; |
| 1080 | |
| 1081 | if (xdr_stream_decode_u32(argp->xdr, &open->op_claim_type) < 0) |
| 1082 | return nfserr_bad_xdr; |
| 1083 | switch (open->op_claim_type) { |
| 1084 | case NFS4_OPEN_CLAIM_NULL: |
| 1085 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1086 | status = nfsd4_decode_component4(argp, &open->op_fname, |
| 1087 | &open->op_fnamelen); |
| 1088 | if (status) |
| 1089 | return status; |
| 1090 | break; |
| 1091 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1092 | if (xdr_stream_decode_u32(argp->xdr, &open->op_delegate_type) < 0) |
| 1093 | return nfserr_bad_xdr; |
| 1094 | break; |
| 1095 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1096 | status = nfsd4_decode_stateid4(argp, &open->op_delegate_stateid); |
| 1097 | if (status) |
| 1098 | return status; |
| 1099 | status = nfsd4_decode_component4(argp, &open->op_fname, |
| 1100 | &open->op_fnamelen); |
| 1101 | if (status) |
| 1102 | return status; |
| 1103 | break; |
| 1104 | case NFS4_OPEN_CLAIM_FH: |
| 1105 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1106 | if (argp->minorversion < 1) |
| 1107 | return nfserr_bad_xdr; |
| 1108 | /* void */ |
| 1109 | break; |
| 1110 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1111 | if (argp->minorversion < 1) |
| 1112 | return nfserr_bad_xdr; |
| 1113 | status = nfsd4_decode_stateid4(argp, &open->op_delegate_stateid); |
| 1114 | if (status) |
| 1115 | return status; |
| 1116 | break; |
| 1117 | default: |
| 1118 | return nfserr_bad_xdr; |
| 1119 | } |
| 1120 | |
| 1121 | return nfs_ok; |
| 1122 | } |
| 1123 | |
| 1124 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 1126 | { |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1127 | __be32 status; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1128 | u32 dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
| 1130 | memset(open->op_bmval, 0, sizeof(open->op_bmval)); |
| 1131 | open->op_iattr.ia_valid = 0; |
J. Bruce Fields | fe0750e | 2011-07-30 23:33:59 -0400 | [diff] [blame] | 1132 | open->op_openowner = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
J. Bruce Fields | 9d313b1 | 2013-02-28 12:51:49 -0800 | [diff] [blame] | 1134 | open->op_xdr_error = 0; |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1135 | if (xdr_stream_decode_u32(argp->xdr, &open->op_seqid) < 0) |
| 1136 | return nfserr_bad_xdr; |
| 1137 | /* deleg_want is ignored */ |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1138 | status = nfsd4_decode_share_access(argp, &open->op_share_access, |
| 1139 | &open->op_deleg_want, &dummy); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1140 | if (status) |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1141 | return status; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1142 | status = nfsd4_decode_share_deny(argp, &open->op_share_deny); |
| 1143 | if (status) |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1144 | return status; |
| 1145 | status = nfsd4_decode_state_owner4(argp, &open->op_clientid, |
| 1146 | &open->op_owner); |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1147 | if (status) |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1148 | return status; |
Chuck Lever | e6ec04b | 2020-11-16 17:41:21 -0500 | [diff] [blame] | 1149 | status = nfsd4_decode_openflag4(argp, open); |
| 1150 | if (status) |
| 1151 | return status; |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1152 | return nfsd4_decode_open_claim4(argp, open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1155 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf) |
| 1157 | { |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1158 | __be32 status; |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1159 | |
| 1160 | if (argp->minorversion >= 1) |
| 1161 | return nfserr_notsupp; |
| 1162 | |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1163 | status = nfsd4_decode_stateid4(argp, &open_conf->oc_req_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1164 | if (status) |
| 1165 | return status; |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1166 | if (xdr_stream_decode_u32(argp->xdr, &open_conf->oc_seqid) < 0) |
| 1167 | return nfserr_bad_xdr; |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1168 | |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1169 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1172 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down) |
| 1174 | { |
Chuck Lever | dca71651 | 2020-11-03 14:21:01 -0500 | [diff] [blame] | 1175 | __be32 status; |
| 1176 | |
| 1177 | status = nfsd4_decode_stateid4(argp, &open_down->od_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1178 | if (status) |
| 1179 | return status; |
Chuck Lever | dca71651 | 2020-11-03 14:21:01 -0500 | [diff] [blame] | 1180 | if (xdr_stream_decode_u32(argp->xdr, &open_down->od_seqid) < 0) |
| 1181 | return nfserr_bad_xdr; |
| 1182 | /* deleg_want is ignored */ |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1183 | status = nfsd4_decode_share_access(argp, &open_down->od_share_access, |
| 1184 | &open_down->od_deleg_want, NULL); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1185 | if (status) |
| 1186 | return status; |
Chuck Lever | dca71651 | 2020-11-03 14:21:01 -0500 | [diff] [blame] | 1187 | return nfsd4_decode_share_deny(argp, &open_down->od_share_deny); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | } |
| 1189 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1190 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh) |
| 1192 | { |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1193 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1195 | if (xdr_stream_decode_u32(argp->xdr, &putfh->pf_fhlen) < 0) |
| 1196 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | if (putfh->pf_fhlen > NFS4_FHSIZE) |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1198 | return nfserr_bad_xdr; |
| 1199 | p = xdr_inline_decode(argp->xdr, putfh->pf_fhlen); |
| 1200 | if (!p) |
| 1201 | return nfserr_bad_xdr; |
| 1202 | putfh->pf_fhval = svcxdr_tmpalloc(argp, putfh->pf_fhlen); |
| 1203 | if (!putfh->pf_fhval) |
| 1204 | return nfserr_jukebox; |
| 1205 | memcpy(putfh->pf_fhval, p, putfh->pf_fhlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1207 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1210 | static __be32 |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1211 | nfsd4_decode_putpubfh(struct nfsd4_compoundargs *argp, void *p) |
| 1212 | { |
| 1213 | if (argp->minorversion == 0) |
| 1214 | return nfs_ok; |
| 1215 | return nfserr_notsupp; |
| 1216 | } |
| 1217 | |
| 1218 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read) |
| 1220 | { |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame^] | 1221 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame^] | 1223 | status = nfsd4_decode_stateid4(argp, &read->rd_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1224 | if (status) |
| 1225 | return status; |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame^] | 1226 | if (xdr_stream_decode_u64(argp->xdr, &read->rd_offset) < 0) |
| 1227 | return nfserr_bad_xdr; |
| 1228 | if (xdr_stream_decode_u32(argp->xdr, &read->rd_length) < 0) |
| 1229 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame^] | 1231 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | } |
| 1233 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1234 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir) |
| 1236 | { |
| 1237 | DECODE_HEAD; |
| 1238 | |
| 1239 | READ_BUF(24); |
J. Bruce Fields | 542d1ab | 2014-06-02 12:45:31 -0400 | [diff] [blame] | 1240 | p = xdr_decode_hyper(p, &readdir->rd_cookie); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | COPYMEM(readdir->rd_verf.data, sizeof(readdir->rd_verf.data)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1242 | readdir->rd_dircount = be32_to_cpup(p++); |
| 1243 | readdir->rd_maxcount = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | if ((status = nfsd4_decode_bitmap(argp, readdir->rd_bmval))) |
| 1245 | goto out; |
| 1246 | |
| 1247 | DECODE_TAIL; |
| 1248 | } |
| 1249 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1250 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove) |
| 1252 | { |
| 1253 | DECODE_HEAD; |
| 1254 | |
| 1255 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1256 | remove->rm_namelen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | READ_BUF(remove->rm_namelen); |
| 1258 | SAVEMEM(remove->rm_name, remove->rm_namelen); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1259 | if ((status = check_filename(remove->rm_name, remove->rm_namelen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | return status; |
| 1261 | |
| 1262 | DECODE_TAIL; |
| 1263 | } |
| 1264 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1265 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename) |
| 1267 | { |
| 1268 | DECODE_HEAD; |
| 1269 | |
| 1270 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1271 | rename->rn_snamelen = be32_to_cpup(p++); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 1272 | READ_BUF(rename->rn_snamelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | SAVEMEM(rename->rn_sname, rename->rn_snamelen); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 1274 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1275 | rename->rn_tnamelen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | READ_BUF(rename->rn_tnamelen); |
| 1277 | SAVEMEM(rename->rn_tname, rename->rn_tnamelen); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1278 | if ((status = check_filename(rename->rn_sname, rename->rn_snamelen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | return status; |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1280 | if ((status = check_filename(rename->rn_tname, rename->rn_tnamelen))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | return status; |
| 1282 | |
| 1283 | DECODE_TAIL; |
| 1284 | } |
| 1285 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1286 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid) |
| 1288 | { |
| 1289 | DECODE_HEAD; |
| 1290 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1291 | if (argp->minorversion >= 1) |
| 1292 | return nfserr_notsupp; |
| 1293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | READ_BUF(sizeof(clientid_t)); |
| 1295 | COPYMEM(clientid, sizeof(clientid_t)); |
| 1296 | |
| 1297 | DECODE_TAIL; |
| 1298 | } |
| 1299 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1300 | static __be32 |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1301 | nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp, |
| 1302 | struct nfsd4_secinfo *secinfo) |
| 1303 | { |
| 1304 | DECODE_HEAD; |
| 1305 | |
| 1306 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1307 | secinfo->si_namelen = be32_to_cpup(p++); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1308 | READ_BUF(secinfo->si_namelen); |
| 1309 | SAVEMEM(secinfo->si_name, secinfo->si_namelen); |
J. Bruce Fields | a36b172 | 2012-11-25 16:31:00 -0500 | [diff] [blame] | 1310 | status = check_filename(secinfo->si_name, secinfo->si_namelen); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1311 | if (status) |
| 1312 | return status; |
| 1313 | DECODE_TAIL; |
| 1314 | } |
| 1315 | |
| 1316 | static __be32 |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 1317 | nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp, |
| 1318 | struct nfsd4_secinfo_no_name *sin) |
| 1319 | { |
| 1320 | DECODE_HEAD; |
| 1321 | |
| 1322 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1323 | sin->sin_style = be32_to_cpup(p++); |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 1324 | DECODE_TAIL; |
| 1325 | } |
| 1326 | |
| 1327 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 | nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr) |
| 1329 | { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1330 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1332 | status = nfsd4_decode_stateid(argp, &setattr->sa_stateid); |
| 1333 | if (status) |
| 1334 | return status; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 1335 | return nfsd4_decode_fattr4(argp, setattr->sa_bmval, |
| 1336 | ARRAY_SIZE(setattr->sa_bmval), |
| 1337 | &setattr->sa_iattr, &setattr->sa_acl, |
| 1338 | &setattr->sa_label, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1341 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid) |
| 1343 | { |
| 1344 | DECODE_HEAD; |
| 1345 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1346 | if (argp->minorversion >= 1) |
| 1347 | return nfserr_notsupp; |
| 1348 | |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 1349 | READ_BUF(NFS4_VERIFIER_SIZE); |
| 1350 | COPYMEM(setclientid->se_verf.data, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1352 | status = nfsd4_decode_opaque(argp, &setclientid->se_name); |
| 1353 | if (status) |
| 1354 | return nfserr_bad_xdr; |
| 1355 | READ_BUF(8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1356 | setclientid->se_callback_prog = be32_to_cpup(p++); |
| 1357 | setclientid->se_callback_netid_len = be32_to_cpup(p++); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 1358 | READ_BUF(setclientid->se_callback_netid_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | SAVEMEM(setclientid->se_callback_netid_val, setclientid->se_callback_netid_len); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 1360 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1361 | setclientid->se_callback_addr_len = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 1363 | READ_BUF(setclientid->se_callback_addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | SAVEMEM(setclientid->se_callback_addr_val, setclientid->se_callback_addr_len); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 1365 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1366 | setclientid->se_callback_ident = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | |
| 1368 | DECODE_TAIL; |
| 1369 | } |
| 1370 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1371 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c) |
| 1373 | { |
| 1374 | DECODE_HEAD; |
| 1375 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1376 | if (argp->minorversion >= 1) |
| 1377 | return nfserr_notsupp; |
| 1378 | |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 1379 | READ_BUF(8 + NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1380 | COPYMEM(&scd_c->sc_clientid, 8); |
Chuck Lever | ab4684d | 2012-03-02 17:13:50 -0500 | [diff] [blame] | 1381 | COPYMEM(&scd_c->sc_confirm, NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | |
| 1383 | DECODE_TAIL; |
| 1384 | } |
| 1385 | |
| 1386 | /* Also used for NVERIFY */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1387 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify) |
| 1389 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | DECODE_HEAD; |
| 1391 | |
| 1392 | if ((status = nfsd4_decode_bitmap(argp, verify->ve_bmval))) |
| 1393 | goto out; |
| 1394 | |
| 1395 | /* For convenience's sake, we compare raw xdr'd attributes in |
J. Bruce Fields | e5f9570 | 2012-11-30 17:24:18 -0500 | [diff] [blame] | 1396 | * nfsd4_proc_verify */ |
| 1397 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1399 | verify->ve_attrlen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | READ_BUF(verify->ve_attrlen); |
| 1401 | SAVEMEM(verify->ve_attrval, verify->ve_attrlen); |
| 1402 | |
| 1403 | DECODE_TAIL; |
| 1404 | } |
| 1405 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1406 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write) |
| 1408 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | DECODE_HEAD; |
| 1410 | |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1411 | status = nfsd4_decode_stateid(argp, &write->wr_stateid); |
| 1412 | if (status) |
| 1413 | return status; |
| 1414 | READ_BUF(16); |
J. Bruce Fields | 542d1ab | 2014-06-02 12:45:31 -0400 | [diff] [blame] | 1415 | p = xdr_decode_hyper(p, &write->wr_offset); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1416 | write->wr_stable_how = be32_to_cpup(p++); |
Kinglong Mee | 54bbb7d | 2016-12-31 20:59:53 +0800 | [diff] [blame] | 1417 | if (write->wr_stable_how > NFS_FILE_SYNC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | goto xdr_error; |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1419 | write->wr_buflen = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1421 | if (!xdr_stream_subsegment(argp->xdr, &write->wr_payload, write->wr_buflen)) |
| 1422 | goto xdr_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | |
| 1424 | DECODE_TAIL; |
| 1425 | } |
| 1426 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1427 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner) |
| 1429 | { |
| 1430 | DECODE_HEAD; |
| 1431 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1432 | if (argp->minorversion >= 1) |
| 1433 | return nfserr_notsupp; |
| 1434 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | READ_BUF(12); |
| 1436 | COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1437 | rlockowner->rl_owner.len = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | READ_BUF(rlockowner->rl_owner.len); |
| 1439 | READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len); |
| 1440 | |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 1441 | if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid)) |
| 1442 | return nfserr_inval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | DECODE_TAIL; |
| 1444 | } |
| 1445 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1446 | static __be32 |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1447 | nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp, |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1448 | struct nfsd4_exchange_id *exid) |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1449 | { |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1450 | int dummy, tmp; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1451 | DECODE_HEAD; |
| 1452 | |
| 1453 | READ_BUF(NFS4_VERIFIER_SIZE); |
| 1454 | COPYMEM(exid->verifier.data, NFS4_VERIFIER_SIZE); |
| 1455 | |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1456 | status = nfsd4_decode_opaque(argp, &exid->clname); |
| 1457 | if (status) |
| 1458 | return nfserr_bad_xdr; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1459 | |
| 1460 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1461 | exid->flags = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1462 | |
| 1463 | /* Ignore state_protect4_a */ |
| 1464 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1465 | exid->spa_how = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1466 | switch (exid->spa_how) { |
| 1467 | case SP4_NONE: |
| 1468 | break; |
| 1469 | case SP4_MACH_CRED: |
| 1470 | /* spo_must_enforce */ |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 1471 | status = nfsd4_decode_bitmap(argp, |
| 1472 | exid->spo_must_enforce); |
| 1473 | if (status) |
| 1474 | goto out; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1475 | /* spo_must_allow */ |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 1476 | status = nfsd4_decode_bitmap(argp, exid->spo_must_allow); |
| 1477 | if (status) |
| 1478 | goto out; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1479 | break; |
| 1480 | case SP4_SSV: |
| 1481 | /* ssp_ops */ |
| 1482 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1483 | dummy = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1484 | READ_BUF(dummy * 4); |
| 1485 | p += dummy; |
| 1486 | |
| 1487 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1488 | dummy = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1489 | READ_BUF(dummy * 4); |
| 1490 | p += dummy; |
| 1491 | |
| 1492 | /* ssp_hash_algs<> */ |
| 1493 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1494 | tmp = be32_to_cpup(p++); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1495 | while (tmp--) { |
| 1496 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1497 | dummy = be32_to_cpup(p++); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1498 | READ_BUF(dummy); |
| 1499 | p += XDR_QUADLEN(dummy); |
| 1500 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1501 | |
| 1502 | /* ssp_encr_algs<> */ |
| 1503 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1504 | tmp = be32_to_cpup(p++); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1505 | while (tmp--) { |
| 1506 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1507 | dummy = be32_to_cpup(p++); |
Mi Jinlong | 5afa040 | 2010-11-09 09:39:23 +0800 | [diff] [blame] | 1508 | READ_BUF(dummy); |
| 1509 | p += XDR_QUADLEN(dummy); |
| 1510 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1511 | |
nixiaoming | 5ed96bc | 2018-07-23 09:57:11 +0800 | [diff] [blame] | 1512 | /* ignore ssp_window and ssp_num_gss_handles: */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1513 | READ_BUF(8); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1514 | break; |
| 1515 | default: |
| 1516 | goto xdr_error; |
| 1517 | } |
| 1518 | |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1519 | READ_BUF(4); /* nfs_impl_id4 array length */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1520 | dummy = be32_to_cpup(p++); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1521 | |
| 1522 | if (dummy > 1) |
| 1523 | goto xdr_error; |
| 1524 | |
| 1525 | if (dummy == 1) { |
J. Bruce Fields | 7912344 | 2019-06-05 12:42:05 -0400 | [diff] [blame] | 1526 | status = nfsd4_decode_opaque(argp, &exid->nii_domain); |
| 1527 | if (status) |
| 1528 | goto xdr_error; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1529 | |
| 1530 | /* nii_name */ |
J. Bruce Fields | 7912344 | 2019-06-05 12:42:05 -0400 | [diff] [blame] | 1531 | status = nfsd4_decode_opaque(argp, &exid->nii_name); |
| 1532 | if (status) |
| 1533 | goto xdr_error; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1534 | |
| 1535 | /* nii_date */ |
J. Bruce Fields | 7912344 | 2019-06-05 12:42:05 -0400 | [diff] [blame] | 1536 | status = nfsd4_decode_time(argp, &exid->nii_time); |
| 1537 | if (status) |
| 1538 | goto xdr_error; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1539 | } |
| 1540 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | static __be32 |
| 1544 | nfsd4_decode_create_session(struct nfsd4_compoundargs *argp, |
| 1545 | struct nfsd4_create_session *sess) |
| 1546 | { |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1547 | DECODE_HEAD; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1548 | |
| 1549 | READ_BUF(16); |
| 1550 | COPYMEM(&sess->clientid, 8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1551 | sess->seqid = be32_to_cpup(p++); |
| 1552 | sess->flags = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1553 | |
| 1554 | /* Fore channel attrs */ |
| 1555 | READ_BUF(28); |
Trond Myklebust | b96811c | 2019-08-18 14:18:58 -0400 | [diff] [blame] | 1556 | p++; /* headerpadsz is always 0 */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1557 | sess->fore_channel.maxreq_sz = be32_to_cpup(p++); |
| 1558 | sess->fore_channel.maxresp_sz = be32_to_cpup(p++); |
| 1559 | sess->fore_channel.maxresp_cached = be32_to_cpup(p++); |
| 1560 | sess->fore_channel.maxops = be32_to_cpup(p++); |
| 1561 | sess->fore_channel.maxreqs = be32_to_cpup(p++); |
| 1562 | sess->fore_channel.nr_rdma_attrs = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1563 | if (sess->fore_channel.nr_rdma_attrs == 1) { |
| 1564 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1565 | sess->fore_channel.rdma_attrs = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1566 | } else if (sess->fore_channel.nr_rdma_attrs > 1) { |
| 1567 | dprintk("Too many fore channel attr bitmaps!\n"); |
| 1568 | goto xdr_error; |
| 1569 | } |
| 1570 | |
| 1571 | /* Back channel attrs */ |
| 1572 | READ_BUF(28); |
Trond Myklebust | b96811c | 2019-08-18 14:18:58 -0400 | [diff] [blame] | 1573 | p++; /* headerpadsz is always 0 */ |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1574 | sess->back_channel.maxreq_sz = be32_to_cpup(p++); |
| 1575 | sess->back_channel.maxresp_sz = be32_to_cpup(p++); |
| 1576 | sess->back_channel.maxresp_cached = be32_to_cpup(p++); |
| 1577 | sess->back_channel.maxops = be32_to_cpup(p++); |
| 1578 | sess->back_channel.maxreqs = be32_to_cpup(p++); |
| 1579 | sess->back_channel.nr_rdma_attrs = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1580 | if (sess->back_channel.nr_rdma_attrs == 1) { |
| 1581 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1582 | sess->back_channel.rdma_attrs = be32_to_cpup(p++); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1583 | } else if (sess->back_channel.nr_rdma_attrs > 1) { |
| 1584 | dprintk("Too many back channel attr bitmaps!\n"); |
| 1585 | goto xdr_error; |
| 1586 | } |
| 1587 | |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 1588 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1589 | sess->callback_prog = be32_to_cpup(p++); |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 1590 | nfsd4_decode_cb_sec(argp, &sess->cb_sec); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1591 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1592 | } |
| 1593 | |
| 1594 | static __be32 |
| 1595 | nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp, |
| 1596 | struct nfsd4_destroy_session *destroy_session) |
| 1597 | { |
Benny Halevy | e10e0cf | 2009-04-03 08:28:38 +0300 | [diff] [blame] | 1598 | DECODE_HEAD; |
| 1599 | READ_BUF(NFS4_MAX_SESSIONID_LEN); |
| 1600 | COPYMEM(destroy_session->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
| 1601 | |
| 1602 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | static __be32 |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 1606 | nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp, |
| 1607 | struct nfsd4_free_stateid *free_stateid) |
| 1608 | { |
| 1609 | DECODE_HEAD; |
| 1610 | |
| 1611 | READ_BUF(sizeof(stateid_t)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1612 | free_stateid->fr_stateid.si_generation = be32_to_cpup(p++); |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 1613 | COPYMEM(&free_stateid->fr_stateid.si_opaque, sizeof(stateid_opaque_t)); |
| 1614 | |
| 1615 | DECODE_TAIL; |
| 1616 | } |
| 1617 | |
| 1618 | static __be32 |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1619 | nfsd4_decode_sequence(struct nfsd4_compoundargs *argp, |
| 1620 | struct nfsd4_sequence *seq) |
| 1621 | { |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1622 | DECODE_HEAD; |
| 1623 | |
| 1624 | READ_BUF(NFS4_MAX_SESSIONID_LEN + 16); |
| 1625 | COPYMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1626 | seq->seqid = be32_to_cpup(p++); |
| 1627 | seq->slotid = be32_to_cpup(p++); |
| 1628 | seq->maxslots = be32_to_cpup(p++); |
| 1629 | seq->cachethis = be32_to_cpup(p++); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 1630 | |
| 1631 | DECODE_TAIL; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1632 | } |
| 1633 | |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1634 | static __be32 |
| 1635 | nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid) |
| 1636 | { |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1637 | int i; |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1638 | __be32 *p, status; |
| 1639 | struct nfsd4_test_stateid_id *stateid; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1640 | |
| 1641 | READ_BUF(4); |
| 1642 | test_stateid->ts_num_ids = ntohl(*p++); |
| 1643 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1644 | INIT_LIST_HEAD(&test_stateid->ts_stateid_list); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1645 | |
| 1646 | for (i = 0; i < test_stateid->ts_num_ids; i++) { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 1647 | stateid = svcxdr_tmpalloc(argp, sizeof(*stateid)); |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1648 | if (!stateid) { |
Al Viro | afcf679 | 2012-04-13 00:15:37 -0400 | [diff] [blame] | 1649 | status = nfserrno(-ENOMEM); |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1650 | goto out; |
| 1651 | } |
| 1652 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1653 | INIT_LIST_HEAD(&stateid->ts_id_list); |
| 1654 | list_add_tail(&stateid->ts_id_list, &test_stateid->ts_stateid_list); |
| 1655 | |
| 1656 | status = nfsd4_decode_stateid(argp, &stateid->ts_id_stateid); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1657 | if (status) |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1658 | goto out; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | status = 0; |
| 1662 | out: |
| 1663 | return status; |
| 1664 | xdr_error: |
| 1665 | dprintk("NFSD: xdr error (%s:%d)\n", __FILE__, __LINE__); |
| 1666 | status = nfserr_bad_xdr; |
| 1667 | goto out; |
| 1668 | } |
| 1669 | |
Mi Jinlong | 345c284 | 2011-10-20 17:51:39 +0800 | [diff] [blame] | 1670 | static __be32 nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs *argp, struct nfsd4_destroy_clientid *dc) |
| 1671 | { |
| 1672 | DECODE_HEAD; |
| 1673 | |
| 1674 | READ_BUF(8); |
| 1675 | COPYMEM(&dc->clientid, 8); |
| 1676 | |
| 1677 | DECODE_TAIL; |
| 1678 | } |
| 1679 | |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1680 | static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, struct nfsd4_reclaim_complete *rc) |
| 1681 | { |
| 1682 | DECODE_HEAD; |
| 1683 | |
| 1684 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1685 | rc->rca_one_fs = be32_to_cpup(p++); |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1686 | |
| 1687 | DECODE_TAIL; |
| 1688 | } |
| 1689 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1690 | #ifdef CONFIG_NFSD_PNFS |
| 1691 | static __be32 |
| 1692 | nfsd4_decode_getdeviceinfo(struct nfsd4_compoundargs *argp, |
| 1693 | struct nfsd4_getdeviceinfo *gdev) |
| 1694 | { |
| 1695 | DECODE_HEAD; |
| 1696 | u32 num, i; |
| 1697 | |
| 1698 | READ_BUF(sizeof(struct nfsd4_deviceid) + 3 * 4); |
| 1699 | COPYMEM(&gdev->gd_devid, sizeof(struct nfsd4_deviceid)); |
| 1700 | gdev->gd_layout_type = be32_to_cpup(p++); |
| 1701 | gdev->gd_maxcount = be32_to_cpup(p++); |
| 1702 | num = be32_to_cpup(p++); |
| 1703 | if (num) { |
Scott Mayhew | 3171822f | 2018-06-08 16:31:46 -0400 | [diff] [blame] | 1704 | if (num > 1000) |
| 1705 | goto xdr_error; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1706 | READ_BUF(4 * num); |
| 1707 | gdev->gd_notify_types = be32_to_cpup(p++); |
| 1708 | for (i = 1; i < num; i++) { |
| 1709 | if (be32_to_cpup(p++)) { |
| 1710 | status = nfserr_inval; |
| 1711 | goto out; |
| 1712 | } |
| 1713 | } |
| 1714 | } |
| 1715 | DECODE_TAIL; |
| 1716 | } |
| 1717 | |
| 1718 | static __be32 |
| 1719 | nfsd4_decode_layoutget(struct nfsd4_compoundargs *argp, |
| 1720 | struct nfsd4_layoutget *lgp) |
| 1721 | { |
| 1722 | DECODE_HEAD; |
| 1723 | |
| 1724 | READ_BUF(36); |
| 1725 | lgp->lg_signal = be32_to_cpup(p++); |
| 1726 | lgp->lg_layout_type = be32_to_cpup(p++); |
| 1727 | lgp->lg_seg.iomode = be32_to_cpup(p++); |
| 1728 | p = xdr_decode_hyper(p, &lgp->lg_seg.offset); |
| 1729 | p = xdr_decode_hyper(p, &lgp->lg_seg.length); |
| 1730 | p = xdr_decode_hyper(p, &lgp->lg_minlength); |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1731 | |
| 1732 | status = nfsd4_decode_stateid(argp, &lgp->lg_sid); |
| 1733 | if (status) |
| 1734 | return status; |
| 1735 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1736 | READ_BUF(4); |
| 1737 | lgp->lg_maxcount = be32_to_cpup(p++); |
| 1738 | |
| 1739 | DECODE_TAIL; |
| 1740 | } |
| 1741 | |
| 1742 | static __be32 |
| 1743 | nfsd4_decode_layoutcommit(struct nfsd4_compoundargs *argp, |
| 1744 | struct nfsd4_layoutcommit *lcp) |
| 1745 | { |
| 1746 | DECODE_HEAD; |
| 1747 | u32 timechange; |
| 1748 | |
| 1749 | READ_BUF(20); |
| 1750 | p = xdr_decode_hyper(p, &lcp->lc_seg.offset); |
| 1751 | p = xdr_decode_hyper(p, &lcp->lc_seg.length); |
| 1752 | lcp->lc_reclaim = be32_to_cpup(p++); |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1753 | |
| 1754 | status = nfsd4_decode_stateid(argp, &lcp->lc_sid); |
| 1755 | if (status) |
| 1756 | return status; |
| 1757 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1758 | READ_BUF(4); |
| 1759 | lcp->lc_newoffset = be32_to_cpup(p++); |
| 1760 | if (lcp->lc_newoffset) { |
| 1761 | READ_BUF(8); |
| 1762 | p = xdr_decode_hyper(p, &lcp->lc_last_wr); |
| 1763 | } else |
| 1764 | lcp->lc_last_wr = 0; |
| 1765 | READ_BUF(4); |
| 1766 | timechange = be32_to_cpup(p++); |
| 1767 | if (timechange) { |
| 1768 | status = nfsd4_decode_time(argp, &lcp->lc_mtime); |
| 1769 | if (status) |
| 1770 | return status; |
| 1771 | } else { |
| 1772 | lcp->lc_mtime.tv_nsec = UTIME_NOW; |
| 1773 | } |
| 1774 | READ_BUF(8); |
| 1775 | lcp->lc_layout_type = be32_to_cpup(p++); |
| 1776 | |
| 1777 | /* |
| 1778 | * Save the layout update in XDR format and let the layout driver deal |
| 1779 | * with it later. |
| 1780 | */ |
| 1781 | lcp->lc_up_len = be32_to_cpup(p++); |
| 1782 | if (lcp->lc_up_len > 0) { |
| 1783 | READ_BUF(lcp->lc_up_len); |
| 1784 | READMEM(lcp->lc_up_layout, lcp->lc_up_len); |
| 1785 | } |
| 1786 | |
| 1787 | DECODE_TAIL; |
| 1788 | } |
| 1789 | |
| 1790 | static __be32 |
| 1791 | nfsd4_decode_layoutreturn(struct nfsd4_compoundargs *argp, |
| 1792 | struct nfsd4_layoutreturn *lrp) |
| 1793 | { |
| 1794 | DECODE_HEAD; |
| 1795 | |
| 1796 | READ_BUF(16); |
| 1797 | lrp->lr_reclaim = be32_to_cpup(p++); |
| 1798 | lrp->lr_layout_type = be32_to_cpup(p++); |
| 1799 | lrp->lr_seg.iomode = be32_to_cpup(p++); |
| 1800 | lrp->lr_return_type = be32_to_cpup(p++); |
| 1801 | if (lrp->lr_return_type == RETURN_FILE) { |
| 1802 | READ_BUF(16); |
| 1803 | p = xdr_decode_hyper(p, &lrp->lr_seg.offset); |
| 1804 | p = xdr_decode_hyper(p, &lrp->lr_seg.length); |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1805 | |
| 1806 | status = nfsd4_decode_stateid(argp, &lrp->lr_sid); |
| 1807 | if (status) |
| 1808 | return status; |
| 1809 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1810 | READ_BUF(4); |
| 1811 | lrp->lrf_body_len = be32_to_cpup(p++); |
| 1812 | if (lrp->lrf_body_len > 0) { |
| 1813 | READ_BUF(lrp->lrf_body_len); |
| 1814 | READMEM(lrp->lrf_body, lrp->lrf_body_len); |
| 1815 | } |
| 1816 | } else { |
| 1817 | lrp->lr_seg.offset = 0; |
| 1818 | lrp->lr_seg.length = NFS4_MAX_UINT64; |
| 1819 | } |
| 1820 | |
| 1821 | DECODE_TAIL; |
| 1822 | } |
| 1823 | #endif /* CONFIG_NFSD_PNFS */ |
| 1824 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1825 | static __be32 |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1826 | nfsd4_decode_fallocate(struct nfsd4_compoundargs *argp, |
| 1827 | struct nfsd4_fallocate *fallocate) |
| 1828 | { |
| 1829 | DECODE_HEAD; |
| 1830 | |
| 1831 | status = nfsd4_decode_stateid(argp, &fallocate->falloc_stateid); |
| 1832 | if (status) |
| 1833 | return status; |
| 1834 | |
| 1835 | READ_BUF(16); |
| 1836 | p = xdr_decode_hyper(p, &fallocate->falloc_offset); |
| 1837 | xdr_decode_hyper(p, &fallocate->falloc_length); |
| 1838 | |
| 1839 | DECODE_TAIL; |
| 1840 | } |
| 1841 | |
| 1842 | static __be32 |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1843 | nfsd4_decode_clone(struct nfsd4_compoundargs *argp, struct nfsd4_clone *clone) |
| 1844 | { |
| 1845 | DECODE_HEAD; |
| 1846 | |
| 1847 | status = nfsd4_decode_stateid(argp, &clone->cl_src_stateid); |
| 1848 | if (status) |
| 1849 | return status; |
| 1850 | status = nfsd4_decode_stateid(argp, &clone->cl_dst_stateid); |
| 1851 | if (status) |
| 1852 | return status; |
| 1853 | |
| 1854 | READ_BUF(8 + 8 + 8); |
| 1855 | p = xdr_decode_hyper(p, &clone->cl_src_pos); |
| 1856 | p = xdr_decode_hyper(p, &clone->cl_dst_pos); |
| 1857 | p = xdr_decode_hyper(p, &clone->cl_count); |
| 1858 | DECODE_TAIL; |
| 1859 | } |
| 1860 | |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1861 | static __be32 nfsd4_decode_nl4_server(struct nfsd4_compoundargs *argp, |
| 1862 | struct nl4_server *ns) |
| 1863 | { |
| 1864 | DECODE_HEAD; |
| 1865 | struct nfs42_netaddr *naddr; |
| 1866 | |
| 1867 | READ_BUF(4); |
| 1868 | ns->nl4_type = be32_to_cpup(p++); |
| 1869 | |
| 1870 | /* currently support for 1 inter-server source server */ |
| 1871 | switch (ns->nl4_type) { |
| 1872 | case NL4_NETADDR: |
| 1873 | naddr = &ns->u.nl4_addr; |
| 1874 | |
| 1875 | READ_BUF(4); |
| 1876 | naddr->netid_len = be32_to_cpup(p++); |
| 1877 | if (naddr->netid_len > RPCBIND_MAXNETIDLEN) |
| 1878 | goto xdr_error; |
| 1879 | |
| 1880 | READ_BUF(naddr->netid_len + 4); /* 4 for uaddr len */ |
| 1881 | COPYMEM(naddr->netid, naddr->netid_len); |
| 1882 | |
| 1883 | naddr->addr_len = be32_to_cpup(p++); |
| 1884 | if (naddr->addr_len > RPCBIND_MAXUADDRLEN) |
| 1885 | goto xdr_error; |
| 1886 | |
| 1887 | READ_BUF(naddr->addr_len); |
| 1888 | COPYMEM(naddr->addr, naddr->addr_len); |
| 1889 | break; |
| 1890 | default: |
| 1891 | goto xdr_error; |
| 1892 | } |
| 1893 | DECODE_TAIL; |
| 1894 | } |
| 1895 | |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1896 | static __be32 |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1897 | nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy) |
| 1898 | { |
| 1899 | DECODE_HEAD; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1900 | struct nl4_server *ns_dummy; |
| 1901 | int i, count; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1902 | |
| 1903 | status = nfsd4_decode_stateid(argp, ©->cp_src_stateid); |
| 1904 | if (status) |
| 1905 | return status; |
| 1906 | status = nfsd4_decode_stateid(argp, ©->cp_dst_stateid); |
| 1907 | if (status) |
| 1908 | return status; |
| 1909 | |
| 1910 | READ_BUF(8 + 8 + 8 + 4 + 4 + 4); |
| 1911 | p = xdr_decode_hyper(p, ©->cp_src_pos); |
| 1912 | p = xdr_decode_hyper(p, ©->cp_dst_pos); |
| 1913 | p = xdr_decode_hyper(p, ©->cp_count); |
J. Bruce Fields | edcc845 | 2018-03-07 15:37:35 -0500 | [diff] [blame] | 1914 | p++; /* ca_consecutive: we always do consecutive copies */ |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1915 | copy->cp_synchronous = be32_to_cpup(p++); |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1916 | |
| 1917 | count = be32_to_cpup(p++); |
| 1918 | |
| 1919 | copy->cp_intra = false; |
| 1920 | if (count == 0) { /* intra-server copy */ |
| 1921 | copy->cp_intra = true; |
| 1922 | goto intra; |
| 1923 | } |
| 1924 | |
| 1925 | /* decode all the supplied server addresses but use first */ |
| 1926 | status = nfsd4_decode_nl4_server(argp, ©->cp_src); |
| 1927 | if (status) |
| 1928 | return status; |
| 1929 | |
| 1930 | ns_dummy = kmalloc(sizeof(struct nl4_server), GFP_KERNEL); |
| 1931 | if (ns_dummy == NULL) |
| 1932 | return nfserrno(-ENOMEM); |
| 1933 | for (i = 0; i < count - 1; i++) { |
| 1934 | status = nfsd4_decode_nl4_server(argp, ns_dummy); |
| 1935 | if (status) { |
| 1936 | kfree(ns_dummy); |
| 1937 | return status; |
| 1938 | } |
| 1939 | } |
| 1940 | kfree(ns_dummy); |
| 1941 | intra: |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1942 | |
| 1943 | DECODE_TAIL; |
| 1944 | } |
| 1945 | |
| 1946 | static __be32 |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 1947 | nfsd4_decode_offload_status(struct nfsd4_compoundargs *argp, |
| 1948 | struct nfsd4_offload_status *os) |
| 1949 | { |
| 1950 | return nfsd4_decode_stateid(argp, &os->stateid); |
| 1951 | } |
| 1952 | |
| 1953 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 1954 | nfsd4_decode_copy_notify(struct nfsd4_compoundargs *argp, |
| 1955 | struct nfsd4_copy_notify *cn) |
| 1956 | { |
Chuck Lever | 5aff7d0 | 2020-09-11 14:47:59 -0400 | [diff] [blame] | 1957 | __be32 status; |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 1958 | |
| 1959 | status = nfsd4_decode_stateid(argp, &cn->cpn_src_stateid); |
| 1960 | if (status) |
| 1961 | return status; |
| 1962 | return nfsd4_decode_nl4_server(argp, &cn->cpn_dst); |
| 1963 | } |
| 1964 | |
| 1965 | static __be32 |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 1966 | nfsd4_decode_seek(struct nfsd4_compoundargs *argp, struct nfsd4_seek *seek) |
| 1967 | { |
| 1968 | DECODE_HEAD; |
| 1969 | |
| 1970 | status = nfsd4_decode_stateid(argp, &seek->seek_stateid); |
| 1971 | if (status) |
| 1972 | return status; |
| 1973 | |
| 1974 | READ_BUF(8 + 4); |
| 1975 | p = xdr_decode_hyper(p, &seek->seek_offset); |
| 1976 | seek->seek_whence = be32_to_cpup(p); |
| 1977 | |
| 1978 | DECODE_TAIL; |
| 1979 | } |
| 1980 | |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1981 | /* |
| 1982 | * XDR data that is more than PAGE_SIZE in size is normally part of a |
| 1983 | * read or write. However, the size of extended attributes is limited |
| 1984 | * by the maximum request size, and then further limited by the underlying |
| 1985 | * filesystem limits. This can exceed PAGE_SIZE (currently, XATTR_SIZE_MAX |
| 1986 | * is 64k). Since there is no kvec- or page-based interface to xattrs, |
| 1987 | * and we're not dealing with contiguous pages, we need to do some copying. |
| 1988 | */ |
| 1989 | |
| 1990 | /* |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1991 | * Decode data into buffer. |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1992 | */ |
| 1993 | static __be32 |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1994 | nfsd4_vbuf_from_vector(struct nfsd4_compoundargs *argp, struct xdr_buf *xdr, |
| 1995 | char **bufp, u32 buflen) |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1996 | { |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1997 | struct page **pages = xdr->pages; |
| 1998 | struct kvec *head = xdr->head; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 1999 | char *tmp, *dp; |
| 2000 | u32 len; |
| 2001 | |
| 2002 | if (buflen <= head->iov_len) { |
| 2003 | /* |
| 2004 | * We're in luck, the head has enough space. Just return |
| 2005 | * the head, no need for copying. |
| 2006 | */ |
| 2007 | *bufp = head->iov_base; |
| 2008 | return 0; |
| 2009 | } |
| 2010 | |
| 2011 | tmp = svcxdr_tmpalloc(argp, buflen); |
| 2012 | if (tmp == NULL) |
| 2013 | return nfserr_jukebox; |
| 2014 | |
| 2015 | dp = tmp; |
| 2016 | memcpy(dp, head->iov_base, head->iov_len); |
| 2017 | buflen -= head->iov_len; |
| 2018 | dp += head->iov_len; |
| 2019 | |
| 2020 | while (buflen > 0) { |
| 2021 | len = min_t(u32, buflen, PAGE_SIZE); |
| 2022 | memcpy(dp, page_address(*pages), len); |
| 2023 | |
| 2024 | buflen -= len; |
| 2025 | dp += len; |
| 2026 | pages++; |
| 2027 | } |
| 2028 | |
| 2029 | *bufp = tmp; |
| 2030 | return 0; |
| 2031 | } |
| 2032 | |
| 2033 | /* |
| 2034 | * Get a user extended attribute name from the XDR buffer. |
| 2035 | * It will not have the "user." prefix, so prepend it. |
| 2036 | * Lastly, check for nul characters in the name. |
| 2037 | */ |
| 2038 | static __be32 |
| 2039 | nfsd4_decode_xattr_name(struct nfsd4_compoundargs *argp, char **namep) |
| 2040 | { |
| 2041 | DECODE_HEAD; |
| 2042 | char *name, *sp, *dp; |
| 2043 | u32 namelen, cnt; |
| 2044 | |
| 2045 | READ_BUF(4); |
| 2046 | namelen = be32_to_cpup(p++); |
| 2047 | |
| 2048 | if (namelen > (XATTR_NAME_MAX - XATTR_USER_PREFIX_LEN)) |
| 2049 | return nfserr_nametoolong; |
| 2050 | |
| 2051 | if (namelen == 0) |
| 2052 | goto xdr_error; |
| 2053 | |
| 2054 | READ_BUF(namelen); |
| 2055 | |
| 2056 | name = svcxdr_tmpalloc(argp, namelen + XATTR_USER_PREFIX_LEN + 1); |
| 2057 | if (!name) |
| 2058 | return nfserr_jukebox; |
| 2059 | |
| 2060 | memcpy(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); |
| 2061 | |
| 2062 | /* |
| 2063 | * Copy the extended attribute name over while checking for 0 |
| 2064 | * characters. |
| 2065 | */ |
| 2066 | sp = (char *)p; |
| 2067 | dp = name + XATTR_USER_PREFIX_LEN; |
| 2068 | cnt = namelen; |
| 2069 | |
| 2070 | while (cnt-- > 0) { |
| 2071 | if (*sp == '\0') |
| 2072 | goto xdr_error; |
| 2073 | *dp++ = *sp++; |
| 2074 | } |
| 2075 | *dp = '\0'; |
| 2076 | |
| 2077 | *namep = name; |
| 2078 | |
| 2079 | DECODE_TAIL; |
| 2080 | } |
| 2081 | |
| 2082 | /* |
| 2083 | * A GETXATTR op request comes without a length specifier. We just set the |
| 2084 | * maximum length for the reply based on XATTR_SIZE_MAX and the maximum |
| 2085 | * channel reply size. nfsd_getxattr will probe the length of the xattr, |
| 2086 | * check it against getxa_len, and allocate + return the value. |
| 2087 | */ |
| 2088 | static __be32 |
| 2089 | nfsd4_decode_getxattr(struct nfsd4_compoundargs *argp, |
| 2090 | struct nfsd4_getxattr *getxattr) |
| 2091 | { |
| 2092 | __be32 status; |
| 2093 | u32 maxcount; |
| 2094 | |
| 2095 | status = nfsd4_decode_xattr_name(argp, &getxattr->getxa_name); |
| 2096 | if (status) |
| 2097 | return status; |
| 2098 | |
| 2099 | maxcount = svc_max_payload(argp->rqstp); |
| 2100 | maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount); |
| 2101 | |
| 2102 | getxattr->getxa_len = maxcount; |
| 2103 | |
| 2104 | return status; |
| 2105 | } |
| 2106 | |
| 2107 | static __be32 |
| 2108 | nfsd4_decode_setxattr(struct nfsd4_compoundargs *argp, |
| 2109 | struct nfsd4_setxattr *setxattr) |
| 2110 | { |
| 2111 | DECODE_HEAD; |
| 2112 | u32 flags, maxcount, size; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2113 | |
| 2114 | READ_BUF(4); |
| 2115 | flags = be32_to_cpup(p++); |
| 2116 | |
| 2117 | if (flags > SETXATTR4_REPLACE) |
| 2118 | return nfserr_inval; |
| 2119 | setxattr->setxa_flags = flags; |
| 2120 | |
| 2121 | status = nfsd4_decode_xattr_name(argp, &setxattr->setxa_name); |
| 2122 | if (status) |
| 2123 | return status; |
| 2124 | |
| 2125 | maxcount = svc_max_payload(argp->rqstp); |
| 2126 | maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount); |
| 2127 | |
| 2128 | READ_BUF(4); |
| 2129 | size = be32_to_cpup(p++); |
| 2130 | if (size > maxcount) |
| 2131 | return nfserr_xattr2big; |
| 2132 | |
| 2133 | setxattr->setxa_len = size; |
| 2134 | if (size > 0) { |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2135 | struct xdr_buf payload; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2136 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2137 | if (!xdr_stream_subsegment(argp->xdr, &payload, size)) |
| 2138 | goto xdr_error; |
| 2139 | status = nfsd4_vbuf_from_vector(argp, &payload, |
| 2140 | &setxattr->setxa_buf, size); |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | DECODE_TAIL; |
| 2144 | } |
| 2145 | |
| 2146 | static __be32 |
| 2147 | nfsd4_decode_listxattrs(struct nfsd4_compoundargs *argp, |
| 2148 | struct nfsd4_listxattrs *listxattrs) |
| 2149 | { |
| 2150 | DECODE_HEAD; |
| 2151 | u32 maxcount; |
| 2152 | |
| 2153 | READ_BUF(12); |
| 2154 | p = xdr_decode_hyper(p, &listxattrs->lsxa_cookie); |
| 2155 | |
| 2156 | /* |
| 2157 | * If the cookie is too large to have even one user.x attribute |
| 2158 | * plus trailing '\0' left in a maximum size buffer, it's invalid. |
| 2159 | */ |
| 2160 | if (listxattrs->lsxa_cookie >= |
| 2161 | (XATTR_LIST_MAX / (XATTR_USER_PREFIX_LEN + 2))) |
| 2162 | return nfserr_badcookie; |
| 2163 | |
| 2164 | maxcount = be32_to_cpup(p++); |
| 2165 | if (maxcount < 8) |
| 2166 | /* Always need at least 2 words (length and one character) */ |
| 2167 | return nfserr_inval; |
| 2168 | |
| 2169 | maxcount = min(maxcount, svc_max_payload(argp->rqstp)); |
| 2170 | listxattrs->lsxa_maxcount = maxcount; |
| 2171 | |
| 2172 | DECODE_TAIL; |
| 2173 | } |
| 2174 | |
| 2175 | static __be32 |
| 2176 | nfsd4_decode_removexattr(struct nfsd4_compoundargs *argp, |
| 2177 | struct nfsd4_removexattr *removexattr) |
| 2178 | { |
| 2179 | return nfsd4_decode_xattr_name(argp, &removexattr->rmxa_name); |
| 2180 | } |
| 2181 | |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 2182 | static __be32 |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2183 | nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p) |
| 2184 | { |
| 2185 | return nfs_ok; |
| 2186 | } |
| 2187 | |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 2188 | static __be32 |
| 2189 | nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p) |
| 2190 | { |
Benny Halevy | 1e685ec | 2009-03-04 23:06:06 +0200 | [diff] [blame] | 2191 | return nfserr_notsupp; |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 2192 | } |
| 2193 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2194 | typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *); |
| 2195 | |
Chuck Lever | c1df609 | 2017-08-01 11:59:58 -0400 | [diff] [blame] | 2196 | static const nfsd4_dec nfsd4_dec_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 2197 | [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access, |
| 2198 | [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close, |
| 2199 | [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit, |
| 2200 | [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create, |
| 2201 | [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2202 | [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn, |
| 2203 | [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr, |
| 2204 | [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2205 | [OP_LINK] = (nfsd4_dec)nfsd4_decode_link, |
| 2206 | [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock, |
| 2207 | [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt, |
| 2208 | [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku, |
| 2209 | [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup, |
| 2210 | [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop, |
| 2211 | [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 2212 | [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open, |
| 2213 | [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2214 | [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm, |
| 2215 | [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade, |
| 2216 | [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh, |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2217 | [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_putpubfh, |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 2218 | [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2219 | [OP_READ] = (nfsd4_dec)nfsd4_decode_read, |
| 2220 | [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir, |
| 2221 | [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop, |
| 2222 | [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove, |
| 2223 | [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename, |
| 2224 | [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew, |
| 2225 | [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2226 | [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2227 | [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo, |
| 2228 | [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr, |
| 2229 | [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid, |
| 2230 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm, |
| 2231 | [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 2232 | [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write, |
| 2233 | [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 2234 | |
| 2235 | /* new operations for NFSv4.1 */ |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 2236 | [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_backchannel_ctl, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 2237 | [OP_BIND_CONN_TO_SESSION]= (nfsd4_dec)nfsd4_decode_bind_conn_to_session, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2238 | [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id, |
| 2239 | [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session, |
| 2240 | [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session, |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 2241 | [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2242 | [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2243 | #ifdef CONFIG_NFSD_PNFS |
| 2244 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_getdeviceinfo, |
| 2245 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2246 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_layoutcommit, |
| 2247 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_layoutget, |
| 2248 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_layoutreturn, |
| 2249 | #else |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2250 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2251 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2252 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2253 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2254 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2255 | #endif |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 2256 | [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_secinfo_no_name, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2257 | [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence, |
| 2258 | [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 2259 | [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_test_stateid, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2260 | [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
Mi Jinlong | 345c284 | 2011-10-20 17:51:39 +0800 | [diff] [blame] | 2261 | [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_destroy_clientid, |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 2262 | [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_reclaim_complete, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2263 | |
| 2264 | /* new operations for NFSv4.2 */ |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 2265 | [OP_ALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 2266 | [OP_COPY] = (nfsd4_dec)nfsd4_decode_copy, |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 2267 | [OP_COPY_NOTIFY] = (nfsd4_dec)nfsd4_decode_copy_notify, |
Anna Schumaker | b0cb908 | 2014-11-07 14:44:27 -0500 | [diff] [blame] | 2268 | [OP_DEALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2269 | [OP_IO_ADVISE] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2270 | [OP_LAYOUTERROR] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2271 | [OP_LAYOUTSTATS] = (nfsd4_dec)nfsd4_decode_notsupp, |
Olga Kornievskaia | 885e2bf | 2018-07-20 18:19:19 -0400 | [diff] [blame] | 2272 | [OP_OFFLOAD_CANCEL] = (nfsd4_dec)nfsd4_decode_offload_status, |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 2273 | [OP_OFFLOAD_STATUS] = (nfsd4_dec)nfsd4_decode_offload_status, |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 2274 | [OP_READ_PLUS] = (nfsd4_dec)nfsd4_decode_read, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 2275 | [OP_SEEK] = (nfsd4_dec)nfsd4_decode_seek, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2276 | [OP_WRITE_SAME] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 2277 | [OP_CLONE] = (nfsd4_dec)nfsd4_decode_clone, |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2278 | /* RFC 8276 extended atributes operations */ |
| 2279 | [OP_GETXATTR] = (nfsd4_dec)nfsd4_decode_getxattr, |
| 2280 | [OP_SETXATTR] = (nfsd4_dec)nfsd4_decode_setxattr, |
| 2281 | [OP_LISTXATTRS] = (nfsd4_dec)nfsd4_decode_listxattrs, |
| 2282 | [OP_REMOVEXATTR] = (nfsd4_dec)nfsd4_decode_removexattr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 2283 | }; |
| 2284 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2285 | static inline bool |
| 2286 | nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op) |
| 2287 | { |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2288 | if (op->opnum < FIRST_NFS4_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2289 | return false; |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2290 | else if (argp->minorversion == 0 && op->opnum > LAST_NFS40_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2291 | return false; |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2292 | else if (argp->minorversion == 1 && op->opnum > LAST_NFS41_OP) |
| 2293 | return false; |
| 2294 | else if (argp->minorversion == 2 && op->opnum > LAST_NFS42_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2295 | return false; |
| 2296 | return true; |
| 2297 | } |
Benny Halevy | f2feb96 | 2008-07-02 11:14:22 +0300 | [diff] [blame] | 2298 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2299 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | nfsd4_decode_compound(struct nfsd4_compoundargs *argp) |
| 2301 | { |
| 2302 | DECODE_HEAD; |
| 2303 | struct nfsd4_op *op; |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2304 | bool cachethis = false; |
J. Bruce Fields | a5cddc8 | 2014-05-12 18:10:58 -0400 | [diff] [blame] | 2305 | int auth_slack= argp->rqstp->rq_auth_slack; |
| 2306 | int max_reply = auth_slack + 8; /* opcnt, status */ |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2307 | int readcount = 0; |
| 2308 | int readbytes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | int i; |
| 2310 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 2312 | argp->taglen = be32_to_cpup(p++); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 2313 | READ_BUF(argp->taglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | SAVEMEM(argp->tag, argp->taglen); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 2315 | READ_BUF(8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 2316 | argp->minorversion = be32_to_cpup(p++); |
| 2317 | argp->opcnt = be32_to_cpup(p++); |
J. Bruce Fields | 4f0cefb | 2014-03-11 15:39:13 -0400 | [diff] [blame] | 2318 | max_reply += 4 + (XDR_QUADLEN(argp->taglen) << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | |
| 2320 | if (argp->taglen > NFSD4_MAX_TAGLEN) |
| 2321 | goto xdr_error; |
J. Bruce Fields | 0078117 | 2017-11-15 12:30:27 -0500 | [diff] [blame] | 2322 | /* |
| 2323 | * NFS4ERR_RESOURCE is a more helpful error than GARBAGE_ARGS |
| 2324 | * here, so we return success at the xdr level so that |
| 2325 | * nfsd4_proc can handle this is an NFS-level error. |
| 2326 | */ |
| 2327 | if (argp->opcnt > NFSD_MAX_OPS_PER_COMPOUND) |
| 2328 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2329 | |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 2330 | if (argp->opcnt > ARRAY_SIZE(argp->iops)) { |
J. Bruce Fields | 5d6031c | 2014-07-17 16:20:39 -0400 | [diff] [blame] | 2331 | argp->ops = kzalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2332 | if (!argp->ops) { |
| 2333 | argp->ops = argp->iops; |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 2334 | dprintk("nfsd: couldn't allocate room for COMPOUND\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | goto xdr_error; |
| 2336 | } |
| 2337 | } |
| 2338 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2339 | if (argp->minorversion > NFSD_SUPPORTED_MINOR_VERSION) |
Benny Halevy | 30cff1f | 2008-07-02 11:13:18 +0300 | [diff] [blame] | 2340 | argp->opcnt = 0; |
| 2341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2342 | for (i = 0; i < argp->opcnt; i++) { |
| 2343 | op = &argp->ops[i]; |
| 2344 | op->replay = NULL; |
| 2345 | |
J. Bruce Fields | 8a61b18 | 2012-11-16 22:28:38 -0500 | [diff] [blame] | 2346 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 2347 | op->opnum = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 2349 | if (nfsd4_opnum_in_range(argp, op)) { |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2350 | op->status = nfsd4_dec_ops[op->opnum](argp, &op->u); |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 2351 | if (op->status != nfs_ok) |
| 2352 | trace_nfsd_compound_decode_err(argp->rqstp, |
| 2353 | argp->opcnt, i, |
| 2354 | op->opnum, |
| 2355 | op->status); |
| 2356 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | op->opnum = OP_ILLEGAL; |
| 2358 | op->status = nfserr_op_illegal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | } |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2360 | op->opdesc = OPDESC(op); |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2361 | /* |
| 2362 | * We'll try to cache the result in the DRC if any one |
| 2363 | * op in the compound wants to be cached: |
| 2364 | */ |
| 2365 | cachethis |= nfsd4_cache_this_op(op); |
J. Bruce Fields | 6ff40de | 2013-11-05 15:07:16 -0500 | [diff] [blame] | 2366 | |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 2367 | if (op->opnum == OP_READ || op->opnum == OP_READ_PLUS) { |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2368 | readcount++; |
| 2369 | readbytes += nfsd4_max_reply(argp->rqstp, op); |
| 2370 | } else |
| 2371 | max_reply += nfsd4_max_reply(argp->rqstp, op); |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2372 | /* |
Kinglong Mee | 7323f0d | 2017-02-03 22:51:46 +0800 | [diff] [blame] | 2373 | * OP_LOCK and OP_LOCKT may return a conflicting lock. |
| 2374 | * (Special case because it will just skip encoding this |
| 2375 | * if it runs out of xdr buffer space, and it is the only |
| 2376 | * operation that behaves this way.) |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2377 | */ |
Kinglong Mee | 7323f0d | 2017-02-03 22:51:46 +0800 | [diff] [blame] | 2378 | if (op->opnum == OP_LOCK || op->opnum == OP_LOCKT) |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2379 | max_reply += NFS4_OPAQUE_LIMIT; |
J. Bruce Fields | e372ba6 | 2014-05-19 12:27:11 -0400 | [diff] [blame] | 2380 | |
| 2381 | if (op->status) { |
| 2382 | argp->opcnt = i+1; |
| 2383 | break; |
| 2384 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2385 | } |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2386 | /* Sessions make the DRC unnecessary: */ |
| 2387 | if (argp->minorversion) |
| 2388 | cachethis = false; |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2389 | svc_reserve(argp->rqstp, max_reply + readbytes); |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2390 | argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | |
J. Bruce Fields | a5cddc8 | 2014-05-12 18:10:58 -0400 | [diff] [blame] | 2392 | if (readcount > 1 || max_reply > PAGE_SIZE - auth_slack) |
Jeff Layton | 779fb0f | 2014-11-19 07:51:18 -0500 | [diff] [blame] | 2393 | clear_bit(RQ_SPLICE_OK, &argp->rqstp->rq_flags); |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | DECODE_TAIL; |
| 2396 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2398 | static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode, |
| 2399 | struct svc_export *exp) |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2400 | { |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2401 | if (exp->ex_flags & NFSEXP_V4ROOT) { |
| 2402 | *p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time)); |
| 2403 | *p++ = 0; |
| 2404 | } else if (IS_I_VERSION(inode)) { |
Amir Goldstein | 39ca1bf | 2018-01-03 17:14:35 +0200 | [diff] [blame] | 2405 | p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode)); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2406 | } else { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2407 | *p++ = cpu_to_be32(stat->ctime.tv_sec); |
| 2408 | *p++ = cpu_to_be32(stat->ctime.tv_nsec); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2409 | } |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2410 | return p; |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2411 | } |
| 2412 | |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2413 | /* |
| 2414 | * ctime (in NFSv4, time_metadata) is not writeable, and the client |
| 2415 | * doesn't really care what resolution could theoretically be stored by |
| 2416 | * the filesystem. |
| 2417 | * |
| 2418 | * The client cares how close together changes can be while still |
| 2419 | * guaranteeing ctime changes. For most filesystems (which have |
| 2420 | * timestamps with nanosecond fields) that is limited by the resolution |
| 2421 | * of the time returned from current_time() (which I'm assuming to be |
| 2422 | * 1/HZ). |
| 2423 | */ |
| 2424 | static __be32 *encode_time_delta(__be32 *p, struct inode *inode) |
| 2425 | { |
Arnd Bergmann | e4598e3 | 2019-10-31 15:14:03 +0100 | [diff] [blame] | 2426 | struct timespec64 ts; |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2427 | u32 ns; |
| 2428 | |
| 2429 | ns = max_t(u32, NSEC_PER_SEC/HZ, inode->i_sb->s_time_gran); |
Arnd Bergmann | e4598e3 | 2019-10-31 15:14:03 +0100 | [diff] [blame] | 2430 | ts = ns_to_timespec64(ns); |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2431 | |
| 2432 | p = xdr_encode_hyper(p, ts.tv_sec); |
| 2433 | *p++ = cpu_to_be32(ts.tv_nsec); |
| 2434 | |
| 2435 | return p; |
| 2436 | } |
| 2437 | |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2438 | static __be32 *encode_cinfo(__be32 *p, struct nfsd4_change_info *c) |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2439 | { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2440 | *p++ = cpu_to_be32(c->atomic); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2441 | if (c->change_supported) { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2442 | p = xdr_encode_hyper(p, c->before_change); |
| 2443 | p = xdr_encode_hyper(p, c->after_change); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2444 | } else { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2445 | *p++ = cpu_to_be32(c->before_ctime_sec); |
| 2446 | *p++ = cpu_to_be32(c->before_ctime_nsec); |
| 2447 | *p++ = cpu_to_be32(c->after_ctime_sec); |
| 2448 | *p++ = cpu_to_be32(c->after_ctime_nsec); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2449 | } |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2450 | return p; |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2451 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2452 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2453 | /* Encode as an array of strings the string given with components |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2454 | * separated @sep, escaped with esc_enter and esc_exit. |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2455 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2456 | static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep, |
| 2457 | char *components, char esc_enter, |
| 2458 | char esc_exit) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2459 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2460 | __be32 *p; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2461 | __be32 pathlen; |
| 2462 | int pathlen_offset; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2463 | int strlen, count=0; |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2464 | char *str, *end, *next; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2465 | |
| 2466 | dprintk("nfsd4_encode_components(%s)\n", components); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2467 | |
| 2468 | pathlen_offset = xdr->buf->len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2469 | p = xdr_reserve_space(xdr, 4); |
| 2470 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2471 | return nfserr_resource; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2472 | p++; /* We will fill this in with @count later */ |
| 2473 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2474 | end = str = components; |
| 2475 | while (*end) { |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2476 | bool found_esc = false; |
| 2477 | |
| 2478 | /* try to parse as esc_start, ..., esc_end, sep */ |
| 2479 | if (*str == esc_enter) { |
| 2480 | for (; *end && (*end != esc_exit); end++) |
| 2481 | /* find esc_exit or end of string */; |
| 2482 | next = end + 1; |
| 2483 | if (*end && (!*next || *next == sep)) { |
| 2484 | str++; |
| 2485 | found_esc = true; |
| 2486 | } |
| 2487 | } |
| 2488 | |
| 2489 | if (!found_esc) |
| 2490 | for (; *end && (*end != sep); end++) |
| 2491 | /* find sep or end of string */; |
| 2492 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2493 | strlen = end - str; |
| 2494 | if (strlen) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2495 | p = xdr_reserve_space(xdr, strlen + 4); |
| 2496 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2497 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 2498 | p = xdr_encode_opaque(p, str, strlen); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2499 | count++; |
| 2500 | } |
| 2501 | else |
| 2502 | end++; |
Benjamin Coddington | 5a64e56 | 2014-12-07 16:05:47 -0500 | [diff] [blame] | 2503 | if (found_esc) |
| 2504 | end = next; |
| 2505 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2506 | str = end; |
| 2507 | } |
Benjamin Coddington | bf7491f | 2014-12-07 16:05:48 -0500 | [diff] [blame] | 2508 | pathlen = htonl(count); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2509 | write_bytes_to_xdr_buf(xdr->buf, pathlen_offset, &pathlen, 4); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2510 | return 0; |
| 2511 | } |
| 2512 | |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2513 | /* Encode as an array of strings the string given with components |
| 2514 | * separated @sep. |
| 2515 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2516 | static __be32 nfsd4_encode_components(struct xdr_stream *xdr, char sep, |
| 2517 | char *components) |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2518 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2519 | return nfsd4_encode_components_esc(xdr, sep, components, 0, 0); |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2520 | } |
| 2521 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2522 | /* |
| 2523 | * encode a location element of a fs_locations structure |
| 2524 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2525 | static __be32 nfsd4_encode_fs_location4(struct xdr_stream *xdr, |
| 2526 | struct nfsd4_fs_location *location) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2527 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2528 | __be32 status; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2529 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2530 | status = nfsd4_encode_components_esc(xdr, ':', location->hosts, |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2531 | '[', ']'); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2532 | if (status) |
| 2533 | return status; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2534 | status = nfsd4_encode_components(xdr, '/', location->path); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2535 | if (status) |
| 2536 | return status; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2537 | return 0; |
| 2538 | } |
| 2539 | |
| 2540 | /* |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2541 | * Encode a path in RFC3530 'pathname4' format |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2542 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2543 | static __be32 nfsd4_encode_path(struct xdr_stream *xdr, |
| 2544 | const struct path *root, |
| 2545 | const struct path *path) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2546 | { |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2547 | struct path cur = *path; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2548 | __be32 *p; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2549 | struct dentry **components = NULL; |
| 2550 | unsigned int ncomponents = 0; |
| 2551 | __be32 err = nfserr_jukebox; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2552 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2553 | dprintk("nfsd4_encode_components("); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2554 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2555 | path_get(&cur); |
| 2556 | /* First walk the path up to the nfsd root, and store the |
| 2557 | * dentries/path components in an array. |
| 2558 | */ |
| 2559 | for (;;) { |
Kinglong Mee | b77a4b2 | 2015-03-15 23:13:32 +0800 | [diff] [blame] | 2560 | if (path_equal(&cur, root)) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2561 | break; |
| 2562 | if (cur.dentry == cur.mnt->mnt_root) { |
| 2563 | if (follow_up(&cur)) |
| 2564 | continue; |
| 2565 | goto out_free; |
| 2566 | } |
| 2567 | if ((ncomponents & 15) == 0) { |
| 2568 | struct dentry **new; |
| 2569 | new = krealloc(components, |
| 2570 | sizeof(*new) * (ncomponents + 16), |
| 2571 | GFP_KERNEL); |
| 2572 | if (!new) |
| 2573 | goto out_free; |
| 2574 | components = new; |
| 2575 | } |
| 2576 | components[ncomponents++] = cur.dentry; |
| 2577 | cur.dentry = dget_parent(cur.dentry); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2578 | } |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2579 | err = nfserr_resource; |
| 2580 | p = xdr_reserve_space(xdr, 4); |
| 2581 | if (!p) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2582 | goto out_free; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2583 | *p++ = cpu_to_be32(ncomponents); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2584 | |
| 2585 | while (ncomponents) { |
| 2586 | struct dentry *dentry = components[ncomponents - 1]; |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2587 | unsigned int len; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2588 | |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2589 | spin_lock(&dentry->d_lock); |
| 2590 | len = dentry->d_name.len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2591 | p = xdr_reserve_space(xdr, len + 4); |
| 2592 | if (!p) { |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2593 | spin_unlock(&dentry->d_lock); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2594 | goto out_free; |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2595 | } |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 2596 | p = xdr_encode_opaque(p, dentry->d_name.name, len); |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 2597 | dprintk("/%pd", dentry); |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2598 | spin_unlock(&dentry->d_lock); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2599 | dput(dentry); |
| 2600 | ncomponents--; |
| 2601 | } |
| 2602 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2603 | err = 0; |
| 2604 | out_free: |
| 2605 | dprintk(")\n"); |
| 2606 | while (ncomponents) |
| 2607 | dput(components[--ncomponents]); |
| 2608 | kfree(components); |
| 2609 | path_put(&cur); |
| 2610 | return err; |
| 2611 | } |
| 2612 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2613 | static __be32 nfsd4_encode_fsloc_fsroot(struct xdr_stream *xdr, |
| 2614 | struct svc_rqst *rqstp, const struct path *path) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2615 | { |
| 2616 | struct svc_export *exp_ps; |
| 2617 | __be32 res; |
| 2618 | |
| 2619 | exp_ps = rqst_find_fsidzero_export(rqstp); |
| 2620 | if (IS_ERR(exp_ps)) |
| 2621 | return nfserrno(PTR_ERR(exp_ps)); |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2622 | res = nfsd4_encode_path(xdr, &exp_ps->ex_path, path); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2623 | exp_put(exp_ps); |
| 2624 | return res; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | /* |
| 2628 | * encode a fs_locations structure |
| 2629 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2630 | static __be32 nfsd4_encode_fs_locations(struct xdr_stream *xdr, |
| 2631 | struct svc_rqst *rqstp, struct svc_export *exp) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2632 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2633 | __be32 status; |
Al Viro | cc45f01 | 2006-10-19 23:28:44 -0700 | [diff] [blame] | 2634 | int i; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2635 | __be32 *p; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2636 | struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2637 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2638 | status = nfsd4_encode_fsloc_fsroot(xdr, rqstp, &exp->ex_path); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2639 | if (status) |
| 2640 | return status; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2641 | p = xdr_reserve_space(xdr, 4); |
| 2642 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2643 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2644 | *p++ = cpu_to_be32(fslocs->locations_count); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2645 | for (i=0; i<fslocs->locations_count; i++) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2646 | status = nfsd4_encode_fs_location4(xdr, &fslocs->locations[i]); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2647 | if (status) |
| 2648 | return status; |
| 2649 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2650 | return 0; |
| 2651 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2653 | static u32 nfs4_file_type(umode_t mode) |
| 2654 | { |
| 2655 | switch (mode & S_IFMT) { |
| 2656 | case S_IFIFO: return NF4FIFO; |
| 2657 | case S_IFCHR: return NF4CHR; |
| 2658 | case S_IFDIR: return NF4DIR; |
| 2659 | case S_IFBLK: return NF4BLK; |
| 2660 | case S_IFLNK: return NF4LNK; |
| 2661 | case S_IFREG: return NF4REG; |
| 2662 | case S_IFSOCK: return NF4SOCK; |
| 2663 | default: return NF4BAD; |
Tom Rix | 25fef48 | 2020-11-01 07:32:34 -0800 | [diff] [blame] | 2664 | } |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2665 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2666 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2667 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2668 | nfsd4_encode_aclname(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2669 | struct nfs4_ace *ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | { |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2671 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2672 | return nfs4_acl_write_who(xdr, ace->whotype); |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2673 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2674 | return nfsd4_encode_group(xdr, rqstp, ace->who_gid); |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2675 | else |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2676 | return nfsd4_encode_user(xdr, rqstp, ace->who_uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2677 | } |
| 2678 | |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2679 | static inline __be32 |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2680 | nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types) |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2681 | { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2682 | __be32 *p; |
| 2683 | unsigned long i = hweight_long(layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2684 | |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2685 | p = xdr_reserve_space(xdr, 4 + 4 * i); |
| 2686 | if (!p) |
| 2687 | return nfserr_resource; |
| 2688 | |
| 2689 | *p++ = cpu_to_be32(i); |
| 2690 | |
| 2691 | for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i) |
| 2692 | if (layout_types & (1 << i)) |
| 2693 | *p++ = cpu_to_be32(i); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2694 | |
| 2695 | return 0; |
| 2696 | } |
| 2697 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2698 | #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \ |
| 2699 | FATTR4_WORD0_RDATTR_ERROR) |
| 2700 | #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2701 | #define WORD2_ABSENT_FS_ATTRS 0 |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2702 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2703 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
| 2704 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2705 | nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2706 | void *context, int len) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2707 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2708 | __be32 *p; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2709 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2710 | p = xdr_reserve_space(xdr, len + 4 + 4 + 4); |
| 2711 | if (!p) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2712 | return nfserr_resource; |
| 2713 | |
| 2714 | /* |
| 2715 | * For now we use a 0 here to indicate the null translation; in |
| 2716 | * the future we may place a call to translation code here. |
| 2717 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2718 | *p++ = cpu_to_be32(0); /* lfs */ |
| 2719 | *p++ = cpu_to_be32(0); /* pi */ |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2720 | p = xdr_encode_opaque(p, context, len); |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2721 | return 0; |
| 2722 | } |
| 2723 | #else |
| 2724 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2725 | nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2726 | void *context, int len) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2727 | { return 0; } |
| 2728 | #endif |
| 2729 | |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2730 | static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *bmval2, u32 *rdattr_err) |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2731 | { |
| 2732 | /* As per referral draft: */ |
| 2733 | if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS || |
| 2734 | *bmval1 & ~WORD1_ABSENT_FS_ATTRS) { |
| 2735 | if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR || |
| 2736 | *bmval0 & FATTR4_WORD0_FS_LOCATIONS) |
| 2737 | *rdattr_err = NFSERR_MOVED; |
| 2738 | else |
| 2739 | return nfserr_moved; |
| 2740 | } |
| 2741 | *bmval0 &= WORD0_ABSENT_FS_ATTRS; |
| 2742 | *bmval1 &= WORD1_ABSENT_FS_ATTRS; |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2743 | *bmval2 &= WORD2_ABSENT_FS_ATTRS; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2744 | return 0; |
| 2745 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2746 | |
J. Bruce Fields | ae7095a | 2012-10-01 17:50:56 -0400 | [diff] [blame] | 2747 | |
| 2748 | static int get_parent_attributes(struct svc_export *exp, struct kstat *stat) |
| 2749 | { |
| 2750 | struct path path = exp->ex_path; |
| 2751 | int err; |
| 2752 | |
| 2753 | path_get(&path); |
| 2754 | while (follow_up(&path)) { |
| 2755 | if (path.dentry != path.mnt->mnt_root) |
| 2756 | break; |
| 2757 | } |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 2758 | err = vfs_getattr(&path, stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); |
J. Bruce Fields | ae7095a | 2012-10-01 17:50:56 -0400 | [diff] [blame] | 2759 | path_put(&path); |
| 2760 | return err; |
| 2761 | } |
| 2762 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 2763 | static __be32 |
| 2764 | nfsd4_encode_bitmap(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2) |
| 2765 | { |
| 2766 | __be32 *p; |
| 2767 | |
| 2768 | if (bmval2) { |
| 2769 | p = xdr_reserve_space(xdr, 16); |
| 2770 | if (!p) |
| 2771 | goto out_resource; |
| 2772 | *p++ = cpu_to_be32(3); |
| 2773 | *p++ = cpu_to_be32(bmval0); |
| 2774 | *p++ = cpu_to_be32(bmval1); |
| 2775 | *p++ = cpu_to_be32(bmval2); |
| 2776 | } else if (bmval1) { |
| 2777 | p = xdr_reserve_space(xdr, 12); |
| 2778 | if (!p) |
| 2779 | goto out_resource; |
| 2780 | *p++ = cpu_to_be32(2); |
| 2781 | *p++ = cpu_to_be32(bmval0); |
| 2782 | *p++ = cpu_to_be32(bmval1); |
| 2783 | } else { |
| 2784 | p = xdr_reserve_space(xdr, 8); |
| 2785 | if (!p) |
| 2786 | goto out_resource; |
| 2787 | *p++ = cpu_to_be32(1); |
| 2788 | *p++ = cpu_to_be32(bmval0); |
| 2789 | } |
| 2790 | |
| 2791 | return 0; |
| 2792 | out_resource: |
| 2793 | return nfserr_resource; |
| 2794 | } |
| 2795 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2796 | /* |
| 2797 | * Note: @fhp can be NULL; in this case, we might have to compose the filehandle |
| 2798 | * ourselves. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | */ |
Jeff Layton | da2ebce | 2014-05-30 09:09:25 -0400 | [diff] [blame] | 2800 | static __be32 |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 2801 | nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, |
| 2802 | struct svc_export *exp, |
| 2803 | struct dentry *dentry, u32 *bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 2804 | struct svc_rqst *rqstp, int ignore_crossmnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2805 | { |
| 2806 | u32 bmval0 = bmval[0]; |
| 2807 | u32 bmval1 = bmval[1]; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2808 | u32 bmval2 = bmval[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | struct kstat stat; |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2810 | struct svc_fh *tempfh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | struct kstatfs statfs; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2812 | __be32 *p; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 2813 | int starting_len = xdr->buf->len; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2814 | int attrlen_offset; |
| 2815 | __be32 attrlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2816 | u32 dummy; |
| 2817 | u64 dummy64; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2818 | u32 rdattr_err = 0; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2819 | __be32 status; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2820 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | struct nfs4_acl *acl = NULL; |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 2822 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2823 | void *context = NULL; |
| 2824 | int contextlen; |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 2825 | #endif |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2826 | bool contextsupport = false; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2827 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
| 2828 | u32 minorversion = resp->cstate.minorversion; |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 2829 | struct path path = { |
| 2830 | .mnt = exp->ex_path.mnt, |
| 2831 | .dentry = dentry, |
| 2832 | }; |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 2833 | struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | |
| 2835 | BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2836 | BUG_ON(!nfsd_attrs_supported(minorversion, bmval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2837 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2838 | if (exp->ex_fslocs.migrated) { |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2839 | status = fattr_handle_absent_fs(&bmval0, &bmval1, &bmval2, &rdattr_err); |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2840 | if (status) |
| 2841 | goto out; |
| 2842 | } |
| 2843 | |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 2844 | err = vfs_getattr(&path, &stat, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2845 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2846 | goto out_nfserr; |
Christoph Hellwig | 1233790 | 2014-05-28 10:46:13 +0200 | [diff] [blame] | 2847 | if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE | |
| 2848 | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2849 | (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | |
| 2850 | FATTR4_WORD1_SPACE_TOTAL))) { |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 2851 | err = vfs_statfs(&path, &statfs); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2852 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2853 | goto out_nfserr; |
| 2854 | } |
| 2855 | if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) { |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2856 | tempfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); |
| 2857 | status = nfserr_jukebox; |
| 2858 | if (!tempfh) |
| 2859 | goto out; |
| 2860 | fh_init(tempfh, NFS4_FHSIZE); |
| 2861 | status = fh_compose(tempfh, exp, dentry, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2862 | if (status) |
| 2863 | goto out; |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2864 | fhp = tempfh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | } |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2866 | if (bmval0 & FATTR4_WORD0_ACL) { |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2867 | err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl); |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2868 | if (err == -EOPNOTSUPP) |
| 2869 | bmval0 &= ~FATTR4_WORD0_ACL; |
| 2870 | else if (err == -EINVAL) { |
| 2871 | status = nfserr_attrnotsupp; |
| 2872 | goto out; |
| 2873 | } else if (err != 0) |
| 2874 | goto out_nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2876 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2877 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2878 | if ((bmval2 & FATTR4_WORD2_SECURITY_LABEL) || |
| 2879 | bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
J. Bruce Fields | 32ddd94 | 2017-01-03 12:30:11 -0500 | [diff] [blame] | 2880 | if (exp->ex_flags & NFSEXP_SECURITY_LABEL) |
| 2881 | err = security_inode_getsecctx(d_inode(dentry), |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2882 | &context, &contextlen); |
J. Bruce Fields | 32ddd94 | 2017-01-03 12:30:11 -0500 | [diff] [blame] | 2883 | else |
| 2884 | err = -EOPNOTSUPP; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2885 | contextsupport = (err == 0); |
| 2886 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
| 2887 | if (err == -EOPNOTSUPP) |
| 2888 | bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2889 | else if (err) |
| 2890 | goto out_nfserr; |
| 2891 | } |
| 2892 | } |
| 2893 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
| 2894 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 2895 | status = nfsd4_encode_bitmap(xdr, bmval0, bmval1, bmval2); |
| 2896 | if (status) |
| 2897 | goto out; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2898 | |
| 2899 | attrlen_offset = xdr->buf->len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2900 | p = xdr_reserve_space(xdr, 4); |
| 2901 | if (!p) |
| 2902 | goto out_resource; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2903 | p++; /* to be backfilled later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2904 | |
| 2905 | if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
J. Bruce Fields | dcd20869 | 2017-01-11 20:34:50 -0500 | [diff] [blame] | 2906 | u32 supp[3]; |
| 2907 | |
| 2908 | memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp)); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2909 | |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2910 | if (!IS_POSIXACL(dentry->d_inode)) |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2911 | supp[0] &= ~FATTR4_WORD0_ACL; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2912 | if (!contextsupport) |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2913 | supp[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2914 | if (!supp[2]) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2915 | p = xdr_reserve_space(xdr, 12); |
| 2916 | if (!p) |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2917 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2918 | *p++ = cpu_to_be32(2); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2919 | *p++ = cpu_to_be32(supp[0]); |
| 2920 | *p++ = cpu_to_be32(supp[1]); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2921 | } else { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2922 | p = xdr_reserve_space(xdr, 16); |
| 2923 | if (!p) |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 2924 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2925 | *p++ = cpu_to_be32(3); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2926 | *p++ = cpu_to_be32(supp[0]); |
| 2927 | *p++ = cpu_to_be32(supp[1]); |
| 2928 | *p++ = cpu_to_be32(supp[2]); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2929 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2930 | } |
| 2931 | if (bmval0 & FATTR4_WORD0_TYPE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2932 | p = xdr_reserve_space(xdr, 4); |
| 2933 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | goto out_resource; |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2935 | dummy = nfs4_file_type(stat.mode); |
J. Bruce Fields | 6b6d8137 | 2013-01-16 17:11:11 -0500 | [diff] [blame] | 2936 | if (dummy == NF4BAD) { |
| 2937 | status = nfserr_serverfault; |
| 2938 | goto out; |
| 2939 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2940 | *p++ = cpu_to_be32(dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2941 | } |
| 2942 | if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2943 | p = xdr_reserve_space(xdr, 4); |
| 2944 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | goto out_resource; |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 2946 | if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2947 | *p++ = cpu_to_be32(NFS4_FH_PERSISTENT); |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 2948 | else |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2949 | *p++ = cpu_to_be32(NFS4_FH_PERSISTENT| |
| 2950 | NFS4_FH_VOL_RENAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | } |
| 2952 | if (bmval0 & FATTR4_WORD0_CHANGE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2953 | p = xdr_reserve_space(xdr, 8); |
| 2954 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2955 | goto out_resource; |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2956 | p = encode_change(p, &stat, d_inode(dentry), exp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | } |
| 2958 | if (bmval0 & FATTR4_WORD0_SIZE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2959 | p = xdr_reserve_space(xdr, 8); |
| 2960 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 2962 | p = xdr_encode_hyper(p, stat.size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2963 | } |
| 2964 | if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2965 | p = xdr_reserve_space(xdr, 4); |
| 2966 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2968 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2969 | } |
| 2970 | if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2971 | p = xdr_reserve_space(xdr, 4); |
| 2972 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2974 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | } |
| 2976 | if (bmval0 & FATTR4_WORD0_NAMED_ATTR) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2977 | p = xdr_reserve_space(xdr, 4); |
| 2978 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2979 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2980 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2981 | } |
| 2982 | if (bmval0 & FATTR4_WORD0_FSID) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2983 | p = xdr_reserve_space(xdr, 16); |
| 2984 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | goto out_resource; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2986 | if (exp->ex_fslocs.migrated) { |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 2987 | p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MAJOR); |
| 2988 | p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MINOR); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2989 | } else switch(fsid_source(fhp)) { |
| 2990 | case FSIDSOURCE_FSID: |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 2991 | p = xdr_encode_hyper(p, (u64)exp->ex_fsid); |
| 2992 | p = xdr_encode_hyper(p, (u64)0); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2993 | break; |
| 2994 | case FSIDSOURCE_DEV: |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2995 | *p++ = cpu_to_be32(0); |
| 2996 | *p++ = cpu_to_be32(MAJOR(stat.dev)); |
| 2997 | *p++ = cpu_to_be32(0); |
| 2998 | *p++ = cpu_to_be32(MINOR(stat.dev)); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 2999 | break; |
| 3000 | case FSIDSOURCE_UUID: |
Kinglong Mee | 94eb368 | 2014-05-23 20:00:19 +0800 | [diff] [blame] | 3001 | p = xdr_encode_opaque_fixed(p, exp->ex_uuid, |
| 3002 | EX_UUID_LEN); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 3003 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3004 | } |
| 3005 | } |
| 3006 | if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3007 | p = xdr_reserve_space(xdr, 4); |
| 3008 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3010 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3011 | } |
| 3012 | if (bmval0 & FATTR4_WORD0_LEASE_TIME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3013 | p = xdr_reserve_space(xdr, 4); |
| 3014 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3016 | *p++ = cpu_to_be32(nn->nfsd4_lease); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | } |
| 3018 | if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3019 | p = xdr_reserve_space(xdr, 4); |
| 3020 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3021 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3022 | *p++ = cpu_to_be32(rdattr_err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | } |
| 3024 | if (bmval0 & FATTR4_WORD0_ACL) { |
| 3025 | struct nfs4_ace *ace; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | |
| 3027 | if (acl == NULL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3028 | p = xdr_reserve_space(xdr, 4); |
| 3029 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | goto out_resource; |
| 3031 | |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3032 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | goto out_acl; |
| 3034 | } |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3035 | p = xdr_reserve_space(xdr, 4); |
| 3036 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3038 | *p++ = cpu_to_be32(acl->naces); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 3040 | for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3041 | p = xdr_reserve_space(xdr, 4*3); |
| 3042 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3044 | *p++ = cpu_to_be32(ace->type); |
| 3045 | *p++ = cpu_to_be32(ace->flag); |
| 3046 | *p++ = cpu_to_be32(ace->access_mask & |
| 3047 | NFS4_ACE_MASK_ALL); |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3048 | status = nfsd4_encode_aclname(xdr, rqstp, ace); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | if (status) |
| 3050 | goto out; |
| 3051 | } |
| 3052 | } |
| 3053 | out_acl: |
| 3054 | if (bmval0 & FATTR4_WORD0_ACLSUPPORT) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3055 | p = xdr_reserve_space(xdr, 4); |
| 3056 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3057 | goto out_resource; |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 3058 | *p++ = cpu_to_be32(IS_POSIXACL(dentry->d_inode) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0); |
| 3060 | } |
| 3061 | if (bmval0 & FATTR4_WORD0_CANSETTIME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3062 | p = xdr_reserve_space(xdr, 4); |
| 3063 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3064 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3065 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | } |
| 3067 | if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3068 | p = xdr_reserve_space(xdr, 4); |
| 3069 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3071 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | } |
| 3073 | if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3074 | p = xdr_reserve_space(xdr, 4); |
| 3075 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3077 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | } |
| 3079 | if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3080 | p = xdr_reserve_space(xdr, 4); |
| 3081 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3083 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | } |
| 3085 | if (bmval0 & FATTR4_WORD0_FILEHANDLE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3086 | p = xdr_reserve_space(xdr, fhp->fh_handle.fh_size + 4); |
| 3087 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | goto out_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3089 | p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, |
| 3090 | fhp->fh_handle.fh_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | } |
| 3092 | if (bmval0 & FATTR4_WORD0_FILEID) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3093 | p = xdr_reserve_space(xdr, 8); |
| 3094 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3095 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3096 | p = xdr_encode_hyper(p, stat.ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | } |
| 3098 | if (bmval0 & FATTR4_WORD0_FILES_AVAIL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3099 | p = xdr_reserve_space(xdr, 8); |
| 3100 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3102 | p = xdr_encode_hyper(p, (u64) statfs.f_ffree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | } |
| 3104 | if (bmval0 & FATTR4_WORD0_FILES_FREE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3105 | p = xdr_reserve_space(xdr, 8); |
| 3106 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3108 | p = xdr_encode_hyper(p, (u64) statfs.f_ffree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3109 | } |
| 3110 | if (bmval0 & FATTR4_WORD0_FILES_TOTAL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3111 | p = xdr_reserve_space(xdr, 8); |
| 3112 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3114 | p = xdr_encode_hyper(p, (u64) statfs.f_files); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 3116 | if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3117 | status = nfsd4_encode_fs_locations(xdr, rqstp, exp); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 3118 | if (status) |
| 3119 | goto out; |
| 3120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3121 | if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3122 | p = xdr_reserve_space(xdr, 4); |
| 3123 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3124 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3125 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | } |
| 3127 | if (bmval0 & FATTR4_WORD0_MAXFILESIZE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3128 | p = xdr_reserve_space(xdr, 8); |
| 3129 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3131 | p = xdr_encode_hyper(p, exp->ex_path.mnt->mnt_sb->s_maxbytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | } |
| 3133 | if (bmval0 & FATTR4_WORD0_MAXLINK) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3134 | p = xdr_reserve_space(xdr, 4); |
| 3135 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3137 | *p++ = cpu_to_be32(255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | } |
| 3139 | if (bmval0 & FATTR4_WORD0_MAXNAME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3140 | p = xdr_reserve_space(xdr, 4); |
| 3141 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3143 | *p++ = cpu_to_be32(statfs.f_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3144 | } |
| 3145 | if (bmval0 & FATTR4_WORD0_MAXREAD) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3146 | p = xdr_reserve_space(xdr, 8); |
| 3147 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3149 | p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3150 | } |
| 3151 | if (bmval0 & FATTR4_WORD0_MAXWRITE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3152 | p = xdr_reserve_space(xdr, 8); |
| 3153 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3155 | p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | } |
| 3157 | if (bmval1 & FATTR4_WORD1_MODE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3158 | p = xdr_reserve_space(xdr, 4); |
| 3159 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3160 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3161 | *p++ = cpu_to_be32(stat.mode & S_IALLUGO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3162 | } |
| 3163 | if (bmval1 & FATTR4_WORD1_NO_TRUNC) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3164 | p = xdr_reserve_space(xdr, 4); |
| 3165 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3166 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3167 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | } |
| 3169 | if (bmval1 & FATTR4_WORD1_NUMLINKS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3170 | p = xdr_reserve_space(xdr, 4); |
| 3171 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3173 | *p++ = cpu_to_be32(stat.nlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3174 | } |
| 3175 | if (bmval1 & FATTR4_WORD1_OWNER) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3176 | status = nfsd4_encode_user(xdr, rqstp, stat.uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | if (status) |
| 3178 | goto out; |
| 3179 | } |
| 3180 | if (bmval1 & FATTR4_WORD1_OWNER_GROUP) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3181 | status = nfsd4_encode_group(xdr, rqstp, stat.gid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | if (status) |
| 3183 | goto out; |
| 3184 | } |
| 3185 | if (bmval1 & FATTR4_WORD1_RAWDEV) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3186 | p = xdr_reserve_space(xdr, 8); |
| 3187 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3189 | *p++ = cpu_to_be32((u32) MAJOR(stat.rdev)); |
| 3190 | *p++ = cpu_to_be32((u32) MINOR(stat.rdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | } |
| 3192 | if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3193 | p = xdr_reserve_space(xdr, 8); |
| 3194 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | goto out_resource; |
| 3196 | dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3197 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | } |
| 3199 | if (bmval1 & FATTR4_WORD1_SPACE_FREE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3200 | p = xdr_reserve_space(xdr, 8); |
| 3201 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | goto out_resource; |
| 3203 | dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3204 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | } |
| 3206 | if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3207 | p = xdr_reserve_space(xdr, 8); |
| 3208 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | goto out_resource; |
| 3210 | dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3211 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | } |
| 3213 | if (bmval1 & FATTR4_WORD1_SPACE_USED) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3214 | p = xdr_reserve_space(xdr, 8); |
| 3215 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | goto out_resource; |
| 3217 | dummy64 = (u64)stat.blocks << 9; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3218 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3219 | } |
| 3220 | if (bmval1 & FATTR4_WORD1_TIME_ACCESS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3221 | p = xdr_reserve_space(xdr, 12); |
| 3222 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3224 | p = xdr_encode_hyper(p, (s64)stat.atime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3225 | *p++ = cpu_to_be32(stat.atime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | } |
| 3227 | if (bmval1 & FATTR4_WORD1_TIME_DELTA) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3228 | p = xdr_reserve_space(xdr, 12); |
| 3229 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | goto out_resource; |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 3231 | p = encode_time_delta(p, d_inode(dentry)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | } |
| 3233 | if (bmval1 & FATTR4_WORD1_TIME_METADATA) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3234 | p = xdr_reserve_space(xdr, 12); |
| 3235 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3236 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3237 | p = xdr_encode_hyper(p, (s64)stat.ctime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3238 | *p++ = cpu_to_be32(stat.ctime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | } |
| 3240 | if (bmval1 & FATTR4_WORD1_TIME_MODIFY) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3241 | p = xdr_reserve_space(xdr, 12); |
| 3242 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3244 | p = xdr_encode_hyper(p, (s64)stat.mtime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3245 | *p++ = cpu_to_be32(stat.mtime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3246 | } |
| 3247 | if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) { |
Kinglong Mee | 0a2050d | 2015-07-30 21:51:54 +0800 | [diff] [blame] | 3248 | struct kstat parent_stat; |
| 3249 | u64 ino = stat.ino; |
| 3250 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3251 | p = xdr_reserve_space(xdr, 8); |
| 3252 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | goto out_resource; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3254 | /* |
| 3255 | * Get parent's attributes if not ignoring crossmount |
| 3256 | * and this is the root of a cross-mounted filesystem. |
| 3257 | */ |
| 3258 | if (ignore_crossmnt == 0 && |
Kinglong Mee | 0a2050d | 2015-07-30 21:51:54 +0800 | [diff] [blame] | 3259 | dentry == exp->ex_path.mnt->mnt_root) { |
| 3260 | err = get_parent_attributes(exp, &parent_stat); |
| 3261 | if (err) |
| 3262 | goto out_nfserr; |
| 3263 | ino = parent_stat.ino; |
| 3264 | } |
| 3265 | p = xdr_encode_hyper(p, ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | } |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3267 | #ifdef CONFIG_NFSD_PNFS |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3268 | if (bmval1 & FATTR4_WORD1_FS_LAYOUT_TYPES) { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 3269 | status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3270 | if (status) |
| 3271 | goto out; |
| 3272 | } |
| 3273 | |
| 3274 | if (bmval2 & FATTR4_WORD2_LAYOUT_TYPES) { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 3275 | status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3276 | if (status) |
| 3277 | goto out; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | if (bmval2 & FATTR4_WORD2_LAYOUT_BLKSIZE) { |
| 3281 | p = xdr_reserve_space(xdr, 4); |
| 3282 | if (!p) |
| 3283 | goto out_resource; |
| 3284 | *p++ = cpu_to_be32(stat.blksize); |
| 3285 | } |
| 3286 | #endif /* CONFIG_NFSD_PNFS */ |
Benny Halevy | 8c18f20 | 2009-04-03 08:29:14 +0300 | [diff] [blame] | 3287 | if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) { |
Trond Myklebust | b26b78c | 2017-05-09 16:24:59 -0400 | [diff] [blame] | 3288 | u32 supp[3]; |
| 3289 | |
| 3290 | memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp)); |
| 3291 | supp[0] &= NFSD_SUPPATTR_EXCLCREAT_WORD0; |
| 3292 | supp[1] &= NFSD_SUPPATTR_EXCLCREAT_WORD1; |
| 3293 | supp[2] &= NFSD_SUPPATTR_EXCLCREAT_WORD2; |
| 3294 | |
| 3295 | status = nfsd4_encode_bitmap(xdr, supp[0], supp[1], supp[2]); |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3296 | if (status) |
| 3297 | goto out; |
Benny Halevy | 8c18f20 | 2009-04-03 08:29:14 +0300 | [diff] [blame] | 3298 | } |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 3299 | |
J. Bruce Fields | a858576 | 2018-04-25 13:26:23 -0400 | [diff] [blame] | 3300 | if (bmval2 & FATTR4_WORD2_CHANGE_ATTR_TYPE) { |
| 3301 | p = xdr_reserve_space(xdr, 4); |
| 3302 | if (!p) |
| 3303 | goto out_resource; |
| 3304 | if (IS_I_VERSION(d_inode(dentry))) |
| 3305 | *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR); |
| 3306 | else |
| 3307 | *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_TIME_METADATA); |
| 3308 | } |
| 3309 | |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 3310 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
Kinglong Mee | 7d58072 | 2015-07-30 21:54:26 +0800 | [diff] [blame] | 3311 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
| 3312 | status = nfsd4_encode_security_label(xdr, rqstp, context, |
| 3313 | contextlen); |
| 3314 | if (status) |
| 3315 | goto out; |
| 3316 | } |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 3317 | #endif |
Kinglong Mee | 7d58072 | 2015-07-30 21:54:26 +0800 | [diff] [blame] | 3318 | |
Frank van der Linden | 0e885e8 | 2020-06-23 22:39:27 +0000 | [diff] [blame] | 3319 | if (bmval2 & FATTR4_WORD2_XATTR_SUPPORT) { |
| 3320 | p = xdr_reserve_space(xdr, 4); |
| 3321 | if (!p) |
| 3322 | goto out_resource; |
| 3323 | err = xattr_supported_namespace(d_inode(dentry), |
| 3324 | XATTR_USER_PREFIX); |
| 3325 | *p++ = cpu_to_be32(err == 0); |
| 3326 | } |
| 3327 | |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 3328 | attrlen = htonl(xdr->buf->len - attrlen_offset - 4); |
| 3329 | write_bytes_to_xdr_buf(xdr->buf, attrlen_offset, &attrlen, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | status = nfs_ok; |
| 3331 | |
| 3332 | out: |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 3333 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 3334 | if (context) |
| 3335 | security_release_secctx(context, contextlen); |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 3336 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 3337 | kfree(acl); |
Yan, Zheng | 18df11d0 | 2014-03-10 12:52:07 +0800 | [diff] [blame] | 3338 | if (tempfh) { |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 3339 | fh_put(tempfh); |
Yan, Zheng | 18df11d0 | 2014-03-10 12:52:07 +0800 | [diff] [blame] | 3340 | kfree(tempfh); |
| 3341 | } |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 3342 | if (status) |
| 3343 | xdr_truncate_encode(xdr, starting_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3344 | return status; |
| 3345 | out_nfserr: |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 3346 | status = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | goto out; |
| 3348 | out_resource: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | status = nfserr_resource; |
| 3350 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | } |
| 3352 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3353 | static void svcxdr_init_encode_from_buffer(struct xdr_stream *xdr, |
| 3354 | struct xdr_buf *buf, __be32 *p, int bytes) |
| 3355 | { |
| 3356 | xdr->scratch.iov_len = 0; |
| 3357 | memset(buf, 0, sizeof(struct xdr_buf)); |
| 3358 | buf->head[0].iov_base = p; |
| 3359 | buf->head[0].iov_len = 0; |
| 3360 | buf->len = 0; |
| 3361 | xdr->buf = buf; |
| 3362 | xdr->iov = buf->head; |
| 3363 | xdr->p = p; |
| 3364 | xdr->end = (void *)p + bytes; |
| 3365 | buf->buflen = bytes; |
| 3366 | } |
| 3367 | |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3368 | __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words, |
| 3369 | struct svc_fh *fhp, struct svc_export *exp, |
| 3370 | struct dentry *dentry, u32 *bmval, |
| 3371 | struct svc_rqst *rqstp, int ignore_crossmnt) |
| 3372 | { |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3373 | struct xdr_buf dummy; |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3374 | struct xdr_stream xdr; |
| 3375 | __be32 ret; |
| 3376 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3377 | svcxdr_init_encode_from_buffer(&xdr, &dummy, *p, words << 2); |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3378 | ret = nfsd4_encode_fattr(&xdr, fhp, exp, dentry, bmval, rqstp, |
| 3379 | ignore_crossmnt); |
| 3380 | *p = xdr.p; |
| 3381 | return ret; |
| 3382 | } |
| 3383 | |
J. Bruce Fields | c0ce6ec | 2008-02-11 15:48:47 -0500 | [diff] [blame] | 3384 | static inline int attributes_need_mount(u32 *bmval) |
| 3385 | { |
| 3386 | if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME)) |
| 3387 | return 1; |
| 3388 | if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 3389 | return 1; |
| 3390 | return 0; |
| 3391 | } |
| 3392 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3393 | static __be32 |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3394 | nfsd4_encode_dirent_fattr(struct xdr_stream *xdr, struct nfsd4_readdir *cd, |
| 3395 | const char *name, int namlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | { |
| 3397 | struct svc_export *exp = cd->rd_fhp->fh_export; |
| 3398 | struct dentry *dentry; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3399 | __be32 nfserr; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3400 | int ignore_crossmnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | |
Al Viro | 6c2d4798 | 2019-10-31 01:21:58 -0400 | [diff] [blame] | 3402 | dentry = lookup_positive_unlocked(name, cd->rd_fhp->fh_dentry, namlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | if (IS_ERR(dentry)) |
| 3404 | return nfserrno(PTR_ERR(dentry)); |
| 3405 | |
| 3406 | exp_get(exp); |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3407 | /* |
| 3408 | * In the case of a mountpoint, the client may be asking for |
| 3409 | * attributes that are only properties of the underlying filesystem |
| 3410 | * as opposed to the cross-mounted file system. In such a case, |
| 3411 | * we will not follow the cross mount and will fill the attribtutes |
| 3412 | * directly from the mountpoint dentry. |
| 3413 | */ |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3414 | if (nfsd_mountpoint(dentry, exp)) { |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 3415 | int err; |
| 3416 | |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3417 | if (!(exp->ex_flags & NFSEXP_V4ROOT) |
| 3418 | && !attributes_need_mount(cd->rd_bmval)) { |
| 3419 | ignore_crossmnt = 1; |
| 3420 | goto out_encode; |
| 3421 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3422 | /* |
| 3423 | * Why the heck aren't we just using nfsd_lookup?? |
| 3424 | * Different "."/".." handling? Something else? |
| 3425 | * At least, add a comment here to explain.... |
| 3426 | */ |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 3427 | err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp); |
| 3428 | if (err) { |
| 3429 | nfserr = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | goto out_put; |
| 3431 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3432 | nfserr = check_nfsd_access(exp, cd->rd_rqstp); |
| 3433 | if (nfserr) |
| 3434 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3435 | |
| 3436 | } |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3437 | out_encode: |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3438 | nfserr = nfsd4_encode_fattr(xdr, NULL, exp, dentry, cd->rd_bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3439 | cd->rd_rqstp, ignore_crossmnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | out_put: |
| 3441 | dput(dentry); |
| 3442 | exp_put(exp); |
| 3443 | return nfserr; |
| 3444 | } |
| 3445 | |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 3446 | static __be32 * |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3447 | nfsd4_encode_rdattr_error(struct xdr_stream *xdr, __be32 nfserr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | { |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3449 | __be32 *p; |
| 3450 | |
Kinglong Mee | c3a4561 | 2014-07-06 11:34:43 +0800 | [diff] [blame] | 3451 | p = xdr_reserve_space(xdr, 20); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3452 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3453 | return NULL; |
| 3454 | *p++ = htonl(2); |
| 3455 | *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */ |
| 3456 | *p++ = htonl(0); /* bmval1 */ |
| 3457 | |
J. Bruce Fields | 87915c6 | 2013-01-16 17:33:28 -0500 | [diff] [blame] | 3458 | *p++ = htonl(4); /* attribute length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3459 | *p++ = nfserr; /* no htonl */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3460 | return p; |
| 3461 | } |
| 3462 | |
| 3463 | static int |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 3464 | nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, |
| 3465 | loff_t offset, u64 ino, unsigned int d_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | { |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 3467 | struct readdir_cd *ccd = ccdv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3468 | struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3469 | struct xdr_stream *xdr = cd->xdr; |
| 3470 | int start_offset = xdr->buf->len; |
| 3471 | int cookie_offset; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3472 | u32 name_and_cookie; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3473 | int entry_bytes; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3474 | __be32 nfserr = nfserr_toosmall; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3475 | __be64 wire_offset; |
| 3476 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | |
| 3478 | /* In nfsv4, "." and ".." never make it onto the wire.. */ |
| 3479 | if (name && isdotent(name, namlen)) { |
| 3480 | cd->common.err = nfs_ok; |
| 3481 | return 0; |
| 3482 | } |
| 3483 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3484 | if (cd->cookie_offset) { |
| 3485 | wire_offset = cpu_to_be64(offset); |
| 3486 | write_bytes_to_xdr_buf(xdr->buf, cd->cookie_offset, |
| 3487 | &wire_offset, 8); |
| 3488 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3490 | p = xdr_reserve_space(xdr, 4); |
| 3491 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3492 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | *p++ = xdr_one; /* mark entry present */ |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3494 | cookie_offset = xdr->buf->len; |
| 3495 | p = xdr_reserve_space(xdr, 3*4 + namlen); |
| 3496 | if (!p) |
| 3497 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */ |
| 3499 | p = xdr_encode_array(p, name, namlen); /* name length & name */ |
| 3500 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3501 | nfserr = nfsd4_encode_dirent_fattr(xdr, cd, name, namlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | switch (nfserr) { |
| 3503 | case nfs_ok: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3504 | break; |
| 3505 | case nfserr_resource: |
| 3506 | nfserr = nfserr_toosmall; |
| 3507 | goto fail; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3508 | case nfserr_noent: |
Kinglong Mee | f41c5ad | 2014-06-13 17:32:42 +0800 | [diff] [blame] | 3509 | xdr_truncate_encode(xdr, start_offset); |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3510 | goto skip_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | default: |
| 3512 | /* |
| 3513 | * If the client requested the RDATTR_ERROR attribute, |
| 3514 | * we stuff the error code into this attribute |
| 3515 | * and continue. If this attribute was not requested, |
| 3516 | * then in accordance with the spec, we fail the |
| 3517 | * entire READDIR operation(!) |
| 3518 | */ |
| 3519 | if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)) |
| 3520 | goto fail; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3521 | p = nfsd4_encode_rdattr_error(xdr, nfserr); |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 3522 | if (p == NULL) { |
| 3523 | nfserr = nfserr_toosmall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | goto fail; |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 3525 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3526 | } |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3527 | nfserr = nfserr_toosmall; |
| 3528 | entry_bytes = xdr->buf->len - start_offset; |
| 3529 | if (entry_bytes > cd->rd_maxcount) |
| 3530 | goto fail; |
| 3531 | cd->rd_maxcount -= entry_bytes; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3532 | /* |
| 3533 | * RFC 3530 14.2.24 describes rd_dircount as only a "hint", so |
| 3534 | * let's always let through the first entry, at least: |
| 3535 | */ |
J. Bruce Fields | 0ec016e | 2014-12-19 18:01:35 -0500 | [diff] [blame] | 3536 | if (!cd->rd_dircount) |
| 3537 | goto fail; |
| 3538 | name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3539 | if (name_and_cookie > cd->rd_dircount && cd->cookie_offset) |
| 3540 | goto fail; |
| 3541 | cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie); |
J. Bruce Fields | 0ec016e | 2014-12-19 18:01:35 -0500 | [diff] [blame] | 3542 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3543 | cd->cookie_offset = cookie_offset; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3544 | skip_entry: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 | cd->common.err = nfs_ok; |
| 3546 | return 0; |
| 3547 | fail: |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3548 | xdr_truncate_encode(xdr, start_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | cd->common.err = nfserr; |
| 3550 | return -EINVAL; |
| 3551 | } |
| 3552 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3553 | static __be32 |
| 3554 | nfsd4_encode_stateid(struct xdr_stream *xdr, stateid_t *sid) |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3555 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3556 | __be32 *p; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3557 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3558 | p = xdr_reserve_space(xdr, sizeof(stateid_t)); |
| 3559 | if (!p) |
| 3560 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3561 | *p++ = cpu_to_be32(sid->si_generation); |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3562 | p = xdr_encode_opaque_fixed(p, &sid->si_opaque, |
| 3563 | sizeof(stateid_opaque_t)); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3564 | return 0; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3565 | } |
| 3566 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3567 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3568 | nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3570 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3571 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3572 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3573 | p = xdr_reserve_space(xdr, 8); |
| 3574 | if (!p) |
| 3575 | return nfserr_resource; |
| 3576 | *p++ = cpu_to_be32(access->ac_supported); |
| 3577 | *p++ = cpu_to_be32(access->ac_resp_access); |
| 3578 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3579 | } |
| 3580 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3581 | static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_bind_conn_to_session *bcts) |
| 3582 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3583 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3584 | __be32 *p; |
| 3585 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3586 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 8); |
| 3587 | if (!p) |
| 3588 | return nfserr_resource; |
| 3589 | p = xdr_encode_opaque_fixed(p, bcts->sessionid.data, |
| 3590 | NFS4_MAX_SESSIONID_LEN); |
| 3591 | *p++ = cpu_to_be32(bcts->dir); |
| 3592 | /* Upshifting from TCP to RDMA is not supported */ |
| 3593 | *p++ = cpu_to_be32(0); |
| 3594 | return 0; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3595 | } |
| 3596 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3597 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3598 | nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_close *close) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3600 | struct xdr_stream *xdr = &resp->xdr; |
| 3601 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3602 | return nfsd4_encode_stateid(xdr, &close->cl_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
| 3605 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3606 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3607 | nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_commit *commit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3609 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3610 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3612 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
| 3613 | if (!p) |
| 3614 | return nfserr_resource; |
| 3615 | p = xdr_encode_opaque_fixed(p, commit->co_verf.data, |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3616 | NFS4_VERIFIER_SIZE); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3617 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | } |
| 3619 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3620 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3621 | nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_create *create) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3622 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3623 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3624 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3625 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3626 | p = xdr_reserve_space(xdr, 20); |
| 3627 | if (!p) |
| 3628 | return nfserr_resource; |
| 3629 | encode_cinfo(p, &create->cr_cinfo); |
Trond Myklebust | b96811c | 2019-08-18 14:18:58 -0400 | [diff] [blame] | 3630 | return nfsd4_encode_bitmap(xdr, create->cr_bmval[0], |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3631 | create->cr_bmval[1], create->cr_bmval[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | } |
| 3633 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3634 | static __be32 |
| 3635 | nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_getattr *getattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | { |
| 3637 | struct svc_fh *fhp = getattr->ga_fhp; |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3638 | struct xdr_stream *xdr = &resp->xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3640 | return nfsd4_encode_fattr(xdr, fhp, fhp->fh_export, fhp->fh_dentry, |
| 3641 | getattr->ga_bmval, resp->rqstp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | } |
| 3643 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3644 | static __be32 |
| 3645 | nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh **fhpp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3647 | struct xdr_stream *xdr = &resp->xdr; |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3648 | struct svc_fh *fhp = *fhpp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | unsigned int len; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3650 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3652 | len = fhp->fh_handle.fh_size; |
| 3653 | p = xdr_reserve_space(xdr, len + 4); |
| 3654 | if (!p) |
| 3655 | return nfserr_resource; |
| 3656 | p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, len); |
| 3657 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3658 | } |
| 3659 | |
| 3660 | /* |
| 3661 | * Including all fields other than the name, a LOCK4denied structure requires |
| 3662 | * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes. |
| 3663 | */ |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3664 | static __be32 |
| 3665 | nfsd4_encode_lock_denied(struct xdr_stream *xdr, struct nfsd4_lock_denied *ld) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3666 | { |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 3667 | struct xdr_netobj *conf = &ld->ld_owner; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3668 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3670 | again: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3671 | p = xdr_reserve_space(xdr, 32 + XDR_LEN(conf->len)); |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3672 | if (!p) { |
| 3673 | /* |
| 3674 | * Don't fail to return the result just because we can't |
| 3675 | * return the conflicting open: |
| 3676 | */ |
| 3677 | if (conf->len) { |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3678 | kfree(conf->data); |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3679 | conf->len = 0; |
| 3680 | conf->data = NULL; |
| 3681 | goto again; |
| 3682 | } |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3683 | return nfserr_resource; |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3684 | } |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3685 | p = xdr_encode_hyper(p, ld->ld_start); |
| 3686 | p = xdr_encode_hyper(p, ld->ld_length); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3687 | *p++ = cpu_to_be32(ld->ld_type); |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 3688 | if (conf->len) { |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3689 | p = xdr_encode_opaque_fixed(p, &ld->ld_clientid, 8); |
| 3690 | p = xdr_encode_opaque(p, conf->data, conf->len); |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3691 | kfree(conf->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3692 | } else { /* non - nfsv4 lock in conflict, no clientid nor owner */ |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3693 | p = xdr_encode_hyper(p, (u64)0); /* clientid */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3694 | *p++ = cpu_to_be32(0); /* length of owner name */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3695 | } |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3696 | return nfserr_denied; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3697 | } |
| 3698 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3699 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3700 | nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lock *lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3701 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3702 | struct xdr_stream *xdr = &resp->xdr; |
| 3703 | |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3704 | if (!nfserr) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3705 | nfserr = nfsd4_encode_stateid(xdr, &lock->lk_resp_stateid); |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3706 | else if (nfserr == nfserr_denied) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3707 | nfserr = nfsd4_encode_lock_denied(xdr, &lock->lk_denied); |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3708 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3709 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3712 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3713 | nfsd4_encode_lockt(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lockt *lockt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3715 | struct xdr_stream *xdr = &resp->xdr; |
| 3716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | if (nfserr == nfserr_denied) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3718 | nfsd4_encode_lock_denied(xdr, &lockt->lt_denied); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3719 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3720 | } |
| 3721 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3722 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3723 | nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_locku *locku) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3724 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3725 | struct xdr_stream *xdr = &resp->xdr; |
| 3726 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3727 | return nfsd4_encode_stateid(xdr, &locku->lu_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3728 | } |
| 3729 | |
| 3730 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3731 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3732 | nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_link *link) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3733 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3734 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3735 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3736 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3737 | p = xdr_reserve_space(xdr, 20); |
| 3738 | if (!p) |
| 3739 | return nfserr_resource; |
| 3740 | p = encode_cinfo(p, &link->li_cinfo); |
| 3741 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3745 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3746 | nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3748 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3749 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3751 | nfserr = nfsd4_encode_stateid(xdr, &open->op_stateid); |
| 3752 | if (nfserr) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3753 | return nfserr; |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3754 | p = xdr_reserve_space(xdr, 24); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3755 | if (!p) |
| 3756 | return nfserr_resource; |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 3757 | p = encode_cinfo(p, &open->op_cinfo); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3758 | *p++ = cpu_to_be32(open->op_rflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3760 | nfserr = nfsd4_encode_bitmap(xdr, open->op_bmval[0], open->op_bmval[1], |
| 3761 | open->op_bmval[2]); |
| 3762 | if (nfserr) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3763 | return nfserr; |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3764 | |
| 3765 | p = xdr_reserve_space(xdr, 4); |
| 3766 | if (!p) |
| 3767 | return nfserr_resource; |
| 3768 | |
| 3769 | *p++ = cpu_to_be32(open->op_delegate_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3770 | switch (open->op_delegate_type) { |
| 3771 | case NFS4_OPEN_DELEGATE_NONE: |
| 3772 | break; |
| 3773 | case NFS4_OPEN_DELEGATE_READ: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3774 | nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid); |
| 3775 | if (nfserr) |
| 3776 | return nfserr; |
| 3777 | p = xdr_reserve_space(xdr, 20); |
| 3778 | if (!p) |
| 3779 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3780 | *p++ = cpu_to_be32(open->op_recall); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | |
| 3782 | /* |
| 3783 | * TODO: ACE's in delegations |
| 3784 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3785 | *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 3786 | *p++ = cpu_to_be32(0); |
| 3787 | *p++ = cpu_to_be32(0); |
| 3788 | *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | break; |
| 3790 | case NFS4_OPEN_DELEGATE_WRITE: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3791 | nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid); |
| 3792 | if (nfserr) |
| 3793 | return nfserr; |
| 3794 | p = xdr_reserve_space(xdr, 32); |
| 3795 | if (!p) |
| 3796 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3797 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3798 | |
| 3799 | /* |
| 3800 | * TODO: space_limit's in delegations |
| 3801 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3802 | *p++ = cpu_to_be32(NFS4_LIMIT_SIZE); |
| 3803 | *p++ = cpu_to_be32(~(u32)0); |
| 3804 | *p++ = cpu_to_be32(~(u32)0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | |
| 3806 | /* |
| 3807 | * TODO: ACE's in delegations |
| 3808 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3809 | *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 3810 | *p++ = cpu_to_be32(0); |
| 3811 | *p++ = cpu_to_be32(0); |
| 3812 | *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | break; |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3814 | case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */ |
| 3815 | switch (open->op_why_no_deleg) { |
| 3816 | case WND4_CONTENTION: |
| 3817 | case WND4_RESOURCE: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3818 | p = xdr_reserve_space(xdr, 8); |
| 3819 | if (!p) |
| 3820 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3821 | *p++ = cpu_to_be32(open->op_why_no_deleg); |
| 3822 | /* deleg signaling not supported yet: */ |
| 3823 | *p++ = cpu_to_be32(0); |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3824 | break; |
| 3825 | default: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3826 | p = xdr_reserve_space(xdr, 4); |
| 3827 | if (!p) |
| 3828 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3829 | *p++ = cpu_to_be32(open->op_why_no_deleg); |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3830 | } |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3831 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | default: |
| 3833 | BUG(); |
| 3834 | } |
| 3835 | /* XXX save filehandle here */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3836 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3837 | } |
| 3838 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3839 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3840 | nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3842 | struct xdr_stream *xdr = &resp->xdr; |
| 3843 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3844 | return nfsd4_encode_stateid(xdr, &oc->oc_resp_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | } |
| 3846 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3847 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3848 | nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3850 | struct xdr_stream *xdr = &resp->xdr; |
| 3851 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3852 | return nfsd4_encode_stateid(xdr, &od->od_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3853 | } |
| 3854 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3855 | static __be32 nfsd4_encode_splice_read( |
| 3856 | struct nfsd4_compoundres *resp, |
| 3857 | struct nfsd4_read *read, |
| 3858 | struct file *file, unsigned long maxcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | { |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3860 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3861 | struct xdr_buf *buf = xdr->buf; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3862 | int status, space_left; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3863 | u32 eof; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3864 | __be32 nfserr; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3865 | __be32 *p = xdr->p - 2; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3866 | |
Kinglong Mee | d5d5c30 | 2014-07-09 21:51:27 +0800 | [diff] [blame] | 3867 | /* Make sure there will be room for padding if needed */ |
| 3868 | if (xdr->end - xdr->p < 1) |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3869 | return nfserr_resource; |
| 3870 | |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3871 | nfserr = nfsd_splice_read(read->rd_rqstp, read->rd_fhp, |
Trond Myklebust | 83a6307 | 2019-08-26 13:03:11 -0400 | [diff] [blame] | 3872 | file, read->rd_offset, &maxcount, &eof); |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3873 | read->rd_length = maxcount; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3874 | if (nfserr) |
| 3875 | goto out_err; |
| 3876 | status = svc_encode_result_payload(read->rd_rqstp, |
| 3877 | buf->head[0].iov_len, maxcount); |
| 3878 | if (status) { |
| 3879 | nfserr = nfserrno(status); |
| 3880 | goto out_err; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3881 | } |
| 3882 | |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3883 | *(p++) = htonl(eof); |
| 3884 | *(p++) = htonl(maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3885 | |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3886 | buf->page_len = maxcount; |
| 3887 | buf->len += maxcount; |
J. Bruce Fields | 15b23ef | 2014-09-24 16:32:34 -0400 | [diff] [blame] | 3888 | xdr->page_ptr += (buf->page_base + maxcount + PAGE_SIZE - 1) |
| 3889 | / PAGE_SIZE; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3890 | |
| 3891 | /* Use rest of head for padding and remaining ops: */ |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3892 | buf->tail[0].iov_base = xdr->p; |
| 3893 | buf->tail[0].iov_len = 0; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3894 | xdr->iov = buf->tail; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3895 | if (maxcount&3) { |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3896 | int pad = 4 - (maxcount&3); |
| 3897 | |
| 3898 | *(xdr->p++) = 0; |
| 3899 | |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3900 | buf->tail[0].iov_base += maxcount&3; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3901 | buf->tail[0].iov_len = pad; |
| 3902 | buf->len += pad; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3903 | } |
| 3904 | |
| 3905 | space_left = min_t(int, (void *)xdr->end - (void *)xdr->p, |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3906 | buf->buflen - buf->len); |
| 3907 | buf->buflen = buf->len + space_left; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3908 | xdr->end = (__be32 *)((void *)xdr->end + space_left); |
| 3909 | |
| 3910 | return 0; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3911 | |
| 3912 | out_err: |
| 3913 | /* |
| 3914 | * nfsd_splice_actor may have already messed with the |
| 3915 | * page length; reset it so as not to confuse |
| 3916 | * xdr_truncate_encode in our caller. |
| 3917 | */ |
| 3918 | buf->page_len = 0; |
| 3919 | return nfserr; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3920 | } |
| 3921 | |
| 3922 | static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, |
| 3923 | struct nfsd4_read *read, |
| 3924 | struct file *file, unsigned long maxcount) |
| 3925 | { |
| 3926 | struct xdr_stream *xdr = &resp->xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3927 | u32 eof; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3928 | int starting_len = xdr->buf->len - 8; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3929 | __be32 nfserr; |
| 3930 | __be32 tmp; |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 3931 | int pad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3932 | |
Anna Schumaker | 403217f | 2020-08-17 12:53:06 -0400 | [diff] [blame] | 3933 | read->rd_vlen = xdr_reserve_space_vec(xdr, resp->rqstp->rq_vec, maxcount); |
| 3934 | if (read->rd_vlen < 0) |
| 3935 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3936 | |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3937 | nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset, |
Trond Myklebust | 83a6307 | 2019-08-26 13:03:11 -0400 | [diff] [blame] | 3938 | resp->rqstp->rq_vec, read->rd_vlen, &maxcount, |
| 3939 | &eof); |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3940 | read->rd_length = maxcount; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3941 | if (nfserr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | return nfserr; |
Chuck Lever | 03493bc | 2020-06-10 10:36:42 -0400 | [diff] [blame] | 3943 | if (svc_encode_result_payload(resp->rqstp, starting_len + 8, maxcount)) |
Chuck Lever | 4120553 | 2020-03-02 14:45:53 -0500 | [diff] [blame] | 3944 | return nfserr_io; |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 3945 | xdr_truncate_encode(xdr, starting_len + 8 + xdr_align_size(maxcount)); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3946 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3947 | tmp = htonl(eof); |
| 3948 | write_bytes_to_xdr_buf(xdr->buf, starting_len , &tmp, 4); |
| 3949 | tmp = htonl(maxcount); |
| 3950 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); |
| 3951 | |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 3952 | tmp = xdr_zero; |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 3953 | pad = (maxcount&3) ? 4 - (maxcount&3) : 0; |
| 3954 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 8 + maxcount, |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 3955 | &tmp, pad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | return 0; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3957 | |
| 3958 | } |
| 3959 | |
| 3960 | static __be32 |
| 3961 | nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 3962 | struct nfsd4_read *read) |
| 3963 | { |
| 3964 | unsigned long maxcount; |
| 3965 | struct xdr_stream *xdr = &resp->xdr; |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 3966 | struct file *file; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3967 | int starting_len = xdr->buf->len; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3968 | __be32 *p; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3969 | |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 3970 | if (nfserr) |
| 3971 | return nfserr; |
| 3972 | file = read->rd_nf->nf_file; |
| 3973 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3974 | p = xdr_reserve_space(xdr, 8); /* eof flag and byte count */ |
| 3975 | if (!p) { |
Jeff Layton | 779fb0f | 2014-11-19 07:51:18 -0500 | [diff] [blame] | 3976 | WARN_ON_ONCE(test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3977 | return nfserr_resource; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3978 | } |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 3979 | if (resp->xdr.buf->page_len && |
| 3980 | test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) { |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 3981 | WARN_ON_ONCE(1); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3982 | return nfserr_resource; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3983 | } |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3984 | xdr_commit_encode(xdr); |
| 3985 | |
| 3986 | maxcount = svc_max_payload(resp->rqstp); |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 3987 | maxcount = min_t(unsigned long, maxcount, |
| 3988 | (xdr->buf->buflen - xdr->buf->len)); |
Kinglong Mee | 3c7aa15 | 2014-06-10 18:08:19 +0800 | [diff] [blame] | 3989 | maxcount = min_t(unsigned long, maxcount, read->rd_length); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3990 | |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 3991 | if (file->f_op->splice_read && |
| 3992 | test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3993 | nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3994 | else |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3995 | nfserr = nfsd4_encode_readv(resp, read, file, maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3996 | |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3997 | if (nfserr) |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3998 | xdr_truncate_encode(xdr, starting_len); |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 3999 | |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 4000 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | } |
| 4002 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4003 | static __be32 |
| 4004 | nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readlink *readlink) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4005 | { |
| 4006 | int maxcount; |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4007 | __be32 wire_count; |
| 4008 | int zero = 0; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 4009 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 4010 | int length_offset = xdr->buf->len; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 4011 | int status; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4012 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4013 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 4014 | p = xdr_reserve_space(xdr, 4); |
| 4015 | if (!p) |
| 4016 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4017 | maxcount = PAGE_SIZE; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4018 | |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4019 | p = xdr_reserve_space(xdr, maxcount); |
| 4020 | if (!p) |
J. Bruce Fields | 4e21ac4 | 2014-03-22 15:15:11 -0400 | [diff] [blame] | 4021 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | /* |
Miklos Szeredi | fd4a0edf | 2016-12-09 16:45:04 +0100 | [diff] [blame] | 4023 | * XXX: By default, vfs_readlink() will truncate symlinks if they |
| 4024 | * would overflow the buffer. Is this kosher in NFSv4? If not, one |
| 4025 | * easy fix is: if vfs_readlink() precisely fills the buffer, assume |
| 4026 | * that truncation occurred, and return NFS4ERR_RESOURCE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4027 | */ |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4028 | nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, |
| 4029 | (char *)p, &maxcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4030 | if (nfserr == nfserr_isdir) |
J. Bruce Fields | d3f627c | 2014-02-26 17:00:38 -0500 | [diff] [blame] | 4031 | nfserr = nfserr_inval; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 4032 | if (nfserr) |
| 4033 | goto out_err; |
| 4034 | status = svc_encode_result_payload(readlink->rl_rqstp, length_offset, |
| 4035 | maxcount); |
| 4036 | if (status) { |
| 4037 | nfserr = nfserrno(status); |
| 4038 | goto out_err; |
J. Bruce Fields | d3f627c | 2014-02-26 17:00:38 -0500 | [diff] [blame] | 4039 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4041 | wire_count = htonl(maxcount); |
| 4042 | write_bytes_to_xdr_buf(xdr->buf, length_offset, &wire_count, 4); |
Avi Kivity | 69bbd9c | 2014-06-26 17:23:12 +0300 | [diff] [blame] | 4043 | xdr_truncate_encode(xdr, length_offset + 4 + ALIGN(maxcount, 4)); |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4044 | if (maxcount & 3) |
| 4045 | write_bytes_to_xdr_buf(xdr->buf, length_offset + 4 + maxcount, |
| 4046 | &zero, 4 - (maxcount&3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4047 | return 0; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 4048 | |
| 4049 | out_err: |
| 4050 | xdr_truncate_encode(xdr, length_offset); |
| 4051 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4052 | } |
| 4053 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4054 | static __be32 |
| 4055 | nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readdir *readdir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4056 | { |
| 4057 | int maxcount; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4058 | int bytes_left; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | loff_t offset; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4060 | __be64 wire_offset; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 4061 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 4062 | int starting_len = xdr->buf->len; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4063 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4065 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
| 4066 | if (!p) |
| 4067 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4068 | |
| 4069 | /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4070 | *p++ = cpu_to_be32(0); |
| 4071 | *p++ = cpu_to_be32(0); |
J. Bruce Fields | 4aea24b | 2014-01-15 15:17:58 -0500 | [diff] [blame] | 4072 | resp->xdr.buf->head[0].iov_len = ((char *)resp->xdr.p) |
| 4073 | - (char *)resp->xdr.buf->head[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | |
| 4075 | /* |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4076 | * Number of bytes left for directory entries allowing for the |
| 4077 | * final 8 bytes of the readdir and a following failed op: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4078 | */ |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4079 | bytes_left = xdr->buf->buflen - xdr->buf->len |
| 4080 | - COMPOUND_ERR_SLACK_SPACE - 8; |
| 4081 | if (bytes_left < 0) { |
| 4082 | nfserr = nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4083 | goto err_no_verf; |
| 4084 | } |
Scott Mayhew | 9c2ece6 | 2018-05-07 09:01:08 -0400 | [diff] [blame] | 4085 | maxcount = svc_max_payload(resp->rqstp); |
| 4086 | maxcount = min_t(u32, readdir->rd_maxcount, maxcount); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4087 | /* |
| 4088 | * Note the rfc defines rd_maxcount as the size of the |
| 4089 | * READDIR4resok structure, which includes the verifier above |
| 4090 | * and the 8 bytes encoded at the end of this function: |
| 4091 | */ |
| 4092 | if (maxcount < 16) { |
| 4093 | nfserr = nfserr_toosmall; |
| 4094 | goto err_no_verf; |
| 4095 | } |
| 4096 | maxcount = min_t(int, maxcount-16, bytes_left); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4097 | |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 4098 | /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */ |
| 4099 | if (!readdir->rd_dircount) |
Scott Mayhew | 9c2ece6 | 2018-05-07 09:01:08 -0400 | [diff] [blame] | 4100 | readdir->rd_dircount = svc_max_payload(resp->rqstp); |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 4101 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4102 | readdir->xdr = xdr; |
| 4103 | readdir->rd_maxcount = maxcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4104 | readdir->common.err = 0; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4105 | readdir->cookie_offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | |
| 4107 | offset = readdir->rd_cookie; |
| 4108 | nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, |
| 4109 | &offset, |
| 4110 | &readdir->common, nfsd4_encode_dirent); |
| 4111 | if (nfserr == nfs_ok && |
| 4112 | readdir->common.err == nfserr_toosmall && |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4113 | xdr->buf->len == starting_len + 8) { |
| 4114 | /* nothing encoded; which limit did we hit?: */ |
| 4115 | if (maxcount - 16 < bytes_left) |
| 4116 | /* It was the fault of rd_maxcount: */ |
| 4117 | nfserr = nfserr_toosmall; |
| 4118 | else |
| 4119 | /* We ran out of buffer space: */ |
| 4120 | nfserr = nfserr_resource; |
| 4121 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | if (nfserr) |
| 4123 | goto err_no_verf; |
| 4124 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4125 | if (readdir->cookie_offset) { |
| 4126 | wire_offset = cpu_to_be64(offset); |
| 4127 | write_bytes_to_xdr_buf(xdr->buf, readdir->cookie_offset, |
| 4128 | &wire_offset, 8); |
| 4129 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4131 | p = xdr_reserve_space(xdr, 8); |
| 4132 | if (!p) { |
| 4133 | WARN_ON_ONCE(1); |
| 4134 | goto err_no_verf; |
| 4135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | *p++ = 0; /* no more entries */ |
| 4137 | *p++ = htonl(readdir->common.err == nfserr_eof); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | |
| 4139 | return 0; |
| 4140 | err_no_verf: |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 4141 | xdr_truncate_encode(xdr, starting_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | return nfserr; |
| 4143 | } |
| 4144 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4145 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4146 | nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_remove *remove) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4147 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4148 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4149 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4151 | p = xdr_reserve_space(xdr, 20); |
| 4152 | if (!p) |
| 4153 | return nfserr_resource; |
| 4154 | p = encode_cinfo(p, &remove->rm_cinfo); |
| 4155 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | } |
| 4157 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4158 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4159 | nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_rename *rename) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4161 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4162 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4164 | p = xdr_reserve_space(xdr, 40); |
| 4165 | if (!p) |
| 4166 | return nfserr_resource; |
| 4167 | p = encode_cinfo(p, &rename->rn_sinfo); |
| 4168 | p = encode_cinfo(p, &rename->rn_tinfo); |
| 4169 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4170 | } |
| 4171 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4172 | static __be32 |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4173 | nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp) |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4174 | { |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4175 | u32 i, nflavs, supported; |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4176 | struct exp_flavor_info *flavs; |
| 4177 | struct exp_flavor_info def_flavs[2]; |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4178 | __be32 *p, *flavorsp; |
| 4179 | static bool report = true; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4180 | |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4181 | if (exp->ex_nflavors) { |
| 4182 | flavs = exp->ex_flavors; |
| 4183 | nflavs = exp->ex_nflavors; |
| 4184 | } else { /* Handling of some defaults in absence of real secinfo: */ |
| 4185 | flavs = def_flavs; |
| 4186 | if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) { |
| 4187 | nflavs = 2; |
| 4188 | flavs[0].pseudoflavor = RPC_AUTH_UNIX; |
| 4189 | flavs[1].pseudoflavor = RPC_AUTH_NULL; |
| 4190 | } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) { |
| 4191 | nflavs = 1; |
| 4192 | flavs[0].pseudoflavor |
| 4193 | = svcauth_gss_flavor(exp->ex_client); |
| 4194 | } else { |
| 4195 | nflavs = 1; |
| 4196 | flavs[0].pseudoflavor |
| 4197 | = exp->ex_client->flavour->flavour; |
| 4198 | } |
| 4199 | } |
| 4200 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4201 | supported = 0; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4202 | p = xdr_reserve_space(xdr, 4); |
| 4203 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4204 | return nfserr_resource; |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4205 | flavorsp = p++; /* to be backfilled later */ |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4206 | |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4207 | for (i = 0; i < nflavs; i++) { |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4208 | rpc_authflavor_t pf = flavs[i].pseudoflavor; |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 4209 | struct rpcsec_gss_info info; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4210 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4211 | if (rpcauth_get_gssinfo(pf, &info) == 0) { |
| 4212 | supported++; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4213 | p = xdr_reserve_space(xdr, 4 + 4 + |
| 4214 | XDR_LEN(info.oid.len) + 4 + 4); |
| 4215 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4216 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4217 | *p++ = cpu_to_be32(RPC_AUTH_GSS); |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4218 | p = xdr_encode_opaque(p, info.oid.data, info.oid.len); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4219 | *p++ = cpu_to_be32(info.qop); |
| 4220 | *p++ = cpu_to_be32(info.service); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4221 | } else if (pf < RPC_AUTH_MAXFLAVOR) { |
| 4222 | supported++; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4223 | p = xdr_reserve_space(xdr, 4); |
| 4224 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4225 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4226 | *p++ = cpu_to_be32(pf); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4227 | } else { |
| 4228 | if (report) |
| 4229 | pr_warn("NFS: SECINFO: security flavor %u " |
| 4230 | "is not supported\n", pf); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4231 | } |
| 4232 | } |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 4233 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4234 | if (nflavs != supported) |
| 4235 | report = false; |
| 4236 | *flavorsp = htonl(supported); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4237 | return 0; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4238 | } |
| 4239 | |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4240 | static __be32 |
| 4241 | nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4242 | struct nfsd4_secinfo *secinfo) |
| 4243 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4244 | struct xdr_stream *xdr = &resp->xdr; |
| 4245 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4246 | return nfsd4_do_encode_secinfo(xdr, secinfo->si_exp); |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4247 | } |
| 4248 | |
| 4249 | static __be32 |
| 4250 | nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4251 | struct nfsd4_secinfo_no_name *secinfo) |
| 4252 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4253 | struct xdr_stream *xdr = &resp->xdr; |
| 4254 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4255 | return nfsd4_do_encode_secinfo(xdr, secinfo->sin_exp); |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4256 | } |
| 4257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4258 | /* |
| 4259 | * The SETATTR encode routine is special -- it always encodes a bitmap, |
| 4260 | * regardless of the error status. |
| 4261 | */ |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4262 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4263 | nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setattr *setattr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4265 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4266 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4268 | p = xdr_reserve_space(xdr, 16); |
| 4269 | if (!p) |
| 4270 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4271 | if (nfserr) { |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4272 | *p++ = cpu_to_be32(3); |
| 4273 | *p++ = cpu_to_be32(0); |
| 4274 | *p++ = cpu_to_be32(0); |
| 4275 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4276 | } |
| 4277 | else { |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4278 | *p++ = cpu_to_be32(3); |
| 4279 | *p++ = cpu_to_be32(setattr->sa_bmval[0]); |
| 4280 | *p++ = cpu_to_be32(setattr->sa_bmval[1]); |
| 4281 | *p++ = cpu_to_be32(setattr->sa_bmval[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4283 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | } |
| 4285 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4286 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4287 | nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setclientid *scd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4288 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4289 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4290 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4291 | |
| 4292 | if (!nfserr) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4293 | p = xdr_reserve_space(xdr, 8 + NFS4_VERIFIER_SIZE); |
| 4294 | if (!p) |
| 4295 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4296 | p = xdr_encode_opaque_fixed(p, &scd->se_clientid, 8); |
| 4297 | p = xdr_encode_opaque_fixed(p, &scd->se_confirm, |
| 4298 | NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4299 | } |
| 4300 | else if (nfserr == nfserr_clid_inuse) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4301 | p = xdr_reserve_space(xdr, 8); |
| 4302 | if (!p) |
| 4303 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4304 | *p++ = cpu_to_be32(0); |
| 4305 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4306 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4307 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4308 | } |
| 4309 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4310 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4311 | nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_write *write) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4313 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4314 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4315 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4316 | p = xdr_reserve_space(xdr, 16); |
| 4317 | if (!p) |
| 4318 | return nfserr_resource; |
| 4319 | *p++ = cpu_to_be32(write->wr_bytes_written); |
| 4320 | *p++ = cpu_to_be32(write->wr_how_written); |
| 4321 | p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, |
| 4322 | NFS4_VERIFIER_SIZE); |
| 4323 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | } |
| 4325 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4326 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4327 | nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4328 | struct nfsd4_exchange_id *exid) |
| 4329 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4330 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4331 | __be32 *p; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4332 | char *major_id; |
| 4333 | char *server_scope; |
| 4334 | int major_id_sz; |
| 4335 | int server_scope_sz; |
| 4336 | uint64_t minor_id = 0; |
Scott Mayhew | 7627d7d | 2020-02-19 15:52:15 -0500 | [diff] [blame] | 4337 | struct nfsd_net *nn = net_generic(SVC_NET(resp->rqstp), nfsd_net_id); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4338 | |
Scott Mayhew | 7627d7d | 2020-02-19 15:52:15 -0500 | [diff] [blame] | 4339 | major_id = nn->nfsd_name; |
| 4340 | major_id_sz = strlen(nn->nfsd_name); |
| 4341 | server_scope = nn->nfsd_name; |
| 4342 | server_scope_sz = strlen(nn->nfsd_name); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4343 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4344 | p = xdr_reserve_space(xdr, |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4345 | 8 /* eir_clientid */ + |
| 4346 | 4 /* eir_sequenceid */ + |
| 4347 | 4 /* eir_flags */ + |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4348 | 4 /* spr_how */); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4349 | if (!p) |
| 4350 | return nfserr_resource; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4351 | |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4352 | p = xdr_encode_opaque_fixed(p, &exid->clientid, 8); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4353 | *p++ = cpu_to_be32(exid->seqid); |
| 4354 | *p++ = cpu_to_be32(exid->flags); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4355 | |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4356 | *p++ = cpu_to_be32(exid->spa_how); |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4357 | |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 4358 | switch (exid->spa_how) { |
| 4359 | case SP4_NONE: |
| 4360 | break; |
| 4361 | case SP4_MACH_CRED: |
| 4362 | /* spo_must_enforce bitmap: */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4363 | nfserr = nfsd4_encode_bitmap(xdr, |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4364 | exid->spo_must_enforce[0], |
| 4365 | exid->spo_must_enforce[1], |
| 4366 | exid->spo_must_enforce[2]); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4367 | if (nfserr) |
| 4368 | return nfserr; |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4369 | /* spo_must_allow bitmap: */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4370 | nfserr = nfsd4_encode_bitmap(xdr, |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4371 | exid->spo_must_allow[0], |
| 4372 | exid->spo_must_allow[1], |
| 4373 | exid->spo_must_allow[2]); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4374 | if (nfserr) |
| 4375 | return nfserr; |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 4376 | break; |
| 4377 | default: |
| 4378 | WARN_ON_ONCE(1); |
| 4379 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4380 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4381 | p = xdr_reserve_space(xdr, |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4382 | 8 /* so_minor_id */ + |
| 4383 | 4 /* so_major_id.len */ + |
| 4384 | (XDR_QUADLEN(major_id_sz) * 4) + |
| 4385 | 4 /* eir_server_scope.len */ + |
| 4386 | (XDR_QUADLEN(server_scope_sz) * 4) + |
| 4387 | 4 /* eir_server_impl_id.count (0) */); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4388 | if (!p) |
| 4389 | return nfserr_resource; |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4390 | |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4391 | /* The server_owner struct */ |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 4392 | p = xdr_encode_hyper(p, minor_id); /* Minor id */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4393 | /* major id */ |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4394 | p = xdr_encode_opaque(p, major_id, major_id_sz); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4395 | |
| 4396 | /* Server scope */ |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4397 | p = xdr_encode_opaque(p, server_scope, server_scope_sz); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4398 | |
| 4399 | /* Implementation id */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4400 | *p++ = cpu_to_be32(0); /* zero length nfs_impl_id4 array */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4401 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4402 | } |
| 4403 | |
| 4404 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4405 | nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4406 | struct nfsd4_create_session *sess) |
| 4407 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4408 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4409 | __be32 *p; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4410 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4411 | p = xdr_reserve_space(xdr, 24); |
| 4412 | if (!p) |
| 4413 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4414 | p = xdr_encode_opaque_fixed(p, sess->sessionid.data, |
| 4415 | NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4416 | *p++ = cpu_to_be32(sess->seqid); |
| 4417 | *p++ = cpu_to_be32(sess->flags); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4418 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4419 | p = xdr_reserve_space(xdr, 28); |
| 4420 | if (!p) |
| 4421 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4422 | *p++ = cpu_to_be32(0); /* headerpadsz */ |
| 4423 | *p++ = cpu_to_be32(sess->fore_channel.maxreq_sz); |
| 4424 | *p++ = cpu_to_be32(sess->fore_channel.maxresp_sz); |
| 4425 | *p++ = cpu_to_be32(sess->fore_channel.maxresp_cached); |
| 4426 | *p++ = cpu_to_be32(sess->fore_channel.maxops); |
| 4427 | *p++ = cpu_to_be32(sess->fore_channel.maxreqs); |
| 4428 | *p++ = cpu_to_be32(sess->fore_channel.nr_rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4429 | |
| 4430 | if (sess->fore_channel.nr_rdma_attrs) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4431 | p = xdr_reserve_space(xdr, 4); |
| 4432 | if (!p) |
| 4433 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4434 | *p++ = cpu_to_be32(sess->fore_channel.rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4435 | } |
| 4436 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4437 | p = xdr_reserve_space(xdr, 28); |
| 4438 | if (!p) |
| 4439 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4440 | *p++ = cpu_to_be32(0); /* headerpadsz */ |
| 4441 | *p++ = cpu_to_be32(sess->back_channel.maxreq_sz); |
| 4442 | *p++ = cpu_to_be32(sess->back_channel.maxresp_sz); |
| 4443 | *p++ = cpu_to_be32(sess->back_channel.maxresp_cached); |
| 4444 | *p++ = cpu_to_be32(sess->back_channel.maxops); |
| 4445 | *p++ = cpu_to_be32(sess->back_channel.maxreqs); |
| 4446 | *p++ = cpu_to_be32(sess->back_channel.nr_rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4447 | |
| 4448 | if (sess->back_channel.nr_rdma_attrs) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4449 | p = xdr_reserve_space(xdr, 4); |
| 4450 | if (!p) |
| 4451 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4452 | *p++ = cpu_to_be32(sess->back_channel.rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4453 | } |
| 4454 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4455 | } |
| 4456 | |
| 4457 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4458 | nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4459 | struct nfsd4_sequence *seq) |
| 4460 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4461 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4462 | __be32 *p; |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4463 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4464 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 20); |
| 4465 | if (!p) |
| 4466 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4467 | p = xdr_encode_opaque_fixed(p, seq->sessionid.data, |
| 4468 | NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4469 | *p++ = cpu_to_be32(seq->seqid); |
| 4470 | *p++ = cpu_to_be32(seq->slotid); |
J. Bruce Fields | b7d7ca3 | 2011-08-31 15:39:30 -0400 | [diff] [blame] | 4471 | /* Note slotid's are numbered from zero: */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4472 | *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_highest_slotid */ |
| 4473 | *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_target_highest_slotid */ |
| 4474 | *p++ = cpu_to_be32(seq->status_flags); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4475 | |
J. Bruce Fields | f523601 | 2014-03-21 17:57:57 -0400 | [diff] [blame] | 4476 | resp->cstate.data_offset = xdr->buf->len; /* DRC cache data pointer */ |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4477 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4478 | } |
| 4479 | |
J. Bruce Fields | 2355c59 | 2012-04-25 16:56:22 -0400 | [diff] [blame] | 4480 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4481 | nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4482 | struct nfsd4_test_stateid *test_stateid) |
| 4483 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4484 | struct xdr_stream *xdr = &resp->xdr; |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 4485 | struct nfsd4_test_stateid_id *stateid, *next; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4486 | __be32 *p; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4487 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4488 | p = xdr_reserve_space(xdr, 4 + (4 * test_stateid->ts_num_ids)); |
| 4489 | if (!p) |
| 4490 | return nfserr_resource; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4491 | *p++ = htonl(test_stateid->ts_num_ids); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4492 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 4493 | list_for_each_entry_safe(stateid, next, &test_stateid->ts_stateid_list, ts_id_list) { |
Al Viro | 02f5fde | 2012-04-13 00:10:34 -0400 | [diff] [blame] | 4494 | *p++ = stateid->ts_id_status; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4495 | } |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4496 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4497 | return 0; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4498 | } |
| 4499 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4500 | #ifdef CONFIG_NFSD_PNFS |
| 4501 | static __be32 |
| 4502 | nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4503 | struct nfsd4_getdeviceinfo *gdev) |
| 4504 | { |
| 4505 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4506 | const struct nfsd4_layout_ops *ops; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4507 | u32 starting_len = xdr->buf->len, needed_len; |
| 4508 | __be32 *p; |
| 4509 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4510 | p = xdr_reserve_space(xdr, 4); |
| 4511 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4512 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4513 | |
| 4514 | *p++ = cpu_to_be32(gdev->gd_layout_type); |
| 4515 | |
| 4516 | /* If maxcount is 0 then just update notifications */ |
| 4517 | if (gdev->gd_maxcount != 0) { |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4518 | ops = nfsd4_layout_ops[gdev->gd_layout_type]; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4519 | nfserr = ops->encode_getdeviceinfo(xdr, gdev); |
| 4520 | if (nfserr) { |
| 4521 | /* |
| 4522 | * We don't bother to burden the layout drivers with |
| 4523 | * enforcing gd_maxcount, just tell the client to |
| 4524 | * come back with a bigger buffer if it's not enough. |
| 4525 | */ |
| 4526 | if (xdr->buf->len + 4 > gdev->gd_maxcount) |
| 4527 | goto toosmall; |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4528 | return nfserr; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4529 | } |
| 4530 | } |
| 4531 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4532 | if (gdev->gd_notify_types) { |
| 4533 | p = xdr_reserve_space(xdr, 4 + 4); |
| 4534 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4535 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4536 | *p++ = cpu_to_be32(1); /* bitmap length */ |
| 4537 | *p++ = cpu_to_be32(gdev->gd_notify_types); |
| 4538 | } else { |
| 4539 | p = xdr_reserve_space(xdr, 4); |
| 4540 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4541 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4542 | *p++ = 0; |
| 4543 | } |
| 4544 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4545 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4546 | toosmall: |
| 4547 | dprintk("%s: maxcount too small\n", __func__); |
| 4548 | needed_len = xdr->buf->len + 4 /* notifications */; |
| 4549 | xdr_truncate_encode(xdr, starting_len); |
| 4550 | p = xdr_reserve_space(xdr, 4); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4551 | if (!p) |
| 4552 | return nfserr_resource; |
| 4553 | *p++ = cpu_to_be32(needed_len); |
| 4554 | return nfserr_toosmall; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4555 | } |
| 4556 | |
| 4557 | static __be32 |
| 4558 | nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4559 | struct nfsd4_layoutget *lgp) |
| 4560 | { |
| 4561 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4562 | const struct nfsd4_layout_ops *ops; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4563 | __be32 *p; |
| 4564 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4565 | p = xdr_reserve_space(xdr, 36 + sizeof(stateid_opaque_t)); |
| 4566 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4567 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4568 | |
| 4569 | *p++ = cpu_to_be32(1); /* we always set return-on-close */ |
| 4570 | *p++ = cpu_to_be32(lgp->lg_sid.si_generation); |
| 4571 | p = xdr_encode_opaque_fixed(p, &lgp->lg_sid.si_opaque, |
| 4572 | sizeof(stateid_opaque_t)); |
| 4573 | |
| 4574 | *p++ = cpu_to_be32(1); /* we always return a single layout */ |
| 4575 | p = xdr_encode_hyper(p, lgp->lg_seg.offset); |
| 4576 | p = xdr_encode_hyper(p, lgp->lg_seg.length); |
| 4577 | *p++ = cpu_to_be32(lgp->lg_seg.iomode); |
| 4578 | *p++ = cpu_to_be32(lgp->lg_layout_type); |
| 4579 | |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4580 | ops = nfsd4_layout_ops[lgp->lg_layout_type]; |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4581 | return ops->encode_layoutget(xdr, lgp); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4582 | } |
| 4583 | |
| 4584 | static __be32 |
| 4585 | nfsd4_encode_layoutcommit(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4586 | struct nfsd4_layoutcommit *lcp) |
| 4587 | { |
| 4588 | struct xdr_stream *xdr = &resp->xdr; |
| 4589 | __be32 *p; |
| 4590 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4591 | p = xdr_reserve_space(xdr, 4); |
| 4592 | if (!p) |
| 4593 | return nfserr_resource; |
| 4594 | *p++ = cpu_to_be32(lcp->lc_size_chg); |
| 4595 | if (lcp->lc_size_chg) { |
| 4596 | p = xdr_reserve_space(xdr, 8); |
| 4597 | if (!p) |
| 4598 | return nfserr_resource; |
| 4599 | p = xdr_encode_hyper(p, lcp->lc_newsize); |
| 4600 | } |
| 4601 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4602 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4603 | } |
| 4604 | |
| 4605 | static __be32 |
| 4606 | nfsd4_encode_layoutreturn(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4607 | struct nfsd4_layoutreturn *lrp) |
| 4608 | { |
| 4609 | struct xdr_stream *xdr = &resp->xdr; |
| 4610 | __be32 *p; |
| 4611 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4612 | p = xdr_reserve_space(xdr, 4); |
| 4613 | if (!p) |
| 4614 | return nfserr_resource; |
| 4615 | *p++ = cpu_to_be32(lrp->lrs_present); |
| 4616 | if (lrp->lrs_present) |
Kinglong Mee | 376675d | 2015-03-22 22:17:10 +0800 | [diff] [blame] | 4617 | return nfsd4_encode_stateid(xdr, &lrp->lr_sid); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4618 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4619 | } |
| 4620 | #endif /* CONFIG_NFSD_PNFS */ |
| 4621 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4622 | static __be32 |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4623 | nfsd42_encode_write_res(struct nfsd4_compoundres *resp, |
| 4624 | struct nfsd42_write_res *write, bool sync) |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4625 | { |
| 4626 | __be32 *p; |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4627 | p = xdr_reserve_space(&resp->xdr, 4); |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4628 | if (!p) |
| 4629 | return nfserr_resource; |
| 4630 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4631 | if (sync) |
| 4632 | *p++ = cpu_to_be32(0); |
| 4633 | else { |
| 4634 | __be32 nfserr; |
| 4635 | *p++ = cpu_to_be32(1); |
| 4636 | nfserr = nfsd4_encode_stateid(&resp->xdr, &write->cb_stateid); |
| 4637 | if (nfserr) |
| 4638 | return nfserr; |
| 4639 | } |
| 4640 | p = xdr_reserve_space(&resp->xdr, 8 + 4 + NFS4_VERIFIER_SIZE); |
| 4641 | if (!p) |
| 4642 | return nfserr_resource; |
| 4643 | |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4644 | p = xdr_encode_hyper(p, write->wr_bytes_written); |
| 4645 | *p++ = cpu_to_be32(write->wr_stable_how); |
| 4646 | p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, |
| 4647 | NFS4_VERIFIER_SIZE); |
| 4648 | return nfs_ok; |
| 4649 | } |
| 4650 | |
| 4651 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 4652 | nfsd42_encode_nl4_server(struct nfsd4_compoundres *resp, struct nl4_server *ns) |
| 4653 | { |
| 4654 | struct xdr_stream *xdr = &resp->xdr; |
| 4655 | struct nfs42_netaddr *addr; |
| 4656 | __be32 *p; |
| 4657 | |
| 4658 | p = xdr_reserve_space(xdr, 4); |
| 4659 | *p++ = cpu_to_be32(ns->nl4_type); |
| 4660 | |
| 4661 | switch (ns->nl4_type) { |
| 4662 | case NL4_NETADDR: |
| 4663 | addr = &ns->u.nl4_addr; |
| 4664 | |
| 4665 | /* netid_len, netid, uaddr_len, uaddr (port included |
| 4666 | * in RPCBIND_MAXUADDRLEN) |
| 4667 | */ |
| 4668 | p = xdr_reserve_space(xdr, |
| 4669 | 4 /* netid len */ + |
| 4670 | (XDR_QUADLEN(addr->netid_len) * 4) + |
| 4671 | 4 /* uaddr len */ + |
| 4672 | (XDR_QUADLEN(addr->addr_len) * 4)); |
| 4673 | if (!p) |
| 4674 | return nfserr_resource; |
| 4675 | |
| 4676 | *p++ = cpu_to_be32(addr->netid_len); |
| 4677 | p = xdr_encode_opaque_fixed(p, addr->netid, |
| 4678 | addr->netid_len); |
| 4679 | *p++ = cpu_to_be32(addr->addr_len); |
| 4680 | p = xdr_encode_opaque_fixed(p, addr->addr, |
| 4681 | addr->addr_len); |
| 4682 | break; |
| 4683 | default: |
| 4684 | WARN_ON_ONCE(ns->nl4_type != NL4_NETADDR); |
| 4685 | return nfserr_inval; |
| 4686 | } |
| 4687 | |
| 4688 | return 0; |
| 4689 | } |
| 4690 | |
| 4691 | static __be32 |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4692 | nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4693 | struct nfsd4_copy *copy) |
| 4694 | { |
| 4695 | __be32 *p; |
| 4696 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4697 | nfserr = nfsd42_encode_write_res(resp, ©->cp_res, |
| 4698 | copy->cp_synchronous); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4699 | if (nfserr) |
| 4700 | return nfserr; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4701 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4702 | p = xdr_reserve_space(&resp->xdr, 4 + 4); |
J. Bruce Fields | edcc845 | 2018-03-07 15:37:35 -0500 | [diff] [blame] | 4703 | *p++ = xdr_one; /* cr_consecutive */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4704 | *p++ = cpu_to_be32(copy->cp_synchronous); |
| 4705 | return 0; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4706 | } |
| 4707 | |
| 4708 | static __be32 |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 4709 | nfsd4_encode_offload_status(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4710 | struct nfsd4_offload_status *os) |
| 4711 | { |
| 4712 | struct xdr_stream *xdr = &resp->xdr; |
| 4713 | __be32 *p; |
| 4714 | |
| 4715 | p = xdr_reserve_space(xdr, 8 + 4); |
| 4716 | if (!p) |
| 4717 | return nfserr_resource; |
| 4718 | p = xdr_encode_hyper(p, os->count); |
| 4719 | *p++ = cpu_to_be32(0); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4720 | return nfserr; |
| 4721 | } |
| 4722 | |
| 4723 | static __be32 |
| 4724 | nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp, |
| 4725 | struct nfsd4_read *read, |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4726 | unsigned long *maxcount, u32 *eof, |
| 4727 | loff_t *pos) |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4728 | { |
| 4729 | struct xdr_stream *xdr = &resp->xdr; |
| 4730 | struct file *file = read->rd_nf->nf_file; |
| 4731 | int starting_len = xdr->buf->len; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4732 | loff_t hole_pos; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4733 | __be32 nfserr; |
| 4734 | __be32 *p, tmp; |
| 4735 | __be64 tmp64; |
| 4736 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4737 | hole_pos = pos ? *pos : vfs_llseek(file, read->rd_offset, SEEK_HOLE); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4738 | if (hole_pos > read->rd_offset) |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4739 | *maxcount = min_t(unsigned long, *maxcount, hole_pos - read->rd_offset); |
| 4740 | *maxcount = min_t(unsigned long, *maxcount, (xdr->buf->buflen - xdr->buf->len)); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4741 | |
| 4742 | /* Content type, offset, byte count */ |
| 4743 | p = xdr_reserve_space(xdr, 4 + 8 + 4); |
| 4744 | if (!p) |
| 4745 | return nfserr_resource; |
| 4746 | |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4747 | read->rd_vlen = xdr_reserve_space_vec(xdr, resp->rqstp->rq_vec, *maxcount); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4748 | if (read->rd_vlen < 0) |
| 4749 | return nfserr_resource; |
| 4750 | |
| 4751 | nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset, |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4752 | resp->rqstp->rq_vec, read->rd_vlen, maxcount, eof); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4753 | if (nfserr) |
| 4754 | return nfserr; |
| 4755 | |
| 4756 | tmp = htonl(NFS4_CONTENT_DATA); |
| 4757 | write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4); |
| 4758 | tmp64 = cpu_to_be64(read->rd_offset); |
| 4759 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp64, 8); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4760 | tmp = htonl(*maxcount); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4761 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 12, &tmp, 4); |
| 4762 | return nfs_ok; |
| 4763 | } |
| 4764 | |
| 4765 | static __be32 |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4766 | nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp, |
| 4767 | struct nfsd4_read *read, |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4768 | unsigned long *maxcount, u32 *eof) |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4769 | { |
| 4770 | struct file *file = read->rd_nf->nf_file; |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4771 | loff_t data_pos = vfs_llseek(file, read->rd_offset, SEEK_DATA); |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4772 | loff_t f_size = i_size_read(file_inode(file)); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4773 | unsigned long count; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4774 | __be32 *p; |
| 4775 | |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4776 | if (data_pos == -ENXIO) |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4777 | data_pos = f_size; |
| 4778 | else if (data_pos <= read->rd_offset || (data_pos < f_size && data_pos % PAGE_SIZE)) |
| 4779 | return nfsd4_encode_read_plus_data(resp, read, maxcount, eof, &f_size); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4780 | count = data_pos - read->rd_offset; |
| 4781 | |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4782 | /* Content type, offset, byte count */ |
| 4783 | p = xdr_reserve_space(&resp->xdr, 4 + 8 + 8); |
| 4784 | if (!p) |
| 4785 | return nfserr_resource; |
| 4786 | |
| 4787 | *p++ = htonl(NFS4_CONTENT_HOLE); |
| 4788 | p = xdr_encode_hyper(p, read->rd_offset); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4789 | p = xdr_encode_hyper(p, count); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4790 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4791 | *eof = (read->rd_offset + count) >= f_size; |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4792 | *maxcount = min_t(unsigned long, count, *maxcount); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4793 | return nfs_ok; |
| 4794 | } |
| 4795 | |
| 4796 | static __be32 |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4797 | nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4798 | struct nfsd4_read *read) |
| 4799 | { |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4800 | unsigned long maxcount, count; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4801 | struct xdr_stream *xdr = &resp->xdr; |
| 4802 | struct file *file; |
| 4803 | int starting_len = xdr->buf->len; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4804 | int last_segment = xdr->buf->len; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4805 | int segments = 0; |
| 4806 | __be32 *p, tmp; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4807 | bool is_data; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4808 | loff_t pos; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4809 | u32 eof; |
| 4810 | |
| 4811 | if (nfserr) |
| 4812 | return nfserr; |
| 4813 | file = read->rd_nf->nf_file; |
| 4814 | |
| 4815 | /* eof flag, segment count */ |
| 4816 | p = xdr_reserve_space(xdr, 4 + 4); |
| 4817 | if (!p) |
| 4818 | return nfserr_resource; |
| 4819 | xdr_commit_encode(xdr); |
| 4820 | |
| 4821 | maxcount = svc_max_payload(resp->rqstp); |
| 4822 | maxcount = min_t(unsigned long, maxcount, |
| 4823 | (xdr->buf->buflen - xdr->buf->len)); |
| 4824 | maxcount = min_t(unsigned long, maxcount, read->rd_length); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4825 | count = maxcount; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4826 | |
| 4827 | eof = read->rd_offset >= i_size_read(file_inode(file)); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4828 | if (eof) |
| 4829 | goto out; |
| 4830 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4831 | pos = vfs_llseek(file, read->rd_offset, SEEK_HOLE); |
| 4832 | is_data = pos > read->rd_offset; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4833 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4834 | while (count > 0 && !eof) { |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4835 | maxcount = count; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4836 | if (is_data) |
| 4837 | nfserr = nfsd4_encode_read_plus_data(resp, read, &maxcount, &eof, |
| 4838 | segments == 0 ? &pos : NULL); |
| 4839 | else |
| 4840 | nfserr = nfsd4_encode_read_plus_hole(resp, read, &maxcount, &eof); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4841 | if (nfserr) |
| 4842 | goto out; |
| 4843 | count -= maxcount; |
| 4844 | read->rd_offset += maxcount; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4845 | is_data = !is_data; |
| 4846 | last_segment = xdr->buf->len; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4847 | segments++; |
| 4848 | } |
| 4849 | |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4850 | out: |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4851 | if (nfserr && segments == 0) |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4852 | xdr_truncate_encode(xdr, starting_len); |
| 4853 | else { |
| 4854 | tmp = htonl(eof); |
| 4855 | write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4); |
| 4856 | tmp = htonl(segments); |
| 4857 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4858 | if (nfserr) { |
| 4859 | xdr_truncate_encode(xdr, last_segment); |
| 4860 | nfserr = nfs_ok; |
| 4861 | } |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4862 | } |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 4863 | |
| 4864 | return nfserr; |
| 4865 | } |
| 4866 | |
| 4867 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 4868 | nfsd4_encode_copy_notify(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4869 | struct nfsd4_copy_notify *cn) |
| 4870 | { |
| 4871 | struct xdr_stream *xdr = &resp->xdr; |
| 4872 | __be32 *p; |
| 4873 | |
| 4874 | if (nfserr) |
| 4875 | return nfserr; |
| 4876 | |
| 4877 | /* 8 sec, 4 nsec */ |
| 4878 | p = xdr_reserve_space(xdr, 12); |
| 4879 | if (!p) |
| 4880 | return nfserr_resource; |
| 4881 | |
| 4882 | /* cnr_lease_time */ |
| 4883 | p = xdr_encode_hyper(p, cn->cpn_sec); |
| 4884 | *p++ = cpu_to_be32(cn->cpn_nsec); |
| 4885 | |
| 4886 | /* cnr_stateid */ |
| 4887 | nfserr = nfsd4_encode_stateid(xdr, &cn->cpn_cnr_stateid); |
| 4888 | if (nfserr) |
| 4889 | return nfserr; |
| 4890 | |
| 4891 | /* cnr_src.nl_nsvr */ |
| 4892 | p = xdr_reserve_space(xdr, 4); |
| 4893 | if (!p) |
| 4894 | return nfserr_resource; |
| 4895 | |
| 4896 | *p++ = cpu_to_be32(1); |
| 4897 | |
| 4898 | return nfsd42_encode_nl4_server(resp, &cn->cpn_src); |
| 4899 | } |
| 4900 | |
| 4901 | static __be32 |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4902 | nfsd4_encode_seek(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4903 | struct nfsd4_seek *seek) |
| 4904 | { |
| 4905 | __be32 *p; |
| 4906 | |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4907 | p = xdr_reserve_space(&resp->xdr, 4 + 8); |
| 4908 | *p++ = cpu_to_be32(seek->seek_eof); |
| 4909 | p = xdr_encode_hyper(p, seek->seek_pos); |
| 4910 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4911 | return 0; |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4912 | } |
| 4913 | |
| 4914 | static __be32 |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4915 | nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p) |
| 4916 | { |
| 4917 | return nfserr; |
| 4918 | } |
| 4919 | |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 4920 | /* |
| 4921 | * Encode kmalloc-ed buffer in to XDR stream. |
| 4922 | */ |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 4923 | static __be32 |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 4924 | nfsd4_vbuf_to_stream(struct xdr_stream *xdr, char *buf, u32 buflen) |
| 4925 | { |
| 4926 | u32 cplen; |
| 4927 | __be32 *p; |
| 4928 | |
| 4929 | cplen = min_t(unsigned long, buflen, |
| 4930 | ((void *)xdr->end - (void *)xdr->p)); |
| 4931 | p = xdr_reserve_space(xdr, cplen); |
| 4932 | if (!p) |
| 4933 | return nfserr_resource; |
| 4934 | |
| 4935 | memcpy(p, buf, cplen); |
| 4936 | buf += cplen; |
| 4937 | buflen -= cplen; |
| 4938 | |
| 4939 | while (buflen) { |
| 4940 | cplen = min_t(u32, buflen, PAGE_SIZE); |
| 4941 | p = xdr_reserve_space(xdr, cplen); |
| 4942 | if (!p) |
| 4943 | return nfserr_resource; |
| 4944 | |
| 4945 | memcpy(p, buf, cplen); |
| 4946 | |
| 4947 | if (cplen < PAGE_SIZE) { |
| 4948 | /* |
| 4949 | * We're done, with a length that wasn't page |
| 4950 | * aligned, so possibly not word aligned. Pad |
| 4951 | * any trailing bytes with 0. |
| 4952 | */ |
| 4953 | xdr_encode_opaque_fixed(p, NULL, cplen); |
| 4954 | break; |
| 4955 | } |
| 4956 | |
| 4957 | buflen -= PAGE_SIZE; |
| 4958 | buf += PAGE_SIZE; |
| 4959 | } |
| 4960 | |
| 4961 | return 0; |
| 4962 | } |
| 4963 | |
| 4964 | static __be32 |
| 4965 | nfsd4_encode_getxattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4966 | struct nfsd4_getxattr *getxattr) |
| 4967 | { |
| 4968 | struct xdr_stream *xdr = &resp->xdr; |
| 4969 | __be32 *p, err; |
| 4970 | |
| 4971 | p = xdr_reserve_space(xdr, 4); |
| 4972 | if (!p) |
| 4973 | return nfserr_resource; |
| 4974 | |
| 4975 | *p = cpu_to_be32(getxattr->getxa_len); |
| 4976 | |
| 4977 | if (getxattr->getxa_len == 0) |
| 4978 | return 0; |
| 4979 | |
| 4980 | err = nfsd4_vbuf_to_stream(xdr, getxattr->getxa_buf, |
| 4981 | getxattr->getxa_len); |
| 4982 | |
| 4983 | kvfree(getxattr->getxa_buf); |
| 4984 | |
| 4985 | return err; |
| 4986 | } |
| 4987 | |
| 4988 | static __be32 |
| 4989 | nfsd4_encode_setxattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4990 | struct nfsd4_setxattr *setxattr) |
| 4991 | { |
| 4992 | struct xdr_stream *xdr = &resp->xdr; |
| 4993 | __be32 *p; |
| 4994 | |
| 4995 | p = xdr_reserve_space(xdr, 20); |
| 4996 | if (!p) |
| 4997 | return nfserr_resource; |
| 4998 | |
| 4999 | encode_cinfo(p, &setxattr->setxa_cinfo); |
| 5000 | |
| 5001 | return 0; |
| 5002 | } |
| 5003 | |
| 5004 | /* |
| 5005 | * See if there are cookie values that can be rejected outright. |
| 5006 | */ |
| 5007 | static __be32 |
| 5008 | nfsd4_listxattr_validate_cookie(struct nfsd4_listxattrs *listxattrs, |
| 5009 | u32 *offsetp) |
| 5010 | { |
| 5011 | u64 cookie = listxattrs->lsxa_cookie; |
| 5012 | |
| 5013 | /* |
| 5014 | * If the cookie is larger than the maximum number we can fit |
| 5015 | * in either the buffer we just got back from vfs_listxattr, or, |
| 5016 | * XDR-encoded, in the return buffer, it's invalid. |
| 5017 | */ |
| 5018 | if (cookie > (listxattrs->lsxa_len) / (XATTR_USER_PREFIX_LEN + 2)) |
| 5019 | return nfserr_badcookie; |
| 5020 | |
| 5021 | if (cookie > (listxattrs->lsxa_maxcount / |
| 5022 | (XDR_QUADLEN(XATTR_USER_PREFIX_LEN + 2) + 4))) |
| 5023 | return nfserr_badcookie; |
| 5024 | |
| 5025 | *offsetp = (u32)cookie; |
| 5026 | return 0; |
| 5027 | } |
| 5028 | |
| 5029 | static __be32 |
| 5030 | nfsd4_encode_listxattrs(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5031 | struct nfsd4_listxattrs *listxattrs) |
| 5032 | { |
| 5033 | struct xdr_stream *xdr = &resp->xdr; |
| 5034 | u32 cookie_offset, count_offset, eof; |
| 5035 | u32 left, xdrleft, slen, count; |
| 5036 | u32 xdrlen, offset; |
| 5037 | u64 cookie; |
| 5038 | char *sp; |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 5039 | __be32 status, tmp; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5040 | __be32 *p; |
| 5041 | u32 nuser; |
| 5042 | |
| 5043 | eof = 1; |
| 5044 | |
| 5045 | status = nfsd4_listxattr_validate_cookie(listxattrs, &offset); |
| 5046 | if (status) |
| 5047 | goto out; |
| 5048 | |
| 5049 | /* |
| 5050 | * Reserve space for the cookie and the name array count. Record |
| 5051 | * the offsets to save them later. |
| 5052 | */ |
| 5053 | cookie_offset = xdr->buf->len; |
| 5054 | count_offset = cookie_offset + 8; |
| 5055 | p = xdr_reserve_space(xdr, 12); |
| 5056 | if (!p) { |
| 5057 | status = nfserr_resource; |
| 5058 | goto out; |
| 5059 | } |
| 5060 | |
| 5061 | count = 0; |
| 5062 | left = listxattrs->lsxa_len; |
| 5063 | sp = listxattrs->lsxa_buf; |
| 5064 | nuser = 0; |
| 5065 | |
| 5066 | xdrleft = listxattrs->lsxa_maxcount; |
| 5067 | |
| 5068 | while (left > 0 && xdrleft > 0) { |
| 5069 | slen = strlen(sp); |
| 5070 | |
| 5071 | /* |
Alex Dewar | 4cce11fa | 2020-08-17 18:51:26 +0100 | [diff] [blame] | 5072 | * Check if this is a "user." attribute, skip it if not. |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5073 | */ |
| 5074 | if (strncmp(sp, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) |
| 5075 | goto contloop; |
| 5076 | |
| 5077 | slen -= XATTR_USER_PREFIX_LEN; |
| 5078 | xdrlen = 4 + ((slen + 3) & ~3); |
| 5079 | if (xdrlen > xdrleft) { |
| 5080 | if (count == 0) { |
| 5081 | /* |
| 5082 | * Can't even fit the first attribute name. |
| 5083 | */ |
| 5084 | status = nfserr_toosmall; |
| 5085 | goto out; |
| 5086 | } |
| 5087 | eof = 0; |
| 5088 | goto wreof; |
| 5089 | } |
| 5090 | |
| 5091 | left -= XATTR_USER_PREFIX_LEN; |
| 5092 | sp += XATTR_USER_PREFIX_LEN; |
| 5093 | if (nuser++ < offset) |
| 5094 | goto contloop; |
| 5095 | |
| 5096 | |
| 5097 | p = xdr_reserve_space(xdr, xdrlen); |
| 5098 | if (!p) { |
| 5099 | status = nfserr_resource; |
| 5100 | goto out; |
| 5101 | } |
| 5102 | |
Alex Dewar | e2a1840 | 2020-08-12 15:12:51 +0100 | [diff] [blame] | 5103 | xdr_encode_opaque(p, sp, slen); |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5104 | |
| 5105 | xdrleft -= xdrlen; |
| 5106 | count++; |
| 5107 | contloop: |
| 5108 | sp += slen + 1; |
| 5109 | left -= slen + 1; |
| 5110 | } |
| 5111 | |
| 5112 | /* |
| 5113 | * If there were user attributes to copy, but we didn't copy |
| 5114 | * any, the offset was too large (e.g. the cookie was invalid). |
| 5115 | */ |
| 5116 | if (nuser > 0 && count == 0) { |
| 5117 | status = nfserr_badcookie; |
| 5118 | goto out; |
| 5119 | } |
| 5120 | |
| 5121 | wreof: |
| 5122 | p = xdr_reserve_space(xdr, 4); |
| 5123 | if (!p) { |
| 5124 | status = nfserr_resource; |
| 5125 | goto out; |
| 5126 | } |
| 5127 | *p = cpu_to_be32(eof); |
| 5128 | |
| 5129 | cookie = offset + count; |
| 5130 | |
| 5131 | write_bytes_to_xdr_buf(xdr->buf, cookie_offset, &cookie, 8); |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 5132 | tmp = cpu_to_be32(count); |
| 5133 | write_bytes_to_xdr_buf(xdr->buf, count_offset, &tmp, 4); |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5134 | out: |
| 5135 | if (listxattrs->lsxa_len) |
| 5136 | kvfree(listxattrs->lsxa_buf); |
| 5137 | return status; |
| 5138 | } |
| 5139 | |
| 5140 | static __be32 |
| 5141 | nfsd4_encode_removexattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5142 | struct nfsd4_removexattr *removexattr) |
| 5143 | { |
| 5144 | struct xdr_stream *xdr = &resp->xdr; |
| 5145 | __be32 *p; |
| 5146 | |
| 5147 | p = xdr_reserve_space(xdr, 20); |
| 5148 | if (!p) |
| 5149 | return nfserr_resource; |
| 5150 | |
| 5151 | p = encode_cinfo(p, &removexattr->rmxa_cinfo); |
| 5152 | return 0; |
| 5153 | } |
| 5154 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5155 | typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *); |
| 5156 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5157 | /* |
| 5158 | * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1 |
| 5159 | * since we don't need to filter out obsolete ops as this is |
| 5160 | * done in the decoding phase. |
| 5161 | */ |
Chuck Lever | c1df609 | 2017-08-01 11:59:58 -0400 | [diff] [blame] | 5162 | static const nfsd4_enc nfsd4_enc_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 5163 | [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access, |
| 5164 | [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close, |
| 5165 | [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit, |
| 5166 | [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create, |
| 5167 | [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5168 | [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
| 5169 | [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr, |
| 5170 | [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh, |
| 5171 | [OP_LINK] = (nfsd4_enc)nfsd4_encode_link, |
| 5172 | [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock, |
| 5173 | [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt, |
| 5174 | [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku, |
| 5175 | [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop, |
| 5176 | [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop, |
| 5177 | [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 5178 | [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open, |
Benny Halevy | 84f09f4 | 2009-03-04 23:05:35 +0200 | [diff] [blame] | 5179 | [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop, |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 5180 | [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm, |
| 5181 | [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade, |
| 5182 | [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5183 | [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5184 | [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5185 | [OP_READ] = (nfsd4_enc)nfsd4_encode_read, |
| 5186 | [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir, |
| 5187 | [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink, |
| 5188 | [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove, |
| 5189 | [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename, |
| 5190 | [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop, |
| 5191 | [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5192 | [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5193 | [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo, |
| 5194 | [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr, |
| 5195 | [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid, |
| 5196 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop, |
| 5197 | [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 5198 | [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write, |
| 5199 | [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5200 | |
| 5201 | /* NFSv4.1 operations */ |
| 5202 | [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 5203 | [OP_BIND_CONN_TO_SESSION] = (nfsd4_enc)nfsd4_encode_bind_conn_to_session, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5204 | [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id, |
| 5205 | [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session, |
Kinglong Mee | 43212cc | 2013-12-09 19:04:23 +0800 | [diff] [blame] | 5206 | [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_noop, |
| 5207 | [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5208 | [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 5209 | #ifdef CONFIG_NFSD_PNFS |
| 5210 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_getdeviceinfo, |
| 5211 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, |
| 5212 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_layoutcommit, |
| 5213 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_layoutget, |
| 5214 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_layoutreturn, |
| 5215 | #else |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5216 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop, |
| 5217 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, |
| 5218 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop, |
| 5219 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop, |
| 5220 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 5221 | #endif |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 5222 | [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_secinfo_no_name, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5223 | [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence, |
| 5224 | [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 5225 | [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_test_stateid, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5226 | [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
| 5227 | [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop, |
| 5228 | [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5229 | |
| 5230 | /* NFSv4.2 operations */ |
| 5231 | [OP_ALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 5232 | [OP_COPY] = (nfsd4_enc)nfsd4_encode_copy, |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 5233 | [OP_COPY_NOTIFY] = (nfsd4_enc)nfsd4_encode_copy_notify, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5234 | [OP_DEALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5235 | [OP_IO_ADVISE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5236 | [OP_LAYOUTERROR] = (nfsd4_enc)nfsd4_encode_noop, |
| 5237 | [OP_LAYOUTSTATS] = (nfsd4_enc)nfsd4_encode_noop, |
| 5238 | [OP_OFFLOAD_CANCEL] = (nfsd4_enc)nfsd4_encode_noop, |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 5239 | [OP_OFFLOAD_STATUS] = (nfsd4_enc)nfsd4_encode_offload_status, |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 5240 | [OP_READ_PLUS] = (nfsd4_enc)nfsd4_encode_read_plus, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 5241 | [OP_SEEK] = (nfsd4_enc)nfsd4_encode_seek, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5242 | [OP_WRITE_SAME] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 5243 | [OP_CLONE] = (nfsd4_enc)nfsd4_encode_noop, |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5244 | |
| 5245 | /* RFC 8276 extended atributes operations */ |
| 5246 | [OP_GETXATTR] = (nfsd4_enc)nfsd4_encode_getxattr, |
| 5247 | [OP_SETXATTR] = (nfsd4_enc)nfsd4_encode_setxattr, |
| 5248 | [OP_LISTXATTRS] = (nfsd4_enc)nfsd4_encode_listxattrs, |
| 5249 | [OP_REMOVEXATTR] = (nfsd4_enc)nfsd4_encode_removexattr, |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5250 | }; |
| 5251 | |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5252 | /* |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5253 | * Calculate whether we still have space to encode repsize bytes. |
| 5254 | * There are two considerations: |
| 5255 | * - For NFS versions >=4.1, the size of the reply must stay within |
| 5256 | * session limits |
| 5257 | * - For all NFS versions, we must stay within limited preallocated |
| 5258 | * buffer space. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5259 | * |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5260 | * This is called before the operation is processed, so can only provide |
| 5261 | * an upper estimate. For some nonidempotent operations (such as |
| 5262 | * getattr), it's not necessarily a problem if that estimate is wrong, |
| 5263 | * as we can fail it after processing without significant side effects. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5264 | */ |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5265 | __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 respsize) |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5266 | { |
J. Bruce Fields | 67492c9 | 2014-03-08 16:42:05 -0500 | [diff] [blame] | 5267 | struct xdr_buf *buf = &resp->rqstp->rq_res; |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5268 | struct nfsd4_slot *slot = resp->cstate.slot; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5269 | |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5270 | if (buf->len + respsize <= buf->buflen) |
| 5271 | return nfs_ok; |
| 5272 | if (!nfsd4_has_session(&resp->cstate)) |
J. Bruce Fields | ea8d772 | 2014-03-08 17:19:55 -0500 | [diff] [blame] | 5273 | return nfserr_resource; |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5274 | if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) { |
| 5275 | WARN_ON_ONCE(1); |
| 5276 | return nfserr_rep_too_big_to_cache; |
J. Bruce Fields | ea8d772 | 2014-03-08 17:19:55 -0500 | [diff] [blame] | 5277 | } |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5278 | return nfserr_rep_too_big; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5279 | } |
| 5280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5281 | void |
| 5282 | nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) |
| 5283 | { |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5284 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5285 | struct nfs4_stateowner *so = resp->cstate.replay_owner; |
J. Bruce Fields | 5f4ab94 | 2014-03-07 11:01:37 -0500 | [diff] [blame] | 5286 | struct svc_rqst *rqstp = resp->rqstp; |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 5287 | const struct nfsd4_operation *opdesc = op->opdesc; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5288 | int post_err_offset; |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5289 | nfsd4_enc encoder; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 5290 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5291 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5292 | p = xdr_reserve_space(xdr, 8); |
| 5293 | if (!p) { |
| 5294 | WARN_ON_ONCE(1); |
| 5295 | return; |
| 5296 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 5297 | *p++ = cpu_to_be32(op->opnum); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5298 | post_err_offset = xdr->buf->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5299 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5300 | if (op->opnum == OP_ILLEGAL) |
| 5301 | goto status; |
J. Bruce Fields | b7571e4 | 2017-05-06 10:49:21 -0400 | [diff] [blame] | 5302 | if (op->status && opdesc && |
| 5303 | !(opdesc->op_flags & OP_NONTRIVIAL_ERROR_ENCODE)) |
| 5304 | goto status; |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5305 | BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) || |
| 5306 | !nfsd4_enc_ops[op->opnum]); |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5307 | encoder = nfsd4_enc_ops[op->opnum]; |
| 5308 | op->status = encoder(resp, op->status, &op->u); |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 5309 | if (op->status) |
| 5310 | trace_nfsd_compound_encode_err(rqstp, op->opnum, op->status); |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 5311 | if (opdesc && opdesc->op_release) |
| 5312 | opdesc->op_release(&op->u); |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 5313 | xdr_commit_encode(xdr); |
| 5314 | |
J. Bruce Fields | 067e1ac | 2014-03-21 17:26:44 -0400 | [diff] [blame] | 5315 | /* nfsd4_check_resp_size guarantees enough room for error status */ |
J. Bruce Fields | 5f4ab94 | 2014-03-07 11:01:37 -0500 | [diff] [blame] | 5316 | if (!op->status) { |
| 5317 | int space_needed = 0; |
| 5318 | if (!nfsd4_last_compound_op(rqstp)) |
| 5319 | space_needed = COMPOUND_ERR_SLACK_SPACE; |
| 5320 | op->status = nfsd4_check_resp_size(resp, space_needed); |
| 5321 | } |
J. Bruce Fields | c8f13d9 | 2014-05-08 17:38:18 -0400 | [diff] [blame] | 5322 | if (op->status == nfserr_resource && nfsd4_has_session(&resp->cstate)) { |
| 5323 | struct nfsd4_slot *slot = resp->cstate.slot; |
| 5324 | |
| 5325 | if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) |
| 5326 | op->status = nfserr_rep_too_big_to_cache; |
| 5327 | else |
| 5328 | op->status = nfserr_rep_too_big; |
| 5329 | } |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5330 | if (op->status == nfserr_resource || |
| 5331 | op->status == nfserr_rep_too_big || |
| 5332 | op->status == nfserr_rep_too_big_to_cache) { |
| 5333 | /* |
| 5334 | * The operation may have already been encoded or |
| 5335 | * partially encoded. No op returns anything additional |
| 5336 | * in the case of one of these three errors, so we can |
| 5337 | * just truncate back to after the status. But it's a |
| 5338 | * bug if we had to do this on a non-idempotent op: |
| 5339 | */ |
| 5340 | warn_on_nonidempotent_op(op); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5341 | xdr_truncate_encode(xdr, post_err_offset); |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5342 | } |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5343 | if (so) { |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5344 | int len = xdr->buf->len - post_err_offset; |
| 5345 | |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5346 | so->so_replay.rp_status = op->status; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5347 | so->so_replay.rp_buflen = len; |
| 5348 | read_bytes_from_xdr_buf(xdr->buf, post_err_offset, |
| 5349 | so->so_replay.rp_buf, len); |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5350 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5351 | status: |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5352 | /* Note that op->status is already in network byte order: */ |
| 5353 | write_bytes_to_xdr_buf(xdr->buf, post_err_offset - 4, &op->status, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5354 | } |
| 5355 | |
| 5356 | /* |
| 5357 | * Encode the reply stored in the stateowner reply cache |
| 5358 | * |
| 5359 | * XDR note: do not encode rp->rp_buflen: the buffer contains the |
| 5360 | * previously sent already encoded operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 | */ |
| 5362 | void |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5363 | nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5364 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 5365 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5366 | struct nfs4_replay *rp = op->replay; |
| 5367 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5368 | p = xdr_reserve_space(xdr, 8 + rp->rp_buflen); |
| 5369 | if (!p) { |
| 5370 | WARN_ON_ONCE(1); |
| 5371 | return; |
| 5372 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 5373 | *p++ = cpu_to_be32(op->opnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5374 | *p++ = rp->rp_status; /* already xdr'ed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5375 | |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 5376 | p = xdr_encode_opaque_fixed(p, rp->rp_buf, rp->rp_buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5377 | } |
| 5378 | |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 5379 | void nfsd4_release_compoundargs(struct svc_rqst *rqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5380 | { |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 5381 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 5382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5383 | if (args->ops != args->iops) { |
| 5384 | kfree(args->ops); |
| 5385 | args->ops = args->iops; |
| 5386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5387 | while (args->to_free) { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 5388 | struct svcxdr_tmpbuf *tb = args->to_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5389 | args->to_free = tb->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 | kfree(tb); |
| 5391 | } |
| 5392 | } |
| 5393 | |
| 5394 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 5395 | nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5396 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 5397 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 5398 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 5399 | /* svcxdr_tmp_alloc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5400 | args->tmpp = NULL; |
| 5401 | args->to_free = NULL; |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 5402 | |
| 5403 | args->xdr = &rqstp->rq_arg_stream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5404 | args->ops = args->iops; |
| 5405 | args->rqstp = rqstp; |
| 5406 | |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 5407 | return !nfsd4_decode_compound(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5408 | } |
| 5409 | |
| 5410 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 5411 | nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5412 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 5413 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
J. Bruce Fields | 6ac9039 | 2014-02-26 17:39:35 -0500 | [diff] [blame] | 5414 | struct xdr_buf *buf = resp->xdr.buf; |
| 5415 | |
| 5416 | WARN_ON_ONCE(buf->len != buf->head[0].iov_len + buf->page_len + |
| 5417 | buf->tail[0].iov_len); |
J. Bruce Fields | dd97fdd | 2014-02-26 17:16:27 -0500 | [diff] [blame] | 5418 | |
Chuck Lever | cc028a1 | 2020-10-02 15:52:44 -0400 | [diff] [blame] | 5419 | *p = resp->cstate.status; |
| 5420 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 5421 | rqstp->rq_next_page = resp->xdr.page_ptr + 1; |
| 5422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5423 | p = resp->tagp; |
| 5424 | *p++ = htonl(resp->taglen); |
| 5425 | memcpy(p, resp->tag, resp->taglen); |
| 5426 | p += XDR_QUADLEN(resp->taglen); |
| 5427 | *p++ = htonl(resp->opcnt); |
| 5428 | |
Trond Myklebust | b607664 | 2014-06-30 11:48:35 -0400 | [diff] [blame] | 5429 | nfsd4_sequence_done(resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5430 | return 1; |
| 5431 | } |
| 5432 | |
| 5433 | /* |
| 5434 | * Local variables: |
| 5435 | * c-basic-offset: 8 |
| 5436 | * End: |
| 5437 | */ |