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 | |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 215 | /* |
| 216 | * This helper handles variable-length opaques which belong to protocol |
| 217 | * elements that this implementation does not support. |
| 218 | */ |
| 219 | static __be32 |
| 220 | nfsd4_decode_ignored_string(struct nfsd4_compoundargs *argp, u32 maxlen) |
| 221 | { |
| 222 | u32 len; |
| 223 | |
| 224 | if (xdr_stream_decode_u32(argp->xdr, &len) < 0) |
| 225 | return nfserr_bad_xdr; |
| 226 | if (maxlen && len > maxlen) |
| 227 | return nfserr_bad_xdr; |
| 228 | if (!xdr_inline_decode(argp->xdr, len)) |
| 229 | return nfserr_bad_xdr; |
| 230 | |
| 231 | return nfs_ok; |
| 232 | } |
| 233 | |
Chuck Lever | 5dcbfab | 2020-11-04 11:41:55 -0500 | [diff] [blame] | 234 | static __be32 |
| 235 | nfsd4_decode_opaque(struct nfsd4_compoundargs *argp, struct xdr_netobj *o) |
| 236 | { |
| 237 | __be32 *p; |
| 238 | u32 len; |
| 239 | |
| 240 | if (xdr_stream_decode_u32(argp->xdr, &len) < 0) |
| 241 | return nfserr_bad_xdr; |
| 242 | if (len == 0 || len > NFS4_OPAQUE_LIMIT) |
| 243 | return nfserr_bad_xdr; |
| 244 | p = xdr_inline_decode(argp->xdr, len); |
| 245 | if (!p) |
| 246 | return nfserr_bad_xdr; |
| 247 | o->data = svcxdr_tmpalloc(argp, len); |
| 248 | if (!o->data) |
| 249 | return nfserr_jukebox; |
| 250 | o->len = len; |
| 251 | memcpy(o->data, p, len); |
| 252 | |
| 253 | return nfs_ok; |
| 254 | } |
| 255 | |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 256 | static __be32 |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 257 | nfsd4_decode_component4(struct nfsd4_compoundargs *argp, char **namp, u32 *lenp) |
| 258 | { |
| 259 | __be32 *p, status; |
| 260 | |
| 261 | if (xdr_stream_decode_u32(argp->xdr, lenp) < 0) |
| 262 | return nfserr_bad_xdr; |
| 263 | p = xdr_inline_decode(argp->xdr, *lenp); |
| 264 | if (!p) |
| 265 | return nfserr_bad_xdr; |
| 266 | status = check_filename((char *)p, *lenp); |
| 267 | if (status) |
| 268 | return status; |
| 269 | *namp = svcxdr_tmpalloc(argp, *lenp); |
| 270 | if (!*namp) |
| 271 | return nfserr_jukebox; |
| 272 | memcpy(*namp, p, *lenp); |
| 273 | |
| 274 | return nfs_ok; |
| 275 | } |
| 276 | |
| 277 | static __be32 |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 278 | nfsd4_decode_nfstime4(struct nfsd4_compoundargs *argp, struct timespec64 *tv) |
| 279 | { |
| 280 | __be32 *p; |
| 281 | |
| 282 | p = xdr_inline_decode(argp->xdr, XDR_UNIT * 3); |
| 283 | if (!p) |
| 284 | return nfserr_bad_xdr; |
| 285 | p = xdr_decode_hyper(p, &tv->tv_sec); |
| 286 | tv->tv_nsec = be32_to_cpup(p++); |
| 287 | if (tv->tv_nsec >= (u32)1000000000) |
| 288 | return nfserr_inval; |
| 289 | return nfs_ok; |
| 290 | } |
| 291 | |
| 292 | static __be32 |
Chuck Lever | 796dd1c | 2020-11-16 17:34:01 -0500 | [diff] [blame] | 293 | nfsd4_decode_verifier4(struct nfsd4_compoundargs *argp, nfs4_verifier *verf) |
| 294 | { |
| 295 | __be32 *p; |
| 296 | |
| 297 | p = xdr_inline_decode(argp->xdr, NFS4_VERIFIER_SIZE); |
| 298 | if (!p) |
| 299 | return nfserr_bad_xdr; |
| 300 | memcpy(verf->data, p, sizeof(verf->data)); |
| 301 | return nfs_ok; |
| 302 | } |
| 303 | |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 304 | /** |
| 305 | * nfsd4_decode_bitmap4 - Decode an NFSv4 bitmap4 |
| 306 | * @argp: NFSv4 compound argument structure |
| 307 | * @bmval: pointer to an array of u32's to decode into |
| 308 | * @bmlen: size of the @bmval array |
| 309 | * |
| 310 | * The server needs to return nfs_ok rather than nfserr_bad_xdr when |
| 311 | * encountering bitmaps containing bits it does not recognize. This |
| 312 | * includes bits in bitmap words past WORDn, where WORDn is the last |
| 313 | * bitmap WORD the implementation currently supports. Thus we are |
| 314 | * careful here to simply ignore bits in bitmap words that this |
| 315 | * implementation has yet to support explicitly. |
| 316 | * |
| 317 | * Return values: |
| 318 | * %nfs_ok: @bmval populated successfully |
| 319 | * %nfserr_bad_xdr: the encoded bitmap was invalid |
| 320 | */ |
| 321 | static __be32 |
| 322 | nfsd4_decode_bitmap4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen) |
| 323 | { |
| 324 | u32 i, count; |
| 325 | __be32 *p; |
| 326 | |
| 327 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 328 | return nfserr_bad_xdr; |
| 329 | /* request sanity */ |
| 330 | if (count > 1000) |
| 331 | return nfserr_bad_xdr; |
| 332 | p = xdr_inline_decode(argp->xdr, count << 2); |
| 333 | if (!p) |
| 334 | return nfserr_bad_xdr; |
| 335 | i = 0; |
| 336 | while (i < count) |
| 337 | bmval[i++] = be32_to_cpup(p++); |
| 338 | while (i < bmlen) |
| 339 | bmval[i++] = 0; |
| 340 | |
| 341 | return nfs_ok; |
| 342 | } |
| 343 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 344 | static __be32 |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 345 | nfsd4_decode_nfsace4(struct nfsd4_compoundargs *argp, struct nfs4_ace *ace) |
| 346 | { |
| 347 | __be32 *p, status; |
| 348 | u32 length; |
| 349 | |
| 350 | if (xdr_stream_decode_u32(argp->xdr, &ace->type) < 0) |
| 351 | return nfserr_bad_xdr; |
| 352 | if (xdr_stream_decode_u32(argp->xdr, &ace->flag) < 0) |
| 353 | return nfserr_bad_xdr; |
| 354 | if (xdr_stream_decode_u32(argp->xdr, &ace->access_mask) < 0) |
| 355 | return nfserr_bad_xdr; |
| 356 | |
| 357 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 358 | return nfserr_bad_xdr; |
| 359 | p = xdr_inline_decode(argp->xdr, length); |
| 360 | if (!p) |
| 361 | return nfserr_bad_xdr; |
| 362 | ace->whotype = nfs4_acl_get_whotype((char *)p, length); |
| 363 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
| 364 | status = nfs_ok; |
| 365 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
| 366 | status = nfsd_map_name_to_gid(argp->rqstp, |
| 367 | (char *)p, length, &ace->who_gid); |
| 368 | else |
| 369 | status = nfsd_map_name_to_uid(argp->rqstp, |
| 370 | (char *)p, length, &ace->who_uid); |
| 371 | |
| 372 | return status; |
| 373 | } |
| 374 | |
| 375 | /* A counted array of nfsace4's */ |
| 376 | static noinline __be32 |
| 377 | nfsd4_decode_acl(struct nfsd4_compoundargs *argp, struct nfs4_acl **acl) |
| 378 | { |
| 379 | struct nfs4_ace *ace; |
| 380 | __be32 status; |
| 381 | u32 count; |
| 382 | |
| 383 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 384 | return nfserr_bad_xdr; |
| 385 | |
| 386 | if (count > xdr_stream_remaining(argp->xdr) / 20) |
| 387 | /* |
| 388 | * Even with 4-byte names there wouldn't be |
| 389 | * space for that many aces; something fishy is |
| 390 | * going on: |
| 391 | */ |
| 392 | return nfserr_fbig; |
| 393 | |
| 394 | *acl = svcxdr_tmpalloc(argp, nfs4_acl_bytes(count)); |
| 395 | if (*acl == NULL) |
| 396 | return nfserr_jukebox; |
| 397 | |
| 398 | (*acl)->naces = count; |
| 399 | for (ace = (*acl)->aces; ace < (*acl)->aces + count; ace++) { |
| 400 | status = nfsd4_decode_nfsace4(argp, ace); |
| 401 | if (status) |
| 402 | return status; |
| 403 | } |
| 404 | |
| 405 | return nfs_ok; |
| 406 | } |
| 407 | |
Chuck Lever | dabe918 | 2020-11-19 14:05:51 -0500 | [diff] [blame] | 408 | static noinline __be32 |
| 409 | nfsd4_decode_security_label(struct nfsd4_compoundargs *argp, |
| 410 | struct xdr_netobj *label) |
| 411 | { |
| 412 | u32 lfs, pi, length; |
| 413 | __be32 *p; |
| 414 | |
| 415 | if (xdr_stream_decode_u32(argp->xdr, &lfs) < 0) |
| 416 | return nfserr_bad_xdr; |
| 417 | if (xdr_stream_decode_u32(argp->xdr, &pi) < 0) |
| 418 | return nfserr_bad_xdr; |
| 419 | |
| 420 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 421 | return nfserr_bad_xdr; |
| 422 | if (length > NFS4_MAXLABELLEN) |
| 423 | return nfserr_badlabel; |
| 424 | p = xdr_inline_decode(argp->xdr, length); |
| 425 | if (!p) |
| 426 | return nfserr_bad_xdr; |
| 427 | label->len = length; |
| 428 | label->data = svcxdr_dupstr(argp, p, length); |
| 429 | if (!label->data) |
| 430 | return nfserr_jukebox; |
| 431 | |
| 432 | return nfs_ok; |
| 433 | } |
| 434 | |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 435 | static __be32 |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 436 | nfsd4_decode_fattr4(struct nfsd4_compoundargs *argp, u32 *bmval, u32 bmlen, |
| 437 | struct iattr *iattr, struct nfs4_acl **acl, |
| 438 | struct xdr_netobj *label, int *umask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | { |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 440 | unsigned int starting_pos; |
| 441 | u32 attrlist4_count; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 442 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | iattr->ia_valid = 0; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 445 | status = nfsd4_decode_bitmap4(argp, bmval, bmlen); |
| 446 | if (status) |
| 447 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
J. Bruce Fields | e864c18 | 2016-06-10 16:56:05 -0400 | [diff] [blame] | 449 | if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0 |
| 450 | || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1 |
| 451 | || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2) { |
| 452 | if (nfsd_attrs_supported(argp->minorversion, bmval)) |
| 453 | return nfserr_inval; |
| 454 | return nfserr_attrnotsupp; |
| 455 | } |
| 456 | |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 457 | if (xdr_stream_decode_u32(argp->xdr, &attrlist4_count) < 0) |
| 458 | return nfserr_bad_xdr; |
| 459 | starting_pos = xdr_stream_pos(argp->xdr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
| 461 | if (bmval[0] & FATTR4_WORD0_SIZE) { |
Chuck Lever | 2ac1b9b | 2020-11-19 13:47:16 -0500 | [diff] [blame] | 462 | u64 size; |
| 463 | |
| 464 | if (xdr_stream_decode_u64(argp->xdr, &size) < 0) |
| 465 | return nfserr_bad_xdr; |
| 466 | iattr->ia_size = size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | iattr->ia_valid |= ATTR_SIZE; |
| 468 | } |
| 469 | if (bmval[0] & FATTR4_WORD0_ACL) { |
Chuck Lever | c941a96 | 2020-11-19 13:02:54 -0500 | [diff] [blame] | 470 | status = nfsd4_decode_acl(argp, acl); |
| 471 | if (status) |
| 472 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | } else |
| 474 | *acl = NULL; |
| 475 | if (bmval[1] & FATTR4_WORD1_MODE) { |
Chuck Lever | 1c8f0ad | 2020-11-19 13:54:26 -0500 | [diff] [blame] | 476 | u32 mode; |
| 477 | |
| 478 | if (xdr_stream_decode_u32(argp->xdr, &mode) < 0) |
| 479 | return nfserr_bad_xdr; |
| 480 | iattr->ia_mode = mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | iattr->ia_mode &= (S_IFMT | S_IALLUGO); |
| 482 | iattr->ia_valid |= ATTR_MODE; |
| 483 | } |
| 484 | if (bmval[1] & FATTR4_WORD1_OWNER) { |
Chuck Lever | 9853a5a | 2020-11-19 13:56:42 -0500 | [diff] [blame] | 485 | u32 length; |
| 486 | |
| 487 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 488 | return nfserr_bad_xdr; |
| 489 | p = xdr_inline_decode(argp->xdr, length); |
| 490 | if (!p) |
| 491 | return nfserr_bad_xdr; |
| 492 | status = nfsd_map_name_to_uid(argp->rqstp, (char *)p, length, |
| 493 | &iattr->ia_uid); |
| 494 | if (status) |
NeilBrown | 47c8529 | 2011-02-16 13:08:35 +1100 | [diff] [blame] | 495 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | iattr->ia_valid |= ATTR_UID; |
| 497 | } |
| 498 | if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) { |
Chuck Lever | 393c31d | 2020-11-19 13:58:18 -0500 | [diff] [blame] | 499 | u32 length; |
| 500 | |
| 501 | if (xdr_stream_decode_u32(argp->xdr, &length) < 0) |
| 502 | return nfserr_bad_xdr; |
| 503 | p = xdr_inline_decode(argp->xdr, length); |
| 504 | if (!p) |
| 505 | return nfserr_bad_xdr; |
| 506 | status = nfsd_map_name_to_gid(argp->rqstp, (char *)p, length, |
| 507 | &iattr->ia_gid); |
| 508 | if (status) |
NeilBrown | 47c8529 | 2011-02-16 13:08:35 +1100 | [diff] [blame] | 509 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | iattr->ia_valid |= ATTR_GID; |
| 511 | } |
| 512 | if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) { |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 513 | u32 set_it; |
| 514 | |
| 515 | if (xdr_stream_decode_u32(argp->xdr, &set_it) < 0) |
| 516 | return nfserr_bad_xdr; |
| 517 | switch (set_it) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | case NFS4_SET_TO_CLIENT_TIME: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 519 | status = nfsd4_decode_nfstime4(argp, &iattr->ia_atime); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 520 | if (status) |
| 521 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET); |
| 523 | break; |
| 524 | case NFS4_SET_TO_SERVER_TIME: |
| 525 | iattr->ia_valid |= ATTR_ATIME; |
| 526 | break; |
| 527 | default: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 528 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | } |
| 530 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) { |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 532 | u32 set_it; |
| 533 | |
| 534 | if (xdr_stream_decode_u32(argp->xdr, &set_it) < 0) |
| 535 | return nfserr_bad_xdr; |
| 536 | switch (set_it) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | case NFS4_SET_TO_CLIENT_TIME: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 538 | status = nfsd4_decode_nfstime4(argp, &iattr->ia_mtime); |
Christoph Hellwig | 4c94e13 | 2015-01-22 12:09:50 +0100 | [diff] [blame] | 539 | if (status) |
| 540 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET); |
| 542 | break; |
| 543 | case NFS4_SET_TO_SERVER_TIME: |
| 544 | iattr->ia_valid |= ATTR_MTIME; |
| 545 | break; |
| 546 | default: |
Chuck Lever | 1c3eff7 | 2020-11-19 14:01:08 -0500 | [diff] [blame] | 547 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |
| 549 | } |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 550 | label->len = 0; |
Arnd Bergmann | 2285ae7 | 2018-01-22 22:09:12 +0100 | [diff] [blame] | 551 | if (IS_ENABLED(CONFIG_NFSD_V4_SECURITY_LABEL) && |
| 552 | bmval[2] & FATTR4_WORD2_SECURITY_LABEL) { |
Chuck Lever | dabe918 | 2020-11-19 14:05:51 -0500 | [diff] [blame] | 553 | status = nfsd4_decode_security_label(argp, label); |
| 554 | if (status) |
| 555 | return status; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 556 | } |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 557 | if (bmval[2] & FATTR4_WORD2_MODE_UMASK) { |
Chuck Lever | 66f0476 | 2020-11-19 14:07:43 -0500 | [diff] [blame] | 558 | u32 mode, mask; |
| 559 | |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 560 | if (!umask) |
Chuck Lever | 66f0476 | 2020-11-19 14:07:43 -0500 | [diff] [blame] | 561 | return nfserr_bad_xdr; |
| 562 | if (xdr_stream_decode_u32(argp->xdr, &mode) < 0) |
| 563 | return nfserr_bad_xdr; |
| 564 | iattr->ia_mode = mode & (S_IFMT | S_IALLUGO); |
| 565 | if (xdr_stream_decode_u32(argp->xdr, &mask) < 0) |
| 566 | return nfserr_bad_xdr; |
| 567 | *umask = mask & S_IRWXUGO; |
Andreas Gruenbacher | 47057ab | 2016-01-12 20:24:14 +0100 | [diff] [blame] | 568 | iattr->ia_valid |= ATTR_MODE; |
| 569 | } |
Chuck Lever | 081d53f | 2020-11-19 13:09:13 -0500 | [diff] [blame] | 570 | |
| 571 | /* request sanity: did attrlist4 contain the expected number of words? */ |
| 572 | if (attrlist4_count != xdr_stream_pos(argp->xdr) - starting_pos) |
| 573 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 575 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | } |
| 577 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 578 | static __be32 |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 579 | nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid) |
| 580 | { |
| 581 | DECODE_HEAD; |
| 582 | |
| 583 | READ_BUF(sizeof(stateid_t)); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 584 | sid->si_generation = be32_to_cpup(p++); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 585 | COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t)); |
| 586 | |
| 587 | DECODE_TAIL; |
| 588 | } |
| 589 | |
Chuck Lever | d3d2f38 | 2020-11-03 13:18:23 -0500 | [diff] [blame] | 590 | static __be32 |
| 591 | nfsd4_decode_stateid4(struct nfsd4_compoundargs *argp, stateid_t *sid) |
| 592 | { |
| 593 | __be32 *p; |
| 594 | |
| 595 | p = xdr_inline_decode(argp->xdr, NFS4_STATEID_SIZE); |
| 596 | if (!p) |
| 597 | return nfserr_bad_xdr; |
| 598 | sid->si_generation = be32_to_cpup(p++); |
| 599 | memcpy(&sid->si_opaque, p, sizeof(sid->si_opaque)); |
| 600 | return nfs_ok; |
| 601 | } |
| 602 | |
Chuck Lever | 144e826 | 2020-11-16 17:25:02 -0500 | [diff] [blame] | 603 | static __be32 |
| 604 | nfsd4_decode_clientid4(struct nfsd4_compoundargs *argp, clientid_t *clientid) |
| 605 | { |
| 606 | __be32 *p; |
| 607 | |
| 608 | p = xdr_inline_decode(argp->xdr, sizeof(__be64)); |
| 609 | if (!p) |
| 610 | return nfserr_bad_xdr; |
| 611 | memcpy(clientid, p, sizeof(*clientid)); |
| 612 | return nfs_ok; |
| 613 | } |
| 614 | |
| 615 | static __be32 |
| 616 | nfsd4_decode_state_owner4(struct nfsd4_compoundargs *argp, |
| 617 | clientid_t *clientid, struct xdr_netobj *owner) |
| 618 | { |
| 619 | __be32 status; |
| 620 | |
| 621 | status = nfsd4_decode_clientid4(argp, clientid); |
| 622 | if (status) |
| 623 | return status; |
| 624 | return nfsd4_decode_opaque(argp, owner); |
| 625 | } |
| 626 | |
Chuck Lever | 0449597 | 2020-11-03 15:03:50 -0500 | [diff] [blame] | 627 | #ifdef CONFIG_NFSD_PNFS |
| 628 | static __be32 |
| 629 | nfsd4_decode_deviceid4(struct nfsd4_compoundargs *argp, |
| 630 | struct nfsd4_deviceid *devid) |
| 631 | { |
| 632 | __be32 *p; |
| 633 | |
| 634 | p = xdr_inline_decode(argp->xdr, NFS4_DEVICEID4_SIZE); |
| 635 | if (!p) |
| 636 | return nfserr_bad_xdr; |
| 637 | memcpy(devid, p, sizeof(*devid)); |
| 638 | return nfs_ok; |
| 639 | } |
Chuck Lever | 5185980 | 2020-11-04 10:40:07 -0500 | [diff] [blame] | 640 | |
| 641 | static __be32 |
| 642 | nfsd4_decode_layoutupdate4(struct nfsd4_compoundargs *argp, |
| 643 | struct nfsd4_layoutcommit *lcp) |
| 644 | { |
| 645 | if (xdr_stream_decode_u32(argp->xdr, &lcp->lc_layout_type) < 0) |
| 646 | return nfserr_bad_xdr; |
| 647 | if (lcp->lc_layout_type < LAYOUT_NFSV4_1_FILES) |
| 648 | return nfserr_bad_xdr; |
| 649 | if (lcp->lc_layout_type >= LAYOUT_TYPE_MAX) |
| 650 | return nfserr_bad_xdr; |
| 651 | |
| 652 | if (xdr_stream_decode_u32(argp->xdr, &lcp->lc_up_len) < 0) |
| 653 | return nfserr_bad_xdr; |
| 654 | if (lcp->lc_up_len > 0) { |
| 655 | lcp->lc_up_layout = xdr_inline_decode(argp->xdr, lcp->lc_up_len); |
| 656 | if (!lcp->lc_up_layout) |
| 657 | return nfserr_bad_xdr; |
| 658 | } |
| 659 | |
| 660 | return nfs_ok; |
| 661 | } |
| 662 | |
Chuck Lever | 645fcad | 2020-11-04 10:42:25 -0500 | [diff] [blame] | 663 | static __be32 |
| 664 | nfsd4_decode_layoutreturn4(struct nfsd4_compoundargs *argp, |
| 665 | struct nfsd4_layoutreturn *lrp) |
| 666 | { |
| 667 | __be32 status; |
| 668 | |
| 669 | if (xdr_stream_decode_u32(argp->xdr, &lrp->lr_return_type) < 0) |
| 670 | return nfserr_bad_xdr; |
| 671 | switch (lrp->lr_return_type) { |
| 672 | case RETURN_FILE: |
| 673 | if (xdr_stream_decode_u64(argp->xdr, &lrp->lr_seg.offset) < 0) |
| 674 | return nfserr_bad_xdr; |
| 675 | if (xdr_stream_decode_u64(argp->xdr, &lrp->lr_seg.length) < 0) |
| 676 | return nfserr_bad_xdr; |
| 677 | status = nfsd4_decode_stateid4(argp, &lrp->lr_sid); |
| 678 | if (status) |
| 679 | return status; |
| 680 | if (xdr_stream_decode_u32(argp->xdr, &lrp->lrf_body_len) < 0) |
| 681 | return nfserr_bad_xdr; |
| 682 | if (lrp->lrf_body_len > 0) { |
| 683 | lrp->lrf_body = xdr_inline_decode(argp->xdr, lrp->lrf_body_len); |
| 684 | if (!lrp->lrf_body) |
| 685 | return nfserr_bad_xdr; |
| 686 | } |
| 687 | break; |
| 688 | case RETURN_FSID: |
| 689 | case RETURN_ALL: |
| 690 | lrp->lr_seg.offset = 0; |
| 691 | lrp->lr_seg.length = NFS4_MAX_UINT64; |
| 692 | break; |
| 693 | default: |
| 694 | return nfserr_bad_xdr; |
| 695 | } |
| 696 | |
| 697 | return nfs_ok; |
| 698 | } |
| 699 | |
Chuck Lever | 0449597 | 2020-11-03 15:03:50 -0500 | [diff] [blame] | 700 | #endif /* CONFIG_NFSD_PNFS */ |
| 701 | |
Chuck Lever | 571e045 | 2020-11-03 13:16:23 -0500 | [diff] [blame] | 702 | static __be32 |
| 703 | nfsd4_decode_sessionid4(struct nfsd4_compoundargs *argp, |
| 704 | struct nfs4_sessionid *sessionid) |
| 705 | { |
| 706 | __be32 *p; |
| 707 | |
| 708 | p = xdr_inline_decode(argp->xdr, NFS4_MAX_SESSIONID_LEN); |
| 709 | if (!p) |
| 710 | return nfserr_bad_xdr; |
| 711 | memcpy(sessionid->data, p, sizeof(sessionid->data)); |
| 712 | return nfs_ok; |
| 713 | } |
| 714 | |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 715 | /* Defined in Appendix A of RFC 5531 */ |
| 716 | static __be32 |
| 717 | nfsd4_decode_authsys_parms(struct nfsd4_compoundargs *argp, |
| 718 | struct nfsd4_cb_sec *cbs) |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 719 | { |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 720 | u32 stamp, gidcount, uid, gid; |
| 721 | __be32 *p, status; |
| 722 | |
| 723 | if (xdr_stream_decode_u32(argp->xdr, &stamp) < 0) |
| 724 | return nfserr_bad_xdr; |
| 725 | /* machine name */ |
| 726 | status = nfsd4_decode_ignored_string(argp, 255); |
| 727 | if (status) |
| 728 | return status; |
| 729 | if (xdr_stream_decode_u32(argp->xdr, &uid) < 0) |
| 730 | return nfserr_bad_xdr; |
| 731 | if (xdr_stream_decode_u32(argp->xdr, &gid) < 0) |
| 732 | return nfserr_bad_xdr; |
| 733 | if (xdr_stream_decode_u32(argp->xdr, &gidcount) < 0) |
| 734 | return nfserr_bad_xdr; |
| 735 | if (gidcount > 16) |
| 736 | return nfserr_bad_xdr; |
| 737 | p = xdr_inline_decode(argp->xdr, gidcount << 2); |
| 738 | if (!p) |
| 739 | return nfserr_bad_xdr; |
| 740 | if (cbs->flavor == (u32)(-1)) { |
| 741 | struct user_namespace *userns = nfsd_user_namespace(argp->rqstp); |
| 742 | |
| 743 | kuid_t kuid = make_kuid(userns, uid); |
| 744 | kgid_t kgid = make_kgid(userns, gid); |
| 745 | if (uid_valid(kuid) && gid_valid(kgid)) { |
| 746 | cbs->uid = kuid; |
| 747 | cbs->gid = kgid; |
| 748 | cbs->flavor = RPC_AUTH_UNIX; |
| 749 | } else { |
| 750 | dprintk("RPC_AUTH_UNIX with invalid uid or gid, ignoring!\n"); |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | return nfs_ok; |
| 755 | } |
| 756 | |
| 757 | static __be32 |
| 758 | nfsd4_decode_gss_cb_handles4(struct nfsd4_compoundargs *argp, |
| 759 | struct nfsd4_cb_sec *cbs) |
| 760 | { |
| 761 | __be32 status; |
| 762 | u32 service; |
| 763 | |
| 764 | dprintk("RPC_AUTH_GSS callback secflavor not supported!\n"); |
| 765 | |
| 766 | if (xdr_stream_decode_u32(argp->xdr, &service) < 0) |
| 767 | return nfserr_bad_xdr; |
| 768 | if (service < RPC_GSS_SVC_NONE || service > RPC_GSS_SVC_PRIVACY) |
| 769 | return nfserr_bad_xdr; |
| 770 | /* gcbp_handle_from_server */ |
| 771 | status = nfsd4_decode_ignored_string(argp, 0); |
| 772 | if (status) |
| 773 | return status; |
| 774 | /* gcbp_handle_from_client */ |
| 775 | status = nfsd4_decode_ignored_string(argp, 0); |
| 776 | if (status) |
| 777 | return status; |
| 778 | |
| 779 | return nfs_ok; |
| 780 | } |
| 781 | |
| 782 | /* a counted array of callback_sec_parms4 items */ |
| 783 | static __be32 |
| 784 | nfsd4_decode_cb_sec(struct nfsd4_compoundargs *argp, struct nfsd4_cb_sec *cbs) |
| 785 | { |
| 786 | u32 i, secflavor, nr_secflavs; |
| 787 | __be32 status; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 788 | |
| 789 | /* callback_sec_params4 */ |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 790 | if (xdr_stream_decode_u32(argp->xdr, &nr_secflavs) < 0) |
| 791 | return nfserr_bad_xdr; |
J. Bruce Fields | 57569a7 | 2013-05-17 16:25:32 -0400 | [diff] [blame] | 792 | if (nr_secflavs) |
| 793 | cbs->flavor = (u32)(-1); |
| 794 | else |
| 795 | /* Is this legal? Be generous, take it to mean AUTH_NONE: */ |
| 796 | cbs->flavor = 0; |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 797 | |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 798 | for (i = 0; i < nr_secflavs; ++i) { |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 799 | if (xdr_stream_decode_u32(argp->xdr, &secflavor) < 0) |
| 800 | return nfserr_bad_xdr; |
| 801 | switch (secflavor) { |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 802 | case RPC_AUTH_NULL: |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 803 | /* void */ |
J. Bruce Fields | 12fc3e9 | 2012-11-05 16:01:48 -0500 | [diff] [blame] | 804 | if (cbs->flavor == (u32)(-1)) |
| 805 | cbs->flavor = RPC_AUTH_NULL; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 806 | break; |
| 807 | case RPC_AUTH_UNIX: |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 808 | status = nfsd4_decode_authsys_parms(argp, cbs); |
| 809 | if (status) |
| 810 | return status; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 811 | break; |
| 812 | case RPC_AUTH_GSS: |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 813 | status = nfsd4_decode_gss_cb_handles4(argp, cbs); |
| 814 | if (status) |
| 815 | return status; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 816 | break; |
| 817 | default: |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 818 | return nfserr_inval; |
| 819 | } |
| 820 | } |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 821 | |
| 822 | return nfs_ok; |
J. Bruce Fields | acb2887 | 2012-03-27 14:50:26 -0400 | [diff] [blame] | 823 | } |
| 824 | |
Chuck Lever | 1a99440 | 2020-11-03 13:09:34 -0500 | [diff] [blame] | 825 | |
Chuck Lever | d169a6a | 2020-11-03 13:12:27 -0500 | [diff] [blame] | 826 | /* |
| 827 | * NFSv4 operation argument decoders |
| 828 | */ |
| 829 | |
| 830 | static __be32 |
| 831 | nfsd4_decode_access(struct nfsd4_compoundargs *argp, |
| 832 | struct nfsd4_access *access) |
| 833 | { |
| 834 | if (xdr_stream_decode_u32(argp->xdr, &access->ac_req_access) < 0) |
| 835 | return nfserr_bad_xdr; |
| 836 | return nfs_ok; |
| 837 | } |
| 838 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 839 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close) |
| 841 | { |
Chuck Lever | d3d2f38 | 2020-11-03 13:18:23 -0500 | [diff] [blame] | 842 | if (xdr_stream_decode_u32(argp->xdr, &close->cl_seqid) < 0) |
| 843 | return nfserr_bad_xdr; |
| 844 | return nfsd4_decode_stateid4(argp, &close->cl_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 848 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit) |
| 850 | { |
Chuck Lever | cbd9abb | 2020-11-03 13:19:51 -0500 | [diff] [blame] | 851 | if (xdr_stream_decode_u64(argp->xdr, &commit->co_offset) < 0) |
| 852 | return nfserr_bad_xdr; |
| 853 | if (xdr_stream_decode_u32(argp->xdr, &commit->co_count) < 0) |
| 854 | return nfserr_bad_xdr; |
| 855 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 858 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create) |
| 860 | { |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 861 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 863 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_type) < 0) |
| 864 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | switch (create->cr_type) { |
| 866 | case NF4LNK: |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 867 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_datalen) < 0) |
| 868 | return nfserr_bad_xdr; |
| 869 | p = xdr_inline_decode(argp->xdr, create->cr_datalen); |
| 870 | if (!p) |
| 871 | return nfserr_bad_xdr; |
J. Bruce Fields | 29c353b | 2014-06-24 17:06:51 -0400 | [diff] [blame] | 872 | create->cr_data = svcxdr_dupstr(argp, p, create->cr_datalen); |
J. Bruce Fields | 7fb8430 | 2014-06-24 15:06:41 -0400 | [diff] [blame] | 873 | if (!create->cr_data) |
J. Bruce Fields | 76f47128 | 2014-06-19 16:44:48 -0400 | [diff] [blame] | 874 | return nfserr_jukebox; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | break; |
| 876 | case NF4BLK: |
| 877 | case NF4CHR: |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 878 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata1) < 0) |
| 879 | return nfserr_bad_xdr; |
| 880 | if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata2) < 0) |
| 881 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | break; |
| 883 | case NF4SOCK: |
| 884 | case NF4FIFO: |
| 885 | case NF4DIR: |
| 886 | default: |
| 887 | break; |
| 888 | } |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 889 | status = nfsd4_decode_component4(argp, &create->cr_name, |
| 890 | &create->cr_namelen); |
| 891 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | return status; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 893 | status = nfsd4_decode_fattr4(argp, create->cr_bmval, |
| 894 | ARRAY_SIZE(create->cr_bmval), |
| 895 | &create->cr_iattr, &create->cr_acl, |
| 896 | &create->cr_label, &create->cr_umask); |
Benny Halevy | c0d6fc8 | 2009-04-03 08:29:05 +0300 | [diff] [blame] | 897 | if (status) |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 898 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
Chuck Lever | 000dfa1 | 2020-11-03 13:24:10 -0500 | [diff] [blame] | 900 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | } |
| 902 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 903 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr) |
| 905 | { |
Chuck Lever | 95e6482 | 2020-11-21 14:11:58 -0500 | [diff] [blame] | 906 | return nfsd4_decode_stateid4(argp, &dr->dr_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 909 | static inline __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr) |
| 911 | { |
Chuck Lever | f759eff | 2020-11-19 14:40:20 -0500 | [diff] [blame] | 912 | return nfsd4_decode_bitmap4(argp, getattr->ga_bmval, |
| 913 | ARRAY_SIZE(getattr->ga_bmval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | } |
| 915 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 916 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link) |
| 918 | { |
Chuck Lever | 5c505d1 | 2020-11-04 15:01:24 -0500 | [diff] [blame] | 919 | return nfsd4_decode_component4(argp, &link->li_name, &link->li_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 922 | static __be32 |
Chuck Lever | 8918cc0 | 2020-11-16 17:16:52 -0500 | [diff] [blame] | 923 | nfsd4_decode_open_to_lock_owner4(struct nfsd4_compoundargs *argp, |
| 924 | struct nfsd4_lock *lock) |
| 925 | { |
| 926 | __be32 status; |
| 927 | |
| 928 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_new_open_seqid) < 0) |
| 929 | return nfserr_bad_xdr; |
| 930 | status = nfsd4_decode_stateid4(argp, &lock->lk_new_open_stateid); |
| 931 | if (status) |
| 932 | return status; |
| 933 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_new_lock_seqid) < 0) |
| 934 | return nfserr_bad_xdr; |
| 935 | return nfsd4_decode_state_owner4(argp, &lock->lk_new_clientid, |
| 936 | &lock->lk_new_owner); |
| 937 | } |
| 938 | |
| 939 | static __be32 |
| 940 | nfsd4_decode_exist_lock_owner4(struct nfsd4_compoundargs *argp, |
| 941 | struct nfsd4_lock *lock) |
| 942 | { |
| 943 | __be32 status; |
| 944 | |
| 945 | status = nfsd4_decode_stateid4(argp, &lock->lk_old_lock_stateid); |
| 946 | if (status) |
| 947 | return status; |
| 948 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_old_lock_seqid) < 0) |
| 949 | return nfserr_bad_xdr; |
| 950 | |
| 951 | return nfs_ok; |
| 952 | } |
| 953 | |
| 954 | static __be32 |
| 955 | nfsd4_decode_locker4(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) |
| 956 | { |
| 957 | if (xdr_stream_decode_bool(argp->xdr, &lock->lk_is_new) < 0) |
| 958 | return nfserr_bad_xdr; |
| 959 | if (lock->lk_is_new) |
| 960 | return nfsd4_decode_open_to_lock_owner4(argp, lock); |
| 961 | return nfsd4_decode_exist_lock_owner4(argp, lock); |
| 962 | } |
| 963 | |
| 964 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock) |
| 966 | { |
Chuck Lever | 7c59dee | 2020-11-03 13:29:27 -0500 | [diff] [blame] | 967 | if (xdr_stream_decode_u32(argp->xdr, &lock->lk_type) < 0) |
| 968 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | 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] | 970 | return nfserr_bad_xdr; |
| 971 | if (xdr_stream_decode_bool(argp->xdr, &lock->lk_reclaim) < 0) |
| 972 | return nfserr_bad_xdr; |
| 973 | if (xdr_stream_decode_u64(argp->xdr, &lock->lk_offset) < 0) |
| 974 | return nfserr_bad_xdr; |
| 975 | if (xdr_stream_decode_u64(argp->xdr, &lock->lk_length) < 0) |
| 976 | return nfserr_bad_xdr; |
| 977 | return nfsd4_decode_locker4(argp, lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | } |
| 979 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 980 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt) |
| 982 | { |
Chuck Lever | 0a146f0 | 2020-11-03 13:31:44 -0500 | [diff] [blame] | 983 | if (xdr_stream_decode_u32(argp->xdr, &lockt->lt_type) < 0) |
| 984 | return nfserr_bad_xdr; |
| 985 | if ((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT)) |
| 986 | return nfserr_bad_xdr; |
| 987 | if (xdr_stream_decode_u64(argp->xdr, &lockt->lt_offset) < 0) |
| 988 | return nfserr_bad_xdr; |
| 989 | if (xdr_stream_decode_u64(argp->xdr, &lockt->lt_length) < 0) |
| 990 | return nfserr_bad_xdr; |
| 991 | return nfsd4_decode_state_owner4(argp, &lockt->lt_clientid, |
| 992 | &lockt->lt_owner); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | } |
| 994 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 995 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku) |
| 997 | { |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 998 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 1000 | if (xdr_stream_decode_u32(argp->xdr, &locku->lu_type) < 0) |
| 1001 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | 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] | 1003 | return nfserr_bad_xdr; |
| 1004 | if (xdr_stream_decode_u32(argp->xdr, &locku->lu_seqid) < 0) |
| 1005 | return nfserr_bad_xdr; |
| 1006 | status = nfsd4_decode_stateid4(argp, &locku->lu_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1007 | if (status) |
| 1008 | return status; |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 1009 | if (xdr_stream_decode_u64(argp->xdr, &locku->lu_offset) < 0) |
| 1010 | return nfserr_bad_xdr; |
| 1011 | if (xdr_stream_decode_u64(argp->xdr, &locku->lu_length) < 0) |
| 1012 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | |
Chuck Lever | ca9cf9f | 2020-11-03 13:33:28 -0500 | [diff] [blame] | 1014 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1017 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup) |
| 1019 | { |
Chuck Lever | 3d5877e | 2020-11-04 15:02:40 -0500 | [diff] [blame] | 1020 | return nfsd4_decode_component4(argp, &lookup->lo_name, &lookup->lo_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Chuck Lever | bf33bab | 2020-11-16 17:37:42 -0500 | [diff] [blame] | 1023 | static __be32 |
| 1024 | nfsd4_decode_createhow4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 1025 | { |
| 1026 | __be32 status; |
| 1027 | |
| 1028 | if (xdr_stream_decode_u32(argp->xdr, &open->op_createmode) < 0) |
| 1029 | return nfserr_bad_xdr; |
| 1030 | switch (open->op_createmode) { |
| 1031 | case NFS4_CREATE_UNCHECKED: |
| 1032 | case NFS4_CREATE_GUARDED: |
| 1033 | status = nfsd4_decode_fattr4(argp, open->op_bmval, |
| 1034 | ARRAY_SIZE(open->op_bmval), |
| 1035 | &open->op_iattr, &open->op_acl, |
| 1036 | &open->op_label, &open->op_umask); |
| 1037 | if (status) |
| 1038 | return status; |
| 1039 | break; |
| 1040 | case NFS4_CREATE_EXCLUSIVE: |
| 1041 | status = nfsd4_decode_verifier4(argp, &open->op_verf); |
| 1042 | if (status) |
| 1043 | return status; |
| 1044 | break; |
| 1045 | case NFS4_CREATE_EXCLUSIVE4_1: |
| 1046 | if (argp->minorversion < 1) |
| 1047 | return nfserr_bad_xdr; |
| 1048 | status = nfsd4_decode_verifier4(argp, &open->op_verf); |
| 1049 | if (status) |
| 1050 | return status; |
| 1051 | status = nfsd4_decode_fattr4(argp, open->op_bmval, |
| 1052 | ARRAY_SIZE(open->op_bmval), |
| 1053 | &open->op_iattr, &open->op_acl, |
| 1054 | &open->op_label, &open->op_umask); |
| 1055 | if (status) |
| 1056 | return status; |
| 1057 | break; |
| 1058 | default: |
| 1059 | return nfserr_bad_xdr; |
| 1060 | } |
| 1061 | |
| 1062 | return nfs_ok; |
| 1063 | } |
| 1064 | |
Chuck Lever | e6ec04b | 2020-11-16 17:41:21 -0500 | [diff] [blame] | 1065 | static __be32 |
| 1066 | nfsd4_decode_openflag4(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 1067 | { |
| 1068 | __be32 status; |
| 1069 | |
| 1070 | if (xdr_stream_decode_u32(argp->xdr, &open->op_create) < 0) |
| 1071 | return nfserr_bad_xdr; |
| 1072 | switch (open->op_create) { |
| 1073 | case NFS4_OPEN_NOCREATE: |
| 1074 | break; |
| 1075 | case NFS4_OPEN_CREATE: |
| 1076 | status = nfsd4_decode_createhow4(argp, open); |
| 1077 | if (status) |
| 1078 | return status; |
| 1079 | break; |
| 1080 | default: |
| 1081 | return nfserr_bad_xdr; |
| 1082 | } |
| 1083 | |
| 1084 | return nfs_ok; |
| 1085 | } |
| 1086 | |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1087 | 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] | 1088 | { |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1089 | u32 w; |
| 1090 | |
Chuck Lever | 9aa62f5 | 2020-11-16 17:54:48 -0500 | [diff] [blame] | 1091 | if (xdr_stream_decode_u32(argp->xdr, &w) < 0) |
| 1092 | return nfserr_bad_xdr; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1093 | *share_access = w & NFS4_SHARE_ACCESS_MASK; |
| 1094 | *deleg_want = w & NFS4_SHARE_WANT_MASK; |
| 1095 | if (deleg_when) |
| 1096 | *deleg_when = w & NFS4_SHARE_WHEN_MASK; |
| 1097 | |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1098 | switch (w & NFS4_SHARE_ACCESS_MASK) { |
| 1099 | case NFS4_SHARE_ACCESS_READ: |
| 1100 | case NFS4_SHARE_ACCESS_WRITE: |
| 1101 | case NFS4_SHARE_ACCESS_BOTH: |
| 1102 | break; |
| 1103 | default: |
| 1104 | return nfserr_bad_xdr; |
| 1105 | } |
Benny Halevy | fc0d14f | 2011-10-27 20:43:01 +0200 | [diff] [blame] | 1106 | w &= ~NFS4_SHARE_ACCESS_MASK; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1107 | if (!w) |
| 1108 | return nfs_ok; |
| 1109 | if (!argp->minorversion) |
| 1110 | return nfserr_bad_xdr; |
| 1111 | switch (w & NFS4_SHARE_WANT_MASK) { |
| 1112 | case NFS4_SHARE_WANT_NO_PREFERENCE: |
| 1113 | case NFS4_SHARE_WANT_READ_DELEG: |
| 1114 | case NFS4_SHARE_WANT_WRITE_DELEG: |
| 1115 | case NFS4_SHARE_WANT_ANY_DELEG: |
| 1116 | case NFS4_SHARE_WANT_NO_DELEG: |
| 1117 | case NFS4_SHARE_WANT_CANCEL: |
| 1118 | break; |
| 1119 | default: |
| 1120 | return nfserr_bad_xdr; |
| 1121 | } |
Benny Halevy | 92bac8c | 2011-10-19 19:13:29 -0700 | [diff] [blame] | 1122 | w &= ~NFS4_SHARE_WANT_MASK; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1123 | if (!w) |
| 1124 | return nfs_ok; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1125 | |
| 1126 | if (!deleg_when) /* open_downgrade */ |
| 1127 | return nfserr_inval; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1128 | switch (w) { |
| 1129 | case NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL: |
| 1130 | case NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED: |
Benny Halevy | c668fc6 | 2011-10-19 19:13:13 -0700 | [diff] [blame] | 1131 | case (NFS4_SHARE_SIGNAL_DELEG_WHEN_RESRC_AVAIL | |
| 1132 | NFS4_SHARE_PUSH_DELEG_WHEN_UNCONTENDED): |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1133 | return nfs_ok; |
| 1134 | } |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1135 | return nfserr_bad_xdr; |
| 1136 | } |
| 1137 | |
| 1138 | static __be32 nfsd4_decode_share_deny(struct nfsd4_compoundargs *argp, u32 *x) |
| 1139 | { |
Chuck Lever | b07bebd | 2020-11-16 17:56:17 -0500 | [diff] [blame] | 1140 | if (xdr_stream_decode_u32(argp->xdr, x) < 0) |
| 1141 | return nfserr_bad_xdr; |
| 1142 | /* Note: unlike access bits, deny bits may be zero. */ |
Dan Carpenter | 01cd4af | 2011-10-17 10:41:17 +0300 | [diff] [blame] | 1143 | if (*x & ~NFS4_SHARE_DENY_BOTH) |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1144 | return nfserr_bad_xdr; |
Chuck Lever | b07bebd | 2020-11-16 17:56:17 -0500 | [diff] [blame] | 1145 | |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1146 | return nfs_ok; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1147 | } |
| 1148 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1149 | static __be32 |
Chuck Lever | 1708e50 | 2020-11-16 17:45:04 -0500 | [diff] [blame] | 1150 | nfsd4_decode_open_claim4(struct nfsd4_compoundargs *argp, |
| 1151 | struct nfsd4_open *open) |
| 1152 | { |
| 1153 | __be32 status; |
| 1154 | |
| 1155 | if (xdr_stream_decode_u32(argp->xdr, &open->op_claim_type) < 0) |
| 1156 | return nfserr_bad_xdr; |
| 1157 | switch (open->op_claim_type) { |
| 1158 | case NFS4_OPEN_CLAIM_NULL: |
| 1159 | case NFS4_OPEN_CLAIM_DELEGATE_PREV: |
| 1160 | status = nfsd4_decode_component4(argp, &open->op_fname, |
| 1161 | &open->op_fnamelen); |
| 1162 | if (status) |
| 1163 | return status; |
| 1164 | break; |
| 1165 | case NFS4_OPEN_CLAIM_PREVIOUS: |
| 1166 | if (xdr_stream_decode_u32(argp->xdr, &open->op_delegate_type) < 0) |
| 1167 | return nfserr_bad_xdr; |
| 1168 | break; |
| 1169 | case NFS4_OPEN_CLAIM_DELEGATE_CUR: |
| 1170 | status = nfsd4_decode_stateid4(argp, &open->op_delegate_stateid); |
| 1171 | if (status) |
| 1172 | return status; |
| 1173 | status = nfsd4_decode_component4(argp, &open->op_fname, |
| 1174 | &open->op_fnamelen); |
| 1175 | if (status) |
| 1176 | return status; |
| 1177 | break; |
| 1178 | case NFS4_OPEN_CLAIM_FH: |
| 1179 | case NFS4_OPEN_CLAIM_DELEG_PREV_FH: |
| 1180 | if (argp->minorversion < 1) |
| 1181 | return nfserr_bad_xdr; |
| 1182 | /* void */ |
| 1183 | break; |
| 1184 | case NFS4_OPEN_CLAIM_DELEG_CUR_FH: |
| 1185 | if (argp->minorversion < 1) |
| 1186 | return nfserr_bad_xdr; |
| 1187 | status = nfsd4_decode_stateid4(argp, &open->op_delegate_stateid); |
| 1188 | if (status) |
| 1189 | return status; |
| 1190 | break; |
| 1191 | default: |
| 1192 | return nfserr_bad_xdr; |
| 1193 | } |
| 1194 | |
| 1195 | return nfs_ok; |
| 1196 | } |
| 1197 | |
| 1198 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open) |
| 1200 | { |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1201 | __be32 status; |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1202 | u32 dummy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | |
| 1204 | memset(open->op_bmval, 0, sizeof(open->op_bmval)); |
| 1205 | open->op_iattr.ia_valid = 0; |
J. Bruce Fields | fe0750e | 2011-07-30 23:33:59 -0400 | [diff] [blame] | 1206 | open->op_openowner = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | |
J. Bruce Fields | 9d313b1 | 2013-02-28 12:51:49 -0800 | [diff] [blame] | 1208 | open->op_xdr_error = 0; |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1209 | if (xdr_stream_decode_u32(argp->xdr, &open->op_seqid) < 0) |
| 1210 | return nfserr_bad_xdr; |
| 1211 | /* deleg_want is ignored */ |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1212 | status = nfsd4_decode_share_access(argp, &open->op_share_access, |
| 1213 | &open->op_deleg_want, &dummy); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1214 | if (status) |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1215 | return status; |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1216 | status = nfsd4_decode_share_deny(argp, &open->op_share_deny); |
| 1217 | if (status) |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1218 | return status; |
| 1219 | status = nfsd4_decode_state_owner4(argp, &open->op_clientid, |
| 1220 | &open->op_owner); |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1221 | if (status) |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1222 | return status; |
Chuck Lever | e6ec04b | 2020-11-16 17:41:21 -0500 | [diff] [blame] | 1223 | status = nfsd4_decode_openflag4(argp, open); |
| 1224 | if (status) |
| 1225 | return status; |
Chuck Lever | 61e5e0b | 2020-11-01 12:04:06 -0500 | [diff] [blame] | 1226 | return nfsd4_decode_open_claim4(argp, open); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | } |
| 1228 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1229 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf) |
| 1231 | { |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1232 | __be32 status; |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1233 | |
| 1234 | if (argp->minorversion >= 1) |
| 1235 | return nfserr_notsupp; |
| 1236 | |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1237 | status = nfsd4_decode_stateid4(argp, &open_conf->oc_req_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1238 | if (status) |
| 1239 | return status; |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1240 | if (xdr_stream_decode_u32(argp->xdr, &open_conf->oc_seqid) < 0) |
| 1241 | return nfserr_bad_xdr; |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1242 | |
Chuck Lever | 06bee69 | 2020-11-03 14:18:57 -0500 | [diff] [blame] | 1243 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1246 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down) |
| 1248 | { |
Chuck Lever | dca71651 | 2020-11-03 14:21:01 -0500 | [diff] [blame] | 1249 | __be32 status; |
| 1250 | |
| 1251 | status = nfsd4_decode_stateid4(argp, &open_down->od_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1252 | if (status) |
| 1253 | return status; |
Chuck Lever | dca71651 | 2020-11-03 14:21:01 -0500 | [diff] [blame] | 1254 | if (xdr_stream_decode_u32(argp->xdr, &open_down->od_seqid) < 0) |
| 1255 | return nfserr_bad_xdr; |
| 1256 | /* deleg_want is ignored */ |
Benny Halevy | 2c8bd7e | 2012-02-16 20:57:09 +0200 | [diff] [blame] | 1257 | status = nfsd4_decode_share_access(argp, &open_down->od_share_access, |
| 1258 | &open_down->od_deleg_want, NULL); |
J. Bruce Fields | 04f9e66 | 2011-10-10 14:37:13 -0400 | [diff] [blame] | 1259 | if (status) |
| 1260 | return status; |
Chuck Lever | dca71651 | 2020-11-03 14:21:01 -0500 | [diff] [blame] | 1261 | return nfsd4_decode_share_deny(argp, &open_down->od_share_deny); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1264 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh) |
| 1266 | { |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1267 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1269 | if (xdr_stream_decode_u32(argp->xdr, &putfh->pf_fhlen) < 0) |
| 1270 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | if (putfh->pf_fhlen > NFS4_FHSIZE) |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1272 | return nfserr_bad_xdr; |
| 1273 | p = xdr_inline_decode(argp->xdr, putfh->pf_fhlen); |
| 1274 | if (!p) |
| 1275 | return nfserr_bad_xdr; |
| 1276 | putfh->pf_fhval = svcxdr_tmpalloc(argp, putfh->pf_fhlen); |
| 1277 | if (!putfh->pf_fhval) |
| 1278 | return nfserr_jukebox; |
| 1279 | memcpy(putfh->pf_fhval, p, putfh->pf_fhlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | |
Chuck Lever | a73bed9 | 2020-11-03 14:23:02 -0500 | [diff] [blame] | 1281 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1284 | static __be32 |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1285 | nfsd4_decode_putpubfh(struct nfsd4_compoundargs *argp, void *p) |
| 1286 | { |
| 1287 | if (argp->minorversion == 0) |
| 1288 | return nfs_ok; |
| 1289 | return nfserr_notsupp; |
| 1290 | } |
| 1291 | |
| 1292 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read) |
| 1294 | { |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame] | 1295 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame] | 1297 | status = nfsd4_decode_stateid4(argp, &read->rd_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1298 | if (status) |
| 1299 | return status; |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame] | 1300 | if (xdr_stream_decode_u64(argp->xdr, &read->rd_offset) < 0) |
| 1301 | return nfserr_bad_xdr; |
| 1302 | if (xdr_stream_decode_u32(argp->xdr, &read->rd_length) < 0) |
| 1303 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | |
Chuck Lever | 3909c3b | 2020-11-03 14:28:24 -0500 | [diff] [blame] | 1305 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1308 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir) |
| 1310 | { |
Chuck Lever | 0dfaf2a | 2020-11-03 14:30:59 -0500 | [diff] [blame] | 1311 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | |
Chuck Lever | 0dfaf2a | 2020-11-03 14:30:59 -0500 | [diff] [blame] | 1313 | if (xdr_stream_decode_u64(argp->xdr, &readdir->rd_cookie) < 0) |
| 1314 | return nfserr_bad_xdr; |
| 1315 | status = nfsd4_decode_verifier4(argp, &readdir->rd_verf); |
| 1316 | if (status) |
| 1317 | return status; |
| 1318 | if (xdr_stream_decode_u32(argp->xdr, &readdir->rd_dircount) < 0) |
| 1319 | return nfserr_bad_xdr; |
| 1320 | if (xdr_stream_decode_u32(argp->xdr, &readdir->rd_maxcount) < 0) |
| 1321 | return nfserr_bad_xdr; |
| 1322 | if (xdr_stream_decode_uint32_array(argp->xdr, readdir->rd_bmval, |
| 1323 | ARRAY_SIZE(readdir->rd_bmval)) < 0) |
| 1324 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | |
Chuck Lever | 0dfaf2a | 2020-11-03 14:30:59 -0500 | [diff] [blame] | 1326 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1329 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove) |
| 1331 | { |
Chuck Lever | b7f5fbf | 2020-11-04 15:04:36 -0500 | [diff] [blame] | 1332 | return nfsd4_decode_component4(argp, &remove->rm_name, &remove->rm_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1335 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename) |
| 1337 | { |
Chuck Lever | ba881a0 | 2020-11-04 15:05:58 -0500 | [diff] [blame] | 1338 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | |
Chuck Lever | ba881a0 | 2020-11-04 15:05:58 -0500 | [diff] [blame] | 1340 | status = nfsd4_decode_component4(argp, &rename->rn_sname, &rename->rn_snamelen); |
| 1341 | if (status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | return status; |
Chuck Lever | ba881a0 | 2020-11-04 15:05:58 -0500 | [diff] [blame] | 1343 | return nfsd4_decode_component4(argp, &rename->rn_tname, &rename->rn_tnamelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1346 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid) |
| 1348 | { |
Chuck Lever | d12f904 | 2020-11-04 15:08:50 -0500 | [diff] [blame] | 1349 | return nfsd4_decode_clientid4(argp, clientid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | } |
| 1351 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1352 | static __be32 |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1353 | nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp, |
| 1354 | struct nfsd4_secinfo *secinfo) |
| 1355 | { |
Chuck Lever | d0abdae | 2020-11-04 15:09:42 -0500 | [diff] [blame] | 1356 | return nfsd4_decode_component4(argp, &secinfo->si_name, &secinfo->si_namelen); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr) |
| 1361 | { |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1362 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | |
Chuck Lever | 44592fe | 2020-11-21 14:14:59 -0500 | [diff] [blame] | 1364 | status = nfsd4_decode_stateid4(argp, &setattr->sa_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1365 | if (status) |
| 1366 | return status; |
Chuck Lever | d1c263a | 2020-11-03 12:56:05 -0500 | [diff] [blame] | 1367 | return nfsd4_decode_fattr4(argp, setattr->sa_bmval, |
| 1368 | ARRAY_SIZE(setattr->sa_bmval), |
| 1369 | &setattr->sa_iattr, &setattr->sa_acl, |
| 1370 | &setattr->sa_label, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1373 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid) |
| 1375 | { |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1376 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1378 | if (argp->minorversion >= 1) |
| 1379 | return nfserr_notsupp; |
| 1380 | |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1381 | status = nfsd4_decode_verifier4(argp, &setclientid->se_verf); |
| 1382 | if (status) |
| 1383 | return status; |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1384 | status = nfsd4_decode_opaque(argp, &setclientid->se_name); |
| 1385 | if (status) |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1386 | return status; |
| 1387 | if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_prog) < 0) |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1388 | return nfserr_bad_xdr; |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1389 | if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_netid_len) < 0) |
| 1390 | return nfserr_bad_xdr; |
| 1391 | p = xdr_inline_decode(argp->xdr, setclientid->se_callback_netid_len); |
| 1392 | if (!p) |
| 1393 | return nfserr_bad_xdr; |
| 1394 | setclientid->se_callback_netid_val = svcxdr_tmpalloc(argp, |
| 1395 | setclientid->se_callback_netid_len); |
| 1396 | if (!setclientid->se_callback_netid_val) |
| 1397 | return nfserr_jukebox; |
| 1398 | memcpy(setclientid->se_callback_netid_val, p, |
| 1399 | setclientid->se_callback_netid_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1401 | if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_addr_len) < 0) |
| 1402 | return nfserr_bad_xdr; |
| 1403 | p = xdr_inline_decode(argp->xdr, setclientid->se_callback_addr_len); |
| 1404 | if (!p) |
| 1405 | return nfserr_bad_xdr; |
| 1406 | setclientid->se_callback_addr_val = svcxdr_tmpalloc(argp, |
| 1407 | setclientid->se_callback_addr_len); |
| 1408 | if (!setclientid->se_callback_addr_val) |
| 1409 | return nfserr_jukebox; |
| 1410 | memcpy(setclientid->se_callback_addr_val, p, |
| 1411 | setclientid->se_callback_addr_len); |
| 1412 | if (xdr_stream_decode_u32(argp->xdr, &setclientid->se_callback_ident) < 0) |
| 1413 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | |
Chuck Lever | 92fa6c0 | 2020-11-03 14:35:02 -0500 | [diff] [blame] | 1415 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1418 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c) |
| 1420 | { |
Chuck Lever | d1ca551 | 2020-11-04 15:12:33 -0500 | [diff] [blame] | 1421 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1423 | if (argp->minorversion >= 1) |
| 1424 | return nfserr_notsupp; |
| 1425 | |
Chuck Lever | d1ca551 | 2020-11-04 15:12:33 -0500 | [diff] [blame] | 1426 | status = nfsd4_decode_clientid4(argp, &scd_c->sc_clientid); |
| 1427 | if (status) |
| 1428 | return status; |
| 1429 | return nfsd4_decode_verifier4(argp, &scd_c->sc_confirm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | /* Also used for NVERIFY */ |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1433 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify) |
| 1435 | { |
Chuck Lever | 67cd453 | 2020-11-03 14:40:32 -0500 | [diff] [blame] | 1436 | __be32 *p, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | |
Chuck Lever | 67cd453 | 2020-11-03 14:40:32 -0500 | [diff] [blame] | 1438 | status = nfsd4_decode_bitmap4(argp, verify->ve_bmval, |
| 1439 | ARRAY_SIZE(verify->ve_bmval)); |
| 1440 | if (status) |
| 1441 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | |
| 1443 | /* For convenience's sake, we compare raw xdr'd attributes in |
J. Bruce Fields | e5f9570 | 2012-11-30 17:24:18 -0500 | [diff] [blame] | 1444 | * nfsd4_proc_verify */ |
| 1445 | |
Chuck Lever | 67cd453 | 2020-11-03 14:40:32 -0500 | [diff] [blame] | 1446 | if (xdr_stream_decode_u32(argp->xdr, &verify->ve_attrlen) < 0) |
| 1447 | return nfserr_bad_xdr; |
| 1448 | p = xdr_inline_decode(argp->xdr, verify->ve_attrlen); |
| 1449 | if (!p) |
| 1450 | return nfserr_bad_xdr; |
| 1451 | verify->ve_attrval = svcxdr_tmpalloc(argp, verify->ve_attrlen); |
| 1452 | if (!verify->ve_attrval) |
| 1453 | return nfserr_jukebox; |
| 1454 | memcpy(verify->ve_attrval, p, verify->ve_attrlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | |
Chuck Lever | 67cd453 | 2020-11-03 14:40:32 -0500 | [diff] [blame] | 1456 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | } |
| 1458 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1459 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write) |
| 1461 | { |
Chuck Lever | 244e2be | 2020-11-03 14:44:28 -0500 | [diff] [blame] | 1462 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | |
Chuck Lever | 244e2be | 2020-11-03 14:44:28 -0500 | [diff] [blame] | 1464 | status = nfsd4_decode_stateid4(argp, &write->wr_stateid); |
Benny Halevy | e31a1b6 | 2008-08-12 20:46:18 +0300 | [diff] [blame] | 1465 | if (status) |
| 1466 | return status; |
Chuck Lever | 244e2be | 2020-11-03 14:44:28 -0500 | [diff] [blame] | 1467 | if (xdr_stream_decode_u64(argp->xdr, &write->wr_offset) < 0) |
| 1468 | return nfserr_bad_xdr; |
| 1469 | if (xdr_stream_decode_u32(argp->xdr, &write->wr_stable_how) < 0) |
| 1470 | return nfserr_bad_xdr; |
Kinglong Mee | 54bbb7d | 2016-12-31 20:59:53 +0800 | [diff] [blame] | 1471 | if (write->wr_stable_how > NFS_FILE_SYNC) |
Chuck Lever | 244e2be | 2020-11-03 14:44:28 -0500 | [diff] [blame] | 1472 | return nfserr_bad_xdr; |
| 1473 | if (xdr_stream_decode_u32(argp->xdr, &write->wr_buflen) < 0) |
| 1474 | return nfserr_bad_xdr; |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 1475 | if (!xdr_stream_subsegment(argp->xdr, &write->wr_payload, write->wr_buflen)) |
Chuck Lever | 244e2be | 2020-11-03 14:44:28 -0500 | [diff] [blame] | 1476 | return nfserr_bad_xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | |
Chuck Lever | 244e2be | 2020-11-03 14:44:28 -0500 | [diff] [blame] | 1478 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1481 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner) |
| 1483 | { |
Chuck Lever | a4a80c1 | 2020-11-04 13:42:25 -0500 | [diff] [blame] | 1484 | __be32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 1486 | if (argp->minorversion >= 1) |
| 1487 | return nfserr_notsupp; |
| 1488 | |
Chuck Lever | a4a80c1 | 2020-11-04 13:42:25 -0500 | [diff] [blame] | 1489 | status = nfsd4_decode_state_owner4(argp, &rlockowner->rl_clientid, |
| 1490 | &rlockowner->rl_owner); |
| 1491 | if (status) |
| 1492 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | |
Andy Adamson | 60adfc5 | 2009-04-03 08:28:50 +0300 | [diff] [blame] | 1494 | if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid)) |
| 1495 | return nfserr_inval; |
Chuck Lever | a4a80c1 | 2020-11-04 13:42:25 -0500 | [diff] [blame] | 1496 | |
| 1497 | return nfs_ok; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | } |
| 1499 | |
Chuck Lever | 0f81d96 | 2020-11-03 13:14:35 -0500 | [diff] [blame] | 1500 | static __be32 nfsd4_decode_backchannel_ctl(struct nfsd4_compoundargs *argp, struct nfsd4_backchannel_ctl *bc) |
| 1501 | { |
| 1502 | if (xdr_stream_decode_u32(argp->xdr, &bc->bc_cb_program) < 0) |
| 1503 | return nfserr_bad_xdr; |
| 1504 | return nfsd4_decode_cb_sec(argp, &bc->bc_cb_sec); |
| 1505 | } |
| 1506 | |
Chuck Lever | 571e045 | 2020-11-03 13:16:23 -0500 | [diff] [blame] | 1507 | static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp, struct nfsd4_bind_conn_to_session *bcts) |
| 1508 | { |
| 1509 | u32 use_conn_in_rdma_mode; |
| 1510 | __be32 status; |
| 1511 | |
| 1512 | status = nfsd4_decode_sessionid4(argp, &bcts->sessionid); |
| 1513 | if (status) |
| 1514 | return status; |
| 1515 | if (xdr_stream_decode_u32(argp->xdr, &bcts->dir) < 0) |
| 1516 | return nfserr_bad_xdr; |
| 1517 | if (xdr_stream_decode_u32(argp->xdr, &use_conn_in_rdma_mode) < 0) |
| 1518 | return nfserr_bad_xdr; |
| 1519 | |
| 1520 | return nfs_ok; |
| 1521 | } |
| 1522 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 1523 | static __be32 |
Chuck Lever | 2548aa7 | 2020-11-03 11:13:00 -0500 | [diff] [blame] | 1524 | nfsd4_decode_state_protect_ops(struct nfsd4_compoundargs *argp, |
| 1525 | struct nfsd4_exchange_id *exid) |
| 1526 | { |
| 1527 | __be32 status; |
| 1528 | |
| 1529 | status = nfsd4_decode_bitmap4(argp, exid->spo_must_enforce, |
| 1530 | ARRAY_SIZE(exid->spo_must_enforce)); |
| 1531 | if (status) |
| 1532 | return nfserr_bad_xdr; |
| 1533 | status = nfsd4_decode_bitmap4(argp, exid->spo_must_allow, |
| 1534 | ARRAY_SIZE(exid->spo_must_allow)); |
| 1535 | if (status) |
| 1536 | return nfserr_bad_xdr; |
| 1537 | |
| 1538 | return nfs_ok; |
| 1539 | } |
| 1540 | |
Chuck Lever | 547bfeb | 2020-11-03 11:17:50 -0500 | [diff] [blame] | 1541 | /* |
| 1542 | * This implementation currently does not support SP4_SSV. |
| 1543 | * This decoder simply skips over these arguments. |
| 1544 | */ |
| 1545 | static noinline __be32 |
| 1546 | nfsd4_decode_ssv_sp_parms(struct nfsd4_compoundargs *argp, |
| 1547 | struct nfsd4_exchange_id *exid) |
| 1548 | { |
| 1549 | u32 count, window, num_gss_handles; |
| 1550 | __be32 status; |
| 1551 | |
| 1552 | /* ssp_ops */ |
| 1553 | status = nfsd4_decode_state_protect_ops(argp, exid); |
| 1554 | if (status) |
| 1555 | return status; |
| 1556 | |
| 1557 | /* ssp_hash_algs<> */ |
| 1558 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 1559 | return nfserr_bad_xdr; |
| 1560 | while (count--) { |
| 1561 | status = nfsd4_decode_ignored_string(argp, 0); |
| 1562 | if (status) |
| 1563 | return status; |
| 1564 | } |
| 1565 | |
| 1566 | /* ssp_encr_algs<> */ |
| 1567 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 1568 | return nfserr_bad_xdr; |
| 1569 | while (count--) { |
| 1570 | status = nfsd4_decode_ignored_string(argp, 0); |
| 1571 | if (status) |
| 1572 | return status; |
| 1573 | } |
| 1574 | |
| 1575 | if (xdr_stream_decode_u32(argp->xdr, &window) < 0) |
| 1576 | return nfserr_bad_xdr; |
| 1577 | if (xdr_stream_decode_u32(argp->xdr, &num_gss_handles) < 0) |
| 1578 | return nfserr_bad_xdr; |
| 1579 | |
| 1580 | return nfs_ok; |
| 1581 | } |
| 1582 | |
Chuck Lever | 2548aa7 | 2020-11-03 11:13:00 -0500 | [diff] [blame] | 1583 | static __be32 |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1584 | nfsd4_decode_state_protect4_a(struct nfsd4_compoundargs *argp, |
| 1585 | struct nfsd4_exchange_id *exid) |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1586 | { |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1587 | __be32 status; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1588 | |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1589 | if (xdr_stream_decode_u32(argp->xdr, &exid->spa_how) < 0) |
J. Bruce Fields | a084daf | 2011-10-10 15:07:40 -0400 | [diff] [blame] | 1590 | return nfserr_bad_xdr; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1591 | switch (exid->spa_how) { |
| 1592 | case SP4_NONE: |
| 1593 | break; |
| 1594 | case SP4_MACH_CRED: |
Chuck Lever | 2548aa7 | 2020-11-03 11:13:00 -0500 | [diff] [blame] | 1595 | status = nfsd4_decode_state_protect_ops(argp, exid); |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 1596 | if (status) |
Chuck Lever | 2548aa7 | 2020-11-03 11:13:00 -0500 | [diff] [blame] | 1597 | return status; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1598 | break; |
| 1599 | case SP4_SSV: |
Chuck Lever | 547bfeb | 2020-11-03 11:17:50 -0500 | [diff] [blame] | 1600 | status = nfsd4_decode_ssv_sp_parms(argp, exid); |
Chuck Lever | 2548aa7 | 2020-11-03 11:13:00 -0500 | [diff] [blame] | 1601 | if (status) |
| 1602 | return status; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1603 | break; |
| 1604 | default: |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1605 | return nfserr_bad_xdr; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 1606 | } |
| 1607 | |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1608 | return nfs_ok; |
| 1609 | } |
| 1610 | |
| 1611 | static __be32 |
Chuck Lever | 10ff842 | 2020-11-16 15:21:55 -0500 | [diff] [blame] | 1612 | nfsd4_decode_nfs_impl_id4(struct nfsd4_compoundargs *argp, |
| 1613 | struct nfsd4_exchange_id *exid) |
| 1614 | { |
| 1615 | __be32 status; |
| 1616 | u32 count; |
| 1617 | |
| 1618 | if (xdr_stream_decode_u32(argp->xdr, &count) < 0) |
| 1619 | return nfserr_bad_xdr; |
| 1620 | switch (count) { |
| 1621 | case 0: |
| 1622 | break; |
| 1623 | case 1: |
| 1624 | /* Note that RFC 8881 places no length limit on |
| 1625 | * nii_domain, but this implementation permits no |
| 1626 | * more than NFS4_OPAQUE_LIMIT bytes */ |
| 1627 | status = nfsd4_decode_opaque(argp, &exid->nii_domain); |
| 1628 | if (status) |
| 1629 | return status; |
| 1630 | /* Note that RFC 8881 places no length limit on |
| 1631 | * nii_name, but this implementation permits no |
| 1632 | * more than NFS4_OPAQUE_LIMIT bytes */ |
| 1633 | status = nfsd4_decode_opaque(argp, &exid->nii_name); |
| 1634 | if (status) |
| 1635 | return status; |
| 1636 | status = nfsd4_decode_nfstime4(argp, &exid->nii_time); |
| 1637 | if (status) |
| 1638 | return status; |
| 1639 | break; |
| 1640 | default: |
| 1641 | return nfserr_bad_xdr; |
| 1642 | } |
| 1643 | |
| 1644 | return nfs_ok; |
| 1645 | } |
| 1646 | |
| 1647 | static __be32 |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1648 | nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp, |
| 1649 | struct nfsd4_exchange_id *exid) |
| 1650 | { |
Chuck Lever | 10ff842 | 2020-11-16 15:21:55 -0500 | [diff] [blame] | 1651 | __be32 status; |
Chuck Lever | 523ec6e | 2020-11-02 15:19:12 -0500 | [diff] [blame] | 1652 | |
| 1653 | status = nfsd4_decode_verifier4(argp, &exid->verifier); |
| 1654 | if (status) |
| 1655 | return status; |
| 1656 | status = nfsd4_decode_opaque(argp, &exid->clname); |
| 1657 | if (status) |
| 1658 | return status; |
| 1659 | if (xdr_stream_decode_u32(argp->xdr, &exid->flags) < 0) |
| 1660 | return nfserr_bad_xdr; |
| 1661 | status = nfsd4_decode_state_protect4_a(argp, exid); |
| 1662 | if (status) |
| 1663 | return status; |
Chuck Lever | 10ff842 | 2020-11-16 15:21:55 -0500 | [diff] [blame] | 1664 | return nfsd4_decode_nfs_impl_id4(argp, exid); |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | static __be32 |
Chuck Lever | 3a3f1fb | 2020-11-16 15:35:05 -0500 | [diff] [blame] | 1668 | nfsd4_decode_channel_attrs4(struct nfsd4_compoundargs *argp, |
| 1669 | struct nfsd4_channel_attrs *ca) |
| 1670 | { |
| 1671 | __be32 *p; |
| 1672 | |
| 1673 | p = xdr_inline_decode(argp->xdr, XDR_UNIT * 7); |
| 1674 | if (!p) |
| 1675 | return nfserr_bad_xdr; |
| 1676 | |
| 1677 | /* headerpadsz is ignored */ |
| 1678 | p++; |
| 1679 | ca->maxreq_sz = be32_to_cpup(p++); |
| 1680 | ca->maxresp_sz = be32_to_cpup(p++); |
| 1681 | ca->maxresp_cached = be32_to_cpup(p++); |
| 1682 | ca->maxops = be32_to_cpup(p++); |
| 1683 | ca->maxreqs = be32_to_cpup(p++); |
| 1684 | ca->nr_rdma_attrs = be32_to_cpup(p); |
| 1685 | switch (ca->nr_rdma_attrs) { |
| 1686 | case 0: |
| 1687 | break; |
| 1688 | case 1: |
| 1689 | if (xdr_stream_decode_u32(argp->xdr, &ca->rdma_attrs) < 0) |
| 1690 | return nfserr_bad_xdr; |
| 1691 | break; |
| 1692 | default: |
| 1693 | return nfserr_bad_xdr; |
| 1694 | } |
| 1695 | |
| 1696 | return nfs_ok; |
| 1697 | } |
| 1698 | |
| 1699 | static __be32 |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1700 | nfsd4_decode_create_session(struct nfsd4_compoundargs *argp, |
| 1701 | struct nfsd4_create_session *sess) |
| 1702 | { |
Chuck Lever | 81243e3 | 2020-11-03 14:52:44 -0500 | [diff] [blame] | 1703 | __be32 status; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1704 | |
Chuck Lever | 81243e3 | 2020-11-03 14:52:44 -0500 | [diff] [blame] | 1705 | status = nfsd4_decode_clientid4(argp, &sess->clientid); |
| 1706 | if (status) |
| 1707 | return status; |
| 1708 | if (xdr_stream_decode_u32(argp->xdr, &sess->seqid) < 0) |
| 1709 | return nfserr_bad_xdr; |
| 1710 | if (xdr_stream_decode_u32(argp->xdr, &sess->flags) < 0) |
| 1711 | return nfserr_bad_xdr; |
Chuck Lever | 3a3f1fb | 2020-11-16 15:35:05 -0500 | [diff] [blame] | 1712 | status = nfsd4_decode_channel_attrs4(argp, &sess->fore_channel); |
| 1713 | if (status) |
| 1714 | return status; |
| 1715 | status = nfsd4_decode_channel_attrs4(argp, &sess->back_channel); |
| 1716 | if (status) |
| 1717 | return status; |
Chuck Lever | 81243e3 | 2020-11-03 14:52:44 -0500 | [diff] [blame] | 1718 | if (xdr_stream_decode_u32(argp->xdr, &sess->callback_prog) < 0) |
| 1719 | return nfserr_bad_xdr; |
| 1720 | status = nfsd4_decode_cb_sec(argp, &sess->cb_sec); |
| 1721 | if (status) |
| 1722 | return status; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 1723 | |
Chuck Lever | 81243e3 | 2020-11-03 14:52:44 -0500 | [diff] [blame] | 1724 | return nfs_ok; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1725 | } |
| 1726 | |
| 1727 | static __be32 |
| 1728 | nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp, |
| 1729 | struct nfsd4_destroy_session *destroy_session) |
| 1730 | { |
Chuck Lever | 94e254a | 2020-11-04 13:50:55 -0500 | [diff] [blame] | 1731 | return nfsd4_decode_sessionid4(argp, &destroy_session->sessionid); |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | static __be32 |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 1735 | nfsd4_decode_free_stateid(struct nfsd4_compoundargs *argp, |
| 1736 | struct nfsd4_free_stateid *free_stateid) |
| 1737 | { |
Chuck Lever | aec387d | 2020-11-01 13:38:27 -0500 | [diff] [blame] | 1738 | return nfsd4_decode_stateid4(argp, &free_stateid->fr_stateid); |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 1739 | } |
| 1740 | |
| 1741 | static __be32 |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1742 | nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid) |
| 1743 | { |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1744 | int i; |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1745 | __be32 *p, status; |
| 1746 | struct nfsd4_test_stateid_id *stateid; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1747 | |
| 1748 | READ_BUF(4); |
| 1749 | test_stateid->ts_num_ids = ntohl(*p++); |
| 1750 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1751 | INIT_LIST_HEAD(&test_stateid->ts_stateid_list); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1752 | |
| 1753 | for (i = 0; i < test_stateid->ts_num_ids; i++) { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 1754 | stateid = svcxdr_tmpalloc(argp, sizeof(*stateid)); |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1755 | if (!stateid) { |
Al Viro | afcf679 | 2012-04-13 00:15:37 -0400 | [diff] [blame] | 1756 | status = nfserrno(-ENOMEM); |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1757 | goto out; |
| 1758 | } |
| 1759 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1760 | INIT_LIST_HEAD(&stateid->ts_id_list); |
| 1761 | list_add_tail(&stateid->ts_id_list, &test_stateid->ts_stateid_list); |
| 1762 | |
| 1763 | status = nfsd4_decode_stateid(argp, &stateid->ts_id_stateid); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1764 | if (status) |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 1765 | goto out; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | status = 0; |
| 1769 | out: |
| 1770 | return status; |
| 1771 | xdr_error: |
| 1772 | dprintk("NFSD: xdr error (%s:%d)\n", __FILE__, __LINE__); |
| 1773 | status = nfserr_bad_xdr; |
| 1774 | goto out; |
| 1775 | } |
| 1776 | |
Mi Jinlong | 345c284 | 2011-10-20 17:51:39 +0800 | [diff] [blame] | 1777 | static __be32 nfsd4_decode_destroy_clientid(struct nfsd4_compoundargs *argp, struct nfsd4_destroy_clientid *dc) |
| 1778 | { |
| 1779 | DECODE_HEAD; |
| 1780 | |
| 1781 | READ_BUF(8); |
| 1782 | COPYMEM(&dc->clientid, 8); |
| 1783 | |
| 1784 | DECODE_TAIL; |
| 1785 | } |
| 1786 | |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1787 | static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, struct nfsd4_reclaim_complete *rc) |
| 1788 | { |
| 1789 | DECODE_HEAD; |
| 1790 | |
| 1791 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 1792 | rc->rca_one_fs = be32_to_cpup(p++); |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 1793 | |
| 1794 | DECODE_TAIL; |
| 1795 | } |
| 1796 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1797 | #ifdef CONFIG_NFSD_PNFS |
| 1798 | static __be32 |
| 1799 | nfsd4_decode_getdeviceinfo(struct nfsd4_compoundargs *argp, |
| 1800 | struct nfsd4_getdeviceinfo *gdev) |
| 1801 | { |
Chuck Lever | 0449597 | 2020-11-03 15:03:50 -0500 | [diff] [blame] | 1802 | __be32 status; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1803 | |
Chuck Lever | 0449597 | 2020-11-03 15:03:50 -0500 | [diff] [blame] | 1804 | status = nfsd4_decode_deviceid4(argp, &gdev->gd_devid); |
| 1805 | if (status) |
| 1806 | return status; |
| 1807 | if (xdr_stream_decode_u32(argp->xdr, &gdev->gd_layout_type) < 0) |
| 1808 | return nfserr_bad_xdr; |
| 1809 | if (xdr_stream_decode_u32(argp->xdr, &gdev->gd_maxcount) < 0) |
| 1810 | return nfserr_bad_xdr; |
| 1811 | if (xdr_stream_decode_uint32_array(argp->xdr, |
| 1812 | &gdev->gd_notify_types, 1) < 0) |
| 1813 | return nfserr_bad_xdr; |
| 1814 | |
| 1815 | return nfs_ok; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | static __be32 |
Chuck Lever | 5185980 | 2020-11-04 10:40:07 -0500 | [diff] [blame] | 1819 | nfsd4_decode_layoutcommit(struct nfsd4_compoundargs *argp, |
| 1820 | struct nfsd4_layoutcommit *lcp) |
| 1821 | { |
| 1822 | __be32 *p, status; |
| 1823 | |
| 1824 | if (xdr_stream_decode_u64(argp->xdr, &lcp->lc_seg.offset) < 0) |
| 1825 | return nfserr_bad_xdr; |
| 1826 | if (xdr_stream_decode_u64(argp->xdr, &lcp->lc_seg.length) < 0) |
| 1827 | return nfserr_bad_xdr; |
| 1828 | if (xdr_stream_decode_bool(argp->xdr, &lcp->lc_reclaim) < 0) |
| 1829 | return nfserr_bad_xdr; |
| 1830 | status = nfsd4_decode_stateid4(argp, &lcp->lc_sid); |
| 1831 | if (status) |
| 1832 | return status; |
| 1833 | if (xdr_stream_decode_u32(argp->xdr, &lcp->lc_newoffset) < 0) |
| 1834 | return nfserr_bad_xdr; |
| 1835 | if (lcp->lc_newoffset) { |
| 1836 | if (xdr_stream_decode_u64(argp->xdr, &lcp->lc_last_wr) < 0) |
| 1837 | return nfserr_bad_xdr; |
| 1838 | } else |
| 1839 | lcp->lc_last_wr = 0; |
| 1840 | p = xdr_inline_decode(argp->xdr, XDR_UNIT); |
| 1841 | if (!p) |
| 1842 | return nfserr_bad_xdr; |
| 1843 | if (xdr_item_is_present(p)) { |
| 1844 | status = nfsd4_decode_nfstime4(argp, &lcp->lc_mtime); |
| 1845 | if (status) |
| 1846 | return status; |
| 1847 | } else { |
| 1848 | lcp->lc_mtime.tv_nsec = UTIME_NOW; |
| 1849 | } |
| 1850 | return nfsd4_decode_layoutupdate4(argp, lcp); |
| 1851 | } |
| 1852 | |
| 1853 | static __be32 |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1854 | nfsd4_decode_layoutget(struct nfsd4_compoundargs *argp, |
| 1855 | struct nfsd4_layoutget *lgp) |
| 1856 | { |
Chuck Lever | c8e88e3 | 2020-11-03 15:06:04 -0500 | [diff] [blame] | 1857 | __be32 status; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1858 | |
Chuck Lever | c8e88e3 | 2020-11-03 15:06:04 -0500 | [diff] [blame] | 1859 | if (xdr_stream_decode_u32(argp->xdr, &lgp->lg_signal) < 0) |
| 1860 | return nfserr_bad_xdr; |
| 1861 | if (xdr_stream_decode_u32(argp->xdr, &lgp->lg_layout_type) < 0) |
| 1862 | return nfserr_bad_xdr; |
| 1863 | if (xdr_stream_decode_u32(argp->xdr, &lgp->lg_seg.iomode) < 0) |
| 1864 | return nfserr_bad_xdr; |
| 1865 | if (xdr_stream_decode_u64(argp->xdr, &lgp->lg_seg.offset) < 0) |
| 1866 | return nfserr_bad_xdr; |
| 1867 | if (xdr_stream_decode_u64(argp->xdr, &lgp->lg_seg.length) < 0) |
| 1868 | return nfserr_bad_xdr; |
| 1869 | if (xdr_stream_decode_u64(argp->xdr, &lgp->lg_minlength) < 0) |
| 1870 | return nfserr_bad_xdr; |
| 1871 | status = nfsd4_decode_stateid4(argp, &lgp->lg_sid); |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1872 | if (status) |
| 1873 | return status; |
Chuck Lever | c8e88e3 | 2020-11-03 15:06:04 -0500 | [diff] [blame] | 1874 | if (xdr_stream_decode_u32(argp->xdr, &lgp->lg_maxcount) < 0) |
| 1875 | return nfserr_bad_xdr; |
Kinglong Mee | db59c0e | 2015-03-19 19:04:41 +0800 | [diff] [blame] | 1876 | |
Chuck Lever | c8e88e3 | 2020-11-03 15:06:04 -0500 | [diff] [blame] | 1877 | return nfs_ok; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | static __be32 |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1881 | nfsd4_decode_layoutreturn(struct nfsd4_compoundargs *argp, |
| 1882 | struct nfsd4_layoutreturn *lrp) |
| 1883 | { |
Chuck Lever | 645fcad | 2020-11-04 10:42:25 -0500 | [diff] [blame] | 1884 | if (xdr_stream_decode_bool(argp->xdr, &lrp->lr_reclaim) < 0) |
| 1885 | return nfserr_bad_xdr; |
| 1886 | if (xdr_stream_decode_u32(argp->xdr, &lrp->lr_layout_type) < 0) |
| 1887 | return nfserr_bad_xdr; |
| 1888 | if (xdr_stream_decode_u32(argp->xdr, &lrp->lr_seg.iomode) < 0) |
| 1889 | return nfserr_bad_xdr; |
| 1890 | return nfsd4_decode_layoutreturn4(argp, lrp); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 1891 | } |
| 1892 | #endif /* CONFIG_NFSD_PNFS */ |
| 1893 | |
Chuck Lever | 53d7087 | 2020-11-03 14:33:12 -0500 | [diff] [blame] | 1894 | static __be32 nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp, |
| 1895 | struct nfsd4_secinfo_no_name *sin) |
| 1896 | { |
| 1897 | if (xdr_stream_decode_u32(argp->xdr, &sin->sin_style) < 0) |
| 1898 | return nfserr_bad_xdr; |
| 1899 | return nfs_ok; |
| 1900 | } |
| 1901 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 1902 | static __be32 |
Chuck Lever | cf907b1 | 2020-11-03 14:55:19 -0500 | [diff] [blame^] | 1903 | nfsd4_decode_sequence(struct nfsd4_compoundargs *argp, |
| 1904 | struct nfsd4_sequence *seq) |
| 1905 | { |
| 1906 | __be32 *p, status; |
| 1907 | |
| 1908 | status = nfsd4_decode_sessionid4(argp, &seq->sessionid); |
| 1909 | if (status) |
| 1910 | return status; |
| 1911 | p = xdr_inline_decode(argp->xdr, XDR_UNIT * 4); |
| 1912 | if (!p) |
| 1913 | return nfserr_bad_xdr; |
| 1914 | seq->seqid = be32_to_cpup(p++); |
| 1915 | seq->slotid = be32_to_cpup(p++); |
| 1916 | seq->maxslots = be32_to_cpup(p++); |
| 1917 | seq->cachethis = be32_to_cpup(p); |
| 1918 | |
| 1919 | return nfs_ok; |
| 1920 | } |
| 1921 | |
| 1922 | static __be32 |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 1923 | nfsd4_decode_fallocate(struct nfsd4_compoundargs *argp, |
| 1924 | struct nfsd4_fallocate *fallocate) |
| 1925 | { |
| 1926 | DECODE_HEAD; |
| 1927 | |
| 1928 | status = nfsd4_decode_stateid(argp, &fallocate->falloc_stateid); |
| 1929 | if (status) |
| 1930 | return status; |
| 1931 | |
| 1932 | READ_BUF(16); |
| 1933 | p = xdr_decode_hyper(p, &fallocate->falloc_offset); |
| 1934 | xdr_decode_hyper(p, &fallocate->falloc_length); |
| 1935 | |
| 1936 | DECODE_TAIL; |
| 1937 | } |
| 1938 | |
| 1939 | static __be32 |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1940 | nfsd4_decode_clone(struct nfsd4_compoundargs *argp, struct nfsd4_clone *clone) |
| 1941 | { |
| 1942 | DECODE_HEAD; |
| 1943 | |
| 1944 | status = nfsd4_decode_stateid(argp, &clone->cl_src_stateid); |
| 1945 | if (status) |
| 1946 | return status; |
| 1947 | status = nfsd4_decode_stateid(argp, &clone->cl_dst_stateid); |
| 1948 | if (status) |
| 1949 | return status; |
| 1950 | |
| 1951 | READ_BUF(8 + 8 + 8); |
| 1952 | p = xdr_decode_hyper(p, &clone->cl_src_pos); |
| 1953 | p = xdr_decode_hyper(p, &clone->cl_dst_pos); |
| 1954 | p = xdr_decode_hyper(p, &clone->cl_count); |
| 1955 | DECODE_TAIL; |
| 1956 | } |
| 1957 | |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1958 | static __be32 nfsd4_decode_nl4_server(struct nfsd4_compoundargs *argp, |
| 1959 | struct nl4_server *ns) |
| 1960 | { |
| 1961 | DECODE_HEAD; |
| 1962 | struct nfs42_netaddr *naddr; |
| 1963 | |
| 1964 | READ_BUF(4); |
| 1965 | ns->nl4_type = be32_to_cpup(p++); |
| 1966 | |
| 1967 | /* currently support for 1 inter-server source server */ |
| 1968 | switch (ns->nl4_type) { |
| 1969 | case NL4_NETADDR: |
| 1970 | naddr = &ns->u.nl4_addr; |
| 1971 | |
| 1972 | READ_BUF(4); |
| 1973 | naddr->netid_len = be32_to_cpup(p++); |
| 1974 | if (naddr->netid_len > RPCBIND_MAXNETIDLEN) |
| 1975 | goto xdr_error; |
| 1976 | |
| 1977 | READ_BUF(naddr->netid_len + 4); /* 4 for uaddr len */ |
| 1978 | COPYMEM(naddr->netid, naddr->netid_len); |
| 1979 | |
| 1980 | naddr->addr_len = be32_to_cpup(p++); |
| 1981 | if (naddr->addr_len > RPCBIND_MAXUADDRLEN) |
| 1982 | goto xdr_error; |
| 1983 | |
| 1984 | READ_BUF(naddr->addr_len); |
| 1985 | COPYMEM(naddr->addr, naddr->addr_len); |
| 1986 | break; |
| 1987 | default: |
| 1988 | goto xdr_error; |
| 1989 | } |
| 1990 | DECODE_TAIL; |
| 1991 | } |
| 1992 | |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 1993 | static __be32 |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1994 | nfsd4_decode_copy(struct nfsd4_compoundargs *argp, struct nfsd4_copy *copy) |
| 1995 | { |
| 1996 | DECODE_HEAD; |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 1997 | struct nl4_server *ns_dummy; |
| 1998 | int i, count; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 1999 | |
| 2000 | status = nfsd4_decode_stateid(argp, ©->cp_src_stateid); |
| 2001 | if (status) |
| 2002 | return status; |
| 2003 | status = nfsd4_decode_stateid(argp, ©->cp_dst_stateid); |
| 2004 | if (status) |
| 2005 | return status; |
| 2006 | |
| 2007 | READ_BUF(8 + 8 + 8 + 4 + 4 + 4); |
| 2008 | p = xdr_decode_hyper(p, ©->cp_src_pos); |
| 2009 | p = xdr_decode_hyper(p, ©->cp_dst_pos); |
| 2010 | p = xdr_decode_hyper(p, ©->cp_count); |
J. Bruce Fields | edcc845 | 2018-03-07 15:37:35 -0500 | [diff] [blame] | 2011 | p++; /* ca_consecutive: we always do consecutive copies */ |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 2012 | copy->cp_synchronous = be32_to_cpup(p++); |
Olga Kornievskaia | 84e1b21 | 2019-09-13 14:00:57 -0400 | [diff] [blame] | 2013 | |
| 2014 | count = be32_to_cpup(p++); |
| 2015 | |
| 2016 | copy->cp_intra = false; |
| 2017 | if (count == 0) { /* intra-server copy */ |
| 2018 | copy->cp_intra = true; |
| 2019 | goto intra; |
| 2020 | } |
| 2021 | |
| 2022 | /* decode all the supplied server addresses but use first */ |
| 2023 | status = nfsd4_decode_nl4_server(argp, ©->cp_src); |
| 2024 | if (status) |
| 2025 | return status; |
| 2026 | |
| 2027 | ns_dummy = kmalloc(sizeof(struct nl4_server), GFP_KERNEL); |
| 2028 | if (ns_dummy == NULL) |
| 2029 | return nfserrno(-ENOMEM); |
| 2030 | for (i = 0; i < count - 1; i++) { |
| 2031 | status = nfsd4_decode_nl4_server(argp, ns_dummy); |
| 2032 | if (status) { |
| 2033 | kfree(ns_dummy); |
| 2034 | return status; |
| 2035 | } |
| 2036 | } |
| 2037 | kfree(ns_dummy); |
| 2038 | intra: |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 2039 | |
| 2040 | DECODE_TAIL; |
| 2041 | } |
| 2042 | |
| 2043 | static __be32 |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 2044 | nfsd4_decode_offload_status(struct nfsd4_compoundargs *argp, |
| 2045 | struct nfsd4_offload_status *os) |
| 2046 | { |
| 2047 | return nfsd4_decode_stateid(argp, &os->stateid); |
| 2048 | } |
| 2049 | |
| 2050 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 2051 | nfsd4_decode_copy_notify(struct nfsd4_compoundargs *argp, |
| 2052 | struct nfsd4_copy_notify *cn) |
| 2053 | { |
Chuck Lever | 5aff7d0 | 2020-09-11 14:47:59 -0400 | [diff] [blame] | 2054 | __be32 status; |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 2055 | |
| 2056 | status = nfsd4_decode_stateid(argp, &cn->cpn_src_stateid); |
| 2057 | if (status) |
| 2058 | return status; |
| 2059 | return nfsd4_decode_nl4_server(argp, &cn->cpn_dst); |
| 2060 | } |
| 2061 | |
| 2062 | static __be32 |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 2063 | nfsd4_decode_seek(struct nfsd4_compoundargs *argp, struct nfsd4_seek *seek) |
| 2064 | { |
| 2065 | DECODE_HEAD; |
| 2066 | |
| 2067 | status = nfsd4_decode_stateid(argp, &seek->seek_stateid); |
| 2068 | if (status) |
| 2069 | return status; |
| 2070 | |
| 2071 | READ_BUF(8 + 4); |
| 2072 | p = xdr_decode_hyper(p, &seek->seek_offset); |
| 2073 | seek->seek_whence = be32_to_cpup(p); |
| 2074 | |
| 2075 | DECODE_TAIL; |
| 2076 | } |
| 2077 | |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2078 | /* |
| 2079 | * XDR data that is more than PAGE_SIZE in size is normally part of a |
| 2080 | * read or write. However, the size of extended attributes is limited |
| 2081 | * by the maximum request size, and then further limited by the underlying |
| 2082 | * filesystem limits. This can exceed PAGE_SIZE (currently, XATTR_SIZE_MAX |
| 2083 | * is 64k). Since there is no kvec- or page-based interface to xattrs, |
| 2084 | * and we're not dealing with contiguous pages, we need to do some copying. |
| 2085 | */ |
| 2086 | |
| 2087 | /* |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2088 | * Decode data into buffer. |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2089 | */ |
| 2090 | static __be32 |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2091 | nfsd4_vbuf_from_vector(struct nfsd4_compoundargs *argp, struct xdr_buf *xdr, |
| 2092 | char **bufp, u32 buflen) |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2093 | { |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2094 | struct page **pages = xdr->pages; |
| 2095 | struct kvec *head = xdr->head; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2096 | char *tmp, *dp; |
| 2097 | u32 len; |
| 2098 | |
| 2099 | if (buflen <= head->iov_len) { |
| 2100 | /* |
| 2101 | * We're in luck, the head has enough space. Just return |
| 2102 | * the head, no need for copying. |
| 2103 | */ |
| 2104 | *bufp = head->iov_base; |
| 2105 | return 0; |
| 2106 | } |
| 2107 | |
| 2108 | tmp = svcxdr_tmpalloc(argp, buflen); |
| 2109 | if (tmp == NULL) |
| 2110 | return nfserr_jukebox; |
| 2111 | |
| 2112 | dp = tmp; |
| 2113 | memcpy(dp, head->iov_base, head->iov_len); |
| 2114 | buflen -= head->iov_len; |
| 2115 | dp += head->iov_len; |
| 2116 | |
| 2117 | while (buflen > 0) { |
| 2118 | len = min_t(u32, buflen, PAGE_SIZE); |
| 2119 | memcpy(dp, page_address(*pages), len); |
| 2120 | |
| 2121 | buflen -= len; |
| 2122 | dp += len; |
| 2123 | pages++; |
| 2124 | } |
| 2125 | |
| 2126 | *bufp = tmp; |
| 2127 | return 0; |
| 2128 | } |
| 2129 | |
| 2130 | /* |
| 2131 | * Get a user extended attribute name from the XDR buffer. |
| 2132 | * It will not have the "user." prefix, so prepend it. |
| 2133 | * Lastly, check for nul characters in the name. |
| 2134 | */ |
| 2135 | static __be32 |
| 2136 | nfsd4_decode_xattr_name(struct nfsd4_compoundargs *argp, char **namep) |
| 2137 | { |
| 2138 | DECODE_HEAD; |
| 2139 | char *name, *sp, *dp; |
| 2140 | u32 namelen, cnt; |
| 2141 | |
| 2142 | READ_BUF(4); |
| 2143 | namelen = be32_to_cpup(p++); |
| 2144 | |
| 2145 | if (namelen > (XATTR_NAME_MAX - XATTR_USER_PREFIX_LEN)) |
| 2146 | return nfserr_nametoolong; |
| 2147 | |
| 2148 | if (namelen == 0) |
| 2149 | goto xdr_error; |
| 2150 | |
| 2151 | READ_BUF(namelen); |
| 2152 | |
| 2153 | name = svcxdr_tmpalloc(argp, namelen + XATTR_USER_PREFIX_LEN + 1); |
| 2154 | if (!name) |
| 2155 | return nfserr_jukebox; |
| 2156 | |
| 2157 | memcpy(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN); |
| 2158 | |
| 2159 | /* |
| 2160 | * Copy the extended attribute name over while checking for 0 |
| 2161 | * characters. |
| 2162 | */ |
| 2163 | sp = (char *)p; |
| 2164 | dp = name + XATTR_USER_PREFIX_LEN; |
| 2165 | cnt = namelen; |
| 2166 | |
| 2167 | while (cnt-- > 0) { |
| 2168 | if (*sp == '\0') |
| 2169 | goto xdr_error; |
| 2170 | *dp++ = *sp++; |
| 2171 | } |
| 2172 | *dp = '\0'; |
| 2173 | |
| 2174 | *namep = name; |
| 2175 | |
| 2176 | DECODE_TAIL; |
| 2177 | } |
| 2178 | |
| 2179 | /* |
| 2180 | * A GETXATTR op request comes without a length specifier. We just set the |
| 2181 | * maximum length for the reply based on XATTR_SIZE_MAX and the maximum |
| 2182 | * channel reply size. nfsd_getxattr will probe the length of the xattr, |
| 2183 | * check it against getxa_len, and allocate + return the value. |
| 2184 | */ |
| 2185 | static __be32 |
| 2186 | nfsd4_decode_getxattr(struct nfsd4_compoundargs *argp, |
| 2187 | struct nfsd4_getxattr *getxattr) |
| 2188 | { |
| 2189 | __be32 status; |
| 2190 | u32 maxcount; |
| 2191 | |
| 2192 | status = nfsd4_decode_xattr_name(argp, &getxattr->getxa_name); |
| 2193 | if (status) |
| 2194 | return status; |
| 2195 | |
| 2196 | maxcount = svc_max_payload(argp->rqstp); |
| 2197 | maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount); |
| 2198 | |
| 2199 | getxattr->getxa_len = maxcount; |
| 2200 | |
| 2201 | return status; |
| 2202 | } |
| 2203 | |
| 2204 | static __be32 |
| 2205 | nfsd4_decode_setxattr(struct nfsd4_compoundargs *argp, |
| 2206 | struct nfsd4_setxattr *setxattr) |
| 2207 | { |
| 2208 | DECODE_HEAD; |
| 2209 | u32 flags, maxcount, size; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2210 | |
| 2211 | READ_BUF(4); |
| 2212 | flags = be32_to_cpup(p++); |
| 2213 | |
| 2214 | if (flags > SETXATTR4_REPLACE) |
| 2215 | return nfserr_inval; |
| 2216 | setxattr->setxa_flags = flags; |
| 2217 | |
| 2218 | status = nfsd4_decode_xattr_name(argp, &setxattr->setxa_name); |
| 2219 | if (status) |
| 2220 | return status; |
| 2221 | |
| 2222 | maxcount = svc_max_payload(argp->rqstp); |
| 2223 | maxcount = min_t(u32, XATTR_SIZE_MAX, maxcount); |
| 2224 | |
| 2225 | READ_BUF(4); |
| 2226 | size = be32_to_cpup(p++); |
| 2227 | if (size > maxcount) |
| 2228 | return nfserr_xattr2big; |
| 2229 | |
| 2230 | setxattr->setxa_len = size; |
| 2231 | if (size > 0) { |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2232 | struct xdr_buf payload; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2233 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 2234 | if (!xdr_stream_subsegment(argp->xdr, &payload, size)) |
| 2235 | goto xdr_error; |
| 2236 | status = nfsd4_vbuf_from_vector(argp, &payload, |
| 2237 | &setxattr->setxa_buf, size); |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | DECODE_TAIL; |
| 2241 | } |
| 2242 | |
| 2243 | static __be32 |
| 2244 | nfsd4_decode_listxattrs(struct nfsd4_compoundargs *argp, |
| 2245 | struct nfsd4_listxattrs *listxattrs) |
| 2246 | { |
| 2247 | DECODE_HEAD; |
| 2248 | u32 maxcount; |
| 2249 | |
| 2250 | READ_BUF(12); |
| 2251 | p = xdr_decode_hyper(p, &listxattrs->lsxa_cookie); |
| 2252 | |
| 2253 | /* |
| 2254 | * If the cookie is too large to have even one user.x attribute |
| 2255 | * plus trailing '\0' left in a maximum size buffer, it's invalid. |
| 2256 | */ |
| 2257 | if (listxattrs->lsxa_cookie >= |
| 2258 | (XATTR_LIST_MAX / (XATTR_USER_PREFIX_LEN + 2))) |
| 2259 | return nfserr_badcookie; |
| 2260 | |
| 2261 | maxcount = be32_to_cpup(p++); |
| 2262 | if (maxcount < 8) |
| 2263 | /* Always need at least 2 words (length and one character) */ |
| 2264 | return nfserr_inval; |
| 2265 | |
| 2266 | maxcount = min(maxcount, svc_max_payload(argp->rqstp)); |
| 2267 | listxattrs->lsxa_maxcount = maxcount; |
| 2268 | |
| 2269 | DECODE_TAIL; |
| 2270 | } |
| 2271 | |
| 2272 | static __be32 |
| 2273 | nfsd4_decode_removexattr(struct nfsd4_compoundargs *argp, |
| 2274 | struct nfsd4_removexattr *removexattr) |
| 2275 | { |
| 2276 | return nfsd4_decode_xattr_name(argp, &removexattr->rmxa_name); |
| 2277 | } |
| 2278 | |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 2279 | static __be32 |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2280 | nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p) |
| 2281 | { |
| 2282 | return nfs_ok; |
| 2283 | } |
| 2284 | |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 2285 | static __be32 |
| 2286 | nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p) |
| 2287 | { |
Benny Halevy | 1e685ec | 2009-03-04 23:06:06 +0200 | [diff] [blame] | 2288 | return nfserr_notsupp; |
Benny Halevy | 3c375c6 | 2008-07-02 11:14:01 +0300 | [diff] [blame] | 2289 | } |
| 2290 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2291 | typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *); |
| 2292 | |
Chuck Lever | c1df609 | 2017-08-01 11:59:58 -0400 | [diff] [blame] | 2293 | static const nfsd4_dec nfsd4_dec_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 2294 | [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access, |
| 2295 | [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close, |
| 2296 | [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit, |
| 2297 | [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create, |
| 2298 | [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2299 | [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn, |
| 2300 | [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr, |
| 2301 | [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2302 | [OP_LINK] = (nfsd4_dec)nfsd4_decode_link, |
| 2303 | [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock, |
| 2304 | [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt, |
| 2305 | [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku, |
| 2306 | [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup, |
| 2307 | [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop, |
| 2308 | [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 2309 | [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open, |
| 2310 | [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2311 | [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm, |
| 2312 | [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade, |
| 2313 | [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh, |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2314 | [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_putpubfh, |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 2315 | [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2316 | [OP_READ] = (nfsd4_dec)nfsd4_decode_read, |
| 2317 | [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir, |
| 2318 | [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop, |
| 2319 | [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove, |
| 2320 | [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename, |
| 2321 | [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew, |
| 2322 | [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2323 | [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop, |
| 2324 | [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo, |
| 2325 | [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr, |
| 2326 | [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid, |
| 2327 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm, |
| 2328 | [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify, |
| 2329 | [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write, |
| 2330 | [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 2331 | |
| 2332 | /* new operations for NFSv4.1 */ |
J. Bruce Fields | cb73a9f | 2012-11-01 18:09:48 -0400 | [diff] [blame] | 2333 | [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_backchannel_ctl, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 2334 | [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] | 2335 | [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id, |
| 2336 | [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session, |
| 2337 | [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session, |
Bryan Schumaker | e1ca12d | 2011-07-13 11:04:21 -0400 | [diff] [blame] | 2338 | [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_free_stateid, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2339 | [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2340 | #ifdef CONFIG_NFSD_PNFS |
| 2341 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_getdeviceinfo, |
| 2342 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2343 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_layoutcommit, |
| 2344 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_layoutget, |
| 2345 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_layoutreturn, |
| 2346 | #else |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2347 | [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2348 | [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2349 | [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2350 | [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2351 | [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 2352 | #endif |
J. Bruce Fields | 04f4ad1 | 2010-12-16 09:51:13 -0500 | [diff] [blame] | 2353 | [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_secinfo_no_name, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2354 | [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence, |
| 2355 | [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 2356 | [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_test_stateid, |
Randy Dunlap | 9064caa | 2009-04-28 16:48:25 -0700 | [diff] [blame] | 2357 | [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp, |
Mi Jinlong | 345c284 | 2011-10-20 17:51:39 +0800 | [diff] [blame] | 2358 | [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_destroy_clientid, |
J. Bruce Fields | 4dc6ec0 | 2010-04-19 15:11:28 -0400 | [diff] [blame] | 2359 | [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_reclaim_complete, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2360 | |
| 2361 | /* new operations for NFSv4.2 */ |
Anna Schumaker | 95d871f | 2014-11-07 14:44:26 -0500 | [diff] [blame] | 2362 | [OP_ALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 2363 | [OP_COPY] = (nfsd4_dec)nfsd4_decode_copy, |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 2364 | [OP_COPY_NOTIFY] = (nfsd4_dec)nfsd4_decode_copy_notify, |
Anna Schumaker | b0cb908 | 2014-11-07 14:44:27 -0500 | [diff] [blame] | 2365 | [OP_DEALLOCATE] = (nfsd4_dec)nfsd4_decode_fallocate, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2366 | [OP_IO_ADVISE] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2367 | [OP_LAYOUTERROR] = (nfsd4_dec)nfsd4_decode_notsupp, |
| 2368 | [OP_LAYOUTSTATS] = (nfsd4_dec)nfsd4_decode_notsupp, |
Olga Kornievskaia | 885e2bf | 2018-07-20 18:19:19 -0400 | [diff] [blame] | 2369 | [OP_OFFLOAD_CANCEL] = (nfsd4_dec)nfsd4_decode_offload_status, |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 2370 | [OP_OFFLOAD_STATUS] = (nfsd4_dec)nfsd4_decode_offload_status, |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 2371 | [OP_READ_PLUS] = (nfsd4_dec)nfsd4_decode_read, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 2372 | [OP_SEEK] = (nfsd4_dec)nfsd4_decode_seek, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 2373 | [OP_WRITE_SAME] = (nfsd4_dec)nfsd4_decode_notsupp, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 2374 | [OP_CLONE] = (nfsd4_dec)nfsd4_decode_clone, |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 2375 | /* RFC 8276 extended atributes operations */ |
| 2376 | [OP_GETXATTR] = (nfsd4_dec)nfsd4_decode_getxattr, |
| 2377 | [OP_SETXATTR] = (nfsd4_dec)nfsd4_decode_setxattr, |
| 2378 | [OP_LISTXATTRS] = (nfsd4_dec)nfsd4_decode_listxattrs, |
| 2379 | [OP_REMOVEXATTR] = (nfsd4_dec)nfsd4_decode_removexattr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 2380 | }; |
| 2381 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2382 | static inline bool |
| 2383 | nfsd4_opnum_in_range(struct nfsd4_compoundargs *argp, struct nfsd4_op *op) |
| 2384 | { |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2385 | if (op->opnum < FIRST_NFS4_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2386 | return false; |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2387 | else if (argp->minorversion == 0 && op->opnum > LAST_NFS40_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2388 | return false; |
Anna Schumaker | 8217d14 | 2013-10-30 13:38:13 -0400 | [diff] [blame] | 2389 | else if (argp->minorversion == 1 && op->opnum > LAST_NFS41_OP) |
| 2390 | return false; |
| 2391 | else if (argp->minorversion == 2 && op->opnum > LAST_NFS42_OP) |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2392 | return false; |
| 2393 | return true; |
| 2394 | } |
Benny Halevy | f2feb96 | 2008-07-02 11:14:22 +0300 | [diff] [blame] | 2395 | |
Benny Halevy | 347e0ad | 2008-07-02 11:13:41 +0300 | [diff] [blame] | 2396 | static __be32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | nfsd4_decode_compound(struct nfsd4_compoundargs *argp) |
| 2398 | { |
| 2399 | DECODE_HEAD; |
| 2400 | struct nfsd4_op *op; |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2401 | bool cachethis = false; |
J. Bruce Fields | a5cddc8 | 2014-05-12 18:10:58 -0400 | [diff] [blame] | 2402 | int auth_slack= argp->rqstp->rq_auth_slack; |
| 2403 | int max_reply = auth_slack + 8; /* opcnt, status */ |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2404 | int readcount = 0; |
| 2405 | int readbytes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | int i; |
| 2407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 2409 | argp->taglen = be32_to_cpup(p++); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 2410 | READ_BUF(argp->taglen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | SAVEMEM(argp->tag, argp->taglen); |
J. Bruce Fields | 4aed9c4 | 2016-02-29 20:21:21 -0500 | [diff] [blame] | 2412 | READ_BUF(8); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 2413 | argp->minorversion = be32_to_cpup(p++); |
| 2414 | argp->opcnt = be32_to_cpup(p++); |
J. Bruce Fields | 4f0cefb | 2014-03-11 15:39:13 -0400 | [diff] [blame] | 2415 | max_reply += 4 + (XDR_QUADLEN(argp->taglen) << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | |
| 2417 | if (argp->taglen > NFSD4_MAX_TAGLEN) |
| 2418 | goto xdr_error; |
J. Bruce Fields | 0078117 | 2017-11-15 12:30:27 -0500 | [diff] [blame] | 2419 | /* |
| 2420 | * NFS4ERR_RESOURCE is a more helpful error than GARBAGE_ARGS |
| 2421 | * here, so we return success at the xdr level so that |
| 2422 | * nfsd4_proc can handle this is an NFS-level error. |
| 2423 | */ |
| 2424 | if (argp->opcnt > NFSD_MAX_OPS_PER_COMPOUND) |
| 2425 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | |
Tobias Klauser | e8c96f8 | 2006-03-24 03:15:34 -0800 | [diff] [blame] | 2427 | if (argp->opcnt > ARRAY_SIZE(argp->iops)) { |
J. Bruce Fields | 5d6031c | 2014-07-17 16:20:39 -0400 | [diff] [blame] | 2428 | argp->ops = kzalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | if (!argp->ops) { |
| 2430 | argp->ops = argp->iops; |
Chuck Lever | 817cb9d | 2007-09-11 18:01:20 -0400 | [diff] [blame] | 2431 | dprintk("nfsd: couldn't allocate room for COMPOUND\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | goto xdr_error; |
| 2433 | } |
| 2434 | } |
| 2435 | |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2436 | if (argp->minorversion > NFSD_SUPPORTED_MINOR_VERSION) |
Benny Halevy | 30cff1f | 2008-07-02 11:13:18 +0300 | [diff] [blame] | 2437 | argp->opcnt = 0; |
| 2438 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | for (i = 0; i < argp->opcnt; i++) { |
| 2440 | op = &argp->ops[i]; |
| 2441 | op->replay = NULL; |
| 2442 | |
J. Bruce Fields | 8a61b18 | 2012-11-16 22:28:38 -0500 | [diff] [blame] | 2443 | READ_BUF(4); |
J. Bruce Fields | 0655399 | 2014-06-02 12:32:51 -0400 | [diff] [blame] | 2444 | op->opnum = be32_to_cpup(p++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 2446 | if (nfsd4_opnum_in_range(argp, op)) { |
Anna Schumaker | e1a90eb | 2013-10-30 10:00:20 -0400 | [diff] [blame] | 2447 | op->status = nfsd4_dec_ops[op->opnum](argp, &op->u); |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 2448 | if (op->status != nfs_ok) |
| 2449 | trace_nfsd_compound_decode_err(argp->rqstp, |
| 2450 | argp->opcnt, i, |
| 2451 | op->opnum, |
| 2452 | op->status); |
| 2453 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | op->opnum = OP_ILLEGAL; |
| 2455 | op->status = nfserr_op_illegal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2456 | } |
J. Bruce Fields | f4f9ef4 | 2017-07-06 17:51:29 -0400 | [diff] [blame] | 2457 | op->opdesc = OPDESC(op); |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2458 | /* |
| 2459 | * We'll try to cache the result in the DRC if any one |
| 2460 | * op in the compound wants to be cached: |
| 2461 | */ |
| 2462 | cachethis |= nfsd4_cache_this_op(op); |
J. Bruce Fields | 6ff40de | 2013-11-05 15:07:16 -0500 | [diff] [blame] | 2463 | |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 2464 | if (op->opnum == OP_READ || op->opnum == OP_READ_PLUS) { |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2465 | readcount++; |
| 2466 | readbytes += nfsd4_max_reply(argp->rqstp, op); |
| 2467 | } else |
| 2468 | max_reply += nfsd4_max_reply(argp->rqstp, op); |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2469 | /* |
Kinglong Mee | 7323f0d | 2017-02-03 22:51:46 +0800 | [diff] [blame] | 2470 | * OP_LOCK and OP_LOCKT may return a conflicting lock. |
| 2471 | * (Special case because it will just skip encoding this |
| 2472 | * if it runs out of xdr buffer space, and it is the only |
| 2473 | * operation that behaves this way.) |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2474 | */ |
Kinglong Mee | 7323f0d | 2017-02-03 22:51:46 +0800 | [diff] [blame] | 2475 | if (op->opnum == OP_LOCK || op->opnum == OP_LOCKT) |
J. Bruce Fields | f7b43d0 | 2014-08-12 11:41:40 -0400 | [diff] [blame] | 2476 | max_reply += NFS4_OPAQUE_LIMIT; |
J. Bruce Fields | e372ba6 | 2014-05-19 12:27:11 -0400 | [diff] [blame] | 2477 | |
| 2478 | if (op->status) { |
| 2479 | argp->opcnt = i+1; |
| 2480 | break; |
| 2481 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2482 | } |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2483 | /* Sessions make the DRC unnecessary: */ |
| 2484 | if (argp->minorversion) |
| 2485 | cachethis = false; |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2486 | svc_reserve(argp->rqstp, max_reply + readbytes); |
J. Bruce Fields | 1091006 | 2011-01-24 12:11:02 -0500 | [diff] [blame] | 2487 | argp->rqstp->rq_cachetype = cachethis ? RC_REPLBUFF : RC_NOCACHE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | |
J. Bruce Fields | a5cddc8 | 2014-05-12 18:10:58 -0400 | [diff] [blame] | 2489 | if (readcount > 1 || max_reply > PAGE_SIZE - auth_slack) |
Jeff Layton | 779fb0f | 2014-11-19 07:51:18 -0500 | [diff] [blame] | 2490 | clear_bit(RQ_SPLICE_OK, &argp->rqstp->rq_flags); |
J. Bruce Fields | b0e35fd | 2014-02-04 10:36:59 -0500 | [diff] [blame] | 2491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | DECODE_TAIL; |
| 2493 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2495 | static __be32 *encode_change(__be32 *p, struct kstat *stat, struct inode *inode, |
| 2496 | struct svc_export *exp) |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2497 | { |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 2498 | if (exp->ex_flags & NFSEXP_V4ROOT) { |
| 2499 | *p++ = cpu_to_be32(convert_to_wallclock(exp->cd->flush_time)); |
| 2500 | *p++ = 0; |
| 2501 | } else if (IS_I_VERSION(inode)) { |
Amir Goldstein | 39ca1bf | 2018-01-03 17:14:35 +0200 | [diff] [blame] | 2502 | p = xdr_encode_hyper(p, nfsd4_change_attribute(stat, inode)); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2503 | } else { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2504 | *p++ = cpu_to_be32(stat->ctime.tv_sec); |
| 2505 | *p++ = cpu_to_be32(stat->ctime.tv_nsec); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2506 | } |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2507 | return p; |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2508 | } |
| 2509 | |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2510 | /* |
| 2511 | * ctime (in NFSv4, time_metadata) is not writeable, and the client |
| 2512 | * doesn't really care what resolution could theoretically be stored by |
| 2513 | * the filesystem. |
| 2514 | * |
| 2515 | * The client cares how close together changes can be while still |
| 2516 | * guaranteeing ctime changes. For most filesystems (which have |
| 2517 | * timestamps with nanosecond fields) that is limited by the resolution |
| 2518 | * of the time returned from current_time() (which I'm assuming to be |
| 2519 | * 1/HZ). |
| 2520 | */ |
| 2521 | static __be32 *encode_time_delta(__be32 *p, struct inode *inode) |
| 2522 | { |
Arnd Bergmann | e4598e3 | 2019-10-31 15:14:03 +0100 | [diff] [blame] | 2523 | struct timespec64 ts; |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2524 | u32 ns; |
| 2525 | |
| 2526 | 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] | 2527 | ts = ns_to_timespec64(ns); |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 2528 | |
| 2529 | p = xdr_encode_hyper(p, ts.tv_sec); |
| 2530 | *p++ = cpu_to_be32(ts.tv_nsec); |
| 2531 | |
| 2532 | return p; |
| 2533 | } |
| 2534 | |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2535 | static __be32 *encode_cinfo(__be32 *p, struct nfsd4_change_info *c) |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2536 | { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2537 | *p++ = cpu_to_be32(c->atomic); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2538 | if (c->change_supported) { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2539 | p = xdr_encode_hyper(p, c->before_change); |
| 2540 | p = xdr_encode_hyper(p, c->after_change); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2541 | } else { |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2542 | *p++ = cpu_to_be32(c->before_ctime_sec); |
| 2543 | *p++ = cpu_to_be32(c->before_ctime_nsec); |
| 2544 | *p++ = cpu_to_be32(c->after_ctime_sec); |
| 2545 | *p++ = cpu_to_be32(c->after_ctime_nsec); |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2546 | } |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 2547 | return p; |
J. Bruce Fields | c654b8a | 2009-04-16 17:33:25 -0400 | [diff] [blame] | 2548 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2550 | /* Encode as an array of strings the string given with components |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2551 | * separated @sep, escaped with esc_enter and esc_exit. |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2552 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2553 | static __be32 nfsd4_encode_components_esc(struct xdr_stream *xdr, char sep, |
| 2554 | char *components, char esc_enter, |
| 2555 | char esc_exit) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2556 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2557 | __be32 *p; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2558 | __be32 pathlen; |
| 2559 | int pathlen_offset; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2560 | int strlen, count=0; |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2561 | char *str, *end, *next; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2562 | |
| 2563 | dprintk("nfsd4_encode_components(%s)\n", components); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2564 | |
| 2565 | pathlen_offset = xdr->buf->len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2566 | p = xdr_reserve_space(xdr, 4); |
| 2567 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2568 | return nfserr_resource; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2569 | p++; /* We will fill this in with @count later */ |
| 2570 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2571 | end = str = components; |
| 2572 | while (*end) { |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2573 | bool found_esc = false; |
| 2574 | |
| 2575 | /* try to parse as esc_start, ..., esc_end, sep */ |
| 2576 | if (*str == esc_enter) { |
| 2577 | for (; *end && (*end != esc_exit); end++) |
| 2578 | /* find esc_exit or end of string */; |
| 2579 | next = end + 1; |
| 2580 | if (*end && (!*next || *next == sep)) { |
| 2581 | str++; |
| 2582 | found_esc = true; |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | if (!found_esc) |
| 2587 | for (; *end && (*end != sep); end++) |
| 2588 | /* find sep or end of string */; |
| 2589 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2590 | strlen = end - str; |
| 2591 | if (strlen) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2592 | p = xdr_reserve_space(xdr, strlen + 4); |
| 2593 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2594 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 2595 | p = xdr_encode_opaque(p, str, strlen); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2596 | count++; |
| 2597 | } |
| 2598 | else |
| 2599 | end++; |
Benjamin Coddington | 5a64e56 | 2014-12-07 16:05:47 -0500 | [diff] [blame] | 2600 | if (found_esc) |
| 2601 | end = next; |
| 2602 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2603 | str = end; |
| 2604 | } |
Benjamin Coddington | bf7491f | 2014-12-07 16:05:48 -0500 | [diff] [blame] | 2605 | pathlen = htonl(count); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2606 | write_bytes_to_xdr_buf(xdr->buf, pathlen_offset, &pathlen, 4); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2607 | return 0; |
| 2608 | } |
| 2609 | |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2610 | /* Encode as an array of strings the string given with components |
| 2611 | * separated @sep. |
| 2612 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2613 | static __be32 nfsd4_encode_components(struct xdr_stream *xdr, char sep, |
| 2614 | char *components) |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2615 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2616 | return nfsd4_encode_components_esc(xdr, sep, components, 0, 0); |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2617 | } |
| 2618 | |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2619 | /* |
| 2620 | * encode a location element of a fs_locations structure |
| 2621 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2622 | static __be32 nfsd4_encode_fs_location4(struct xdr_stream *xdr, |
| 2623 | struct nfsd4_fs_location *location) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2624 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2625 | __be32 status; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2626 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2627 | status = nfsd4_encode_components_esc(xdr, ':', location->hosts, |
Weston Andros Adamson | e7a0444 | 2012-04-24 11:07:59 -0400 | [diff] [blame] | 2628 | '[', ']'); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2629 | if (status) |
| 2630 | return status; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2631 | status = nfsd4_encode_components(xdr, '/', location->path); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2632 | if (status) |
| 2633 | return status; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2634 | return 0; |
| 2635 | } |
| 2636 | |
| 2637 | /* |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2638 | * Encode a path in RFC3530 'pathname4' format |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2639 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2640 | static __be32 nfsd4_encode_path(struct xdr_stream *xdr, |
| 2641 | const struct path *root, |
| 2642 | const struct path *path) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2643 | { |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2644 | struct path cur = *path; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2645 | __be32 *p; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2646 | struct dentry **components = NULL; |
| 2647 | unsigned int ncomponents = 0; |
| 2648 | __be32 err = nfserr_jukebox; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2649 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2650 | dprintk("nfsd4_encode_components("); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2651 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2652 | path_get(&cur); |
| 2653 | /* First walk the path up to the nfsd root, and store the |
| 2654 | * dentries/path components in an array. |
| 2655 | */ |
| 2656 | for (;;) { |
Kinglong Mee | b77a4b2 | 2015-03-15 23:13:32 +0800 | [diff] [blame] | 2657 | if (path_equal(&cur, root)) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2658 | break; |
| 2659 | if (cur.dentry == cur.mnt->mnt_root) { |
| 2660 | if (follow_up(&cur)) |
| 2661 | continue; |
| 2662 | goto out_free; |
| 2663 | } |
| 2664 | if ((ncomponents & 15) == 0) { |
| 2665 | struct dentry **new; |
| 2666 | new = krealloc(components, |
| 2667 | sizeof(*new) * (ncomponents + 16), |
| 2668 | GFP_KERNEL); |
| 2669 | if (!new) |
| 2670 | goto out_free; |
| 2671 | components = new; |
| 2672 | } |
| 2673 | components[ncomponents++] = cur.dentry; |
| 2674 | cur.dentry = dget_parent(cur.dentry); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2675 | } |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2676 | err = nfserr_resource; |
| 2677 | p = xdr_reserve_space(xdr, 4); |
| 2678 | if (!p) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2679 | goto out_free; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2680 | *p++ = cpu_to_be32(ncomponents); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2681 | |
| 2682 | while (ncomponents) { |
| 2683 | struct dentry *dentry = components[ncomponents - 1]; |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2684 | unsigned int len; |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2685 | |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2686 | spin_lock(&dentry->d_lock); |
| 2687 | len = dentry->d_name.len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2688 | p = xdr_reserve_space(xdr, len + 4); |
| 2689 | if (!p) { |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2690 | spin_unlock(&dentry->d_lock); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2691 | goto out_free; |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2692 | } |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 2693 | p = xdr_encode_opaque(p, dentry->d_name.name, len); |
Al Viro | a455589 | 2014-10-21 20:11:25 -0400 | [diff] [blame] | 2694 | dprintk("/%pd", dentry); |
Al Viro | 301f026 | 2013-09-01 16:06:39 -0400 | [diff] [blame] | 2695 | spin_unlock(&dentry->d_lock); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2696 | dput(dentry); |
| 2697 | ncomponents--; |
| 2698 | } |
| 2699 | |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2700 | err = 0; |
| 2701 | out_free: |
| 2702 | dprintk(")\n"); |
| 2703 | while (ncomponents) |
| 2704 | dput(components[--ncomponents]); |
| 2705 | kfree(components); |
| 2706 | path_put(&cur); |
| 2707 | return err; |
| 2708 | } |
| 2709 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2710 | static __be32 nfsd4_encode_fsloc_fsroot(struct xdr_stream *xdr, |
| 2711 | struct svc_rqst *rqstp, const struct path *path) |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2712 | { |
| 2713 | struct svc_export *exp_ps; |
| 2714 | __be32 res; |
| 2715 | |
| 2716 | exp_ps = rqst_find_fsidzero_export(rqstp); |
| 2717 | if (IS_ERR(exp_ps)) |
| 2718 | return nfserrno(PTR_ERR(exp_ps)); |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2719 | res = nfsd4_encode_path(xdr, &exp_ps->ex_path, path); |
Trond Myklebust | ed748aa | 2011-09-12 19:37:06 -0400 | [diff] [blame] | 2720 | exp_put(exp_ps); |
| 2721 | return res; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | /* |
| 2725 | * encode a fs_locations structure |
| 2726 | */ |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2727 | static __be32 nfsd4_encode_fs_locations(struct xdr_stream *xdr, |
| 2728 | struct svc_rqst *rqstp, struct svc_export *exp) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2729 | { |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2730 | __be32 status; |
Al Viro | cc45f01 | 2006-10-19 23:28:44 -0700 | [diff] [blame] | 2731 | int i; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2732 | __be32 *p; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2733 | struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs; |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2734 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2735 | status = nfsd4_encode_fsloc_fsroot(xdr, rqstp, &exp->ex_path); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2736 | if (status) |
| 2737 | return status; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2738 | p = xdr_reserve_space(xdr, 4); |
| 2739 | if (!p) |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2740 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2741 | *p++ = cpu_to_be32(fslocs->locations_count); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2742 | for (i=0; i<fslocs->locations_count; i++) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2743 | status = nfsd4_encode_fs_location4(xdr, &fslocs->locations[i]); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2744 | if (status) |
| 2745 | return status; |
| 2746 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 2747 | return 0; |
| 2748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2750 | static u32 nfs4_file_type(umode_t mode) |
| 2751 | { |
| 2752 | switch (mode & S_IFMT) { |
| 2753 | case S_IFIFO: return NF4FIFO; |
| 2754 | case S_IFCHR: return NF4CHR; |
| 2755 | case S_IFDIR: return NF4DIR; |
| 2756 | case S_IFBLK: return NF4BLK; |
| 2757 | case S_IFLNK: return NF4LNK; |
| 2758 | case S_IFREG: return NF4REG; |
| 2759 | case S_IFSOCK: return NF4SOCK; |
| 2760 | default: return NF4BAD; |
Tom Rix | 25fef48 | 2020-11-01 07:32:34 -0800 | [diff] [blame] | 2761 | } |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 2762 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2764 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2765 | nfsd4_encode_aclname(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2766 | struct nfs4_ace *ace) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | { |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2768 | if (ace->whotype != NFS4_ACL_WHO_NAMED) |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2769 | return nfs4_acl_write_who(xdr, ace->whotype); |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2770 | else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP) |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2771 | return nfsd4_encode_group(xdr, rqstp, ace->who_gid); |
J. Bruce Fields | 3554116 | 2014-01-08 09:49:01 -0500 | [diff] [blame] | 2772 | else |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2773 | return nfsd4_encode_user(xdr, rqstp, ace->who_uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2774 | } |
| 2775 | |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2776 | static inline __be32 |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2777 | nfsd4_encode_layout_types(struct xdr_stream *xdr, u32 layout_types) |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2778 | { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2779 | __be32 *p; |
| 2780 | unsigned long i = hweight_long(layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2781 | |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 2782 | p = xdr_reserve_space(xdr, 4 + 4 * i); |
| 2783 | if (!p) |
| 2784 | return nfserr_resource; |
| 2785 | |
| 2786 | *p++ = cpu_to_be32(i); |
| 2787 | |
| 2788 | for (i = LAYOUT_NFSV4_1_FILES; i < LAYOUT_TYPE_MAX; ++i) |
| 2789 | if (layout_types & (1 << i)) |
| 2790 | *p++ = cpu_to_be32(i); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 2791 | |
| 2792 | return 0; |
| 2793 | } |
| 2794 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2795 | #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \ |
| 2796 | FATTR4_WORD0_RDATTR_ERROR) |
| 2797 | #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2798 | #define WORD2_ABSENT_FS_ATTRS 0 |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2799 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2800 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
| 2801 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2802 | nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2803 | void *context, int len) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2804 | { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2805 | __be32 *p; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2806 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2807 | p = xdr_reserve_space(xdr, len + 4 + 4 + 4); |
| 2808 | if (!p) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2809 | return nfserr_resource; |
| 2810 | |
| 2811 | /* |
| 2812 | * For now we use a 0 here to indicate the null translation; in |
| 2813 | * the future we may place a call to translation code here. |
| 2814 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 2815 | *p++ = cpu_to_be32(0); /* lfs */ |
| 2816 | *p++ = cpu_to_be32(0); /* pi */ |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2817 | p = xdr_encode_opaque(p, context, len); |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2818 | return 0; |
| 2819 | } |
| 2820 | #else |
| 2821 | static inline __be32 |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2822 | nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, |
| 2823 | void *context, int len) |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2824 | { return 0; } |
| 2825 | #endif |
| 2826 | |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2827 | 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] | 2828 | { |
| 2829 | /* As per referral draft: */ |
| 2830 | if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS || |
| 2831 | *bmval1 & ~WORD1_ABSENT_FS_ATTRS) { |
| 2832 | if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR || |
| 2833 | *bmval0 & FATTR4_WORD0_FS_LOCATIONS) |
| 2834 | *rdattr_err = NFSERR_MOVED; |
| 2835 | else |
| 2836 | return nfserr_moved; |
| 2837 | } |
| 2838 | *bmval0 &= WORD0_ABSENT_FS_ATTRS; |
| 2839 | *bmval1 &= WORD1_ABSENT_FS_ATTRS; |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2840 | *bmval2 &= WORD2_ABSENT_FS_ATTRS; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2841 | return 0; |
| 2842 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2843 | |
J. Bruce Fields | ae7095a | 2012-10-01 17:50:56 -0400 | [diff] [blame] | 2844 | |
| 2845 | static int get_parent_attributes(struct svc_export *exp, struct kstat *stat) |
| 2846 | { |
| 2847 | struct path path = exp->ex_path; |
| 2848 | int err; |
| 2849 | |
| 2850 | path_get(&path); |
| 2851 | while (follow_up(&path)) { |
| 2852 | if (path.dentry != path.mnt->mnt_root) |
| 2853 | break; |
| 2854 | } |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 2855 | 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] | 2856 | path_put(&path); |
| 2857 | return err; |
| 2858 | } |
| 2859 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 2860 | static __be32 |
| 2861 | nfsd4_encode_bitmap(struct xdr_stream *xdr, u32 bmval0, u32 bmval1, u32 bmval2) |
| 2862 | { |
| 2863 | __be32 *p; |
| 2864 | |
| 2865 | if (bmval2) { |
| 2866 | p = xdr_reserve_space(xdr, 16); |
| 2867 | if (!p) |
| 2868 | goto out_resource; |
| 2869 | *p++ = cpu_to_be32(3); |
| 2870 | *p++ = cpu_to_be32(bmval0); |
| 2871 | *p++ = cpu_to_be32(bmval1); |
| 2872 | *p++ = cpu_to_be32(bmval2); |
| 2873 | } else if (bmval1) { |
| 2874 | p = xdr_reserve_space(xdr, 12); |
| 2875 | if (!p) |
| 2876 | goto out_resource; |
| 2877 | *p++ = cpu_to_be32(2); |
| 2878 | *p++ = cpu_to_be32(bmval0); |
| 2879 | *p++ = cpu_to_be32(bmval1); |
| 2880 | } else { |
| 2881 | p = xdr_reserve_space(xdr, 8); |
| 2882 | if (!p) |
| 2883 | goto out_resource; |
| 2884 | *p++ = cpu_to_be32(1); |
| 2885 | *p++ = cpu_to_be32(bmval0); |
| 2886 | } |
| 2887 | |
| 2888 | return 0; |
| 2889 | out_resource: |
| 2890 | return nfserr_resource; |
| 2891 | } |
| 2892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | /* |
| 2894 | * Note: @fhp can be NULL; in this case, we might have to compose the filehandle |
| 2895 | * ourselves. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2896 | */ |
Jeff Layton | da2ebce | 2014-05-30 09:09:25 -0400 | [diff] [blame] | 2897 | static __be32 |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 2898 | nfsd4_encode_fattr(struct xdr_stream *xdr, struct svc_fh *fhp, |
| 2899 | struct svc_export *exp, |
| 2900 | struct dentry *dentry, u32 *bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 2901 | struct svc_rqst *rqstp, int ignore_crossmnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2902 | { |
| 2903 | u32 bmval0 = bmval[0]; |
| 2904 | u32 bmval1 = bmval[1]; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2905 | u32 bmval2 = bmval[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2906 | struct kstat stat; |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2907 | struct svc_fh *tempfh = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2908 | struct kstatfs statfs; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2909 | __be32 *p; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 2910 | int starting_len = xdr->buf->len; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2911 | int attrlen_offset; |
| 2912 | __be32 attrlen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2913 | u32 dummy; |
| 2914 | u64 dummy64; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2915 | u32 rdattr_err = 0; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 2916 | __be32 status; |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2917 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | struct nfs4_acl *acl = NULL; |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 2919 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2920 | void *context = NULL; |
| 2921 | int contextlen; |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 2922 | #endif |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2923 | bool contextsupport = false; |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 2924 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
| 2925 | u32 minorversion = resp->cstate.minorversion; |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 2926 | struct path path = { |
| 2927 | .mnt = exp->ex_path.mnt, |
| 2928 | .dentry = dentry, |
| 2929 | }; |
Stanislav Kinsbursky | 3d73371 | 2012-11-27 14:11:44 +0300 | [diff] [blame] | 2930 | struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2931 | |
| 2932 | BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 2933 | BUG_ON(!nfsd_attrs_supported(minorversion, bmval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2935 | if (exp->ex_fslocs.migrated) { |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2936 | status = fattr_handle_absent_fs(&bmval0, &bmval1, &bmval2, &rdattr_err); |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 2937 | if (status) |
| 2938 | goto out; |
| 2939 | } |
| 2940 | |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 2941 | 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] | 2942 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2943 | goto out_nfserr; |
Christoph Hellwig | 1233790 | 2014-05-28 10:46:13 +0200 | [diff] [blame] | 2944 | if ((bmval0 & (FATTR4_WORD0_FILES_AVAIL | FATTR4_WORD0_FILES_FREE | |
| 2945 | FATTR4_WORD0_FILES_TOTAL | FATTR4_WORD0_MAXNAME)) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2946 | (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE | |
| 2947 | FATTR4_WORD1_SPACE_TOTAL))) { |
Christoph Hellwig | ebabe9a | 2010-07-07 18:53:11 +0200 | [diff] [blame] | 2948 | err = vfs_statfs(&path, &statfs); |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2949 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | goto out_nfserr; |
| 2951 | } |
| 2952 | if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) { |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2953 | tempfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL); |
| 2954 | status = nfserr_jukebox; |
| 2955 | if (!tempfh) |
| 2956 | goto out; |
| 2957 | fh_init(tempfh, NFS4_FHSIZE); |
| 2958 | status = fh_compose(tempfh, exp, dentry, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2959 | if (status) |
| 2960 | goto out; |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 2961 | fhp = tempfh; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2962 | } |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2963 | if (bmval0 & FATTR4_WORD0_ACL) { |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 2964 | err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl); |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 2965 | if (err == -EOPNOTSUPP) |
| 2966 | bmval0 &= ~FATTR4_WORD0_ACL; |
| 2967 | else if (err == -EINVAL) { |
| 2968 | status = nfserr_attrnotsupp; |
| 2969 | goto out; |
| 2970 | } else if (err != 0) |
| 2971 | goto out_nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2974 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
Kinglong Mee | c2227a3 | 2015-07-07 10:16:37 +0800 | [diff] [blame] | 2975 | if ((bmval2 & FATTR4_WORD2_SECURITY_LABEL) || |
| 2976 | bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
J. Bruce Fields | 32ddd94 | 2017-01-03 12:30:11 -0500 | [diff] [blame] | 2977 | if (exp->ex_flags & NFSEXP_SECURITY_LABEL) |
| 2978 | err = security_inode_getsecctx(d_inode(dentry), |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2979 | &context, &contextlen); |
J. Bruce Fields | 32ddd94 | 2017-01-03 12:30:11 -0500 | [diff] [blame] | 2980 | else |
| 2981 | err = -EOPNOTSUPP; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 2982 | contextsupport = (err == 0); |
| 2983 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
| 2984 | if (err == -EOPNOTSUPP) |
| 2985 | bmval2 &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 2986 | else if (err) |
| 2987 | goto out_nfserr; |
| 2988 | } |
| 2989 | } |
| 2990 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
| 2991 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 2992 | status = nfsd4_encode_bitmap(xdr, bmval0, bmval1, bmval2); |
| 2993 | if (status) |
| 2994 | goto out; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 2995 | |
| 2996 | attrlen_offset = xdr->buf->len; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 2997 | p = xdr_reserve_space(xdr, 4); |
| 2998 | if (!p) |
| 2999 | goto out_resource; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 3000 | p++; /* to be backfilled later */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3001 | |
| 3002 | if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) { |
J. Bruce Fields | dcd20869 | 2017-01-11 20:34:50 -0500 | [diff] [blame] | 3003 | u32 supp[3]; |
| 3004 | |
| 3005 | memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp)); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 3006 | |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 3007 | if (!IS_POSIXACL(dentry->d_inode)) |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 3008 | supp[0] &= ~FATTR4_WORD0_ACL; |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 3009 | if (!contextsupport) |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 3010 | supp[2] &= ~FATTR4_WORD2_SECURITY_LABEL; |
| 3011 | if (!supp[2]) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3012 | p = xdr_reserve_space(xdr, 12); |
| 3013 | if (!p) |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 3014 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3015 | *p++ = cpu_to_be32(2); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 3016 | *p++ = cpu_to_be32(supp[0]); |
| 3017 | *p++ = cpu_to_be32(supp[1]); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 3018 | } else { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3019 | p = xdr_reserve_space(xdr, 16); |
| 3020 | if (!p) |
Benny Halevy | 2b44f1b | 2010-09-30 20:47:46 +0200 | [diff] [blame] | 3021 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3022 | *p++ = cpu_to_be32(3); |
J. Bruce Fields | 916d2d8 | 2016-10-18 14:18:40 -0400 | [diff] [blame] | 3023 | *p++ = cpu_to_be32(supp[0]); |
| 3024 | *p++ = cpu_to_be32(supp[1]); |
| 3025 | *p++ = cpu_to_be32(supp[2]); |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 3026 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | } |
| 3028 | if (bmval0 & FATTR4_WORD0_TYPE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3029 | p = xdr_reserve_space(xdr, 4); |
| 3030 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3031 | goto out_resource; |
J. Bruce Fields | 3d2544b | 2011-08-15 11:49:30 -0400 | [diff] [blame] | 3032 | dummy = nfs4_file_type(stat.mode); |
J. Bruce Fields | 6b6d8137 | 2013-01-16 17:11:11 -0500 | [diff] [blame] | 3033 | if (dummy == NF4BAD) { |
| 3034 | status = nfserr_serverfault; |
| 3035 | goto out; |
| 3036 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3037 | *p++ = cpu_to_be32(dummy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3038 | } |
| 3039 | if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3040 | p = xdr_reserve_space(xdr, 4); |
| 3041 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | goto out_resource; |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 3043 | if (exp->ex_flags & NFSEXP_NOSUBTREECHECK) |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3044 | *p++ = cpu_to_be32(NFS4_FH_PERSISTENT); |
NeilBrown | 4964000 | 2005-06-23 22:02:58 -0700 | [diff] [blame] | 3045 | else |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3046 | *p++ = cpu_to_be32(NFS4_FH_PERSISTENT| |
| 3047 | NFS4_FH_VOL_RENAME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3048 | } |
| 3049 | if (bmval0 & FATTR4_WORD0_CHANGE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3050 | p = xdr_reserve_space(xdr, 8); |
| 3051 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | goto out_resource; |
NeilBrown | b880092 | 2017-01-30 17:17:00 +1100 | [diff] [blame] | 3053 | p = encode_change(p, &stat, d_inode(dentry), exp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | } |
| 3055 | if (bmval0 & FATTR4_WORD0_SIZE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3056 | p = xdr_reserve_space(xdr, 8); |
| 3057 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3058 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3059 | p = xdr_encode_hyper(p, stat.size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | } |
| 3061 | if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) { |
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_SYMLINK_SUPPORT) { |
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(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3072 | } |
| 3073 | if (bmval0 & FATTR4_WORD0_NAMED_ATTR) { |
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(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3078 | } |
| 3079 | if (bmval0 & FATTR4_WORD0_FSID) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3080 | p = xdr_reserve_space(xdr, 16); |
| 3081 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | goto out_resource; |
J.Bruce Fields | 42ca099 | 2006-10-04 02:16:20 -0700 | [diff] [blame] | 3083 | if (exp->ex_fslocs.migrated) { |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3084 | p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MAJOR); |
| 3085 | p = xdr_encode_hyper(p, NFS4_REFERRAL_FSID_MINOR); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 3086 | } else switch(fsid_source(fhp)) { |
| 3087 | case FSIDSOURCE_FSID: |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3088 | p = xdr_encode_hyper(p, (u64)exp->ex_fsid); |
| 3089 | p = xdr_encode_hyper(p, (u64)0); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 3090 | break; |
| 3091 | case FSIDSOURCE_DEV: |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3092 | *p++ = cpu_to_be32(0); |
| 3093 | *p++ = cpu_to_be32(MAJOR(stat.dev)); |
| 3094 | *p++ = cpu_to_be32(0); |
| 3095 | *p++ = cpu_to_be32(MINOR(stat.dev)); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 3096 | break; |
| 3097 | case FSIDSOURCE_UUID: |
Kinglong Mee | 94eb368 | 2014-05-23 20:00:19 +0800 | [diff] [blame] | 3098 | p = xdr_encode_opaque_fixed(p, exp->ex_uuid, |
| 3099 | EX_UUID_LEN); |
NeilBrown | af6a4e2 | 2007-02-14 00:33:12 -0800 | [diff] [blame] | 3100 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3101 | } |
| 3102 | } |
| 3103 | if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3104 | p = xdr_reserve_space(xdr, 4); |
| 3105 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3106 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3107 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3108 | } |
| 3109 | if (bmval0 & FATTR4_WORD0_LEASE_TIME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3110 | p = xdr_reserve_space(xdr, 4); |
| 3111 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3113 | *p++ = cpu_to_be32(nn->nfsd4_lease); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3114 | } |
| 3115 | if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3116 | p = xdr_reserve_space(xdr, 4); |
| 3117 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3118 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3119 | *p++ = cpu_to_be32(rdattr_err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | } |
| 3121 | if (bmval0 & FATTR4_WORD0_ACL) { |
| 3122 | struct nfs4_ace *ace; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3123 | |
| 3124 | if (acl == NULL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3125 | p = xdr_reserve_space(xdr, 4); |
| 3126 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | goto out_resource; |
| 3128 | |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3129 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | goto out_acl; |
| 3131 | } |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3132 | p = xdr_reserve_space(xdr, 4); |
| 3133 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3134 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3135 | *p++ = cpu_to_be32(acl->naces); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 3137 | for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3138 | p = xdr_reserve_space(xdr, 4*3); |
| 3139 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3141 | *p++ = cpu_to_be32(ace->type); |
| 3142 | *p++ = cpu_to_be32(ace->flag); |
| 3143 | *p++ = cpu_to_be32(ace->access_mask & |
| 3144 | NFS4_ACE_MASK_ALL); |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3145 | status = nfsd4_encode_aclname(xdr, rqstp, ace); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | if (status) |
| 3147 | goto out; |
| 3148 | } |
| 3149 | } |
| 3150 | out_acl: |
| 3151 | if (bmval0 & FATTR4_WORD0_ACLSUPPORT) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3152 | p = xdr_reserve_space(xdr, 4); |
| 3153 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3154 | goto out_resource; |
Andreas Gruenbacher | 0c9d65e | 2015-04-24 13:04:00 +0200 | [diff] [blame] | 3155 | *p++ = cpu_to_be32(IS_POSIXACL(dentry->d_inode) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0); |
| 3157 | } |
| 3158 | if (bmval0 & FATTR4_WORD0_CANSETTIME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3159 | p = xdr_reserve_space(xdr, 4); |
| 3160 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3162 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3163 | } |
| 3164 | if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3165 | p = xdr_reserve_space(xdr, 4); |
| 3166 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3168 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | } |
| 3170 | if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3171 | p = xdr_reserve_space(xdr, 4); |
| 3172 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3173 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3174 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | } |
| 3176 | if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3177 | p = xdr_reserve_space(xdr, 4); |
| 3178 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3180 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | } |
| 3182 | if (bmval0 & FATTR4_WORD0_FILEHANDLE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3183 | p = xdr_reserve_space(xdr, fhp->fh_handle.fh_size + 4); |
| 3184 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | goto out_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3186 | p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, |
| 3187 | fhp->fh_handle.fh_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | } |
| 3189 | if (bmval0 & FATTR4_WORD0_FILEID) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3190 | p = xdr_reserve_space(xdr, 8); |
| 3191 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3193 | p = xdr_encode_hyper(p, stat.ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3194 | } |
| 3195 | if (bmval0 & FATTR4_WORD0_FILES_AVAIL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3196 | p = xdr_reserve_space(xdr, 8); |
| 3197 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3199 | p = xdr_encode_hyper(p, (u64) statfs.f_ffree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3200 | } |
| 3201 | if (bmval0 & FATTR4_WORD0_FILES_FREE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3202 | p = xdr_reserve_space(xdr, 8); |
| 3203 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3204 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3205 | p = xdr_encode_hyper(p, (u64) statfs.f_ffree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | } |
| 3207 | if (bmval0 & FATTR4_WORD0_FILES_TOTAL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3208 | p = xdr_reserve_space(xdr, 8); |
| 3209 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3211 | p = xdr_encode_hyper(p, (u64) statfs.f_files); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | } |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 3213 | if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3214 | status = nfsd4_encode_fs_locations(xdr, rqstp, exp); |
J.Bruce Fields | 81c3f41 | 2006-10-04 02:16:19 -0700 | [diff] [blame] | 3215 | if (status) |
| 3216 | goto out; |
| 3217 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3219 | p = xdr_reserve_space(xdr, 4); |
| 3220 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3221 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3222 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | } |
| 3224 | if (bmval0 & FATTR4_WORD0_MAXFILESIZE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3225 | p = xdr_reserve_space(xdr, 8); |
| 3226 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3227 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3228 | 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] | 3229 | } |
| 3230 | if (bmval0 & FATTR4_WORD0_MAXLINK) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3231 | p = xdr_reserve_space(xdr, 4); |
| 3232 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3233 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3234 | *p++ = cpu_to_be32(255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3235 | } |
| 3236 | if (bmval0 & FATTR4_WORD0_MAXNAME) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3237 | p = xdr_reserve_space(xdr, 4); |
| 3238 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3240 | *p++ = cpu_to_be32(statfs.f_namelen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3241 | } |
| 3242 | if (bmval0 & FATTR4_WORD0_MAXREAD) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3243 | p = xdr_reserve_space(xdr, 8); |
| 3244 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3246 | p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | } |
| 3248 | if (bmval0 & FATTR4_WORD0_MAXWRITE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3249 | p = xdr_reserve_space(xdr, 8); |
| 3250 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3252 | p = xdr_encode_hyper(p, (u64) svc_max_payload(rqstp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | } |
| 3254 | if (bmval1 & FATTR4_WORD1_MODE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3255 | p = xdr_reserve_space(xdr, 4); |
| 3256 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3258 | *p++ = cpu_to_be32(stat.mode & S_IALLUGO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | } |
| 3260 | if (bmval1 & FATTR4_WORD1_NO_TRUNC) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3261 | p = xdr_reserve_space(xdr, 4); |
| 3262 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3263 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3264 | *p++ = cpu_to_be32(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | } |
| 3266 | if (bmval1 & FATTR4_WORD1_NUMLINKS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3267 | p = xdr_reserve_space(xdr, 4); |
| 3268 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3270 | *p++ = cpu_to_be32(stat.nlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3271 | } |
| 3272 | if (bmval1 & FATTR4_WORD1_OWNER) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3273 | status = nfsd4_encode_user(xdr, rqstp, stat.uid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | if (status) |
| 3275 | goto out; |
| 3276 | } |
| 3277 | if (bmval1 & FATTR4_WORD1_OWNER_GROUP) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3278 | status = nfsd4_encode_group(xdr, rqstp, stat.gid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | if (status) |
| 3280 | goto out; |
| 3281 | } |
| 3282 | if (bmval1 & FATTR4_WORD1_RAWDEV) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3283 | p = xdr_reserve_space(xdr, 8); |
| 3284 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | goto out_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3286 | *p++ = cpu_to_be32((u32) MAJOR(stat.rdev)); |
| 3287 | *p++ = cpu_to_be32((u32) MINOR(stat.rdev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | } |
| 3289 | if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3290 | p = xdr_reserve_space(xdr, 8); |
| 3291 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | goto out_resource; |
| 3293 | dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3294 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | } |
| 3296 | if (bmval1 & FATTR4_WORD1_SPACE_FREE) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3297 | p = xdr_reserve_space(xdr, 8); |
| 3298 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3299 | goto out_resource; |
| 3300 | dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3301 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | } |
| 3303 | if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3304 | p = xdr_reserve_space(xdr, 8); |
| 3305 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3306 | goto out_resource; |
| 3307 | dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3308 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | } |
| 3310 | if (bmval1 & FATTR4_WORD1_SPACE_USED) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3311 | p = xdr_reserve_space(xdr, 8); |
| 3312 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | goto out_resource; |
| 3314 | dummy64 = (u64)stat.blocks << 9; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3315 | p = xdr_encode_hyper(p, dummy64); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | } |
| 3317 | if (bmval1 & FATTR4_WORD1_TIME_ACCESS) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3318 | p = xdr_reserve_space(xdr, 12); |
| 3319 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3321 | p = xdr_encode_hyper(p, (s64)stat.atime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3322 | *p++ = cpu_to_be32(stat.atime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | } |
| 3324 | if (bmval1 & FATTR4_WORD1_TIME_DELTA) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3325 | p = xdr_reserve_space(xdr, 12); |
| 3326 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | goto out_resource; |
J. Bruce Fields | 1694514 | 2018-04-25 14:34:11 -0400 | [diff] [blame] | 3328 | p = encode_time_delta(p, d_inode(dentry)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3329 | } |
| 3330 | if (bmval1 & FATTR4_WORD1_TIME_METADATA) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3331 | p = xdr_reserve_space(xdr, 12); |
| 3332 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3334 | p = xdr_encode_hyper(p, (s64)stat.ctime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3335 | *p++ = cpu_to_be32(stat.ctime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3336 | } |
| 3337 | if (bmval1 & FATTR4_WORD1_TIME_MODIFY) { |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3338 | p = xdr_reserve_space(xdr, 12); |
| 3339 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 | goto out_resource; |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3341 | p = xdr_encode_hyper(p, (s64)stat.mtime.tv_sec); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3342 | *p++ = cpu_to_be32(stat.mtime.tv_nsec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | } |
| 3344 | if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) { |
Kinglong Mee | 0a2050d | 2015-07-30 21:51:54 +0800 | [diff] [blame] | 3345 | struct kstat parent_stat; |
| 3346 | u64 ino = stat.ino; |
| 3347 | |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 3348 | p = xdr_reserve_space(xdr, 8); |
| 3349 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | goto out_resource; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3351 | /* |
| 3352 | * Get parent's attributes if not ignoring crossmount |
| 3353 | * and this is the root of a cross-mounted filesystem. |
| 3354 | */ |
| 3355 | if (ignore_crossmnt == 0 && |
Kinglong Mee | 0a2050d | 2015-07-30 21:51:54 +0800 | [diff] [blame] | 3356 | dentry == exp->ex_path.mnt->mnt_root) { |
| 3357 | err = get_parent_attributes(exp, &parent_stat); |
| 3358 | if (err) |
| 3359 | goto out_nfserr; |
| 3360 | ino = parent_stat.ino; |
| 3361 | } |
| 3362 | p = xdr_encode_hyper(p, ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | } |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3364 | #ifdef CONFIG_NFSD_PNFS |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3365 | if (bmval1 & FATTR4_WORD1_FS_LAYOUT_TYPES) { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 3366 | status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3367 | if (status) |
| 3368 | goto out; |
| 3369 | } |
| 3370 | |
| 3371 | if (bmval2 & FATTR4_WORD2_LAYOUT_TYPES) { |
Jeff Layton | 8a4c392 | 2016-07-10 15:55:58 -0400 | [diff] [blame] | 3372 | status = nfsd4_encode_layout_types(xdr, exp->ex_layout_types); |
Kinglong Mee | 6896f15 | 2015-07-30 21:52:44 +0800 | [diff] [blame] | 3373 | if (status) |
| 3374 | goto out; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | if (bmval2 & FATTR4_WORD2_LAYOUT_BLKSIZE) { |
| 3378 | p = xdr_reserve_space(xdr, 4); |
| 3379 | if (!p) |
| 3380 | goto out_resource; |
| 3381 | *p++ = cpu_to_be32(stat.blksize); |
| 3382 | } |
| 3383 | #endif /* CONFIG_NFSD_PNFS */ |
Benny Halevy | 8c18f20 | 2009-04-03 08:29:14 +0300 | [diff] [blame] | 3384 | if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) { |
Trond Myklebust | b26b78c | 2017-05-09 16:24:59 -0400 | [diff] [blame] | 3385 | u32 supp[3]; |
| 3386 | |
| 3387 | memcpy(supp, nfsd_suppattrs[minorversion], sizeof(supp)); |
| 3388 | supp[0] &= NFSD_SUPPATTR_EXCLCREAT_WORD0; |
| 3389 | supp[1] &= NFSD_SUPPATTR_EXCLCREAT_WORD1; |
| 3390 | supp[2] &= NFSD_SUPPATTR_EXCLCREAT_WORD2; |
| 3391 | |
| 3392 | status = nfsd4_encode_bitmap(xdr, supp[0], supp[1], supp[2]); |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3393 | if (status) |
| 3394 | goto out; |
Benny Halevy | 8c18f20 | 2009-04-03 08:29:14 +0300 | [diff] [blame] | 3395 | } |
Andy Adamson | 7e70570 | 2009-04-03 08:29:11 +0300 | [diff] [blame] | 3396 | |
J. Bruce Fields | a858576 | 2018-04-25 13:26:23 -0400 | [diff] [blame] | 3397 | if (bmval2 & FATTR4_WORD2_CHANGE_ATTR_TYPE) { |
| 3398 | p = xdr_reserve_space(xdr, 4); |
| 3399 | if (!p) |
| 3400 | goto out_resource; |
| 3401 | if (IS_I_VERSION(d_inode(dentry))) |
| 3402 | *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_MONOTONIC_INCR); |
| 3403 | else |
| 3404 | *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_TIME_METADATA); |
| 3405 | } |
| 3406 | |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 3407 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
Kinglong Mee | 7d58072 | 2015-07-30 21:54:26 +0800 | [diff] [blame] | 3408 | if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { |
| 3409 | status = nfsd4_encode_security_label(xdr, rqstp, context, |
| 3410 | contextlen); |
| 3411 | if (status) |
| 3412 | goto out; |
| 3413 | } |
Arnd Bergmann | 0ab88ca | 2019-03-22 15:07:11 +0100 | [diff] [blame] | 3414 | #endif |
Kinglong Mee | 7d58072 | 2015-07-30 21:54:26 +0800 | [diff] [blame] | 3415 | |
Frank van der Linden | 0e885e8 | 2020-06-23 22:39:27 +0000 | [diff] [blame] | 3416 | if (bmval2 & FATTR4_WORD2_XATTR_SUPPORT) { |
| 3417 | p = xdr_reserve_space(xdr, 4); |
| 3418 | if (!p) |
| 3419 | goto out_resource; |
| 3420 | err = xattr_supported_namespace(d_inode(dentry), |
| 3421 | XATTR_USER_PREFIX); |
| 3422 | *p++ = cpu_to_be32(err == 0); |
| 3423 | } |
| 3424 | |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 3425 | attrlen = htonl(xdr->buf->len - attrlen_offset - 4); |
| 3426 | write_bytes_to_xdr_buf(xdr->buf, attrlen_offset, &attrlen, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | status = nfs_ok; |
| 3428 | |
| 3429 | out: |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 3430 | #ifdef CONFIG_NFSD_V4_SECURITY_LABEL |
David Quigley | 18032ca | 2013-05-02 13:19:10 -0400 | [diff] [blame] | 3431 | if (context) |
| 3432 | security_release_secctx(context, contextlen); |
J. Bruce Fields | ba4e55b | 2013-05-15 10:27:52 -0400 | [diff] [blame] | 3433 | #endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ |
J. Bruce Fields | 28e05dd | 2007-02-16 01:28:30 -0800 | [diff] [blame] | 3434 | kfree(acl); |
Yan, Zheng | 18df11d0 | 2014-03-10 12:52:07 +0800 | [diff] [blame] | 3435 | if (tempfh) { |
J. Bruce Fields | d50e6136 | 2014-01-15 12:21:12 -0500 | [diff] [blame] | 3436 | fh_put(tempfh); |
Yan, Zheng | 18df11d0 | 2014-03-10 12:52:07 +0800 | [diff] [blame] | 3437 | kfree(tempfh); |
| 3438 | } |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 3439 | if (status) |
| 3440 | xdr_truncate_encode(xdr, starting_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3441 | return status; |
| 3442 | out_nfserr: |
Al Viro | b8dd7b9 | 2006-10-19 23:29:01 -0700 | [diff] [blame] | 3443 | status = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3444 | goto out; |
| 3445 | out_resource: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3446 | status = nfserr_resource; |
| 3447 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3448 | } |
| 3449 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3450 | static void svcxdr_init_encode_from_buffer(struct xdr_stream *xdr, |
| 3451 | struct xdr_buf *buf, __be32 *p, int bytes) |
| 3452 | { |
| 3453 | xdr->scratch.iov_len = 0; |
| 3454 | memset(buf, 0, sizeof(struct xdr_buf)); |
| 3455 | buf->head[0].iov_base = p; |
| 3456 | buf->head[0].iov_len = 0; |
| 3457 | buf->len = 0; |
| 3458 | xdr->buf = buf; |
| 3459 | xdr->iov = buf->head; |
| 3460 | xdr->p = p; |
| 3461 | xdr->end = (void *)p + bytes; |
| 3462 | buf->buflen = bytes; |
| 3463 | } |
| 3464 | |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3465 | __be32 nfsd4_encode_fattr_to_buf(__be32 **p, int words, |
| 3466 | struct svc_fh *fhp, struct svc_export *exp, |
| 3467 | struct dentry *dentry, u32 *bmval, |
| 3468 | struct svc_rqst *rqstp, int ignore_crossmnt) |
| 3469 | { |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3470 | struct xdr_buf dummy; |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3471 | struct xdr_stream xdr; |
| 3472 | __be32 ret; |
| 3473 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3474 | svcxdr_init_encode_from_buffer(&xdr, &dummy, *p, words << 2); |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3475 | ret = nfsd4_encode_fattr(&xdr, fhp, exp, dentry, bmval, rqstp, |
| 3476 | ignore_crossmnt); |
| 3477 | *p = xdr.p; |
| 3478 | return ret; |
| 3479 | } |
| 3480 | |
J. Bruce Fields | c0ce6ec | 2008-02-11 15:48:47 -0500 | [diff] [blame] | 3481 | static inline int attributes_need_mount(u32 *bmval) |
| 3482 | { |
| 3483 | if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME)) |
| 3484 | return 1; |
| 3485 | if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID) |
| 3486 | return 1; |
| 3487 | return 0; |
| 3488 | } |
| 3489 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3490 | static __be32 |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3491 | nfsd4_encode_dirent_fattr(struct xdr_stream *xdr, struct nfsd4_readdir *cd, |
| 3492 | const char *name, int namlen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | { |
| 3494 | struct svc_export *exp = cd->rd_fhp->fh_export; |
| 3495 | struct dentry *dentry; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3496 | __be32 nfserr; |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3497 | int ignore_crossmnt = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3498 | |
Al Viro | 6c2d4798 | 2019-10-31 01:21:58 -0400 | [diff] [blame] | 3499 | dentry = lookup_positive_unlocked(name, cd->rd_fhp->fh_dentry, namlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3500 | if (IS_ERR(dentry)) |
| 3501 | return nfserrno(PTR_ERR(dentry)); |
| 3502 | |
| 3503 | exp_get(exp); |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3504 | /* |
| 3505 | * In the case of a mountpoint, the client may be asking for |
| 3506 | * attributes that are only properties of the underlying filesystem |
| 3507 | * as opposed to the cross-mounted file system. In such a case, |
| 3508 | * we will not follow the cross mount and will fill the attribtutes |
| 3509 | * directly from the mountpoint dentry. |
| 3510 | */ |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3511 | if (nfsd_mountpoint(dentry, exp)) { |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 3512 | int err; |
| 3513 | |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3514 | if (!(exp->ex_flags & NFSEXP_V4ROOT) |
| 3515 | && !attributes_need_mount(cd->rd_bmval)) { |
| 3516 | ignore_crossmnt = 1; |
| 3517 | goto out_encode; |
| 3518 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3519 | /* |
| 3520 | * Why the heck aren't we just using nfsd_lookup?? |
| 3521 | * Different "."/".." handling? Something else? |
| 3522 | * At least, add a comment here to explain.... |
| 3523 | */ |
J.Bruce Fields | 021d3a7 | 2006-12-13 00:35:24 -0800 | [diff] [blame] | 3524 | err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp); |
| 3525 | if (err) { |
| 3526 | nfserr = nfserrno(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | goto out_put; |
| 3528 | } |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 3529 | nfserr = check_nfsd_access(exp, cd->rd_rqstp); |
| 3530 | if (nfserr) |
| 3531 | goto out_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | |
| 3533 | } |
J. Bruce Fields | 3227fa4 | 2009-10-25 21:43:01 -0400 | [diff] [blame] | 3534 | out_encode: |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3535 | nfserr = nfsd4_encode_fattr(xdr, NULL, exp, dentry, cd->rd_bmval, |
Frank Filz | 406a7ea | 2007-11-27 11:34:05 -0800 | [diff] [blame] | 3536 | cd->rd_rqstp, ignore_crossmnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | out_put: |
| 3538 | dput(dentry); |
| 3539 | exp_put(exp); |
| 3540 | return nfserr; |
| 3541 | } |
| 3542 | |
Al Viro | 2ebbc01 | 2006-10-19 23:28:58 -0700 | [diff] [blame] | 3543 | static __be32 * |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3544 | nfsd4_encode_rdattr_error(struct xdr_stream *xdr, __be32 nfserr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3545 | { |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3546 | __be32 *p; |
| 3547 | |
Kinglong Mee | c3a4561 | 2014-07-06 11:34:43 +0800 | [diff] [blame] | 3548 | p = xdr_reserve_space(xdr, 20); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3549 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3550 | return NULL; |
| 3551 | *p++ = htonl(2); |
| 3552 | *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */ |
| 3553 | *p++ = htonl(0); /* bmval1 */ |
| 3554 | |
J. Bruce Fields | 87915c6 | 2013-01-16 17:33:28 -0500 | [diff] [blame] | 3555 | *p++ = htonl(4); /* attribute length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | *p++ = nfserr; /* no htonl */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | return p; |
| 3558 | } |
| 3559 | |
| 3560 | static int |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 3561 | nfsd4_encode_dirent(void *ccdv, const char *name, int namlen, |
| 3562 | loff_t offset, u64 ino, unsigned int d_type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | { |
NeilBrown | a0ad13e | 2007-01-26 00:57:10 -0800 | [diff] [blame] | 3564 | struct readdir_cd *ccd = ccdv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3566 | struct xdr_stream *xdr = cd->xdr; |
| 3567 | int start_offset = xdr->buf->len; |
| 3568 | int cookie_offset; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3569 | u32 name_and_cookie; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3570 | int entry_bytes; |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3571 | __be32 nfserr = nfserr_toosmall; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3572 | __be64 wire_offset; |
| 3573 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | |
| 3575 | /* In nfsv4, "." and ".." never make it onto the wire.. */ |
| 3576 | if (name && isdotent(name, namlen)) { |
| 3577 | cd->common.err = nfs_ok; |
| 3578 | return 0; |
| 3579 | } |
| 3580 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3581 | if (cd->cookie_offset) { |
| 3582 | wire_offset = cpu_to_be64(offset); |
| 3583 | write_bytes_to_xdr_buf(xdr->buf, cd->cookie_offset, |
| 3584 | &wire_offset, 8); |
| 3585 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3586 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3587 | p = xdr_reserve_space(xdr, 4); |
| 3588 | if (!p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | *p++ = xdr_one; /* mark entry present */ |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3591 | cookie_offset = xdr->buf->len; |
| 3592 | p = xdr_reserve_space(xdr, 3*4 + namlen); |
| 3593 | if (!p) |
| 3594 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */ |
| 3596 | p = xdr_encode_array(p, name, namlen); /* name length & name */ |
| 3597 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3598 | nfserr = nfsd4_encode_dirent_fattr(xdr, cd, name, namlen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | switch (nfserr) { |
| 3600 | case nfs_ok: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | break; |
| 3602 | case nfserr_resource: |
| 3603 | nfserr = nfserr_toosmall; |
| 3604 | goto fail; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3605 | case nfserr_noent: |
Kinglong Mee | f41c5ad | 2014-06-13 17:32:42 +0800 | [diff] [blame] | 3606 | xdr_truncate_encode(xdr, start_offset); |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3607 | goto skip_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | default: |
| 3609 | /* |
| 3610 | * If the client requested the RDATTR_ERROR attribute, |
| 3611 | * we stuff the error code into this attribute |
| 3612 | * and continue. If this attribute was not requested, |
| 3613 | * then in accordance with the spec, we fail the |
| 3614 | * entire READDIR operation(!) |
| 3615 | */ |
| 3616 | if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)) |
| 3617 | goto fail; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3618 | p = nfsd4_encode_rdattr_error(xdr, nfserr); |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 3619 | if (p == NULL) { |
| 3620 | nfserr = nfserr_toosmall; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | goto fail; |
Fred Isaman | 34081ef | 2006-01-18 17:43:40 -0800 | [diff] [blame] | 3622 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | } |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3624 | nfserr = nfserr_toosmall; |
| 3625 | entry_bytes = xdr->buf->len - start_offset; |
| 3626 | if (entry_bytes > cd->rd_maxcount) |
| 3627 | goto fail; |
| 3628 | cd->rd_maxcount -= entry_bytes; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3629 | /* |
| 3630 | * RFC 3530 14.2.24 describes rd_dircount as only a "hint", so |
| 3631 | * let's always let through the first entry, at least: |
| 3632 | */ |
J. Bruce Fields | 0ec016e | 2014-12-19 18:01:35 -0500 | [diff] [blame] | 3633 | if (!cd->rd_dircount) |
| 3634 | goto fail; |
| 3635 | name_and_cookie = 4 + 4 * XDR_QUADLEN(namlen) + 8; |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 3636 | if (name_and_cookie > cd->rd_dircount && cd->cookie_offset) |
| 3637 | goto fail; |
| 3638 | cd->rd_dircount -= min(cd->rd_dircount, name_and_cookie); |
J. Bruce Fields | 0ec016e | 2014-12-19 18:01:35 -0500 | [diff] [blame] | 3639 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3640 | cd->cookie_offset = cookie_offset; |
J. Bruce Fields | b2c0cea | 2009-05-05 19:04:29 -0400 | [diff] [blame] | 3641 | skip_entry: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3642 | cd->common.err = nfs_ok; |
| 3643 | return 0; |
| 3644 | fail: |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 3645 | xdr_truncate_encode(xdr, start_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3646 | cd->common.err = nfserr; |
| 3647 | return -EINVAL; |
| 3648 | } |
| 3649 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3650 | static __be32 |
| 3651 | nfsd4_encode_stateid(struct xdr_stream *xdr, stateid_t *sid) |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3652 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3653 | __be32 *p; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3654 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3655 | p = xdr_reserve_space(xdr, sizeof(stateid_t)); |
| 3656 | if (!p) |
| 3657 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3658 | *p++ = cpu_to_be32(sid->si_generation); |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3659 | p = xdr_encode_opaque_fixed(p, &sid->si_opaque, |
| 3660 | sizeof(stateid_opaque_t)); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3661 | return 0; |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3662 | } |
| 3663 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3664 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3665 | 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] | 3666 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3667 | struct xdr_stream *xdr = &resp->xdr; |
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 | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3670 | p = xdr_reserve_space(xdr, 8); |
| 3671 | if (!p) |
| 3672 | return nfserr_resource; |
| 3673 | *p++ = cpu_to_be32(access->ac_supported); |
| 3674 | *p++ = cpu_to_be32(access->ac_resp_access); |
| 3675 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3676 | } |
| 3677 | |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3678 | static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_bind_conn_to_session *bcts) |
| 3679 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3680 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3681 | __be32 *p; |
| 3682 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3683 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 8); |
| 3684 | if (!p) |
| 3685 | return nfserr_resource; |
| 3686 | p = xdr_encode_opaque_fixed(p, bcts->sessionid.data, |
| 3687 | NFS4_MAX_SESSIONID_LEN); |
| 3688 | *p++ = cpu_to_be32(bcts->dir); |
| 3689 | /* Upshifting from TCP to RDMA is not supported */ |
| 3690 | *p++ = cpu_to_be32(0); |
| 3691 | return 0; |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 3692 | } |
| 3693 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3694 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3695 | 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] | 3696 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3697 | struct xdr_stream *xdr = &resp->xdr; |
| 3698 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3699 | return nfsd4_encode_stateid(xdr, &close->cl_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3700 | } |
| 3701 | |
| 3702 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3703 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3704 | 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] | 3705 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3706 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3707 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3709 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
| 3710 | if (!p) |
| 3711 | return nfserr_resource; |
| 3712 | p = xdr_encode_opaque_fixed(p, commit->co_verf.data, |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3713 | NFS4_VERIFIER_SIZE); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3714 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | } |
| 3716 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3717 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3718 | 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] | 3719 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3720 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3721 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3722 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3723 | p = xdr_reserve_space(xdr, 20); |
| 3724 | if (!p) |
| 3725 | return nfserr_resource; |
| 3726 | encode_cinfo(p, &create->cr_cinfo); |
Trond Myklebust | b96811c | 2019-08-18 14:18:58 -0400 | [diff] [blame] | 3727 | return nfsd4_encode_bitmap(xdr, create->cr_bmval[0], |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3728 | create->cr_bmval[1], create->cr_bmval[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3729 | } |
| 3730 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3731 | static __be32 |
| 3732 | 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] | 3733 | { |
| 3734 | struct svc_fh *fhp = getattr->ga_fhp; |
J. Bruce Fields | d518465 | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 3735 | struct xdr_stream *xdr = &resp->xdr; |
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 | return nfsd4_encode_fattr(xdr, fhp, fhp->fh_export, fhp->fh_dentry, |
| 3738 | getattr->ga_bmval, resp->rqstp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | } |
| 3740 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3741 | static __be32 |
| 3742 | 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] | 3743 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3744 | struct xdr_stream *xdr = &resp->xdr; |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3745 | struct svc_fh *fhp = *fhpp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3746 | unsigned int len; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3747 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3748 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3749 | len = fhp->fh_handle.fh_size; |
| 3750 | p = xdr_reserve_space(xdr, len + 4); |
| 3751 | if (!p) |
| 3752 | return nfserr_resource; |
| 3753 | p = xdr_encode_opaque(p, &fhp->fh_handle.fh_base, len); |
| 3754 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | /* |
| 3758 | * Including all fields other than the name, a LOCK4denied structure requires |
| 3759 | * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes. |
| 3760 | */ |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3761 | static __be32 |
| 3762 | 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] | 3763 | { |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 3764 | struct xdr_netobj *conf = &ld->ld_owner; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3765 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3766 | |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3767 | again: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3768 | p = xdr_reserve_space(xdr, 32 + XDR_LEN(conf->len)); |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3769 | if (!p) { |
| 3770 | /* |
| 3771 | * Don't fail to return the result just because we can't |
| 3772 | * return the conflicting open: |
| 3773 | */ |
| 3774 | if (conf->len) { |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3775 | kfree(conf->data); |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3776 | conf->len = 0; |
| 3777 | conf->data = NULL; |
| 3778 | goto again; |
| 3779 | } |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3780 | return nfserr_resource; |
J. Bruce Fields | 8c7424c | 2014-03-10 12:19:10 -0400 | [diff] [blame] | 3781 | } |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3782 | p = xdr_encode_hyper(p, ld->ld_start); |
| 3783 | p = xdr_encode_hyper(p, ld->ld_length); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3784 | *p++ = cpu_to_be32(ld->ld_type); |
J. Bruce Fields | 7c13f34 | 2011-08-30 22:15:47 -0400 | [diff] [blame] | 3785 | if (conf->len) { |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 3786 | p = xdr_encode_opaque_fixed(p, &ld->ld_clientid, 8); |
| 3787 | p = xdr_encode_opaque(p, conf->data, conf->len); |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3788 | kfree(conf->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | } else { /* non - nfsv4 lock in conflict, no clientid nor owner */ |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 3790 | p = xdr_encode_hyper(p, (u64)0); /* clientid */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3791 | *p++ = cpu_to_be32(0); /* length of owner name */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | } |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3793 | return nfserr_denied; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3794 | } |
| 3795 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3796 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3797 | 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] | 3798 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3799 | struct xdr_stream *xdr = &resp->xdr; |
| 3800 | |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3801 | if (!nfserr) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3802 | nfserr = nfsd4_encode_stateid(xdr, &lock->lk_resp_stateid); |
Benny Halevy | e2f282b | 2008-08-12 20:45:07 +0300 | [diff] [blame] | 3803 | else if (nfserr == nfserr_denied) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3804 | nfserr = nfsd4_encode_lock_denied(xdr, &lock->lk_denied); |
Kinglong Mee | f98bac5 | 2014-07-07 22:10:56 +0800 | [diff] [blame] | 3805 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3806 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | } |
| 3808 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3809 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3810 | 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] | 3811 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3812 | struct xdr_stream *xdr = &resp->xdr; |
| 3813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | if (nfserr == nfserr_denied) |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3815 | nfsd4_encode_lock_denied(xdr, &lockt->lt_denied); |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3816 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | } |
| 3818 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3819 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3820 | 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] | 3821 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3822 | struct xdr_stream *xdr = &resp->xdr; |
| 3823 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3824 | return nfsd4_encode_stateid(xdr, &locku->lu_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | } |
| 3826 | |
| 3827 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3828 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3829 | 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] | 3830 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3831 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3832 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3834 | p = xdr_reserve_space(xdr, 20); |
| 3835 | if (!p) |
| 3836 | return nfserr_resource; |
| 3837 | p = encode_cinfo(p, &link->li_cinfo); |
| 3838 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | } |
| 3840 | |
| 3841 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3842 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3843 | 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] | 3844 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3845 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 3846 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3847 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3848 | nfserr = nfsd4_encode_stateid(xdr, &open->op_stateid); |
| 3849 | if (nfserr) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3850 | return nfserr; |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3851 | p = xdr_reserve_space(xdr, 24); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3852 | if (!p) |
| 3853 | return nfserr_resource; |
J. Bruce Fields | d05d574 | 2014-03-22 18:48:39 -0400 | [diff] [blame] | 3854 | p = encode_cinfo(p, &open->op_cinfo); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3855 | *p++ = cpu_to_be32(open->op_rflags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3857 | nfserr = nfsd4_encode_bitmap(xdr, open->op_bmval[0], open->op_bmval[1], |
| 3858 | open->op_bmval[2]); |
| 3859 | if (nfserr) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3860 | return nfserr; |
Kinglong Mee | 75976de | 2015-07-30 21:55:30 +0800 | [diff] [blame] | 3861 | |
| 3862 | p = xdr_reserve_space(xdr, 4); |
| 3863 | if (!p) |
| 3864 | return nfserr_resource; |
| 3865 | |
| 3866 | *p++ = cpu_to_be32(open->op_delegate_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3867 | switch (open->op_delegate_type) { |
| 3868 | case NFS4_OPEN_DELEGATE_NONE: |
| 3869 | break; |
| 3870 | case NFS4_OPEN_DELEGATE_READ: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3871 | nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid); |
| 3872 | if (nfserr) |
| 3873 | return nfserr; |
| 3874 | p = xdr_reserve_space(xdr, 20); |
| 3875 | if (!p) |
| 3876 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3877 | *p++ = cpu_to_be32(open->op_recall); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3878 | |
| 3879 | /* |
| 3880 | * TODO: ACE's in delegations |
| 3881 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3882 | *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 3883 | *p++ = cpu_to_be32(0); |
| 3884 | *p++ = cpu_to_be32(0); |
| 3885 | *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3886 | break; |
| 3887 | case NFS4_OPEN_DELEGATE_WRITE: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3888 | nfserr = nfsd4_encode_stateid(xdr, &open->op_delegate_stateid); |
| 3889 | if (nfserr) |
| 3890 | return nfserr; |
| 3891 | p = xdr_reserve_space(xdr, 32); |
| 3892 | if (!p) |
| 3893 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3894 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3895 | |
| 3896 | /* |
| 3897 | * TODO: space_limit's in delegations |
| 3898 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3899 | *p++ = cpu_to_be32(NFS4_LIMIT_SIZE); |
| 3900 | *p++ = cpu_to_be32(~(u32)0); |
| 3901 | *p++ = cpu_to_be32(~(u32)0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3902 | |
| 3903 | /* |
| 3904 | * TODO: ACE's in delegations |
| 3905 | */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3906 | *p++ = cpu_to_be32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE); |
| 3907 | *p++ = cpu_to_be32(0); |
| 3908 | *p++ = cpu_to_be32(0); |
| 3909 | *p++ = cpu_to_be32(0); /* XXX: is NULL principal ok? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | break; |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3911 | case NFS4_OPEN_DELEGATE_NONE_EXT: /* 4.1 */ |
| 3912 | switch (open->op_why_no_deleg) { |
| 3913 | case WND4_CONTENTION: |
| 3914 | case WND4_RESOURCE: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3915 | p = xdr_reserve_space(xdr, 8); |
| 3916 | if (!p) |
| 3917 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3918 | *p++ = cpu_to_be32(open->op_why_no_deleg); |
| 3919 | /* deleg signaling not supported yet: */ |
| 3920 | *p++ = cpu_to_be32(0); |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3921 | break; |
| 3922 | default: |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3923 | p = xdr_reserve_space(xdr, 4); |
| 3924 | if (!p) |
| 3925 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 3926 | *p++ = cpu_to_be32(open->op_why_no_deleg); |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3927 | } |
Benny Halevy | d24433c | 2012-02-16 20:57:17 +0200 | [diff] [blame] | 3928 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3929 | default: |
| 3930 | BUG(); |
| 3931 | } |
| 3932 | /* XXX save filehandle here */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3933 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3934 | } |
| 3935 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3936 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3937 | 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] | 3938 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3939 | struct xdr_stream *xdr = &resp->xdr; |
| 3940 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3941 | return nfsd4_encode_stateid(xdr, &oc->oc_resp_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3942 | } |
| 3943 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 3944 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 3945 | 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] | 3946 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 3947 | struct xdr_stream *xdr = &resp->xdr; |
| 3948 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 3949 | return nfsd4_encode_stateid(xdr, &od->od_stateid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | } |
| 3951 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3952 | static __be32 nfsd4_encode_splice_read( |
| 3953 | struct nfsd4_compoundres *resp, |
| 3954 | struct nfsd4_read *read, |
| 3955 | struct file *file, unsigned long maxcount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3956 | { |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3957 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3958 | struct xdr_buf *buf = xdr->buf; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3959 | int status, space_left; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3960 | u32 eof; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3961 | __be32 nfserr; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3962 | __be32 *p = xdr->p - 2; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3963 | |
Kinglong Mee | d5d5c30 | 2014-07-09 21:51:27 +0800 | [diff] [blame] | 3964 | /* Make sure there will be room for padding if needed */ |
| 3965 | if (xdr->end - xdr->p < 1) |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3966 | return nfserr_resource; |
| 3967 | |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3968 | nfserr = nfsd_splice_read(read->rd_rqstp, read->rd_fhp, |
Trond Myklebust | 83a6307 | 2019-08-26 13:03:11 -0400 | [diff] [blame] | 3969 | file, read->rd_offset, &maxcount, &eof); |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 3970 | read->rd_length = maxcount; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 3971 | if (nfserr) |
| 3972 | goto out_err; |
| 3973 | status = svc_encode_result_payload(read->rd_rqstp, |
| 3974 | buf->head[0].iov_len, maxcount); |
| 3975 | if (status) { |
| 3976 | nfserr = nfserrno(status); |
| 3977 | goto out_err; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3978 | } |
| 3979 | |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3980 | *(p++) = htonl(eof); |
| 3981 | *(p++) = htonl(maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3982 | |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3983 | buf->page_len = maxcount; |
| 3984 | buf->len += maxcount; |
J. Bruce Fields | 15b23ef | 2014-09-24 16:32:34 -0400 | [diff] [blame] | 3985 | xdr->page_ptr += (buf->page_base + maxcount + PAGE_SIZE - 1) |
| 3986 | / PAGE_SIZE; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3987 | |
| 3988 | /* Use rest of head for padding and remaining ops: */ |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3989 | buf->tail[0].iov_base = xdr->p; |
| 3990 | buf->tail[0].iov_len = 0; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3991 | xdr->iov = buf->tail; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 3992 | if (maxcount&3) { |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3993 | int pad = 4 - (maxcount&3); |
| 3994 | |
| 3995 | *(xdr->p++) = 0; |
| 3996 | |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 3997 | buf->tail[0].iov_base += maxcount&3; |
J. Bruce Fields | fec25fa | 2014-05-13 17:27:03 -0400 | [diff] [blame] | 3998 | buf->tail[0].iov_len = pad; |
| 3999 | buf->len += pad; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | space_left = min_t(int, (void *)xdr->end - (void *)xdr->p, |
J. Bruce Fields | 34a78b48 | 2014-05-13 16:32:04 -0400 | [diff] [blame] | 4003 | buf->buflen - buf->len); |
| 4004 | buf->buflen = buf->len + space_left; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4005 | xdr->end = (__be32 *)((void *)xdr->end + space_left); |
| 4006 | |
| 4007 | return 0; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 4008 | |
| 4009 | out_err: |
| 4010 | /* |
| 4011 | * nfsd_splice_actor may have already messed with the |
| 4012 | * page length; reset it so as not to confuse |
| 4013 | * xdr_truncate_encode in our caller. |
| 4014 | */ |
| 4015 | buf->page_len = 0; |
| 4016 | return nfserr; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4017 | } |
| 4018 | |
| 4019 | static __be32 nfsd4_encode_readv(struct nfsd4_compoundres *resp, |
| 4020 | struct nfsd4_read *read, |
| 4021 | struct file *file, unsigned long maxcount) |
| 4022 | { |
| 4023 | struct xdr_stream *xdr = &resp->xdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4024 | u32 eof; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4025 | int starting_len = xdr->buf->len - 8; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4026 | __be32 nfserr; |
| 4027 | __be32 tmp; |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 4028 | int pad; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | |
Anna Schumaker | 403217f | 2020-08-17 12:53:06 -0400 | [diff] [blame] | 4030 | read->rd_vlen = xdr_reserve_space_vec(xdr, resp->rqstp->rq_vec, maxcount); |
| 4031 | if (read->rd_vlen < 0) |
| 4032 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 4034 | nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset, |
Trond Myklebust | 83a6307 | 2019-08-26 13:03:11 -0400 | [diff] [blame] | 4035 | resp->rqstp->rq_vec, read->rd_vlen, &maxcount, |
| 4036 | &eof); |
Chuck Lever | 87c5942 | 2018-03-28 13:29:11 -0400 | [diff] [blame] | 4037 | read->rd_length = maxcount; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4038 | if (nfserr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4039 | return nfserr; |
Chuck Lever | 03493bc | 2020-06-10 10:36:42 -0400 | [diff] [blame] | 4040 | if (svc_encode_result_payload(resp->rqstp, starting_len + 8, maxcount)) |
Chuck Lever | 4120553 | 2020-03-02 14:45:53 -0500 | [diff] [blame] | 4041 | return nfserr_io; |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 4042 | xdr_truncate_encode(xdr, starting_len + 8 + xdr_align_size(maxcount)); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4043 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4044 | tmp = htonl(eof); |
| 4045 | write_bytes_to_xdr_buf(xdr->buf, starting_len , &tmp, 4); |
| 4046 | tmp = htonl(maxcount); |
| 4047 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); |
| 4048 | |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 4049 | tmp = xdr_zero; |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 4050 | pad = (maxcount&3) ? 4 - (maxcount&3) : 0; |
| 4051 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 8 + maxcount, |
Chuck Lever | 7dcf4ab | 2020-03-02 15:00:04 -0500 | [diff] [blame] | 4052 | &tmp, pad); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | return 0; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4054 | |
| 4055 | } |
| 4056 | |
| 4057 | static __be32 |
| 4058 | nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4059 | struct nfsd4_read *read) |
| 4060 | { |
| 4061 | unsigned long maxcount; |
| 4062 | struct xdr_stream *xdr = &resp->xdr; |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 4063 | struct file *file; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4064 | int starting_len = xdr->buf->len; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4065 | __be32 *p; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4066 | |
Jeff Layton | 5c4583b | 2019-08-18 14:18:54 -0400 | [diff] [blame] | 4067 | if (nfserr) |
| 4068 | return nfserr; |
| 4069 | file = read->rd_nf->nf_file; |
| 4070 | |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4071 | p = xdr_reserve_space(xdr, 8); /* eof flag and byte count */ |
| 4072 | if (!p) { |
Jeff Layton | 779fb0f | 2014-11-19 07:51:18 -0500 | [diff] [blame] | 4073 | 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] | 4074 | return nfserr_resource; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4075 | } |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 4076 | if (resp->xdr.buf->page_len && |
| 4077 | test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) { |
J. Bruce Fields | b042098 | 2014-03-18 17:44:10 -0400 | [diff] [blame] | 4078 | WARN_ON_ONCE(1); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4079 | return nfserr_resource; |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4080 | } |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4081 | xdr_commit_encode(xdr); |
| 4082 | |
| 4083 | maxcount = svc_max_payload(resp->rqstp); |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 4084 | maxcount = min_t(unsigned long, maxcount, |
| 4085 | (xdr->buf->buflen - xdr->buf->len)); |
Kinglong Mee | 3c7aa15 | 2014-06-10 18:08:19 +0800 | [diff] [blame] | 4086 | maxcount = min_t(unsigned long, maxcount, read->rd_length); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4087 | |
Christoph Hellwig | 68e8bb0 | 2015-06-18 16:45:02 +0200 | [diff] [blame] | 4088 | if (file->f_op->splice_read && |
| 4089 | test_bit(RQ_SPLICE_OK, &resp->rqstp->rq_flags)) |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 4090 | nfserr = nfsd4_encode_splice_read(resp, read, file, maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4091 | else |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 4092 | nfserr = nfsd4_encode_readv(resp, read, file, maxcount); |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4093 | |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 4094 | if (nfserr) |
J. Bruce Fields | dc97618 | 2014-03-18 17:01:51 -0400 | [diff] [blame] | 4095 | xdr_truncate_encode(xdr, starting_len); |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 4096 | |
Christoph Hellwig | 96bcad5 | 2015-06-18 16:45:01 +0200 | [diff] [blame] | 4097 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4098 | } |
| 4099 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4100 | static __be32 |
| 4101 | 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] | 4102 | { |
| 4103 | int maxcount; |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4104 | __be32 wire_count; |
| 4105 | int zero = 0; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 4106 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 4107 | int length_offset = xdr->buf->len; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 4108 | int status; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4109 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 4111 | p = xdr_reserve_space(xdr, 4); |
| 4112 | if (!p) |
| 4113 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4114 | maxcount = PAGE_SIZE; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4115 | |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4116 | p = xdr_reserve_space(xdr, maxcount); |
| 4117 | if (!p) |
J. Bruce Fields | 4e21ac4 | 2014-03-22 15:15:11 -0400 | [diff] [blame] | 4118 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4119 | /* |
Miklos Szeredi | fd4a0edf | 2016-12-09 16:45:04 +0100 | [diff] [blame] | 4120 | * XXX: By default, vfs_readlink() will truncate symlinks if they |
| 4121 | * would overflow the buffer. Is this kosher in NFSv4? If not, one |
| 4122 | * easy fix is: if vfs_readlink() precisely fills the buffer, assume |
| 4123 | * that truncation occurred, and return NFS4ERR_RESOURCE. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | */ |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4125 | nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, |
| 4126 | (char *)p, &maxcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 | if (nfserr == nfserr_isdir) |
J. Bruce Fields | d3f627c | 2014-02-26 17:00:38 -0500 | [diff] [blame] | 4128 | nfserr = nfserr_inval; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 4129 | if (nfserr) |
| 4130 | goto out_err; |
| 4131 | status = svc_encode_result_payload(readlink->rl_rqstp, length_offset, |
| 4132 | maxcount); |
| 4133 | if (status) { |
| 4134 | nfserr = nfserrno(status); |
| 4135 | goto out_err; |
J. Bruce Fields | d3f627c | 2014-02-26 17:00:38 -0500 | [diff] [blame] | 4136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4137 | |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4138 | wire_count = htonl(maxcount); |
| 4139 | write_bytes_to_xdr_buf(xdr->buf, length_offset, &wire_count, 4); |
Avi Kivity | 69bbd9c | 2014-06-26 17:23:12 +0300 | [diff] [blame] | 4140 | xdr_truncate_encode(xdr, length_offset + 4 + ALIGN(maxcount, 4)); |
J. Bruce Fields | 476a7b1 | 2014-01-20 17:08:27 -0500 | [diff] [blame] | 4141 | if (maxcount & 3) |
| 4142 | write_bytes_to_xdr_buf(xdr->buf, length_offset + 4 + maxcount, |
| 4143 | &zero, 4 - (maxcount&3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4144 | return 0; |
Chuck Lever | 76e5492 | 2020-11-05 10:24:19 -0500 | [diff] [blame] | 4145 | |
| 4146 | out_err: |
| 4147 | xdr_truncate_encode(xdr, length_offset); |
| 4148 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4149 | } |
| 4150 | |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4151 | static __be32 |
| 4152 | 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] | 4153 | { |
| 4154 | int maxcount; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4155 | int bytes_left; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4156 | loff_t offset; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4157 | __be64 wire_offset; |
J. Bruce Fields | ddd1ea5 | 2013-08-27 21:32:25 -0400 | [diff] [blame] | 4158 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 4159 | int starting_len = xdr->buf->len; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4160 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4162 | p = xdr_reserve_space(xdr, NFS4_VERIFIER_SIZE); |
| 4163 | if (!p) |
| 4164 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4165 | |
| 4166 | /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4167 | *p++ = cpu_to_be32(0); |
| 4168 | *p++ = cpu_to_be32(0); |
J. Bruce Fields | 4aea24b | 2014-01-15 15:17:58 -0500 | [diff] [blame] | 4169 | resp->xdr.buf->head[0].iov_len = ((char *)resp->xdr.p) |
| 4170 | - (char *)resp->xdr.buf->head[0].iov_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4171 | |
| 4172 | /* |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4173 | * Number of bytes left for directory entries allowing for the |
| 4174 | * final 8 bytes of the readdir and a following failed op: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4175 | */ |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4176 | bytes_left = xdr->buf->buflen - xdr->buf->len |
| 4177 | - COMPOUND_ERR_SLACK_SPACE - 8; |
| 4178 | if (bytes_left < 0) { |
| 4179 | nfserr = nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4180 | goto err_no_verf; |
| 4181 | } |
Scott Mayhew | 9c2ece6 | 2018-05-07 09:01:08 -0400 | [diff] [blame] | 4182 | maxcount = svc_max_payload(resp->rqstp); |
| 4183 | maxcount = min_t(u32, readdir->rd_maxcount, maxcount); |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4184 | /* |
| 4185 | * Note the rfc defines rd_maxcount as the size of the |
| 4186 | * READDIR4resok structure, which includes the verifier above |
| 4187 | * and the 8 bytes encoded at the end of this function: |
| 4188 | */ |
| 4189 | if (maxcount < 16) { |
| 4190 | nfserr = nfserr_toosmall; |
| 4191 | goto err_no_verf; |
| 4192 | } |
| 4193 | maxcount = min_t(int, maxcount-16, bytes_left); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 4195 | /* RFC 3530 14.2.24 allows us to ignore dircount when it's 0: */ |
| 4196 | if (!readdir->rd_dircount) |
Scott Mayhew | 9c2ece6 | 2018-05-07 09:01:08 -0400 | [diff] [blame] | 4197 | readdir->rd_dircount = svc_max_payload(resp->rqstp); |
J. Bruce Fields | aee3776 | 2014-08-20 14:49:50 -0400 | [diff] [blame] | 4198 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4199 | readdir->xdr = xdr; |
| 4200 | readdir->rd_maxcount = maxcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | readdir->common.err = 0; |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4202 | readdir->cookie_offset = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4203 | |
| 4204 | offset = readdir->rd_cookie; |
| 4205 | nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp, |
| 4206 | &offset, |
| 4207 | &readdir->common, nfsd4_encode_dirent); |
| 4208 | if (nfserr == nfs_ok && |
| 4209 | readdir->common.err == nfserr_toosmall && |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4210 | xdr->buf->len == starting_len + 8) { |
| 4211 | /* nothing encoded; which limit did we hit?: */ |
| 4212 | if (maxcount - 16 < bytes_left) |
| 4213 | /* It was the fault of rd_maxcount: */ |
| 4214 | nfserr = nfserr_toosmall; |
| 4215 | else |
| 4216 | /* We ran out of buffer space: */ |
| 4217 | nfserr = nfserr_resource; |
| 4218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4219 | if (nfserr) |
| 4220 | goto err_no_verf; |
| 4221 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4222 | if (readdir->cookie_offset) { |
| 4223 | wire_offset = cpu_to_be64(offset); |
| 4224 | write_bytes_to_xdr_buf(xdr->buf, readdir->cookie_offset, |
| 4225 | &wire_offset, 8); |
| 4226 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | |
J. Bruce Fields | 561f0ed | 2014-01-20 16:37:11 -0500 | [diff] [blame] | 4228 | p = xdr_reserve_space(xdr, 8); |
| 4229 | if (!p) { |
| 4230 | WARN_ON_ONCE(1); |
| 4231 | goto err_no_verf; |
| 4232 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4233 | *p++ = 0; /* no more entries */ |
| 4234 | *p++ = htonl(readdir->common.err == nfserr_eof); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | |
| 4236 | return 0; |
| 4237 | err_no_verf: |
J. Bruce Fields | 1fcea5b | 2014-02-26 20:17:02 -0500 | [diff] [blame] | 4238 | xdr_truncate_encode(xdr, starting_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4239 | return nfserr; |
| 4240 | } |
| 4241 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4242 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4243 | 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] | 4244 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4245 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4246 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4247 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4248 | p = xdr_reserve_space(xdr, 20); |
| 4249 | if (!p) |
| 4250 | return nfserr_resource; |
| 4251 | p = encode_cinfo(p, &remove->rm_cinfo); |
| 4252 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | } |
| 4254 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4255 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4256 | 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] | 4257 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4258 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4259 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4261 | p = xdr_reserve_space(xdr, 40); |
| 4262 | if (!p) |
| 4263 | return nfserr_resource; |
| 4264 | p = encode_cinfo(p, &rename->rn_sinfo); |
| 4265 | p = encode_cinfo(p, &rename->rn_tinfo); |
| 4266 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4267 | } |
| 4268 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4269 | static __be32 |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4270 | nfsd4_do_encode_secinfo(struct xdr_stream *xdr, struct svc_export *exp) |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4271 | { |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4272 | u32 i, nflavs, supported; |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4273 | struct exp_flavor_info *flavs; |
| 4274 | struct exp_flavor_info def_flavs[2]; |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4275 | __be32 *p, *flavorsp; |
| 4276 | static bool report = true; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4277 | |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4278 | if (exp->ex_nflavors) { |
| 4279 | flavs = exp->ex_flavors; |
| 4280 | nflavs = exp->ex_nflavors; |
| 4281 | } else { /* Handling of some defaults in absence of real secinfo: */ |
| 4282 | flavs = def_flavs; |
| 4283 | if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) { |
| 4284 | nflavs = 2; |
| 4285 | flavs[0].pseudoflavor = RPC_AUTH_UNIX; |
| 4286 | flavs[1].pseudoflavor = RPC_AUTH_NULL; |
| 4287 | } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) { |
| 4288 | nflavs = 1; |
| 4289 | flavs[0].pseudoflavor |
| 4290 | = svcauth_gss_flavor(exp->ex_client); |
| 4291 | } else { |
| 4292 | nflavs = 1; |
| 4293 | flavs[0].pseudoflavor |
| 4294 | = exp->ex_client->flavour->flavour; |
| 4295 | } |
| 4296 | } |
| 4297 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4298 | supported = 0; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4299 | p = xdr_reserve_space(xdr, 4); |
| 4300 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4301 | return nfserr_resource; |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4302 | flavorsp = p++; /* to be backfilled later */ |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4303 | |
J. Bruce Fields | 4796f45 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4304 | for (i = 0; i < nflavs; i++) { |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4305 | rpc_authflavor_t pf = flavs[i].pseudoflavor; |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 4306 | struct rpcsec_gss_info info; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4307 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4308 | if (rpcauth_get_gssinfo(pf, &info) == 0) { |
| 4309 | supported++; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4310 | p = xdr_reserve_space(xdr, 4 + 4 + |
| 4311 | XDR_LEN(info.oid.len) + 4 + 4); |
| 4312 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4313 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4314 | *p++ = cpu_to_be32(RPC_AUTH_GSS); |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4315 | p = xdr_encode_opaque(p, info.oid.data, info.oid.len); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4316 | *p++ = cpu_to_be32(info.qop); |
| 4317 | *p++ = cpu_to_be32(info.service); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4318 | } else if (pf < RPC_AUTH_MAXFLAVOR) { |
| 4319 | supported++; |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4320 | p = xdr_reserve_space(xdr, 4); |
| 4321 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4322 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4323 | *p++ = cpu_to_be32(pf); |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4324 | } else { |
| 4325 | if (report) |
| 4326 | pr_warn("NFS: SECINFO: security flavor %u " |
| 4327 | "is not supported\n", pf); |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4328 | } |
| 4329 | } |
Chuck Lever | a77c806 | 2013-03-16 15:55:10 -0400 | [diff] [blame] | 4330 | |
Chuck Lever | 676e4eb | 2013-04-30 18:48:54 -0400 | [diff] [blame] | 4331 | if (nflavs != supported) |
| 4332 | report = false; |
| 4333 | *flavorsp = htonl(supported); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4334 | return 0; |
Andy Adamson | dcb488a3 | 2007-07-17 04:04:51 -0700 | [diff] [blame] | 4335 | } |
| 4336 | |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4337 | static __be32 |
| 4338 | nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4339 | struct nfsd4_secinfo *secinfo) |
| 4340 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4341 | struct xdr_stream *xdr = &resp->xdr; |
| 4342 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4343 | return nfsd4_do_encode_secinfo(xdr, secinfo->si_exp); |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4344 | } |
| 4345 | |
| 4346 | static __be32 |
| 4347 | nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4348 | struct nfsd4_secinfo_no_name *secinfo) |
| 4349 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4350 | struct xdr_stream *xdr = &resp->xdr; |
| 4351 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4352 | return nfsd4_do_encode_secinfo(xdr, secinfo->sin_exp); |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 4353 | } |
| 4354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4355 | /* |
| 4356 | * The SETATTR encode routine is special -- it always encodes a bitmap, |
| 4357 | * regardless of the error status. |
| 4358 | */ |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4359 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4360 | 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] | 4361 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4362 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4363 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4364 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4365 | p = xdr_reserve_space(xdr, 16); |
| 4366 | if (!p) |
| 4367 | return nfserr_resource; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4368 | if (nfserr) { |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4369 | *p++ = cpu_to_be32(3); |
| 4370 | *p++ = cpu_to_be32(0); |
| 4371 | *p++ = cpu_to_be32(0); |
| 4372 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | } |
| 4374 | else { |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4375 | *p++ = cpu_to_be32(3); |
| 4376 | *p++ = cpu_to_be32(setattr->sa_bmval[0]); |
| 4377 | *p++ = cpu_to_be32(setattr->sa_bmval[1]); |
| 4378 | *p++ = cpu_to_be32(setattr->sa_bmval[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4379 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4380 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4381 | } |
| 4382 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4383 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4384 | 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] | 4385 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4386 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4387 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | |
| 4389 | if (!nfserr) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4390 | p = xdr_reserve_space(xdr, 8 + NFS4_VERIFIER_SIZE); |
| 4391 | if (!p) |
| 4392 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4393 | p = xdr_encode_opaque_fixed(p, &scd->se_clientid, 8); |
| 4394 | p = xdr_encode_opaque_fixed(p, &scd->se_confirm, |
| 4395 | NFS4_VERIFIER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4396 | } |
| 4397 | else if (nfserr == nfserr_clid_inuse) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4398 | p = xdr_reserve_space(xdr, 8); |
| 4399 | if (!p) |
| 4400 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4401 | *p++ = cpu_to_be32(0); |
| 4402 | *p++ = cpu_to_be32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4403 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4404 | return nfserr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | } |
| 4406 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4407 | static __be32 |
Al Viro | b37ad28 | 2006-10-19 23:28:59 -0700 | [diff] [blame] | 4408 | 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] | 4409 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4410 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4411 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4413 | p = xdr_reserve_space(xdr, 16); |
| 4414 | if (!p) |
| 4415 | return nfserr_resource; |
| 4416 | *p++ = cpu_to_be32(write->wr_bytes_written); |
| 4417 | *p++ = cpu_to_be32(write->wr_how_written); |
| 4418 | p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, |
| 4419 | NFS4_VERIFIER_SIZE); |
| 4420 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4421 | } |
| 4422 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 4423 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4424 | nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4425 | struct nfsd4_exchange_id *exid) |
| 4426 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4427 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4428 | __be32 *p; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4429 | char *major_id; |
| 4430 | char *server_scope; |
| 4431 | int major_id_sz; |
| 4432 | int server_scope_sz; |
| 4433 | uint64_t minor_id = 0; |
Scott Mayhew | 7627d7d | 2020-02-19 15:52:15 -0500 | [diff] [blame] | 4434 | 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] | 4435 | |
Scott Mayhew | 7627d7d | 2020-02-19 15:52:15 -0500 | [diff] [blame] | 4436 | major_id = nn->nfsd_name; |
| 4437 | major_id_sz = strlen(nn->nfsd_name); |
| 4438 | server_scope = nn->nfsd_name; |
| 4439 | server_scope_sz = strlen(nn->nfsd_name); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4440 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4441 | p = xdr_reserve_space(xdr, |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4442 | 8 /* eir_clientid */ + |
| 4443 | 4 /* eir_sequenceid */ + |
| 4444 | 4 /* eir_flags */ + |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4445 | 4 /* spr_how */); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4446 | if (!p) |
| 4447 | return nfserr_resource; |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4448 | |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4449 | p = xdr_encode_opaque_fixed(p, &exid->clientid, 8); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4450 | *p++ = cpu_to_be32(exid->seqid); |
| 4451 | *p++ = cpu_to_be32(exid->flags); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4452 | |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4453 | *p++ = cpu_to_be32(exid->spa_how); |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4454 | |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 4455 | switch (exid->spa_how) { |
| 4456 | case SP4_NONE: |
| 4457 | break; |
| 4458 | case SP4_MACH_CRED: |
| 4459 | /* spo_must_enforce bitmap: */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4460 | nfserr = nfsd4_encode_bitmap(xdr, |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4461 | exid->spo_must_enforce[0], |
| 4462 | exid->spo_must_enforce[1], |
| 4463 | exid->spo_must_enforce[2]); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4464 | if (nfserr) |
| 4465 | return nfserr; |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4466 | /* spo_must_allow bitmap: */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4467 | nfserr = nfsd4_encode_bitmap(xdr, |
Andrew Elble | ed94164 | 2016-06-15 12:52:09 -0400 | [diff] [blame] | 4468 | exid->spo_must_allow[0], |
| 4469 | exid->spo_must_allow[1], |
| 4470 | exid->spo_must_allow[2]); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4471 | if (nfserr) |
| 4472 | return nfserr; |
J. Bruce Fields | 57266a6 | 2013-04-13 14:27:29 -0400 | [diff] [blame] | 4473 | break; |
| 4474 | default: |
| 4475 | WARN_ON_ONCE(1); |
| 4476 | } |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4477 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4478 | p = xdr_reserve_space(xdr, |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4479 | 8 /* so_minor_id */ + |
| 4480 | 4 /* so_major_id.len */ + |
| 4481 | (XDR_QUADLEN(major_id_sz) * 4) + |
| 4482 | 4 /* eir_server_scope.len */ + |
| 4483 | (XDR_QUADLEN(server_scope_sz) * 4) + |
| 4484 | 4 /* eir_server_impl_id.count (0) */); |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4485 | if (!p) |
| 4486 | return nfserr_resource; |
Kinglong Mee | a8bb84b | 2013-12-10 15:24:36 +0800 | [diff] [blame] | 4487 | |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4488 | /* The server_owner struct */ |
J. Bruce Fields | b64c7f3 | 2014-03-22 17:11:35 -0400 | [diff] [blame] | 4489 | p = xdr_encode_hyper(p, minor_id); /* Minor id */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4490 | /* major id */ |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4491 | p = xdr_encode_opaque(p, major_id, major_id_sz); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4492 | |
| 4493 | /* Server scope */ |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4494 | p = xdr_encode_opaque(p, server_scope, server_scope_sz); |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4495 | |
| 4496 | /* Implementation id */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4497 | *p++ = cpu_to_be32(0); /* zero length nfs_impl_id4 array */ |
Andy Adamson | 0733d21 | 2009-04-03 08:28:01 +0300 | [diff] [blame] | 4498 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4499 | } |
| 4500 | |
| 4501 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4502 | nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4503 | struct nfsd4_create_session *sess) |
| 4504 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4505 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4506 | __be32 *p; |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4507 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4508 | p = xdr_reserve_space(xdr, 24); |
| 4509 | if (!p) |
| 4510 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4511 | p = xdr_encode_opaque_fixed(p, sess->sessionid.data, |
| 4512 | NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4513 | *p++ = cpu_to_be32(sess->seqid); |
| 4514 | *p++ = cpu_to_be32(sess->flags); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4515 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4516 | p = xdr_reserve_space(xdr, 28); |
| 4517 | if (!p) |
| 4518 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4519 | *p++ = cpu_to_be32(0); /* headerpadsz */ |
| 4520 | *p++ = cpu_to_be32(sess->fore_channel.maxreq_sz); |
| 4521 | *p++ = cpu_to_be32(sess->fore_channel.maxresp_sz); |
| 4522 | *p++ = cpu_to_be32(sess->fore_channel.maxresp_cached); |
| 4523 | *p++ = cpu_to_be32(sess->fore_channel.maxops); |
| 4524 | *p++ = cpu_to_be32(sess->fore_channel.maxreqs); |
| 4525 | *p++ = cpu_to_be32(sess->fore_channel.nr_rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4526 | |
| 4527 | if (sess->fore_channel.nr_rdma_attrs) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4528 | p = xdr_reserve_space(xdr, 4); |
| 4529 | if (!p) |
| 4530 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4531 | *p++ = cpu_to_be32(sess->fore_channel.rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4532 | } |
| 4533 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4534 | p = xdr_reserve_space(xdr, 28); |
| 4535 | if (!p) |
| 4536 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4537 | *p++ = cpu_to_be32(0); /* headerpadsz */ |
| 4538 | *p++ = cpu_to_be32(sess->back_channel.maxreq_sz); |
| 4539 | *p++ = cpu_to_be32(sess->back_channel.maxresp_sz); |
| 4540 | *p++ = cpu_to_be32(sess->back_channel.maxresp_cached); |
| 4541 | *p++ = cpu_to_be32(sess->back_channel.maxops); |
| 4542 | *p++ = cpu_to_be32(sess->back_channel.maxreqs); |
| 4543 | *p++ = cpu_to_be32(sess->back_channel.nr_rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4544 | |
| 4545 | if (sess->back_channel.nr_rdma_attrs) { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4546 | p = xdr_reserve_space(xdr, 4); |
| 4547 | if (!p) |
| 4548 | return nfserr_resource; |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4549 | *p++ = cpu_to_be32(sess->back_channel.rdma_attrs); |
Andy Adamson | ec6b5d7 | 2009-04-03 08:28:28 +0300 | [diff] [blame] | 4550 | } |
| 4551 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4552 | } |
| 4553 | |
| 4554 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4555 | nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4556 | struct nfsd4_sequence *seq) |
| 4557 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4558 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 4559 | __be32 *p; |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4560 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4561 | p = xdr_reserve_space(xdr, NFS4_MAX_SESSIONID_LEN + 20); |
| 4562 | if (!p) |
| 4563 | return nfserr_resource; |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 4564 | p = xdr_encode_opaque_fixed(p, seq->sessionid.data, |
| 4565 | NFS4_MAX_SESSIONID_LEN); |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4566 | *p++ = cpu_to_be32(seq->seqid); |
| 4567 | *p++ = cpu_to_be32(seq->slotid); |
J. Bruce Fields | b7d7ca3 | 2011-08-31 15:39:30 -0400 | [diff] [blame] | 4568 | /* Note slotid's are numbered from zero: */ |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 4569 | *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_highest_slotid */ |
| 4570 | *p++ = cpu_to_be32(seq->maxslots - 1); /* sr_target_highest_slotid */ |
| 4571 | *p++ = cpu_to_be32(seq->status_flags); |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4572 | |
J. Bruce Fields | f523601 | 2014-03-21 17:57:57 -0400 | [diff] [blame] | 4573 | resp->cstate.data_offset = xdr->buf->len; /* DRC cache data pointer */ |
Benny Halevy | b85d4c0 | 2009-04-03 08:28:08 +0300 | [diff] [blame] | 4574 | return 0; |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4575 | } |
| 4576 | |
J. Bruce Fields | 2355c59 | 2012-04-25 16:56:22 -0400 | [diff] [blame] | 4577 | static __be32 |
J. Bruce Fields | 57b7b43 | 2012-04-25 17:58:50 -0400 | [diff] [blame] | 4578 | nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4579 | struct nfsd4_test_stateid *test_stateid) |
| 4580 | { |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4581 | struct xdr_stream *xdr = &resp->xdr; |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 4582 | struct nfsd4_test_stateid_id *stateid, *next; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4583 | __be32 *p; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4584 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 4585 | p = xdr_reserve_space(xdr, 4 + (4 * test_stateid->ts_num_ids)); |
| 4586 | if (!p) |
| 4587 | return nfserr_resource; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4588 | *p++ = htonl(test_stateid->ts_num_ids); |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4589 | |
Bryan Schumaker | 03cfb42 | 2012-01-27 10:22:49 -0500 | [diff] [blame] | 4590 | 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] | 4591 | *p++ = stateid->ts_id_status; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4592 | } |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4593 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4594 | return 0; |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 4595 | } |
| 4596 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4597 | #ifdef CONFIG_NFSD_PNFS |
| 4598 | static __be32 |
| 4599 | nfsd4_encode_getdeviceinfo(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4600 | struct nfsd4_getdeviceinfo *gdev) |
| 4601 | { |
| 4602 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4603 | const struct nfsd4_layout_ops *ops; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4604 | u32 starting_len = xdr->buf->len, needed_len; |
| 4605 | __be32 *p; |
| 4606 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4607 | p = xdr_reserve_space(xdr, 4); |
| 4608 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4609 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4610 | |
| 4611 | *p++ = cpu_to_be32(gdev->gd_layout_type); |
| 4612 | |
| 4613 | /* If maxcount is 0 then just update notifications */ |
| 4614 | if (gdev->gd_maxcount != 0) { |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4615 | ops = nfsd4_layout_ops[gdev->gd_layout_type]; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4616 | nfserr = ops->encode_getdeviceinfo(xdr, gdev); |
| 4617 | if (nfserr) { |
| 4618 | /* |
| 4619 | * We don't bother to burden the layout drivers with |
| 4620 | * enforcing gd_maxcount, just tell the client to |
| 4621 | * come back with a bigger buffer if it's not enough. |
| 4622 | */ |
| 4623 | if (xdr->buf->len + 4 > gdev->gd_maxcount) |
| 4624 | goto toosmall; |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4625 | return nfserr; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4626 | } |
| 4627 | } |
| 4628 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4629 | if (gdev->gd_notify_types) { |
| 4630 | p = xdr_reserve_space(xdr, 4 + 4); |
| 4631 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4632 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4633 | *p++ = cpu_to_be32(1); /* bitmap length */ |
| 4634 | *p++ = cpu_to_be32(gdev->gd_notify_types); |
| 4635 | } else { |
| 4636 | p = xdr_reserve_space(xdr, 4); |
| 4637 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4638 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4639 | *p++ = 0; |
| 4640 | } |
| 4641 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4642 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4643 | toosmall: |
| 4644 | dprintk("%s: maxcount too small\n", __func__); |
| 4645 | needed_len = xdr->buf->len + 4 /* notifications */; |
| 4646 | xdr_truncate_encode(xdr, starting_len); |
| 4647 | p = xdr_reserve_space(xdr, 4); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4648 | if (!p) |
| 4649 | return nfserr_resource; |
| 4650 | *p++ = cpu_to_be32(needed_len); |
| 4651 | return nfserr_toosmall; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | static __be32 |
| 4655 | nfsd4_encode_layoutget(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4656 | struct nfsd4_layoutget *lgp) |
| 4657 | { |
| 4658 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4659 | const struct nfsd4_layout_ops *ops; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4660 | __be32 *p; |
| 4661 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4662 | p = xdr_reserve_space(xdr, 36 + sizeof(stateid_opaque_t)); |
| 4663 | if (!p) |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4664 | return nfserr_resource; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4665 | |
| 4666 | *p++ = cpu_to_be32(1); /* we always set return-on-close */ |
| 4667 | *p++ = cpu_to_be32(lgp->lg_sid.si_generation); |
| 4668 | p = xdr_encode_opaque_fixed(p, &lgp->lg_sid.si_opaque, |
| 4669 | sizeof(stateid_opaque_t)); |
| 4670 | |
| 4671 | *p++ = cpu_to_be32(1); /* we always return a single layout */ |
| 4672 | p = xdr_encode_hyper(p, lgp->lg_seg.offset); |
| 4673 | p = xdr_encode_hyper(p, lgp->lg_seg.length); |
| 4674 | *p++ = cpu_to_be32(lgp->lg_seg.iomode); |
| 4675 | *p++ = cpu_to_be32(lgp->lg_layout_type); |
| 4676 | |
J. Bruce Fields | f961e3f | 2017-05-05 16:17:57 -0400 | [diff] [blame] | 4677 | ops = nfsd4_layout_ops[lgp->lg_layout_type]; |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4678 | return ops->encode_layoutget(xdr, lgp); |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4679 | } |
| 4680 | |
| 4681 | static __be32 |
| 4682 | nfsd4_encode_layoutcommit(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4683 | struct nfsd4_layoutcommit *lcp) |
| 4684 | { |
| 4685 | struct xdr_stream *xdr = &resp->xdr; |
| 4686 | __be32 *p; |
| 4687 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4688 | p = xdr_reserve_space(xdr, 4); |
| 4689 | if (!p) |
| 4690 | return nfserr_resource; |
| 4691 | *p++ = cpu_to_be32(lcp->lc_size_chg); |
| 4692 | if (lcp->lc_size_chg) { |
| 4693 | p = xdr_reserve_space(xdr, 8); |
| 4694 | if (!p) |
| 4695 | return nfserr_resource; |
| 4696 | p = xdr_encode_hyper(p, lcp->lc_newsize); |
| 4697 | } |
| 4698 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4699 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | static __be32 |
| 4703 | nfsd4_encode_layoutreturn(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4704 | struct nfsd4_layoutreturn *lrp) |
| 4705 | { |
| 4706 | struct xdr_stream *xdr = &resp->xdr; |
| 4707 | __be32 *p; |
| 4708 | |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4709 | p = xdr_reserve_space(xdr, 4); |
| 4710 | if (!p) |
| 4711 | return nfserr_resource; |
| 4712 | *p++ = cpu_to_be32(lrp->lrs_present); |
| 4713 | if (lrp->lrs_present) |
Kinglong Mee | 376675d | 2015-03-22 22:17:10 +0800 | [diff] [blame] | 4714 | return nfsd4_encode_stateid(xdr, &lrp->lr_sid); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4715 | return 0; |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 4716 | } |
| 4717 | #endif /* CONFIG_NFSD_PNFS */ |
| 4718 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 4719 | static __be32 |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4720 | nfsd42_encode_write_res(struct nfsd4_compoundres *resp, |
| 4721 | struct nfsd42_write_res *write, bool sync) |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4722 | { |
| 4723 | __be32 *p; |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4724 | p = xdr_reserve_space(&resp->xdr, 4); |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4725 | if (!p) |
| 4726 | return nfserr_resource; |
| 4727 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4728 | if (sync) |
| 4729 | *p++ = cpu_to_be32(0); |
| 4730 | else { |
| 4731 | __be32 nfserr; |
| 4732 | *p++ = cpu_to_be32(1); |
| 4733 | nfserr = nfsd4_encode_stateid(&resp->xdr, &write->cb_stateid); |
| 4734 | if (nfserr) |
| 4735 | return nfserr; |
| 4736 | } |
| 4737 | p = xdr_reserve_space(&resp->xdr, 8 + 4 + NFS4_VERIFIER_SIZE); |
| 4738 | if (!p) |
| 4739 | return nfserr_resource; |
| 4740 | |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4741 | p = xdr_encode_hyper(p, write->wr_bytes_written); |
| 4742 | *p++ = cpu_to_be32(write->wr_stable_how); |
| 4743 | p = xdr_encode_opaque_fixed(p, write->wr_verifier.data, |
| 4744 | NFS4_VERIFIER_SIZE); |
| 4745 | return nfs_ok; |
| 4746 | } |
| 4747 | |
| 4748 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 4749 | nfsd42_encode_nl4_server(struct nfsd4_compoundres *resp, struct nl4_server *ns) |
| 4750 | { |
| 4751 | struct xdr_stream *xdr = &resp->xdr; |
| 4752 | struct nfs42_netaddr *addr; |
| 4753 | __be32 *p; |
| 4754 | |
| 4755 | p = xdr_reserve_space(xdr, 4); |
| 4756 | *p++ = cpu_to_be32(ns->nl4_type); |
| 4757 | |
| 4758 | switch (ns->nl4_type) { |
| 4759 | case NL4_NETADDR: |
| 4760 | addr = &ns->u.nl4_addr; |
| 4761 | |
| 4762 | /* netid_len, netid, uaddr_len, uaddr (port included |
| 4763 | * in RPCBIND_MAXUADDRLEN) |
| 4764 | */ |
| 4765 | p = xdr_reserve_space(xdr, |
| 4766 | 4 /* netid len */ + |
| 4767 | (XDR_QUADLEN(addr->netid_len) * 4) + |
| 4768 | 4 /* uaddr len */ + |
| 4769 | (XDR_QUADLEN(addr->addr_len) * 4)); |
| 4770 | if (!p) |
| 4771 | return nfserr_resource; |
| 4772 | |
| 4773 | *p++ = cpu_to_be32(addr->netid_len); |
| 4774 | p = xdr_encode_opaque_fixed(p, addr->netid, |
| 4775 | addr->netid_len); |
| 4776 | *p++ = cpu_to_be32(addr->addr_len); |
| 4777 | p = xdr_encode_opaque_fixed(p, addr->addr, |
| 4778 | addr->addr_len); |
| 4779 | break; |
| 4780 | default: |
| 4781 | WARN_ON_ONCE(ns->nl4_type != NL4_NETADDR); |
| 4782 | return nfserr_inval; |
| 4783 | } |
| 4784 | |
| 4785 | return 0; |
| 4786 | } |
| 4787 | |
| 4788 | static __be32 |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4789 | nfsd4_encode_copy(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4790 | struct nfsd4_copy *copy) |
| 4791 | { |
| 4792 | __be32 *p; |
| 4793 | |
Olga Kornievskaia | e0639dc | 2018-07-20 18:19:20 -0400 | [diff] [blame] | 4794 | nfserr = nfsd42_encode_write_res(resp, ©->cp_res, |
| 4795 | copy->cp_synchronous); |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4796 | if (nfserr) |
| 4797 | return nfserr; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4798 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4799 | p = xdr_reserve_space(&resp->xdr, 4 + 4); |
J. Bruce Fields | edcc845 | 2018-03-07 15:37:35 -0500 | [diff] [blame] | 4800 | *p++ = xdr_one; /* cr_consecutive */ |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 4801 | *p++ = cpu_to_be32(copy->cp_synchronous); |
| 4802 | return 0; |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | static __be32 |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 4806 | nfsd4_encode_offload_status(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4807 | struct nfsd4_offload_status *os) |
| 4808 | { |
| 4809 | struct xdr_stream *xdr = &resp->xdr; |
| 4810 | __be32 *p; |
| 4811 | |
| 4812 | p = xdr_reserve_space(xdr, 8 + 4); |
| 4813 | if (!p) |
| 4814 | return nfserr_resource; |
| 4815 | p = xdr_encode_hyper(p, os->count); |
| 4816 | *p++ = cpu_to_be32(0); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4817 | return nfserr; |
| 4818 | } |
| 4819 | |
| 4820 | static __be32 |
| 4821 | nfsd4_encode_read_plus_data(struct nfsd4_compoundres *resp, |
| 4822 | struct nfsd4_read *read, |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4823 | unsigned long *maxcount, u32 *eof, |
| 4824 | loff_t *pos) |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4825 | { |
| 4826 | struct xdr_stream *xdr = &resp->xdr; |
| 4827 | struct file *file = read->rd_nf->nf_file; |
| 4828 | int starting_len = xdr->buf->len; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4829 | loff_t hole_pos; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4830 | __be32 nfserr; |
| 4831 | __be32 *p, tmp; |
| 4832 | __be64 tmp64; |
| 4833 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4834 | hole_pos = pos ? *pos : vfs_llseek(file, read->rd_offset, SEEK_HOLE); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4835 | if (hole_pos > read->rd_offset) |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4836 | *maxcount = min_t(unsigned long, *maxcount, hole_pos - read->rd_offset); |
| 4837 | *maxcount = min_t(unsigned long, *maxcount, (xdr->buf->buflen - xdr->buf->len)); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4838 | |
| 4839 | /* Content type, offset, byte count */ |
| 4840 | p = xdr_reserve_space(xdr, 4 + 8 + 4); |
| 4841 | if (!p) |
| 4842 | return nfserr_resource; |
| 4843 | |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4844 | 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] | 4845 | if (read->rd_vlen < 0) |
| 4846 | return nfserr_resource; |
| 4847 | |
| 4848 | nfserr = nfsd_readv(resp->rqstp, read->rd_fhp, file, read->rd_offset, |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4849 | resp->rqstp->rq_vec, read->rd_vlen, maxcount, eof); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4850 | if (nfserr) |
| 4851 | return nfserr; |
| 4852 | |
| 4853 | tmp = htonl(NFS4_CONTENT_DATA); |
| 4854 | write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4); |
| 4855 | tmp64 = cpu_to_be64(read->rd_offset); |
| 4856 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp64, 8); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4857 | tmp = htonl(*maxcount); |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4858 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 12, &tmp, 4); |
| 4859 | return nfs_ok; |
| 4860 | } |
| 4861 | |
| 4862 | static __be32 |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4863 | nfsd4_encode_read_plus_hole(struct nfsd4_compoundres *resp, |
| 4864 | struct nfsd4_read *read, |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4865 | unsigned long *maxcount, u32 *eof) |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4866 | { |
| 4867 | struct file *file = read->rd_nf->nf_file; |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4868 | loff_t data_pos = vfs_llseek(file, read->rd_offset, SEEK_DATA); |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4869 | loff_t f_size = i_size_read(file_inode(file)); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4870 | unsigned long count; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4871 | __be32 *p; |
| 4872 | |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4873 | if (data_pos == -ENXIO) |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4874 | data_pos = f_size; |
| 4875 | else if (data_pos <= read->rd_offset || (data_pos < f_size && data_pos % PAGE_SIZE)) |
| 4876 | return nfsd4_encode_read_plus_data(resp, read, maxcount, eof, &f_size); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4877 | count = data_pos - read->rd_offset; |
| 4878 | |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4879 | /* Content type, offset, byte count */ |
| 4880 | p = xdr_reserve_space(&resp->xdr, 4 + 8 + 8); |
| 4881 | if (!p) |
| 4882 | return nfserr_resource; |
| 4883 | |
| 4884 | *p++ = htonl(NFS4_CONTENT_HOLE); |
| 4885 | p = xdr_encode_hyper(p, read->rd_offset); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4886 | p = xdr_encode_hyper(p, count); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4887 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4888 | *eof = (read->rd_offset + count) >= f_size; |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4889 | *maxcount = min_t(unsigned long, count, *maxcount); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4890 | return nfs_ok; |
| 4891 | } |
| 4892 | |
| 4893 | static __be32 |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4894 | nfsd4_encode_read_plus(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4895 | struct nfsd4_read *read) |
| 4896 | { |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4897 | unsigned long maxcount, count; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4898 | struct xdr_stream *xdr = &resp->xdr; |
| 4899 | struct file *file; |
| 4900 | int starting_len = xdr->buf->len; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4901 | int last_segment = xdr->buf->len; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4902 | int segments = 0; |
| 4903 | __be32 *p, tmp; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4904 | bool is_data; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4905 | loff_t pos; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4906 | u32 eof; |
| 4907 | |
| 4908 | if (nfserr) |
| 4909 | return nfserr; |
| 4910 | file = read->rd_nf->nf_file; |
| 4911 | |
| 4912 | /* eof flag, segment count */ |
| 4913 | p = xdr_reserve_space(xdr, 4 + 4); |
| 4914 | if (!p) |
| 4915 | return nfserr_resource; |
| 4916 | xdr_commit_encode(xdr); |
| 4917 | |
| 4918 | maxcount = svc_max_payload(resp->rqstp); |
| 4919 | maxcount = min_t(unsigned long, maxcount, |
| 4920 | (xdr->buf->buflen - xdr->buf->len)); |
| 4921 | maxcount = min_t(unsigned long, maxcount, read->rd_length); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4922 | count = maxcount; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4923 | |
| 4924 | eof = read->rd_offset >= i_size_read(file_inode(file)); |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4925 | if (eof) |
| 4926 | goto out; |
| 4927 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4928 | pos = vfs_llseek(file, read->rd_offset, SEEK_HOLE); |
| 4929 | is_data = pos > read->rd_offset; |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4930 | |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4931 | while (count > 0 && !eof) { |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4932 | maxcount = count; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4933 | if (is_data) |
| 4934 | nfserr = nfsd4_encode_read_plus_data(resp, read, &maxcount, &eof, |
| 4935 | segments == 0 ? &pos : NULL); |
| 4936 | else |
| 4937 | nfserr = nfsd4_encode_read_plus_hole(resp, read, &maxcount, &eof); |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4938 | if (nfserr) |
| 4939 | goto out; |
| 4940 | count -= maxcount; |
| 4941 | read->rd_offset += maxcount; |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4942 | is_data = !is_data; |
| 4943 | last_segment = xdr->buf->len; |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4944 | segments++; |
| 4945 | } |
| 4946 | |
Anna Schumaker | 2db2799 | 2020-09-28 13:08:59 -0400 | [diff] [blame] | 4947 | out: |
Anna Schumaker | 278765e | 2020-09-28 13:09:00 -0400 | [diff] [blame] | 4948 | if (nfserr && segments == 0) |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4949 | xdr_truncate_encode(xdr, starting_len); |
| 4950 | else { |
| 4951 | tmp = htonl(eof); |
| 4952 | write_bytes_to_xdr_buf(xdr->buf, starting_len, &tmp, 4); |
| 4953 | tmp = htonl(segments); |
| 4954 | write_bytes_to_xdr_buf(xdr->buf, starting_len + 4, &tmp, 4); |
Anna Schumaker | 9f0b579 | 2020-09-28 13:09:01 -0400 | [diff] [blame] | 4955 | if (nfserr) { |
| 4956 | xdr_truncate_encode(xdr, last_segment); |
| 4957 | nfserr = nfs_ok; |
| 4958 | } |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 4959 | } |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 4960 | |
| 4961 | return nfserr; |
| 4962 | } |
| 4963 | |
| 4964 | static __be32 |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 4965 | nfsd4_encode_copy_notify(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 4966 | struct nfsd4_copy_notify *cn) |
| 4967 | { |
| 4968 | struct xdr_stream *xdr = &resp->xdr; |
| 4969 | __be32 *p; |
| 4970 | |
| 4971 | if (nfserr) |
| 4972 | return nfserr; |
| 4973 | |
| 4974 | /* 8 sec, 4 nsec */ |
| 4975 | p = xdr_reserve_space(xdr, 12); |
| 4976 | if (!p) |
| 4977 | return nfserr_resource; |
| 4978 | |
| 4979 | /* cnr_lease_time */ |
| 4980 | p = xdr_encode_hyper(p, cn->cpn_sec); |
| 4981 | *p++ = cpu_to_be32(cn->cpn_nsec); |
| 4982 | |
| 4983 | /* cnr_stateid */ |
| 4984 | nfserr = nfsd4_encode_stateid(xdr, &cn->cpn_cnr_stateid); |
| 4985 | if (nfserr) |
| 4986 | return nfserr; |
| 4987 | |
| 4988 | /* cnr_src.nl_nsvr */ |
| 4989 | p = xdr_reserve_space(xdr, 4); |
| 4990 | if (!p) |
| 4991 | return nfserr_resource; |
| 4992 | |
| 4993 | *p++ = cpu_to_be32(1); |
| 4994 | |
| 4995 | return nfsd42_encode_nl4_server(resp, &cn->cpn_src); |
| 4996 | } |
| 4997 | |
| 4998 | static __be32 |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 4999 | nfsd4_encode_seek(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5000 | struct nfsd4_seek *seek) |
| 5001 | { |
| 5002 | __be32 *p; |
| 5003 | |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 5004 | p = xdr_reserve_space(&resp->xdr, 4 + 8); |
| 5005 | *p++ = cpu_to_be32(seek->seek_eof); |
| 5006 | p = xdr_encode_hyper(p, seek->seek_pos); |
| 5007 | |
J. Bruce Fields | bac966d | 2017-05-06 11:12:04 -0400 | [diff] [blame] | 5008 | return 0; |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 5009 | } |
| 5010 | |
| 5011 | static __be32 |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5012 | nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p) |
| 5013 | { |
| 5014 | return nfserr; |
| 5015 | } |
| 5016 | |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5017 | /* |
| 5018 | * Encode kmalloc-ed buffer in to XDR stream. |
| 5019 | */ |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 5020 | static __be32 |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5021 | nfsd4_vbuf_to_stream(struct xdr_stream *xdr, char *buf, u32 buflen) |
| 5022 | { |
| 5023 | u32 cplen; |
| 5024 | __be32 *p; |
| 5025 | |
| 5026 | cplen = min_t(unsigned long, buflen, |
| 5027 | ((void *)xdr->end - (void *)xdr->p)); |
| 5028 | p = xdr_reserve_space(xdr, cplen); |
| 5029 | if (!p) |
| 5030 | return nfserr_resource; |
| 5031 | |
| 5032 | memcpy(p, buf, cplen); |
| 5033 | buf += cplen; |
| 5034 | buflen -= cplen; |
| 5035 | |
| 5036 | while (buflen) { |
| 5037 | cplen = min_t(u32, buflen, PAGE_SIZE); |
| 5038 | p = xdr_reserve_space(xdr, cplen); |
| 5039 | if (!p) |
| 5040 | return nfserr_resource; |
| 5041 | |
| 5042 | memcpy(p, buf, cplen); |
| 5043 | |
| 5044 | if (cplen < PAGE_SIZE) { |
| 5045 | /* |
| 5046 | * We're done, with a length that wasn't page |
| 5047 | * aligned, so possibly not word aligned. Pad |
| 5048 | * any trailing bytes with 0. |
| 5049 | */ |
| 5050 | xdr_encode_opaque_fixed(p, NULL, cplen); |
| 5051 | break; |
| 5052 | } |
| 5053 | |
| 5054 | buflen -= PAGE_SIZE; |
| 5055 | buf += PAGE_SIZE; |
| 5056 | } |
| 5057 | |
| 5058 | return 0; |
| 5059 | } |
| 5060 | |
| 5061 | static __be32 |
| 5062 | nfsd4_encode_getxattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5063 | struct nfsd4_getxattr *getxattr) |
| 5064 | { |
| 5065 | struct xdr_stream *xdr = &resp->xdr; |
| 5066 | __be32 *p, err; |
| 5067 | |
| 5068 | p = xdr_reserve_space(xdr, 4); |
| 5069 | if (!p) |
| 5070 | return nfserr_resource; |
| 5071 | |
| 5072 | *p = cpu_to_be32(getxattr->getxa_len); |
| 5073 | |
| 5074 | if (getxattr->getxa_len == 0) |
| 5075 | return 0; |
| 5076 | |
| 5077 | err = nfsd4_vbuf_to_stream(xdr, getxattr->getxa_buf, |
| 5078 | getxattr->getxa_len); |
| 5079 | |
| 5080 | kvfree(getxattr->getxa_buf); |
| 5081 | |
| 5082 | return err; |
| 5083 | } |
| 5084 | |
| 5085 | static __be32 |
| 5086 | nfsd4_encode_setxattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5087 | struct nfsd4_setxattr *setxattr) |
| 5088 | { |
| 5089 | struct xdr_stream *xdr = &resp->xdr; |
| 5090 | __be32 *p; |
| 5091 | |
| 5092 | p = xdr_reserve_space(xdr, 20); |
| 5093 | if (!p) |
| 5094 | return nfserr_resource; |
| 5095 | |
| 5096 | encode_cinfo(p, &setxattr->setxa_cinfo); |
| 5097 | |
| 5098 | return 0; |
| 5099 | } |
| 5100 | |
| 5101 | /* |
| 5102 | * See if there are cookie values that can be rejected outright. |
| 5103 | */ |
| 5104 | static __be32 |
| 5105 | nfsd4_listxattr_validate_cookie(struct nfsd4_listxattrs *listxattrs, |
| 5106 | u32 *offsetp) |
| 5107 | { |
| 5108 | u64 cookie = listxattrs->lsxa_cookie; |
| 5109 | |
| 5110 | /* |
| 5111 | * If the cookie is larger than the maximum number we can fit |
| 5112 | * in either the buffer we just got back from vfs_listxattr, or, |
| 5113 | * XDR-encoded, in the return buffer, it's invalid. |
| 5114 | */ |
| 5115 | if (cookie > (listxattrs->lsxa_len) / (XATTR_USER_PREFIX_LEN + 2)) |
| 5116 | return nfserr_badcookie; |
| 5117 | |
| 5118 | if (cookie > (listxattrs->lsxa_maxcount / |
| 5119 | (XDR_QUADLEN(XATTR_USER_PREFIX_LEN + 2) + 4))) |
| 5120 | return nfserr_badcookie; |
| 5121 | |
| 5122 | *offsetp = (u32)cookie; |
| 5123 | return 0; |
| 5124 | } |
| 5125 | |
| 5126 | static __be32 |
| 5127 | nfsd4_encode_listxattrs(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5128 | struct nfsd4_listxattrs *listxattrs) |
| 5129 | { |
| 5130 | struct xdr_stream *xdr = &resp->xdr; |
| 5131 | u32 cookie_offset, count_offset, eof; |
| 5132 | u32 left, xdrleft, slen, count; |
| 5133 | u32 xdrlen, offset; |
| 5134 | u64 cookie; |
| 5135 | char *sp; |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 5136 | __be32 status, tmp; |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5137 | __be32 *p; |
| 5138 | u32 nuser; |
| 5139 | |
| 5140 | eof = 1; |
| 5141 | |
| 5142 | status = nfsd4_listxattr_validate_cookie(listxattrs, &offset); |
| 5143 | if (status) |
| 5144 | goto out; |
| 5145 | |
| 5146 | /* |
| 5147 | * Reserve space for the cookie and the name array count. Record |
| 5148 | * the offsets to save them later. |
| 5149 | */ |
| 5150 | cookie_offset = xdr->buf->len; |
| 5151 | count_offset = cookie_offset + 8; |
| 5152 | p = xdr_reserve_space(xdr, 12); |
| 5153 | if (!p) { |
| 5154 | status = nfserr_resource; |
| 5155 | goto out; |
| 5156 | } |
| 5157 | |
| 5158 | count = 0; |
| 5159 | left = listxattrs->lsxa_len; |
| 5160 | sp = listxattrs->lsxa_buf; |
| 5161 | nuser = 0; |
| 5162 | |
| 5163 | xdrleft = listxattrs->lsxa_maxcount; |
| 5164 | |
| 5165 | while (left > 0 && xdrleft > 0) { |
| 5166 | slen = strlen(sp); |
| 5167 | |
| 5168 | /* |
Alex Dewar | 4cce11fa | 2020-08-17 18:51:26 +0100 | [diff] [blame] | 5169 | * 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] | 5170 | */ |
| 5171 | if (strncmp(sp, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) |
| 5172 | goto contloop; |
| 5173 | |
| 5174 | slen -= XATTR_USER_PREFIX_LEN; |
| 5175 | xdrlen = 4 + ((slen + 3) & ~3); |
| 5176 | if (xdrlen > xdrleft) { |
| 5177 | if (count == 0) { |
| 5178 | /* |
| 5179 | * Can't even fit the first attribute name. |
| 5180 | */ |
| 5181 | status = nfserr_toosmall; |
| 5182 | goto out; |
| 5183 | } |
| 5184 | eof = 0; |
| 5185 | goto wreof; |
| 5186 | } |
| 5187 | |
| 5188 | left -= XATTR_USER_PREFIX_LEN; |
| 5189 | sp += XATTR_USER_PREFIX_LEN; |
| 5190 | if (nuser++ < offset) |
| 5191 | goto contloop; |
| 5192 | |
| 5193 | |
| 5194 | p = xdr_reserve_space(xdr, xdrlen); |
| 5195 | if (!p) { |
| 5196 | status = nfserr_resource; |
| 5197 | goto out; |
| 5198 | } |
| 5199 | |
Alex Dewar | e2a1840 | 2020-08-12 15:12:51 +0100 | [diff] [blame] | 5200 | xdr_encode_opaque(p, sp, slen); |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5201 | |
| 5202 | xdrleft -= xdrlen; |
| 5203 | count++; |
| 5204 | contloop: |
| 5205 | sp += slen + 1; |
| 5206 | left -= slen + 1; |
| 5207 | } |
| 5208 | |
| 5209 | /* |
| 5210 | * If there were user attributes to copy, but we didn't copy |
| 5211 | * any, the offset was too large (e.g. the cookie was invalid). |
| 5212 | */ |
| 5213 | if (nuser > 0 && count == 0) { |
| 5214 | status = nfserr_badcookie; |
| 5215 | goto out; |
| 5216 | } |
| 5217 | |
| 5218 | wreof: |
| 5219 | p = xdr_reserve_space(xdr, 4); |
| 5220 | if (!p) { |
| 5221 | status = nfserr_resource; |
| 5222 | goto out; |
| 5223 | } |
| 5224 | *p = cpu_to_be32(eof); |
| 5225 | |
| 5226 | cookie = offset + count; |
| 5227 | |
| 5228 | write_bytes_to_xdr_buf(xdr->buf, cookie_offset, &cookie, 8); |
Chuck Lever | b9a4923 | 2020-09-11 14:47:53 -0400 | [diff] [blame] | 5229 | tmp = cpu_to_be32(count); |
| 5230 | 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] | 5231 | out: |
| 5232 | if (listxattrs->lsxa_len) |
| 5233 | kvfree(listxattrs->lsxa_buf); |
| 5234 | return status; |
| 5235 | } |
| 5236 | |
| 5237 | static __be32 |
| 5238 | nfsd4_encode_removexattr(struct nfsd4_compoundres *resp, __be32 nfserr, |
| 5239 | struct nfsd4_removexattr *removexattr) |
| 5240 | { |
| 5241 | struct xdr_stream *xdr = &resp->xdr; |
| 5242 | __be32 *p; |
| 5243 | |
| 5244 | p = xdr_reserve_space(xdr, 20); |
| 5245 | if (!p) |
| 5246 | return nfserr_resource; |
| 5247 | |
| 5248 | p = encode_cinfo(p, &removexattr->rmxa_cinfo); |
| 5249 | return 0; |
| 5250 | } |
| 5251 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5252 | typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *); |
| 5253 | |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5254 | /* |
| 5255 | * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1 |
| 5256 | * since we don't need to filter out obsolete ops as this is |
| 5257 | * done in the decoding phase. |
| 5258 | */ |
Chuck Lever | c1df609 | 2017-08-01 11:59:58 -0400 | [diff] [blame] | 5259 | static const nfsd4_enc nfsd4_enc_ops[] = { |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 5260 | [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access, |
| 5261 | [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close, |
| 5262 | [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit, |
| 5263 | [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create, |
| 5264 | [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5265 | [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
| 5266 | [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr, |
| 5267 | [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh, |
| 5268 | [OP_LINK] = (nfsd4_enc)nfsd4_encode_link, |
| 5269 | [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock, |
| 5270 | [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt, |
| 5271 | [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku, |
| 5272 | [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop, |
| 5273 | [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop, |
| 5274 | [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 5275 | [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open, |
Benny Halevy | 84f09f4 | 2009-03-04 23:05:35 +0200 | [diff] [blame] | 5276 | [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop, |
J. Bruce Fields | ad1060c | 2008-07-18 15:04:16 -0400 | [diff] [blame] | 5277 | [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm, |
| 5278 | [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade, |
| 5279 | [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5280 | [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5281 | [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5282 | [OP_READ] = (nfsd4_enc)nfsd4_encode_read, |
| 5283 | [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir, |
| 5284 | [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink, |
| 5285 | [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove, |
| 5286 | [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename, |
| 5287 | [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop, |
| 5288 | [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5289 | [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop, |
| 5290 | [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo, |
| 5291 | [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr, |
| 5292 | [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid, |
| 5293 | [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop, |
| 5294 | [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop, |
| 5295 | [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write, |
| 5296 | [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5297 | |
| 5298 | /* NFSv4.1 operations */ |
| 5299 | [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop, |
J. Bruce Fields | 1d1bc8f | 2010-10-04 23:12:59 -0400 | [diff] [blame] | 5300 | [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] | 5301 | [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id, |
| 5302 | [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session, |
Kinglong Mee | 43212cc | 2013-12-09 19:04:23 +0800 | [diff] [blame] | 5303 | [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_noop, |
| 5304 | [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5305 | [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 5306 | #ifdef CONFIG_NFSD_PNFS |
| 5307 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_getdeviceinfo, |
| 5308 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, |
| 5309 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_layoutcommit, |
| 5310 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_layoutget, |
| 5311 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_layoutreturn, |
| 5312 | #else |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5313 | [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop, |
| 5314 | [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop, |
| 5315 | [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop, |
| 5316 | [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop, |
| 5317 | [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | 9cf514c | 2014-05-05 13:11:59 +0200 | [diff] [blame] | 5318 | #endif |
Mi Jinlong | 22b6dee | 2010-12-27 14:29:57 +0800 | [diff] [blame] | 5319 | [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_secinfo_no_name, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5320 | [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence, |
| 5321 | [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop, |
Bryan Schumaker | 1745680 | 2011-07-13 10:50:48 -0400 | [diff] [blame] | 5322 | [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_test_stateid, |
Andy Adamson | 2db134e | 2009-04-03 08:27:55 +0300 | [diff] [blame] | 5323 | [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop, |
| 5324 | [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop, |
| 5325 | [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5326 | |
| 5327 | /* NFSv4.2 operations */ |
| 5328 | [OP_ALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, |
Anna Schumaker | 29ae7f9 | 2016-09-07 15:57:30 -0400 | [diff] [blame] | 5329 | [OP_COPY] = (nfsd4_enc)nfsd4_encode_copy, |
Olga Kornievskaia | 5191186 | 2019-08-08 11:14:59 -0400 | [diff] [blame] | 5330 | [OP_COPY_NOTIFY] = (nfsd4_enc)nfsd4_encode_copy_notify, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5331 | [OP_DEALLOCATE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5332 | [OP_IO_ADVISE] = (nfsd4_enc)nfsd4_encode_noop, |
| 5333 | [OP_LAYOUTERROR] = (nfsd4_enc)nfsd4_encode_noop, |
| 5334 | [OP_LAYOUTSTATS] = (nfsd4_enc)nfsd4_encode_noop, |
| 5335 | [OP_OFFLOAD_CANCEL] = (nfsd4_enc)nfsd4_encode_noop, |
Olga Kornievskaia | 6308bc9 | 2018-07-20 18:19:18 -0400 | [diff] [blame] | 5336 | [OP_OFFLOAD_STATUS] = (nfsd4_enc)nfsd4_encode_offload_status, |
Anna Schumaker | 528b849 | 2020-09-28 13:08:58 -0400 | [diff] [blame] | 5337 | [OP_READ_PLUS] = (nfsd4_enc)nfsd4_encode_read_plus, |
Anna Schumaker | 24bab49 | 2014-09-26 13:58:27 -0400 | [diff] [blame] | 5338 | [OP_SEEK] = (nfsd4_enc)nfsd4_encode_seek, |
Anna Schumaker | 87a15a8 | 2014-09-26 13:58:26 -0400 | [diff] [blame] | 5339 | [OP_WRITE_SAME] = (nfsd4_enc)nfsd4_encode_noop, |
Christoph Hellwig | ffa0160 | 2015-12-03 12:59:52 +0100 | [diff] [blame] | 5340 | [OP_CLONE] = (nfsd4_enc)nfsd4_encode_noop, |
Frank van der Linden | 23e50fe | 2020-06-23 22:39:26 +0000 | [diff] [blame] | 5341 | |
| 5342 | /* RFC 8276 extended atributes operations */ |
| 5343 | [OP_GETXATTR] = (nfsd4_enc)nfsd4_encode_getxattr, |
| 5344 | [OP_SETXATTR] = (nfsd4_enc)nfsd4_encode_setxattr, |
| 5345 | [OP_LISTXATTRS] = (nfsd4_enc)nfsd4_encode_listxattrs, |
| 5346 | [OP_REMOVEXATTR] = (nfsd4_enc)nfsd4_encode_removexattr, |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5347 | }; |
| 5348 | |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5349 | /* |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5350 | * Calculate whether we still have space to encode repsize bytes. |
| 5351 | * There are two considerations: |
| 5352 | * - For NFS versions >=4.1, the size of the reply must stay within |
| 5353 | * session limits |
| 5354 | * - For all NFS versions, we must stay within limited preallocated |
| 5355 | * buffer space. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5356 | * |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5357 | * This is called before the operation is processed, so can only provide |
| 5358 | * an upper estimate. For some nonidempotent operations (such as |
| 5359 | * getattr), it's not necessarily a problem if that estimate is wrong, |
| 5360 | * as we can fail it after processing without significant side effects. |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5361 | */ |
J. Bruce Fields | a8095f7 | 2014-03-11 17:54:34 -0400 | [diff] [blame] | 5362 | __be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 respsize) |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5363 | { |
J. Bruce Fields | 67492c9 | 2014-03-08 16:42:05 -0500 | [diff] [blame] | 5364 | struct xdr_buf *buf = &resp->rqstp->rq_res; |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5365 | struct nfsd4_slot *slot = resp->cstate.slot; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5366 | |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5367 | if (buf->len + respsize <= buf->buflen) |
| 5368 | return nfs_ok; |
| 5369 | if (!nfsd4_has_session(&resp->cstate)) |
J. Bruce Fields | ea8d772 | 2014-03-08 17:19:55 -0500 | [diff] [blame] | 5370 | return nfserr_resource; |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5371 | if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) { |
| 5372 | WARN_ON_ONCE(1); |
| 5373 | return nfserr_rep_too_big_to_cache; |
J. Bruce Fields | ea8d772 | 2014-03-08 17:19:55 -0500 | [diff] [blame] | 5374 | } |
J. Bruce Fields | 47ee529 | 2014-03-12 21:39:35 -0400 | [diff] [blame] | 5375 | return nfserr_rep_too_big; |
Andy Adamson | 496c262 | 2009-04-03 08:28:48 +0300 | [diff] [blame] | 5376 | } |
| 5377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5378 | void |
| 5379 | nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) |
| 5380 | { |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5381 | struct xdr_stream *xdr = &resp->xdr; |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5382 | struct nfs4_stateowner *so = resp->cstate.replay_owner; |
J. Bruce Fields | 5f4ab94 | 2014-03-07 11:01:37 -0500 | [diff] [blame] | 5383 | struct svc_rqst *rqstp = resp->rqstp; |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 5384 | const struct nfsd4_operation *opdesc = op->opdesc; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5385 | int post_err_offset; |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5386 | nfsd4_enc encoder; |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 5387 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5388 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5389 | p = xdr_reserve_space(xdr, 8); |
| 5390 | if (!p) { |
| 5391 | WARN_ON_ONCE(1); |
| 5392 | return; |
| 5393 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 5394 | *p++ = cpu_to_be32(op->opnum); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5395 | post_err_offset = xdr->buf->len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5396 | |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5397 | if (op->opnum == OP_ILLEGAL) |
| 5398 | goto status; |
J. Bruce Fields | b7571e4 | 2017-05-06 10:49:21 -0400 | [diff] [blame] | 5399 | if (op->status && opdesc && |
| 5400 | !(opdesc->op_flags & OP_NONTRIVIAL_ERROR_ENCODE)) |
| 5401 | goto status; |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5402 | BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) || |
| 5403 | !nfsd4_enc_ops[op->opnum]); |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5404 | encoder = nfsd4_enc_ops[op->opnum]; |
| 5405 | op->status = encoder(resp, op->status, &op->u); |
Chuck Lever | 0828134 | 2020-11-21 11:36:42 -0500 | [diff] [blame] | 5406 | if (op->status) |
| 5407 | trace_nfsd_compound_encode_err(rqstp, op->opnum, op->status); |
J. Bruce Fields | 34b1744c | 2017-05-05 17:09:37 -0400 | [diff] [blame] | 5408 | if (opdesc && opdesc->op_release) |
| 5409 | opdesc->op_release(&op->u); |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 5410 | xdr_commit_encode(xdr); |
| 5411 | |
J. Bruce Fields | 067e1ac | 2014-03-21 17:26:44 -0400 | [diff] [blame] | 5412 | /* nfsd4_check_resp_size guarantees enough room for error status */ |
J. Bruce Fields | 5f4ab94 | 2014-03-07 11:01:37 -0500 | [diff] [blame] | 5413 | if (!op->status) { |
| 5414 | int space_needed = 0; |
| 5415 | if (!nfsd4_last_compound_op(rqstp)) |
| 5416 | space_needed = COMPOUND_ERR_SLACK_SPACE; |
| 5417 | op->status = nfsd4_check_resp_size(resp, space_needed); |
| 5418 | } |
J. Bruce Fields | c8f13d9 | 2014-05-08 17:38:18 -0400 | [diff] [blame] | 5419 | if (op->status == nfserr_resource && nfsd4_has_session(&resp->cstate)) { |
| 5420 | struct nfsd4_slot *slot = resp->cstate.slot; |
| 5421 | |
| 5422 | if (slot->sl_flags & NFSD4_SLOT_CACHETHIS) |
| 5423 | op->status = nfserr_rep_too_big_to_cache; |
| 5424 | else |
| 5425 | op->status = nfserr_rep_too_big; |
| 5426 | } |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5427 | if (op->status == nfserr_resource || |
| 5428 | op->status == nfserr_rep_too_big || |
| 5429 | op->status == nfserr_rep_too_big_to_cache) { |
| 5430 | /* |
| 5431 | * The operation may have already been encoded or |
| 5432 | * partially encoded. No op returns anything additional |
| 5433 | * in the case of one of these three errors, so we can |
| 5434 | * just truncate back to after the status. But it's a |
| 5435 | * bug if we had to do this on a non-idempotent op: |
| 5436 | */ |
| 5437 | warn_on_nonidempotent_op(op); |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5438 | xdr_truncate_encode(xdr, post_err_offset); |
J. Bruce Fields | 07d1f80 | 2014-03-06 20:39:29 -0500 | [diff] [blame] | 5439 | } |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5440 | if (so) { |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5441 | int len = xdr->buf->len - post_err_offset; |
| 5442 | |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5443 | so->so_replay.rp_status = op->status; |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5444 | so->so_replay.rp_buflen = len; |
| 5445 | read_bytes_from_xdr_buf(xdr->buf, post_err_offset, |
| 5446 | so->so_replay.rp_buf, len); |
J. Bruce Fields | 9411b1d | 2013-04-01 16:37:12 -0400 | [diff] [blame] | 5447 | } |
Benny Halevy | 695e12f | 2008-07-04 14:38:33 +0300 | [diff] [blame] | 5448 | status: |
J. Bruce Fields | 082d4bd | 2013-08-29 15:42:52 -0400 | [diff] [blame] | 5449 | /* Note that op->status is already in network byte order: */ |
| 5450 | 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] | 5451 | } |
| 5452 | |
| 5453 | /* |
| 5454 | * Encode the reply stored in the stateowner reply cache |
| 5455 | * |
| 5456 | * XDR note: do not encode rp->rp_buflen: the buffer contains the |
| 5457 | * previously sent already encoded operation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5458 | */ |
| 5459 | void |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5460 | nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5461 | { |
J. Bruce Fields | bc749ca | 2009-04-07 16:55:27 -0700 | [diff] [blame] | 5462 | __be32 *p; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5463 | struct nfs4_replay *rp = op->replay; |
| 5464 | |
J. Bruce Fields | d0a381d | 2014-01-30 17:18:38 -0500 | [diff] [blame] | 5465 | p = xdr_reserve_space(xdr, 8 + rp->rp_buflen); |
| 5466 | if (!p) { |
| 5467 | WARN_ON_ONCE(1); |
| 5468 | return; |
| 5469 | } |
J. Bruce Fields | c373b0a | 2014-03-22 17:09:18 -0400 | [diff] [blame] | 5470 | *p++ = cpu_to_be32(op->opnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5471 | *p++ = rp->rp_status; /* already xdr'ed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5472 | |
J. Bruce Fields | 0c0c267 | 2014-03-22 18:43:16 -0400 | [diff] [blame] | 5473 | p = xdr_encode_opaque_fixed(p, rp->rp_buf, rp->rp_buflen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5474 | } |
| 5475 | |
Christoph Hellwig | 8537488 | 2017-05-08 18:48:24 +0200 | [diff] [blame] | 5476 | void nfsd4_release_compoundargs(struct svc_rqst *rqstp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5477 | { |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 5478 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 5479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5480 | if (args->ops != args->iops) { |
| 5481 | kfree(args->ops); |
| 5482 | args->ops = args->iops; |
| 5483 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5484 | while (args->to_free) { |
J. Bruce Fields | d5e2338 | 2014-06-24 17:43:45 -0400 | [diff] [blame] | 5485 | struct svcxdr_tmpbuf *tb = args->to_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5486 | args->to_free = tb->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | kfree(tb); |
| 5488 | } |
| 5489 | } |
| 5490 | |
| 5491 | int |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 5492 | nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5493 | { |
Christoph Hellwig | 026fec7 | 2017-05-08 19:01:48 +0200 | [diff] [blame] | 5494 | struct nfsd4_compoundargs *args = rqstp->rq_argp; |
| 5495 | |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 5496 | /* svcxdr_tmp_alloc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5497 | args->tmpp = NULL; |
| 5498 | args->to_free = NULL; |
Chuck Lever | c1346a12 | 2020-11-03 11:54:23 -0500 | [diff] [blame] | 5499 | |
| 5500 | args->xdr = &rqstp->rq_arg_stream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5501 | args->ops = args->iops; |
| 5502 | args->rqstp = rqstp; |
| 5503 | |
J. Bruce Fields | 3e98abf | 2011-07-16 17:15:10 -0400 | [diff] [blame] | 5504 | return !nfsd4_decode_compound(args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | } |
| 5506 | |
| 5507 | int |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 5508 | nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | { |
Christoph Hellwig | 63f8de3 | 2017-05-08 19:42:02 +0200 | [diff] [blame] | 5510 | struct nfsd4_compoundres *resp = rqstp->rq_resp; |
J. Bruce Fields | 6ac9039 | 2014-02-26 17:39:35 -0500 | [diff] [blame] | 5511 | struct xdr_buf *buf = resp->xdr.buf; |
| 5512 | |
| 5513 | WARN_ON_ONCE(buf->len != buf->head[0].iov_len + buf->page_len + |
| 5514 | buf->tail[0].iov_len); |
J. Bruce Fields | dd97fdd | 2014-02-26 17:16:27 -0500 | [diff] [blame] | 5515 | |
Chuck Lever | cc028a1 | 2020-10-02 15:52:44 -0400 | [diff] [blame] | 5516 | *p = resp->cstate.status; |
| 5517 | |
J. Bruce Fields | 2825a7f | 2013-08-26 16:04:46 -0400 | [diff] [blame] | 5518 | rqstp->rq_next_page = resp->xdr.page_ptr + 1; |
| 5519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | p = resp->tagp; |
| 5521 | *p++ = htonl(resp->taglen); |
| 5522 | memcpy(p, resp->tag, resp->taglen); |
| 5523 | p += XDR_QUADLEN(resp->taglen); |
| 5524 | *p++ = htonl(resp->opcnt); |
| 5525 | |
Trond Myklebust | b607664 | 2014-06-30 11:48:35 -0400 | [diff] [blame] | 5526 | nfsd4_sequence_done(resp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5527 | return 1; |
| 5528 | } |
| 5529 | |
| 5530 | /* |
| 5531 | * Local variables: |
| 5532 | * c-basic-offset: 8 |
| 5533 | * End: |
| 5534 | */ |