| .. | .. |
|---|
| 21 | 21 | #include <linux/nfs3.h> |
|---|
| 22 | 22 | #include <linux/nfs_fs.h> |
|---|
| 23 | 23 | #include <linux/nfsacl.h> |
|---|
| 24 | +#include "nfstrace.h" |
|---|
| 24 | 25 | #include "internal.h" |
|---|
| 25 | 26 | |
|---|
| 26 | 27 | #define NFSDBG_FACILITY NFSDBG_XDR |
|---|
| .. | .. |
|---|
| 69 | 70 | #define NFS3_removeres_sz (NFS3_setattrres_sz) |
|---|
| 70 | 71 | #define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz)) |
|---|
| 71 | 72 | #define NFS3_accessres_sz (1+NFS3_post_op_attr_sz+1) |
|---|
| 72 | | -#define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1) |
|---|
| 73 | | -#define NFS3_readres_sz (1+NFS3_post_op_attr_sz+3) |
|---|
| 73 | +#define NFS3_readlinkres_sz (1+NFS3_post_op_attr_sz+1+1) |
|---|
| 74 | +#define NFS3_readres_sz (1+NFS3_post_op_attr_sz+3+1) |
|---|
| 74 | 75 | #define NFS3_writeres_sz (1+NFS3_wcc_data_sz+4) |
|---|
| 75 | 76 | #define NFS3_createres_sz (1+NFS3_post_op_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz) |
|---|
| 76 | 77 | #define NFS3_renameres_sz (1+(2 * NFS3_wcc_data_sz)) |
|---|
| 77 | 78 | #define NFS3_linkres_sz (1+NFS3_post_op_attr_sz+NFS3_wcc_data_sz) |
|---|
| 78 | | -#define NFS3_readdirres_sz (1+NFS3_post_op_attr_sz+2) |
|---|
| 79 | +#define NFS3_readdirres_sz (1+NFS3_post_op_attr_sz+2+1) |
|---|
| 79 | 80 | #define NFS3_fsstatres_sz (1+NFS3_post_op_attr_sz+13) |
|---|
| 80 | 81 | #define NFS3_fsinfores_sz (1+NFS3_post_op_attr_sz+12) |
|---|
| 81 | 82 | #define NFS3_pathconfres_sz (1+NFS3_post_op_attr_sz+6) |
|---|
| .. | .. |
|---|
| 85 | 86 | #define ACL3_setaclargs_sz (NFS3_fh_sz+1+ \ |
|---|
| 86 | 87 | XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)) |
|---|
| 87 | 88 | #define ACL3_getaclres_sz (1+NFS3_post_op_attr_sz+1+ \ |
|---|
| 88 | | - XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)) |
|---|
| 89 | + XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)+1) |
|---|
| 89 | 90 | #define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz) |
|---|
| 90 | 91 | |
|---|
| 91 | 92 | static int nfs3_stat_to_errno(enum nfs_stat); |
|---|
| .. | .. |
|---|
| 104 | 105 | [NF3FIFO] = S_IFIFO, |
|---|
| 105 | 106 | }; |
|---|
| 106 | 107 | |
|---|
| 107 | | -/* |
|---|
| 108 | | - * While encoding arguments, set up the reply buffer in advance to |
|---|
| 109 | | - * receive reply data directly into the page cache. |
|---|
| 110 | | - */ |
|---|
| 111 | | -static void prepare_reply_buffer(struct rpc_rqst *req, struct page **pages, |
|---|
| 112 | | - unsigned int base, unsigned int len, |
|---|
| 113 | | - unsigned int bufsize) |
|---|
| 108 | +static struct user_namespace *rpc_userns(const struct rpc_clnt *clnt) |
|---|
| 114 | 109 | { |
|---|
| 115 | | - struct rpc_auth *auth = req->rq_cred->cr_auth; |
|---|
| 116 | | - unsigned int replen; |
|---|
| 117 | | - |
|---|
| 118 | | - replen = RPC_REPHDRSIZE + auth->au_rslack + bufsize; |
|---|
| 119 | | - xdr_inline_pages(&req->rq_rcv_buf, replen << 2, pages, base, len); |
|---|
| 110 | + if (clnt && clnt->cl_cred) |
|---|
| 111 | + return clnt->cl_cred->user_ns; |
|---|
| 112 | + return &init_user_ns; |
|---|
| 120 | 113 | } |
|---|
| 121 | 114 | |
|---|
| 122 | | -/* |
|---|
| 123 | | - * Handle decode buffer overflows out-of-line. |
|---|
| 124 | | - */ |
|---|
| 125 | | -static void print_overflow_msg(const char *func, const struct xdr_stream *xdr) |
|---|
| 115 | +static struct user_namespace *rpc_rqst_userns(const struct rpc_rqst *rqstp) |
|---|
| 126 | 116 | { |
|---|
| 127 | | - dprintk("NFS: %s prematurely hit the end of our receive buffer. " |
|---|
| 128 | | - "Remaining buffer length is %tu words.\n", |
|---|
| 129 | | - func, xdr->end - xdr->p); |
|---|
| 117 | + if (rqstp->rq_task) |
|---|
| 118 | + return rpc_userns(rqstp->rq_task->tk_client); |
|---|
| 119 | + return &init_user_ns; |
|---|
| 130 | 120 | } |
|---|
| 131 | | - |
|---|
| 132 | 121 | |
|---|
| 133 | 122 | /* |
|---|
| 134 | 123 | * Encode/decode NFSv3 basic data types |
|---|
| .. | .. |
|---|
| 152 | 141 | __be32 *p; |
|---|
| 153 | 142 | |
|---|
| 154 | 143 | p = xdr_inline_decode(xdr, 4); |
|---|
| 155 | | - if (unlikely(p == NULL)) |
|---|
| 156 | | - goto out_overflow; |
|---|
| 144 | + if (unlikely(!p)) |
|---|
| 145 | + return -EIO; |
|---|
| 157 | 146 | *value = be32_to_cpup(p); |
|---|
| 158 | 147 | return 0; |
|---|
| 159 | | -out_overflow: |
|---|
| 160 | | - print_overflow_msg(__func__, xdr); |
|---|
| 161 | | - return -EIO; |
|---|
| 162 | 148 | } |
|---|
| 163 | 149 | |
|---|
| 164 | 150 | static int decode_uint64(struct xdr_stream *xdr, u64 *value) |
|---|
| .. | .. |
|---|
| 166 | 152 | __be32 *p; |
|---|
| 167 | 153 | |
|---|
| 168 | 154 | p = xdr_inline_decode(xdr, 8); |
|---|
| 169 | | - if (unlikely(p == NULL)) |
|---|
| 170 | | - goto out_overflow; |
|---|
| 155 | + if (unlikely(!p)) |
|---|
| 156 | + return -EIO; |
|---|
| 171 | 157 | xdr_decode_hyper(p, value); |
|---|
| 172 | 158 | return 0; |
|---|
| 173 | | -out_overflow: |
|---|
| 174 | | - print_overflow_msg(__func__, xdr); |
|---|
| 175 | | - return -EIO; |
|---|
| 176 | 159 | } |
|---|
| 177 | 160 | |
|---|
| 178 | 161 | /* |
|---|
| .. | .. |
|---|
| 212 | 195 | u32 count; |
|---|
| 213 | 196 | |
|---|
| 214 | 197 | p = xdr_inline_decode(xdr, 4); |
|---|
| 215 | | - if (unlikely(p == NULL)) |
|---|
| 216 | | - goto out_overflow; |
|---|
| 198 | + if (unlikely(!p)) |
|---|
| 199 | + return -EIO; |
|---|
| 217 | 200 | count = be32_to_cpup(p); |
|---|
| 218 | 201 | if (count > NFS3_MAXNAMLEN) |
|---|
| 219 | 202 | goto out_nametoolong; |
|---|
| 220 | 203 | p = xdr_inline_decode(xdr, count); |
|---|
| 221 | | - if (unlikely(p == NULL)) |
|---|
| 222 | | - goto out_overflow; |
|---|
| 204 | + if (unlikely(!p)) |
|---|
| 205 | + return -EIO; |
|---|
| 223 | 206 | *name = (const char *)p; |
|---|
| 224 | 207 | *length = count; |
|---|
| 225 | 208 | return 0; |
|---|
| .. | .. |
|---|
| 227 | 210 | out_nametoolong: |
|---|
| 228 | 211 | dprintk("NFS: returned filename too long: %u\n", count); |
|---|
| 229 | 212 | return -ENAMETOOLONG; |
|---|
| 230 | | -out_overflow: |
|---|
| 231 | | - print_overflow_msg(__func__, xdr); |
|---|
| 232 | | - return -EIO; |
|---|
| 233 | 213 | } |
|---|
| 234 | 214 | |
|---|
| 235 | 215 | /* |
|---|
| .. | .. |
|---|
| 250 | 230 | __be32 *p; |
|---|
| 251 | 231 | |
|---|
| 252 | 232 | p = xdr_inline_decode(xdr, 4); |
|---|
| 253 | | - if (unlikely(p == NULL)) |
|---|
| 254 | | - goto out_overflow; |
|---|
| 233 | + if (unlikely(!p)) |
|---|
| 234 | + return -EIO; |
|---|
| 255 | 235 | count = be32_to_cpup(p); |
|---|
| 256 | 236 | if (unlikely(count >= xdr->buf->page_len || count > NFS3_MAXPATHLEN)) |
|---|
| 257 | 237 | goto out_nametoolong; |
|---|
| .. | .. |
|---|
| 267 | 247 | out_cheating: |
|---|
| 268 | 248 | dprintk("NFS: server cheating in pathname result: " |
|---|
| 269 | 249 | "count %u > recvd %u\n", count, recvd); |
|---|
| 270 | | - return -EIO; |
|---|
| 271 | | -out_overflow: |
|---|
| 272 | | - print_overflow_msg(__func__, xdr); |
|---|
| 273 | 250 | return -EIO; |
|---|
| 274 | 251 | } |
|---|
| 275 | 252 | |
|---|
| .. | .. |
|---|
| 304 | 281 | __be32 *p; |
|---|
| 305 | 282 | |
|---|
| 306 | 283 | p = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE); |
|---|
| 307 | | - if (unlikely(p == NULL)) |
|---|
| 308 | | - goto out_overflow; |
|---|
| 284 | + if (unlikely(!p)) |
|---|
| 285 | + return -EIO; |
|---|
| 309 | 286 | memcpy(verifier, p, NFS3_COOKIEVERFSIZE); |
|---|
| 310 | 287 | return 0; |
|---|
| 311 | | -out_overflow: |
|---|
| 312 | | - print_overflow_msg(__func__, xdr); |
|---|
| 313 | | - return -EIO; |
|---|
| 314 | 288 | } |
|---|
| 315 | 289 | |
|---|
| 316 | 290 | /* |
|---|
| .. | .. |
|---|
| 331 | 305 | __be32 *p; |
|---|
| 332 | 306 | |
|---|
| 333 | 307 | p = xdr_inline_decode(xdr, NFS3_WRITEVERFSIZE); |
|---|
| 334 | | - if (unlikely(p == NULL)) |
|---|
| 335 | | - goto out_overflow; |
|---|
| 308 | + if (unlikely(!p)) |
|---|
| 309 | + return -EIO; |
|---|
| 336 | 310 | memcpy(verifier->data, p, NFS3_WRITEVERFSIZE); |
|---|
| 337 | 311 | return 0; |
|---|
| 338 | | -out_overflow: |
|---|
| 339 | | - print_overflow_msg(__func__, xdr); |
|---|
| 340 | | - return -EIO; |
|---|
| 341 | 312 | } |
|---|
| 342 | 313 | |
|---|
| 343 | 314 | /* |
|---|
| .. | .. |
|---|
| 365 | 336 | __be32 *p; |
|---|
| 366 | 337 | |
|---|
| 367 | 338 | p = xdr_inline_decode(xdr, 4); |
|---|
| 368 | | - if (unlikely(p == NULL)) |
|---|
| 369 | | - goto out_overflow; |
|---|
| 370 | | - *status = be32_to_cpup(p); |
|---|
| 339 | + if (unlikely(!p)) |
|---|
| 340 | + return -EIO; |
|---|
| 341 | + if (unlikely(*p != cpu_to_be32(NFS3_OK))) |
|---|
| 342 | + goto out_status; |
|---|
| 343 | + *status = 0; |
|---|
| 371 | 344 | return 0; |
|---|
| 372 | | -out_overflow: |
|---|
| 373 | | - print_overflow_msg(__func__, xdr); |
|---|
| 374 | | - return -EIO; |
|---|
| 345 | +out_status: |
|---|
| 346 | + *status = be32_to_cpup(p); |
|---|
| 347 | + trace_nfs_xdr_status(xdr, (int)*status); |
|---|
| 348 | + return 0; |
|---|
| 375 | 349 | } |
|---|
| 376 | 350 | |
|---|
| 377 | 351 | /* |
|---|
| .. | .. |
|---|
| 454 | 428 | __be32 *p; |
|---|
| 455 | 429 | |
|---|
| 456 | 430 | p = xdr_inline_decode(xdr, 4); |
|---|
| 457 | | - if (unlikely(p == NULL)) |
|---|
| 458 | | - goto out_overflow; |
|---|
| 431 | + if (unlikely(!p)) |
|---|
| 432 | + return -EIO; |
|---|
| 459 | 433 | length = be32_to_cpup(p++); |
|---|
| 460 | 434 | if (unlikely(length > NFS3_FHSIZE)) |
|---|
| 461 | 435 | goto out_toobig; |
|---|
| 462 | 436 | p = xdr_inline_decode(xdr, length); |
|---|
| 463 | | - if (unlikely(p == NULL)) |
|---|
| 464 | | - goto out_overflow; |
|---|
| 437 | + if (unlikely(!p)) |
|---|
| 438 | + return -EIO; |
|---|
| 465 | 439 | fh->size = length; |
|---|
| 466 | 440 | memcpy(fh->data, p, length); |
|---|
| 467 | 441 | return 0; |
|---|
| 468 | 442 | out_toobig: |
|---|
| 469 | 443 | dprintk("NFS: file handle size (%u) too big\n", length); |
|---|
| 470 | 444 | return -E2BIG; |
|---|
| 471 | | -out_overflow: |
|---|
| 472 | | - print_overflow_msg(__func__, xdr); |
|---|
| 473 | | - return -EIO; |
|---|
| 474 | 445 | } |
|---|
| 475 | 446 | |
|---|
| 476 | 447 | static void zero_nfs_fh3(struct nfs_fh *fh) |
|---|
| .. | .. |
|---|
| 486 | 457 | * uint32 nseconds; |
|---|
| 487 | 458 | * }; |
|---|
| 488 | 459 | */ |
|---|
| 489 | | -static __be32 *xdr_encode_nfstime3(__be32 *p, const struct timespec *timep) |
|---|
| 460 | +static __be32 *xdr_encode_nfstime3(__be32 *p, const struct timespec64 *timep) |
|---|
| 490 | 461 | { |
|---|
| 491 | | - *p++ = cpu_to_be32(timep->tv_sec); |
|---|
| 462 | + *p++ = cpu_to_be32((u32)timep->tv_sec); |
|---|
| 492 | 463 | *p++ = cpu_to_be32(timep->tv_nsec); |
|---|
| 493 | 464 | return p; |
|---|
| 494 | 465 | } |
|---|
| 495 | 466 | |
|---|
| 496 | | -static __be32 *xdr_decode_nfstime3(__be32 *p, struct timespec *timep) |
|---|
| 467 | +static __be32 *xdr_decode_nfstime3(__be32 *p, struct timespec64 *timep) |
|---|
| 497 | 468 | { |
|---|
| 498 | 469 | timep->tv_sec = be32_to_cpup(p++); |
|---|
| 499 | 470 | timep->tv_nsec = be32_to_cpup(p++); |
|---|
| .. | .. |
|---|
| 560 | 531 | * set_mtime mtime; |
|---|
| 561 | 532 | * }; |
|---|
| 562 | 533 | */ |
|---|
| 563 | | -static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr) |
|---|
| 534 | +static void encode_sattr3(struct xdr_stream *xdr, const struct iattr *attr, |
|---|
| 535 | + struct user_namespace *userns) |
|---|
| 564 | 536 | { |
|---|
| 565 | | - struct timespec ts; |
|---|
| 566 | 537 | u32 nbytes; |
|---|
| 567 | 538 | __be32 *p; |
|---|
| 568 | 539 | |
|---|
| .. | .. |
|---|
| 595 | 566 | |
|---|
| 596 | 567 | if (attr->ia_valid & ATTR_UID) { |
|---|
| 597 | 568 | *p++ = xdr_one; |
|---|
| 598 | | - *p++ = cpu_to_be32(from_kuid(&init_user_ns, attr->ia_uid)); |
|---|
| 569 | + *p++ = cpu_to_be32(from_kuid_munged(userns, attr->ia_uid)); |
|---|
| 599 | 570 | } else |
|---|
| 600 | 571 | *p++ = xdr_zero; |
|---|
| 601 | 572 | |
|---|
| 602 | 573 | if (attr->ia_valid & ATTR_GID) { |
|---|
| 603 | 574 | *p++ = xdr_one; |
|---|
| 604 | | - *p++ = cpu_to_be32(from_kgid(&init_user_ns, attr->ia_gid)); |
|---|
| 575 | + *p++ = cpu_to_be32(from_kgid_munged(userns, attr->ia_gid)); |
|---|
| 605 | 576 | } else |
|---|
| 606 | 577 | *p++ = xdr_zero; |
|---|
| 607 | 578 | |
|---|
| .. | .. |
|---|
| 612 | 583 | *p++ = xdr_zero; |
|---|
| 613 | 584 | |
|---|
| 614 | 585 | if (attr->ia_valid & ATTR_ATIME_SET) { |
|---|
| 615 | | - struct timespec ts; |
|---|
| 616 | 586 | *p++ = xdr_two; |
|---|
| 617 | | - ts = timespec64_to_timespec(attr->ia_atime); |
|---|
| 618 | | - p = xdr_encode_nfstime3(p, &ts); |
|---|
| 587 | + p = xdr_encode_nfstime3(p, &attr->ia_atime); |
|---|
| 619 | 588 | } else if (attr->ia_valid & ATTR_ATIME) { |
|---|
| 620 | 589 | *p++ = xdr_one; |
|---|
| 621 | 590 | } else |
|---|
| .. | .. |
|---|
| 623 | 592 | |
|---|
| 624 | 593 | if (attr->ia_valid & ATTR_MTIME_SET) { |
|---|
| 625 | 594 | *p++ = xdr_two; |
|---|
| 626 | | - ts = timespec64_to_timespec(attr->ia_mtime); |
|---|
| 627 | | - xdr_encode_nfstime3(p, &ts); |
|---|
| 595 | + xdr_encode_nfstime3(p, &attr->ia_mtime); |
|---|
| 628 | 596 | } else if (attr->ia_valid & ATTR_MTIME) { |
|---|
| 629 | 597 | *p = xdr_one; |
|---|
| 630 | 598 | } else |
|---|
| .. | .. |
|---|
| 650 | 618 | * nfstime3 ctime; |
|---|
| 651 | 619 | * }; |
|---|
| 652 | 620 | */ |
|---|
| 653 | | -static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr) |
|---|
| 621 | +static int decode_fattr3(struct xdr_stream *xdr, struct nfs_fattr *fattr, |
|---|
| 622 | + struct user_namespace *userns) |
|---|
| 654 | 623 | { |
|---|
| 655 | 624 | umode_t fmode; |
|---|
| 656 | 625 | __be32 *p; |
|---|
| 657 | 626 | |
|---|
| 658 | 627 | p = xdr_inline_decode(xdr, NFS3_fattr_sz << 2); |
|---|
| 659 | | - if (unlikely(p == NULL)) |
|---|
| 660 | | - goto out_overflow; |
|---|
| 628 | + if (unlikely(!p)) |
|---|
| 629 | + return -EIO; |
|---|
| 661 | 630 | |
|---|
| 662 | 631 | p = xdr_decode_ftype3(p, &fmode); |
|---|
| 663 | 632 | |
|---|
| 664 | 633 | fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode; |
|---|
| 665 | 634 | fattr->nlink = be32_to_cpup(p++); |
|---|
| 666 | | - fattr->uid = make_kuid(&init_user_ns, be32_to_cpup(p++)); |
|---|
| 635 | + fattr->uid = make_kuid(userns, be32_to_cpup(p++)); |
|---|
| 667 | 636 | if (!uid_valid(fattr->uid)) |
|---|
| 668 | 637 | goto out_uid; |
|---|
| 669 | | - fattr->gid = make_kgid(&init_user_ns, be32_to_cpup(p++)); |
|---|
| 638 | + fattr->gid = make_kgid(userns, be32_to_cpup(p++)); |
|---|
| 670 | 639 | if (!gid_valid(fattr->gid)) |
|---|
| 671 | 640 | goto out_gid; |
|---|
| 672 | 641 | |
|---|
| .. | .. |
|---|
| 691 | 660 | out_gid: |
|---|
| 692 | 661 | dprintk("NFS: returned invalid gid\n"); |
|---|
| 693 | 662 | return -EINVAL; |
|---|
| 694 | | -out_overflow: |
|---|
| 695 | | - print_overflow_msg(__func__, xdr); |
|---|
| 696 | | - return -EIO; |
|---|
| 697 | 663 | } |
|---|
| 698 | 664 | |
|---|
| 699 | 665 | /* |
|---|
| .. | .. |
|---|
| 706 | 672 | * void; |
|---|
| 707 | 673 | * }; |
|---|
| 708 | 674 | */ |
|---|
| 709 | | -static int decode_post_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr) |
|---|
| 675 | +static int decode_post_op_attr(struct xdr_stream *xdr, struct nfs_fattr *fattr, |
|---|
| 676 | + struct user_namespace *userns) |
|---|
| 710 | 677 | { |
|---|
| 711 | 678 | __be32 *p; |
|---|
| 712 | 679 | |
|---|
| 713 | 680 | p = xdr_inline_decode(xdr, 4); |
|---|
| 714 | | - if (unlikely(p == NULL)) |
|---|
| 715 | | - goto out_overflow; |
|---|
| 681 | + if (unlikely(!p)) |
|---|
| 682 | + return -EIO; |
|---|
| 716 | 683 | if (*p != xdr_zero) |
|---|
| 717 | | - return decode_fattr3(xdr, fattr); |
|---|
| 684 | + return decode_fattr3(xdr, fattr, userns); |
|---|
| 718 | 685 | return 0; |
|---|
| 719 | | -out_overflow: |
|---|
| 720 | | - print_overflow_msg(__func__, xdr); |
|---|
| 721 | | - return -EIO; |
|---|
| 722 | 686 | } |
|---|
| 723 | 687 | |
|---|
| 724 | 688 | /* |
|---|
| .. | .. |
|---|
| 734 | 698 | __be32 *p; |
|---|
| 735 | 699 | |
|---|
| 736 | 700 | p = xdr_inline_decode(xdr, NFS3_wcc_attr_sz << 2); |
|---|
| 737 | | - if (unlikely(p == NULL)) |
|---|
| 738 | | - goto out_overflow; |
|---|
| 701 | + if (unlikely(!p)) |
|---|
| 702 | + return -EIO; |
|---|
| 739 | 703 | |
|---|
| 740 | 704 | fattr->valid |= NFS_ATTR_FATTR_PRESIZE |
|---|
| 741 | 705 | | NFS_ATTR_FATTR_PRECHANGE |
|---|
| .. | .. |
|---|
| 748 | 712 | fattr->pre_change_attr = nfs_timespec_to_change_attr(&fattr->pre_ctime); |
|---|
| 749 | 713 | |
|---|
| 750 | 714 | return 0; |
|---|
| 751 | | -out_overflow: |
|---|
| 752 | | - print_overflow_msg(__func__, xdr); |
|---|
| 753 | | - return -EIO; |
|---|
| 754 | 715 | } |
|---|
| 755 | 716 | |
|---|
| 756 | 717 | /* |
|---|
| .. | .. |
|---|
| 774 | 735 | __be32 *p; |
|---|
| 775 | 736 | |
|---|
| 776 | 737 | p = xdr_inline_decode(xdr, 4); |
|---|
| 777 | | - if (unlikely(p == NULL)) |
|---|
| 778 | | - goto out_overflow; |
|---|
| 738 | + if (unlikely(!p)) |
|---|
| 739 | + return -EIO; |
|---|
| 779 | 740 | if (*p != xdr_zero) |
|---|
| 780 | 741 | return decode_wcc_attr(xdr, fattr); |
|---|
| 781 | 742 | return 0; |
|---|
| 782 | | -out_overflow: |
|---|
| 783 | | - print_overflow_msg(__func__, xdr); |
|---|
| 784 | | - return -EIO; |
|---|
| 785 | 743 | } |
|---|
| 786 | 744 | |
|---|
| 787 | | -static int decode_wcc_data(struct xdr_stream *xdr, struct nfs_fattr *fattr) |
|---|
| 745 | +static int decode_wcc_data(struct xdr_stream *xdr, struct nfs_fattr *fattr, |
|---|
| 746 | + struct user_namespace *userns) |
|---|
| 788 | 747 | { |
|---|
| 789 | 748 | int error; |
|---|
| 790 | 749 | |
|---|
| 791 | 750 | error = decode_pre_op_attr(xdr, fattr); |
|---|
| 792 | 751 | if (unlikely(error)) |
|---|
| 793 | 752 | goto out; |
|---|
| 794 | | - error = decode_post_op_attr(xdr, fattr); |
|---|
| 753 | + error = decode_post_op_attr(xdr, fattr, userns); |
|---|
| 795 | 754 | out: |
|---|
| 796 | 755 | return error; |
|---|
| 797 | 756 | } |
|---|
| .. | .. |
|---|
| 809 | 768 | static int decode_post_op_fh3(struct xdr_stream *xdr, struct nfs_fh *fh) |
|---|
| 810 | 769 | { |
|---|
| 811 | 770 | __be32 *p = xdr_inline_decode(xdr, 4); |
|---|
| 812 | | - if (unlikely(p == NULL)) |
|---|
| 813 | | - goto out_overflow; |
|---|
| 771 | + if (unlikely(!p)) |
|---|
| 772 | + return -EIO; |
|---|
| 814 | 773 | if (*p != xdr_zero) |
|---|
| 815 | 774 | return decode_nfs_fh3(xdr, fh); |
|---|
| 816 | 775 | zero_nfs_fh3(fh); |
|---|
| 817 | 776 | return 0; |
|---|
| 818 | | -out_overflow: |
|---|
| 819 | | - print_overflow_msg(__func__, xdr); |
|---|
| 820 | | - return -EIO; |
|---|
| 821 | 777 | } |
|---|
| 822 | 778 | |
|---|
| 823 | 779 | /* |
|---|
| .. | .. |
|---|
| 896 | 852 | { |
|---|
| 897 | 853 | const struct nfs3_sattrargs *args = data; |
|---|
| 898 | 854 | encode_nfs_fh3(xdr, args->fh); |
|---|
| 899 | | - encode_sattr3(xdr, args->sattr); |
|---|
| 855 | + encode_sattr3(xdr, args->sattr, rpc_rqst_userns(req)); |
|---|
| 900 | 856 | encode_sattrguard3(xdr, args); |
|---|
| 901 | 857 | } |
|---|
| 902 | 858 | |
|---|
| .. | .. |
|---|
| 954 | 910 | const struct nfs3_readlinkargs *args = data; |
|---|
| 955 | 911 | |
|---|
| 956 | 912 | encode_nfs_fh3(xdr, args->fh); |
|---|
| 957 | | - prepare_reply_buffer(req, args->pages, args->pgbase, |
|---|
| 958 | | - args->pglen, NFS3_readlinkres_sz); |
|---|
| 913 | + rpc_prepare_reply_pages(req, args->pages, args->pgbase, |
|---|
| 914 | + args->pglen, NFS3_readlinkres_sz); |
|---|
| 959 | 915 | } |
|---|
| 960 | 916 | |
|---|
| 961 | 917 | /* |
|---|
| .. | .. |
|---|
| 984 | 940 | const void *data) |
|---|
| 985 | 941 | { |
|---|
| 986 | 942 | const struct nfs_pgio_args *args = data; |
|---|
| 943 | + unsigned int replen = args->replen ? args->replen : NFS3_readres_sz; |
|---|
| 987 | 944 | |
|---|
| 988 | 945 | encode_read3args(xdr, args); |
|---|
| 989 | | - prepare_reply_buffer(req, args->pages, args->pgbase, |
|---|
| 990 | | - args->count, NFS3_readres_sz); |
|---|
| 946 | + rpc_prepare_reply_pages(req, args->pages, args->pgbase, |
|---|
| 947 | + args->count, replen); |
|---|
| 991 | 948 | req->rq_rcv_buf.flags |= XDRBUF_READ; |
|---|
| 992 | 949 | } |
|---|
| 993 | 950 | |
|---|
| .. | .. |
|---|
| 1056 | 1013 | * }; |
|---|
| 1057 | 1014 | */ |
|---|
| 1058 | 1015 | static void encode_createhow3(struct xdr_stream *xdr, |
|---|
| 1059 | | - const struct nfs3_createargs *args) |
|---|
| 1016 | + const struct nfs3_createargs *args, |
|---|
| 1017 | + struct user_namespace *userns) |
|---|
| 1060 | 1018 | { |
|---|
| 1061 | 1019 | encode_uint32(xdr, args->createmode); |
|---|
| 1062 | 1020 | switch (args->createmode) { |
|---|
| 1063 | 1021 | case NFS3_CREATE_UNCHECKED: |
|---|
| 1064 | 1022 | case NFS3_CREATE_GUARDED: |
|---|
| 1065 | | - encode_sattr3(xdr, args->sattr); |
|---|
| 1023 | + encode_sattr3(xdr, args->sattr, userns); |
|---|
| 1066 | 1024 | break; |
|---|
| 1067 | 1025 | case NFS3_CREATE_EXCLUSIVE: |
|---|
| 1068 | 1026 | encode_createverf3(xdr, args->verifier); |
|---|
| .. | .. |
|---|
| 1079 | 1037 | const struct nfs3_createargs *args = data; |
|---|
| 1080 | 1038 | |
|---|
| 1081 | 1039 | encode_diropargs3(xdr, args->fh, args->name, args->len); |
|---|
| 1082 | | - encode_createhow3(xdr, args); |
|---|
| 1040 | + encode_createhow3(xdr, args, rpc_rqst_userns(req)); |
|---|
| 1083 | 1041 | } |
|---|
| 1084 | 1042 | |
|---|
| 1085 | 1043 | /* |
|---|
| .. | .. |
|---|
| 1097 | 1055 | const struct nfs3_mkdirargs *args = data; |
|---|
| 1098 | 1056 | |
|---|
| 1099 | 1057 | encode_diropargs3(xdr, args->fh, args->name, args->len); |
|---|
| 1100 | | - encode_sattr3(xdr, args->sattr); |
|---|
| 1058 | + encode_sattr3(xdr, args->sattr, rpc_rqst_userns(req)); |
|---|
| 1101 | 1059 | } |
|---|
| 1102 | 1060 | |
|---|
| 1103 | 1061 | /* |
|---|
| .. | .. |
|---|
| 1114 | 1072 | * }; |
|---|
| 1115 | 1073 | */ |
|---|
| 1116 | 1074 | static void encode_symlinkdata3(struct xdr_stream *xdr, |
|---|
| 1117 | | - const void *data) |
|---|
| 1075 | + const void *data, |
|---|
| 1076 | + struct user_namespace *userns) |
|---|
| 1118 | 1077 | { |
|---|
| 1119 | 1078 | const struct nfs3_symlinkargs *args = data; |
|---|
| 1120 | 1079 | |
|---|
| 1121 | | - encode_sattr3(xdr, args->sattr); |
|---|
| 1080 | + encode_sattr3(xdr, args->sattr, userns); |
|---|
| 1122 | 1081 | encode_nfspath3(xdr, args->pages, args->pathlen); |
|---|
| 1123 | 1082 | } |
|---|
| 1124 | 1083 | |
|---|
| .. | .. |
|---|
| 1129 | 1088 | const struct nfs3_symlinkargs *args = data; |
|---|
| 1130 | 1089 | |
|---|
| 1131 | 1090 | encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen); |
|---|
| 1132 | | - encode_symlinkdata3(xdr, args); |
|---|
| 1091 | + encode_symlinkdata3(xdr, args, rpc_rqst_userns(req)); |
|---|
| 1133 | 1092 | xdr->buf->flags |= XDRBUF_WRITE; |
|---|
| 1134 | 1093 | } |
|---|
| 1135 | 1094 | |
|---|
| .. | .. |
|---|
| 1158 | 1117 | * }; |
|---|
| 1159 | 1118 | */ |
|---|
| 1160 | 1119 | static void encode_devicedata3(struct xdr_stream *xdr, |
|---|
| 1161 | | - const struct nfs3_mknodargs *args) |
|---|
| 1120 | + const struct nfs3_mknodargs *args, |
|---|
| 1121 | + struct user_namespace *userns) |
|---|
| 1162 | 1122 | { |
|---|
| 1163 | | - encode_sattr3(xdr, args->sattr); |
|---|
| 1123 | + encode_sattr3(xdr, args->sattr, userns); |
|---|
| 1164 | 1124 | encode_specdata3(xdr, args->rdev); |
|---|
| 1165 | 1125 | } |
|---|
| 1166 | 1126 | |
|---|
| 1167 | 1127 | static void encode_mknoddata3(struct xdr_stream *xdr, |
|---|
| 1168 | | - const struct nfs3_mknodargs *args) |
|---|
| 1128 | + const struct nfs3_mknodargs *args, |
|---|
| 1129 | + struct user_namespace *userns) |
|---|
| 1169 | 1130 | { |
|---|
| 1170 | 1131 | encode_ftype3(xdr, args->type); |
|---|
| 1171 | 1132 | switch (args->type) { |
|---|
| 1172 | 1133 | case NF3CHR: |
|---|
| 1173 | 1134 | case NF3BLK: |
|---|
| 1174 | | - encode_devicedata3(xdr, args); |
|---|
| 1135 | + encode_devicedata3(xdr, args, userns); |
|---|
| 1175 | 1136 | break; |
|---|
| 1176 | 1137 | case NF3SOCK: |
|---|
| 1177 | 1138 | case NF3FIFO: |
|---|
| 1178 | | - encode_sattr3(xdr, args->sattr); |
|---|
| 1139 | + encode_sattr3(xdr, args->sattr, userns); |
|---|
| 1179 | 1140 | break; |
|---|
| 1180 | 1141 | case NF3REG: |
|---|
| 1181 | 1142 | case NF3DIR: |
|---|
| .. | .. |
|---|
| 1192 | 1153 | const struct nfs3_mknodargs *args = data; |
|---|
| 1193 | 1154 | |
|---|
| 1194 | 1155 | encode_diropargs3(xdr, args->fh, args->name, args->len); |
|---|
| 1195 | | - encode_mknoddata3(xdr, args); |
|---|
| 1156 | + encode_mknoddata3(xdr, args, rpc_rqst_userns(req)); |
|---|
| 1196 | 1157 | } |
|---|
| 1197 | 1158 | |
|---|
| 1198 | 1159 | /* |
|---|
| .. | .. |
|---|
| 1279 | 1240 | const struct nfs3_readdirargs *args = data; |
|---|
| 1280 | 1241 | |
|---|
| 1281 | 1242 | encode_readdir3args(xdr, args); |
|---|
| 1282 | | - prepare_reply_buffer(req, args->pages, 0, |
|---|
| 1243 | + rpc_prepare_reply_pages(req, args->pages, 0, |
|---|
| 1283 | 1244 | args->count, NFS3_readdirres_sz); |
|---|
| 1284 | 1245 | } |
|---|
| 1285 | 1246 | |
|---|
| .. | .. |
|---|
| 1321 | 1282 | const struct nfs3_readdirargs *args = data; |
|---|
| 1322 | 1283 | |
|---|
| 1323 | 1284 | encode_readdirplus3args(xdr, args); |
|---|
| 1324 | | - prepare_reply_buffer(req, args->pages, 0, |
|---|
| 1285 | + rpc_prepare_reply_pages(req, args->pages, 0, |
|---|
| 1325 | 1286 | args->count, NFS3_readdirres_sz); |
|---|
| 1326 | 1287 | } |
|---|
| 1327 | 1288 | |
|---|
| .. | .. |
|---|
| 1365 | 1326 | |
|---|
| 1366 | 1327 | encode_nfs_fh3(xdr, args->fh); |
|---|
| 1367 | 1328 | encode_uint32(xdr, args->mask); |
|---|
| 1368 | | - if (args->mask & (NFS_ACL | NFS_DFACL)) |
|---|
| 1369 | | - prepare_reply_buffer(req, args->pages, 0, |
|---|
| 1329 | + if (args->mask & (NFS_ACL | NFS_DFACL)) { |
|---|
| 1330 | + rpc_prepare_reply_pages(req, args->pages, 0, |
|---|
| 1370 | 1331 | NFSACL_MAXPAGES << PAGE_SHIFT, |
|---|
| 1371 | 1332 | ACL3_getaclres_sz); |
|---|
| 1333 | + req->rq_rcv_buf.flags |= XDRBUF_SPARSE_PAGES; |
|---|
| 1334 | + } |
|---|
| 1372 | 1335 | } |
|---|
| 1373 | 1336 | |
|---|
| 1374 | 1337 | static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req, |
|---|
| .. | .. |
|---|
| 1435 | 1398 | goto out; |
|---|
| 1436 | 1399 | if (status != NFS3_OK) |
|---|
| 1437 | 1400 | goto out_default; |
|---|
| 1438 | | - error = decode_fattr3(xdr, result); |
|---|
| 1401 | + error = decode_fattr3(xdr, result, rpc_rqst_userns(req)); |
|---|
| 1439 | 1402 | out: |
|---|
| 1440 | 1403 | return error; |
|---|
| 1441 | 1404 | out_default: |
|---|
| .. | .. |
|---|
| 1470 | 1433 | error = decode_nfsstat3(xdr, &status); |
|---|
| 1471 | 1434 | if (unlikely(error)) |
|---|
| 1472 | 1435 | goto out; |
|---|
| 1473 | | - error = decode_wcc_data(xdr, result); |
|---|
| 1436 | + error = decode_wcc_data(xdr, result, rpc_rqst_userns(req)); |
|---|
| 1474 | 1437 | if (unlikely(error)) |
|---|
| 1475 | 1438 | goto out; |
|---|
| 1476 | 1439 | if (status != NFS3_OK) |
|---|
| .. | .. |
|---|
| 1505 | 1468 | struct xdr_stream *xdr, |
|---|
| 1506 | 1469 | void *data) |
|---|
| 1507 | 1470 | { |
|---|
| 1471 | + struct user_namespace *userns = rpc_rqst_userns(req); |
|---|
| 1508 | 1472 | struct nfs3_diropres *result = data; |
|---|
| 1509 | 1473 | enum nfs_stat status; |
|---|
| 1510 | 1474 | int error; |
|---|
| .. | .. |
|---|
| 1517 | 1481 | error = decode_nfs_fh3(xdr, result->fh); |
|---|
| 1518 | 1482 | if (unlikely(error)) |
|---|
| 1519 | 1483 | goto out; |
|---|
| 1520 | | - error = decode_post_op_attr(xdr, result->fattr); |
|---|
| 1484 | + error = decode_post_op_attr(xdr, result->fattr, userns); |
|---|
| 1521 | 1485 | if (unlikely(error)) |
|---|
| 1522 | 1486 | goto out; |
|---|
| 1523 | | - error = decode_post_op_attr(xdr, result->dir_attr); |
|---|
| 1487 | + error = decode_post_op_attr(xdr, result->dir_attr, userns); |
|---|
| 1524 | 1488 | out: |
|---|
| 1525 | 1489 | return error; |
|---|
| 1526 | 1490 | out_default: |
|---|
| 1527 | | - error = decode_post_op_attr(xdr, result->dir_attr); |
|---|
| 1491 | + error = decode_post_op_attr(xdr, result->dir_attr, userns); |
|---|
| 1528 | 1492 | if (unlikely(error)) |
|---|
| 1529 | 1493 | goto out; |
|---|
| 1530 | 1494 | return nfs3_stat_to_errno(status); |
|---|
| .. | .. |
|---|
| 1560 | 1524 | error = decode_nfsstat3(xdr, &status); |
|---|
| 1561 | 1525 | if (unlikely(error)) |
|---|
| 1562 | 1526 | goto out; |
|---|
| 1563 | | - error = decode_post_op_attr(xdr, result->fattr); |
|---|
| 1527 | + error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req)); |
|---|
| 1564 | 1528 | if (unlikely(error)) |
|---|
| 1565 | 1529 | goto out; |
|---|
| 1566 | 1530 | if (status != NFS3_OK) |
|---|
| .. | .. |
|---|
| 1601 | 1565 | error = decode_nfsstat3(xdr, &status); |
|---|
| 1602 | 1566 | if (unlikely(error)) |
|---|
| 1603 | 1567 | goto out; |
|---|
| 1604 | | - error = decode_post_op_attr(xdr, result); |
|---|
| 1568 | + error = decode_post_op_attr(xdr, result, rpc_rqst_userns(req)); |
|---|
| 1605 | 1569 | if (unlikely(error)) |
|---|
| 1606 | 1570 | goto out; |
|---|
| 1607 | 1571 | if (status != NFS3_OK) |
|---|
| .. | .. |
|---|
| 1641 | 1605 | __be32 *p; |
|---|
| 1642 | 1606 | |
|---|
| 1643 | 1607 | p = xdr_inline_decode(xdr, 4 + 4 + 4); |
|---|
| 1644 | | - if (unlikely(p == NULL)) |
|---|
| 1645 | | - goto out_overflow; |
|---|
| 1608 | + if (unlikely(!p)) |
|---|
| 1609 | + return -EIO; |
|---|
| 1646 | 1610 | count = be32_to_cpup(p++); |
|---|
| 1647 | 1611 | eof = be32_to_cpup(p++); |
|---|
| 1648 | 1612 | ocount = be32_to_cpup(p++); |
|---|
| .. | .. |
|---|
| 1665 | 1629 | count = recvd; |
|---|
| 1666 | 1630 | eof = 0; |
|---|
| 1667 | 1631 | goto out; |
|---|
| 1668 | | -out_overflow: |
|---|
| 1669 | | - print_overflow_msg(__func__, xdr); |
|---|
| 1670 | | - return -EIO; |
|---|
| 1671 | 1632 | } |
|---|
| 1672 | 1633 | |
|---|
| 1673 | 1634 | static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr, |
|---|
| 1674 | 1635 | void *data) |
|---|
| 1675 | 1636 | { |
|---|
| 1676 | 1637 | struct nfs_pgio_res *result = data; |
|---|
| 1638 | + unsigned int pos; |
|---|
| 1677 | 1639 | enum nfs_stat status; |
|---|
| 1678 | 1640 | int error; |
|---|
| 1679 | 1641 | |
|---|
| 1642 | + pos = xdr_stream_pos(xdr); |
|---|
| 1680 | 1643 | error = decode_nfsstat3(xdr, &status); |
|---|
| 1681 | 1644 | if (unlikely(error)) |
|---|
| 1682 | 1645 | goto out; |
|---|
| 1683 | | - error = decode_post_op_attr(xdr, result->fattr); |
|---|
| 1646 | + error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req)); |
|---|
| 1684 | 1647 | if (unlikely(error)) |
|---|
| 1685 | 1648 | goto out; |
|---|
| 1686 | 1649 | result->op_status = status; |
|---|
| 1687 | 1650 | if (status != NFS3_OK) |
|---|
| 1688 | 1651 | goto out_status; |
|---|
| 1652 | + result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2); |
|---|
| 1689 | 1653 | error = decode_read3resok(xdr, result); |
|---|
| 1690 | 1654 | out: |
|---|
| 1691 | 1655 | return error; |
|---|
| .. | .. |
|---|
| 1726 | 1690 | __be32 *p; |
|---|
| 1727 | 1691 | |
|---|
| 1728 | 1692 | p = xdr_inline_decode(xdr, 4 + 4); |
|---|
| 1729 | | - if (unlikely(p == NULL)) |
|---|
| 1730 | | - goto out_overflow; |
|---|
| 1693 | + if (unlikely(!p)) |
|---|
| 1694 | + return -EIO; |
|---|
| 1731 | 1695 | result->count = be32_to_cpup(p++); |
|---|
| 1732 | 1696 | result->verf->committed = be32_to_cpup(p++); |
|---|
| 1733 | 1697 | if (unlikely(result->verf->committed > NFS_FILE_SYNC)) |
|---|
| 1734 | 1698 | goto out_badvalue; |
|---|
| 1735 | 1699 | if (decode_writeverf3(xdr, &result->verf->verifier)) |
|---|
| 1736 | | - goto out_eio; |
|---|
| 1700 | + return -EIO; |
|---|
| 1737 | 1701 | return result->count; |
|---|
| 1738 | 1702 | out_badvalue: |
|---|
| 1739 | 1703 | dprintk("NFS: bad stable_how value: %u\n", result->verf->committed); |
|---|
| 1740 | | - return -EIO; |
|---|
| 1741 | | -out_overflow: |
|---|
| 1742 | | - print_overflow_msg(__func__, xdr); |
|---|
| 1743 | | -out_eio: |
|---|
| 1744 | 1704 | return -EIO; |
|---|
| 1745 | 1705 | } |
|---|
| 1746 | 1706 | |
|---|
| .. | .. |
|---|
| 1754 | 1714 | error = decode_nfsstat3(xdr, &status); |
|---|
| 1755 | 1715 | if (unlikely(error)) |
|---|
| 1756 | 1716 | goto out; |
|---|
| 1757 | | - error = decode_wcc_data(xdr, result->fattr); |
|---|
| 1717 | + error = decode_wcc_data(xdr, result->fattr, rpc_rqst_userns(req)); |
|---|
| 1758 | 1718 | if (unlikely(error)) |
|---|
| 1759 | 1719 | goto out; |
|---|
| 1760 | 1720 | result->op_status = status; |
|---|
| .. | .. |
|---|
| 1788 | 1748 | * }; |
|---|
| 1789 | 1749 | */ |
|---|
| 1790 | 1750 | static int decode_create3resok(struct xdr_stream *xdr, |
|---|
| 1791 | | - struct nfs3_diropres *result) |
|---|
| 1751 | + struct nfs3_diropres *result, |
|---|
| 1752 | + struct user_namespace *userns) |
|---|
| 1792 | 1753 | { |
|---|
| 1793 | 1754 | int error; |
|---|
| 1794 | 1755 | |
|---|
| 1795 | 1756 | error = decode_post_op_fh3(xdr, result->fh); |
|---|
| 1796 | 1757 | if (unlikely(error)) |
|---|
| 1797 | 1758 | goto out; |
|---|
| 1798 | | - error = decode_post_op_attr(xdr, result->fattr); |
|---|
| 1759 | + error = decode_post_op_attr(xdr, result->fattr, userns); |
|---|
| 1799 | 1760 | if (unlikely(error)) |
|---|
| 1800 | 1761 | goto out; |
|---|
| 1801 | 1762 | /* The server isn't required to return a file handle. |
|---|
| .. | .. |
|---|
| 1804 | 1765 | * values for the new object. */ |
|---|
| 1805 | 1766 | if (result->fh->size == 0) |
|---|
| 1806 | 1767 | result->fattr->valid = 0; |
|---|
| 1807 | | - error = decode_wcc_data(xdr, result->dir_attr); |
|---|
| 1768 | + error = decode_wcc_data(xdr, result->dir_attr, userns); |
|---|
| 1808 | 1769 | out: |
|---|
| 1809 | 1770 | return error; |
|---|
| 1810 | 1771 | } |
|---|
| .. | .. |
|---|
| 1813 | 1774 | struct xdr_stream *xdr, |
|---|
| 1814 | 1775 | void *data) |
|---|
| 1815 | 1776 | { |
|---|
| 1777 | + struct user_namespace *userns = rpc_rqst_userns(req); |
|---|
| 1816 | 1778 | struct nfs3_diropres *result = data; |
|---|
| 1817 | 1779 | enum nfs_stat status; |
|---|
| 1818 | 1780 | int error; |
|---|
| .. | .. |
|---|
| 1822 | 1784 | goto out; |
|---|
| 1823 | 1785 | if (status != NFS3_OK) |
|---|
| 1824 | 1786 | goto out_default; |
|---|
| 1825 | | - error = decode_create3resok(xdr, result); |
|---|
| 1787 | + error = decode_create3resok(xdr, result, userns); |
|---|
| 1826 | 1788 | out: |
|---|
| 1827 | 1789 | return error; |
|---|
| 1828 | 1790 | out_default: |
|---|
| 1829 | | - error = decode_wcc_data(xdr, result->dir_attr); |
|---|
| 1791 | + error = decode_wcc_data(xdr, result->dir_attr, userns); |
|---|
| 1830 | 1792 | if (unlikely(error)) |
|---|
| 1831 | 1793 | goto out; |
|---|
| 1832 | 1794 | return nfs3_stat_to_errno(status); |
|---|
| .. | .. |
|---|
| 1861 | 1823 | error = decode_nfsstat3(xdr, &status); |
|---|
| 1862 | 1824 | if (unlikely(error)) |
|---|
| 1863 | 1825 | goto out; |
|---|
| 1864 | | - error = decode_wcc_data(xdr, result->dir_attr); |
|---|
| 1826 | + error = decode_wcc_data(xdr, result->dir_attr, rpc_rqst_userns(req)); |
|---|
| 1865 | 1827 | if (unlikely(error)) |
|---|
| 1866 | 1828 | goto out; |
|---|
| 1867 | 1829 | if (status != NFS3_OK) |
|---|
| .. | .. |
|---|
| 1896 | 1858 | struct xdr_stream *xdr, |
|---|
| 1897 | 1859 | void *data) |
|---|
| 1898 | 1860 | { |
|---|
| 1861 | + struct user_namespace *userns = rpc_rqst_userns(req); |
|---|
| 1899 | 1862 | struct nfs_renameres *result = data; |
|---|
| 1900 | 1863 | enum nfs_stat status; |
|---|
| 1901 | 1864 | int error; |
|---|
| .. | .. |
|---|
| 1903 | 1866 | error = decode_nfsstat3(xdr, &status); |
|---|
| 1904 | 1867 | if (unlikely(error)) |
|---|
| 1905 | 1868 | goto out; |
|---|
| 1906 | | - error = decode_wcc_data(xdr, result->old_fattr); |
|---|
| 1869 | + error = decode_wcc_data(xdr, result->old_fattr, userns); |
|---|
| 1907 | 1870 | if (unlikely(error)) |
|---|
| 1908 | 1871 | goto out; |
|---|
| 1909 | | - error = decode_wcc_data(xdr, result->new_fattr); |
|---|
| 1872 | + error = decode_wcc_data(xdr, result->new_fattr, userns); |
|---|
| 1910 | 1873 | if (unlikely(error)) |
|---|
| 1911 | 1874 | goto out; |
|---|
| 1912 | 1875 | if (status != NFS3_OK) |
|---|
| .. | .. |
|---|
| 1940 | 1903 | static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr, |
|---|
| 1941 | 1904 | void *data) |
|---|
| 1942 | 1905 | { |
|---|
| 1906 | + struct user_namespace *userns = rpc_rqst_userns(req); |
|---|
| 1943 | 1907 | struct nfs3_linkres *result = data; |
|---|
| 1944 | 1908 | enum nfs_stat status; |
|---|
| 1945 | 1909 | int error; |
|---|
| .. | .. |
|---|
| 1947 | 1911 | error = decode_nfsstat3(xdr, &status); |
|---|
| 1948 | 1912 | if (unlikely(error)) |
|---|
| 1949 | 1913 | goto out; |
|---|
| 1950 | | - error = decode_post_op_attr(xdr, result->fattr); |
|---|
| 1914 | + error = decode_post_op_attr(xdr, result->fattr, userns); |
|---|
| 1951 | 1915 | if (unlikely(error)) |
|---|
| 1952 | 1916 | goto out; |
|---|
| 1953 | | - error = decode_wcc_data(xdr, result->dir_attr); |
|---|
| 1917 | + error = decode_wcc_data(xdr, result->dir_attr, userns); |
|---|
| 1954 | 1918 | if (unlikely(error)) |
|---|
| 1955 | 1919 | goto out; |
|---|
| 1956 | 1920 | if (status != NFS3_OK) |
|---|
| .. | .. |
|---|
| 1999 | 1963 | int nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry, |
|---|
| 2000 | 1964 | bool plus) |
|---|
| 2001 | 1965 | { |
|---|
| 2002 | | - struct nfs_entry old = *entry; |
|---|
| 1966 | + struct user_namespace *userns = rpc_userns(entry->server->client); |
|---|
| 2003 | 1967 | __be32 *p; |
|---|
| 2004 | 1968 | int error; |
|---|
| 2005 | 1969 | u64 new_cookie; |
|---|
| 2006 | 1970 | |
|---|
| 2007 | 1971 | p = xdr_inline_decode(xdr, 4); |
|---|
| 2008 | | - if (unlikely(p == NULL)) |
|---|
| 2009 | | - goto out_overflow; |
|---|
| 1972 | + if (unlikely(!p)) |
|---|
| 1973 | + return -EAGAIN; |
|---|
| 2010 | 1974 | if (*p == xdr_zero) { |
|---|
| 2011 | 1975 | p = xdr_inline_decode(xdr, 4); |
|---|
| 2012 | | - if (unlikely(p == NULL)) |
|---|
| 2013 | | - goto out_overflow; |
|---|
| 1976 | + if (unlikely(!p)) |
|---|
| 1977 | + return -EAGAIN; |
|---|
| 2014 | 1978 | if (*p == xdr_zero) |
|---|
| 2015 | 1979 | return -EAGAIN; |
|---|
| 2016 | 1980 | entry->eof = 1; |
|---|
| .. | .. |
|---|
| 2019 | 1983 | |
|---|
| 2020 | 1984 | error = decode_fileid3(xdr, &entry->ino); |
|---|
| 2021 | 1985 | if (unlikely(error)) |
|---|
| 2022 | | - return error; |
|---|
| 1986 | + return -EAGAIN; |
|---|
| 2023 | 1987 | |
|---|
| 2024 | 1988 | error = decode_inline_filename3(xdr, &entry->name, &entry->len); |
|---|
| 2025 | 1989 | if (unlikely(error)) |
|---|
| 2026 | | - return error; |
|---|
| 1990 | + return error == -ENAMETOOLONG ? -ENAMETOOLONG : -EAGAIN; |
|---|
| 2027 | 1991 | |
|---|
| 2028 | 1992 | error = decode_cookie3(xdr, &new_cookie); |
|---|
| 2029 | 1993 | if (unlikely(error)) |
|---|
| 2030 | | - return error; |
|---|
| 1994 | + return -EAGAIN; |
|---|
| 2031 | 1995 | |
|---|
| 2032 | 1996 | entry->d_type = DT_UNKNOWN; |
|---|
| 2033 | 1997 | |
|---|
| 2034 | 1998 | if (plus) { |
|---|
| 2035 | 1999 | entry->fattr->valid = 0; |
|---|
| 2036 | | - error = decode_post_op_attr(xdr, entry->fattr); |
|---|
| 2000 | + error = decode_post_op_attr(xdr, entry->fattr, userns); |
|---|
| 2037 | 2001 | if (unlikely(error)) |
|---|
| 2038 | | - return error; |
|---|
| 2002 | + return -EAGAIN; |
|---|
| 2039 | 2003 | if (entry->fattr->valid & NFS_ATTR_FATTR_V3) |
|---|
| 2040 | 2004 | entry->d_type = nfs_umode_to_dtype(entry->fattr->mode); |
|---|
| 2041 | 2005 | |
|---|
| .. | .. |
|---|
| 2046 | 2010 | |
|---|
| 2047 | 2011 | /* In fact, a post_op_fh3: */ |
|---|
| 2048 | 2012 | p = xdr_inline_decode(xdr, 4); |
|---|
| 2049 | | - if (unlikely(p == NULL)) |
|---|
| 2050 | | - goto out_overflow; |
|---|
| 2013 | + if (unlikely(!p)) |
|---|
| 2014 | + return -EAGAIN; |
|---|
| 2051 | 2015 | if (*p != xdr_zero) { |
|---|
| 2052 | 2016 | error = decode_nfs_fh3(xdr, entry->fh); |
|---|
| 2053 | | - if (unlikely(error)) { |
|---|
| 2054 | | - if (error == -E2BIG) |
|---|
| 2055 | | - goto out_truncated; |
|---|
| 2056 | | - return error; |
|---|
| 2057 | | - } |
|---|
| 2017 | + if (unlikely(error)) |
|---|
| 2018 | + return -EAGAIN; |
|---|
| 2058 | 2019 | } else |
|---|
| 2059 | 2020 | zero_nfs_fh3(entry->fh); |
|---|
| 2060 | 2021 | } |
|---|
| .. | .. |
|---|
| 2063 | 2024 | entry->cookie = new_cookie; |
|---|
| 2064 | 2025 | |
|---|
| 2065 | 2026 | return 0; |
|---|
| 2066 | | - |
|---|
| 2067 | | -out_overflow: |
|---|
| 2068 | | - print_overflow_msg(__func__, xdr); |
|---|
| 2069 | | - return -EAGAIN; |
|---|
| 2070 | | -out_truncated: |
|---|
| 2071 | | - dprintk("NFS: directory entry contains invalid file handle\n"); |
|---|
| 2072 | | - *entry = old; |
|---|
| 2073 | | - return -EAGAIN; |
|---|
| 2074 | 2027 | } |
|---|
| 2075 | 2028 | |
|---|
| 2076 | 2029 | /* |
|---|
| .. | .. |
|---|
| 2108 | 2061 | } |
|---|
| 2109 | 2062 | |
|---|
| 2110 | 2063 | static int decode_readdir3resok(struct xdr_stream *xdr, |
|---|
| 2111 | | - struct nfs3_readdirres *result) |
|---|
| 2064 | + struct nfs3_readdirres *result, |
|---|
| 2065 | + struct user_namespace *userns) |
|---|
| 2112 | 2066 | { |
|---|
| 2113 | 2067 | int error; |
|---|
| 2114 | 2068 | |
|---|
| 2115 | | - error = decode_post_op_attr(xdr, result->dir_attr); |
|---|
| 2069 | + error = decode_post_op_attr(xdr, result->dir_attr, userns); |
|---|
| 2116 | 2070 | if (unlikely(error)) |
|---|
| 2117 | 2071 | goto out; |
|---|
| 2118 | 2072 | /* XXX: do we need to check if result->verf != NULL ? */ |
|---|
| .. | .. |
|---|
| 2137 | 2091 | goto out; |
|---|
| 2138 | 2092 | if (status != NFS3_OK) |
|---|
| 2139 | 2093 | goto out_default; |
|---|
| 2140 | | - error = decode_readdir3resok(xdr, result); |
|---|
| 2094 | + error = decode_readdir3resok(xdr, result, rpc_rqst_userns(req)); |
|---|
| 2141 | 2095 | out: |
|---|
| 2142 | 2096 | return error; |
|---|
| 2143 | 2097 | out_default: |
|---|
| 2144 | | - error = decode_post_op_attr(xdr, result->dir_attr); |
|---|
| 2098 | + error = decode_post_op_attr(xdr, result->dir_attr, rpc_rqst_userns(req)); |
|---|
| 2145 | 2099 | if (unlikely(error)) |
|---|
| 2146 | 2100 | goto out; |
|---|
| 2147 | 2101 | return nfs3_stat_to_errno(status); |
|---|
| .. | .. |
|---|
| 2178 | 2132 | __be32 *p; |
|---|
| 2179 | 2133 | |
|---|
| 2180 | 2134 | p = xdr_inline_decode(xdr, 8 * 6 + 4); |
|---|
| 2181 | | - if (unlikely(p == NULL)) |
|---|
| 2182 | | - goto out_overflow; |
|---|
| 2135 | + if (unlikely(!p)) |
|---|
| 2136 | + return -EIO; |
|---|
| 2183 | 2137 | p = xdr_decode_size3(p, &result->tbytes); |
|---|
| 2184 | 2138 | p = xdr_decode_size3(p, &result->fbytes); |
|---|
| 2185 | 2139 | p = xdr_decode_size3(p, &result->abytes); |
|---|
| .. | .. |
|---|
| 2188 | 2142 | xdr_decode_size3(p, &result->afiles); |
|---|
| 2189 | 2143 | /* ignore invarsec */ |
|---|
| 2190 | 2144 | return 0; |
|---|
| 2191 | | -out_overflow: |
|---|
| 2192 | | - print_overflow_msg(__func__, xdr); |
|---|
| 2193 | | - return -EIO; |
|---|
| 2194 | 2145 | } |
|---|
| 2195 | 2146 | |
|---|
| 2196 | 2147 | static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req, |
|---|
| .. | .. |
|---|
| 2204 | 2155 | error = decode_nfsstat3(xdr, &status); |
|---|
| 2205 | 2156 | if (unlikely(error)) |
|---|
| 2206 | 2157 | goto out; |
|---|
| 2207 | | - error = decode_post_op_attr(xdr, result->fattr); |
|---|
| 2158 | + error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req)); |
|---|
| 2208 | 2159 | if (unlikely(error)) |
|---|
| 2209 | 2160 | goto out; |
|---|
| 2210 | 2161 | if (status != NFS3_OK) |
|---|
| .. | .. |
|---|
| 2250 | 2201 | __be32 *p; |
|---|
| 2251 | 2202 | |
|---|
| 2252 | 2203 | p = xdr_inline_decode(xdr, 4 * 7 + 8 + 8 + 4); |
|---|
| 2253 | | - if (unlikely(p == NULL)) |
|---|
| 2254 | | - goto out_overflow; |
|---|
| 2204 | + if (unlikely(!p)) |
|---|
| 2205 | + return -EIO; |
|---|
| 2255 | 2206 | result->rtmax = be32_to_cpup(p++); |
|---|
| 2256 | 2207 | result->rtpref = be32_to_cpup(p++); |
|---|
| 2257 | 2208 | result->rtmult = be32_to_cpup(p++); |
|---|
| .. | .. |
|---|
| 2265 | 2216 | /* ignore properties */ |
|---|
| 2266 | 2217 | result->lease_time = 0; |
|---|
| 2267 | 2218 | return 0; |
|---|
| 2268 | | -out_overflow: |
|---|
| 2269 | | - print_overflow_msg(__func__, xdr); |
|---|
| 2270 | | - return -EIO; |
|---|
| 2271 | 2219 | } |
|---|
| 2272 | 2220 | |
|---|
| 2273 | 2221 | static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req, |
|---|
| .. | .. |
|---|
| 2281 | 2229 | error = decode_nfsstat3(xdr, &status); |
|---|
| 2282 | 2230 | if (unlikely(error)) |
|---|
| 2283 | 2231 | goto out; |
|---|
| 2284 | | - error = decode_post_op_attr(xdr, result->fattr); |
|---|
| 2232 | + error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req)); |
|---|
| 2285 | 2233 | if (unlikely(error)) |
|---|
| 2286 | 2234 | goto out; |
|---|
| 2287 | 2235 | if (status != NFS3_OK) |
|---|
| .. | .. |
|---|
| 2323 | 2271 | __be32 *p; |
|---|
| 2324 | 2272 | |
|---|
| 2325 | 2273 | p = xdr_inline_decode(xdr, 4 * 6); |
|---|
| 2326 | | - if (unlikely(p == NULL)) |
|---|
| 2327 | | - goto out_overflow; |
|---|
| 2274 | + if (unlikely(!p)) |
|---|
| 2275 | + return -EIO; |
|---|
| 2328 | 2276 | result->max_link = be32_to_cpup(p++); |
|---|
| 2329 | 2277 | result->max_namelen = be32_to_cpup(p); |
|---|
| 2330 | 2278 | /* ignore remaining fields */ |
|---|
| 2331 | 2279 | return 0; |
|---|
| 2332 | | -out_overflow: |
|---|
| 2333 | | - print_overflow_msg(__func__, xdr); |
|---|
| 2334 | | - return -EIO; |
|---|
| 2335 | 2280 | } |
|---|
| 2336 | 2281 | |
|---|
| 2337 | 2282 | static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req, |
|---|
| .. | .. |
|---|
| 2345 | 2290 | error = decode_nfsstat3(xdr, &status); |
|---|
| 2346 | 2291 | if (unlikely(error)) |
|---|
| 2347 | 2292 | goto out; |
|---|
| 2348 | | - error = decode_post_op_attr(xdr, result->fattr); |
|---|
| 2293 | + error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req)); |
|---|
| 2349 | 2294 | if (unlikely(error)) |
|---|
| 2350 | 2295 | goto out; |
|---|
| 2351 | 2296 | if (status != NFS3_OK) |
|---|
| .. | .. |
|---|
| 2388 | 2333 | error = decode_nfsstat3(xdr, &status); |
|---|
| 2389 | 2334 | if (unlikely(error)) |
|---|
| 2390 | 2335 | goto out; |
|---|
| 2391 | | - error = decode_wcc_data(xdr, result->fattr); |
|---|
| 2336 | + error = decode_wcc_data(xdr, result->fattr, rpc_rqst_userns(req)); |
|---|
| 2392 | 2337 | if (unlikely(error)) |
|---|
| 2393 | 2338 | goto out; |
|---|
| 2394 | 2339 | result->op_status = status; |
|---|
| .. | .. |
|---|
| 2406 | 2351 | #ifdef CONFIG_NFS_V3_ACL |
|---|
| 2407 | 2352 | |
|---|
| 2408 | 2353 | static inline int decode_getacl3resok(struct xdr_stream *xdr, |
|---|
| 2409 | | - struct nfs3_getaclres *result) |
|---|
| 2354 | + struct nfs3_getaclres *result, |
|---|
| 2355 | + struct user_namespace *userns) |
|---|
| 2410 | 2356 | { |
|---|
| 2411 | 2357 | struct posix_acl **acl; |
|---|
| 2412 | 2358 | unsigned int *aclcnt; |
|---|
| 2413 | 2359 | size_t hdrlen; |
|---|
| 2414 | 2360 | int error; |
|---|
| 2415 | 2361 | |
|---|
| 2416 | | - error = decode_post_op_attr(xdr, result->fattr); |
|---|
| 2362 | + error = decode_post_op_attr(xdr, result->fattr, userns); |
|---|
| 2417 | 2363 | if (unlikely(error)) |
|---|
| 2418 | 2364 | goto out; |
|---|
| 2419 | 2365 | error = decode_uint32(xdr, &result->mask); |
|---|
| .. | .. |
|---|
| 2461 | 2407 | goto out; |
|---|
| 2462 | 2408 | if (status != NFS3_OK) |
|---|
| 2463 | 2409 | goto out_default; |
|---|
| 2464 | | - error = decode_getacl3resok(xdr, result); |
|---|
| 2410 | + error = decode_getacl3resok(xdr, result, rpc_rqst_userns(req)); |
|---|
| 2465 | 2411 | out: |
|---|
| 2466 | 2412 | return error; |
|---|
| 2467 | 2413 | out_default: |
|---|
| .. | .. |
|---|
| 2480 | 2426 | goto out; |
|---|
| 2481 | 2427 | if (status != NFS3_OK) |
|---|
| 2482 | 2428 | goto out_default; |
|---|
| 2483 | | - error = decode_post_op_attr(xdr, result); |
|---|
| 2429 | + error = decode_post_op_attr(xdr, result, rpc_rqst_userns(req)); |
|---|
| 2484 | 2430 | out: |
|---|
| 2485 | 2431 | return error; |
|---|
| 2486 | 2432 | out_default: |
|---|