hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/nfs/nfs3xdr.c
....@@ -21,6 +21,7 @@
2121 #include <linux/nfs3.h>
2222 #include <linux/nfs_fs.h>
2323 #include <linux/nfsacl.h>
24
+#include "nfstrace.h"
2425 #include "internal.h"
2526
2627 #define NFSDBG_FACILITY NFSDBG_XDR
....@@ -69,13 +70,13 @@
6970 #define NFS3_removeres_sz (NFS3_setattrres_sz)
7071 #define NFS3_lookupres_sz (1+NFS3_fh_sz+(2 * NFS3_post_op_attr_sz))
7172 #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)
7475 #define NFS3_writeres_sz (1+NFS3_wcc_data_sz+4)
7576 #define NFS3_createres_sz (1+NFS3_post_op_fh_sz+NFS3_post_op_attr_sz+NFS3_wcc_data_sz)
7677 #define NFS3_renameres_sz (1+(2 * NFS3_wcc_data_sz))
7778 #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)
7980 #define NFS3_fsstatres_sz (1+NFS3_post_op_attr_sz+13)
8081 #define NFS3_fsinfores_sz (1+NFS3_post_op_attr_sz+12)
8182 #define NFS3_pathconfres_sz (1+NFS3_post_op_attr_sz+6)
....@@ -85,7 +86,7 @@
8586 #define ACL3_setaclargs_sz (NFS3_fh_sz+1+ \
8687 XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
8788 #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)
8990 #define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz)
9091
9192 static int nfs3_stat_to_errno(enum nfs_stat);
....@@ -104,31 +105,19 @@
104105 [NF3FIFO] = S_IFIFO,
105106 };
106107
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)
114109 {
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;
120113 }
121114
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)
126116 {
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;
130120 }
131
-
132121
133122 /*
134123 * Encode/decode NFSv3 basic data types
....@@ -152,13 +141,10 @@
152141 __be32 *p;
153142
154143 p = xdr_inline_decode(xdr, 4);
155
- if (unlikely(p == NULL))
156
- goto out_overflow;
144
+ if (unlikely(!p))
145
+ return -EIO;
157146 *value = be32_to_cpup(p);
158147 return 0;
159
-out_overflow:
160
- print_overflow_msg(__func__, xdr);
161
- return -EIO;
162148 }
163149
164150 static int decode_uint64(struct xdr_stream *xdr, u64 *value)
....@@ -166,13 +152,10 @@
166152 __be32 *p;
167153
168154 p = xdr_inline_decode(xdr, 8);
169
- if (unlikely(p == NULL))
170
- goto out_overflow;
155
+ if (unlikely(!p))
156
+ return -EIO;
171157 xdr_decode_hyper(p, value);
172158 return 0;
173
-out_overflow:
174
- print_overflow_msg(__func__, xdr);
175
- return -EIO;
176159 }
177160
178161 /*
....@@ -212,14 +195,14 @@
212195 u32 count;
213196
214197 p = xdr_inline_decode(xdr, 4);
215
- if (unlikely(p == NULL))
216
- goto out_overflow;
198
+ if (unlikely(!p))
199
+ return -EIO;
217200 count = be32_to_cpup(p);
218201 if (count > NFS3_MAXNAMLEN)
219202 goto out_nametoolong;
220203 p = xdr_inline_decode(xdr, count);
221
- if (unlikely(p == NULL))
222
- goto out_overflow;
204
+ if (unlikely(!p))
205
+ return -EIO;
223206 *name = (const char *)p;
224207 *length = count;
225208 return 0;
....@@ -227,9 +210,6 @@
227210 out_nametoolong:
228211 dprintk("NFS: returned filename too long: %u\n", count);
229212 return -ENAMETOOLONG;
230
-out_overflow:
231
- print_overflow_msg(__func__, xdr);
232
- return -EIO;
233213 }
234214
235215 /*
....@@ -250,8 +230,8 @@
250230 __be32 *p;
251231
252232 p = xdr_inline_decode(xdr, 4);
253
- if (unlikely(p == NULL))
254
- goto out_overflow;
233
+ if (unlikely(!p))
234
+ return -EIO;
255235 count = be32_to_cpup(p);
256236 if (unlikely(count >= xdr->buf->page_len || count > NFS3_MAXPATHLEN))
257237 goto out_nametoolong;
....@@ -267,9 +247,6 @@
267247 out_cheating:
268248 dprintk("NFS: server cheating in pathname result: "
269249 "count %u > recvd %u\n", count, recvd);
270
- return -EIO;
271
-out_overflow:
272
- print_overflow_msg(__func__, xdr);
273250 return -EIO;
274251 }
275252
....@@ -304,13 +281,10 @@
304281 __be32 *p;
305282
306283 p = xdr_inline_decode(xdr, NFS3_COOKIEVERFSIZE);
307
- if (unlikely(p == NULL))
308
- goto out_overflow;
284
+ if (unlikely(!p))
285
+ return -EIO;
309286 memcpy(verifier, p, NFS3_COOKIEVERFSIZE);
310287 return 0;
311
-out_overflow:
312
- print_overflow_msg(__func__, xdr);
313
- return -EIO;
314288 }
315289
316290 /*
....@@ -331,13 +305,10 @@
331305 __be32 *p;
332306
333307 p = xdr_inline_decode(xdr, NFS3_WRITEVERFSIZE);
334
- if (unlikely(p == NULL))
335
- goto out_overflow;
308
+ if (unlikely(!p))
309
+ return -EIO;
336310 memcpy(verifier->data, p, NFS3_WRITEVERFSIZE);
337311 return 0;
338
-out_overflow:
339
- print_overflow_msg(__func__, xdr);
340
- return -EIO;
341312 }
342313
343314 /*
....@@ -365,13 +336,16 @@
365336 __be32 *p;
366337
367338 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;
371344 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;
375349 }
376350
377351 /*
....@@ -454,23 +428,20 @@
454428 __be32 *p;
455429
456430 p = xdr_inline_decode(xdr, 4);
457
- if (unlikely(p == NULL))
458
- goto out_overflow;
431
+ if (unlikely(!p))
432
+ return -EIO;
459433 length = be32_to_cpup(p++);
460434 if (unlikely(length > NFS3_FHSIZE))
461435 goto out_toobig;
462436 p = xdr_inline_decode(xdr, length);
463
- if (unlikely(p == NULL))
464
- goto out_overflow;
437
+ if (unlikely(!p))
438
+ return -EIO;
465439 fh->size = length;
466440 memcpy(fh->data, p, length);
467441 return 0;
468442 out_toobig:
469443 dprintk("NFS: file handle size (%u) too big\n", length);
470444 return -E2BIG;
471
-out_overflow:
472
- print_overflow_msg(__func__, xdr);
473
- return -EIO;
474445 }
475446
476447 static void zero_nfs_fh3(struct nfs_fh *fh)
....@@ -486,14 +457,14 @@
486457 * uint32 nseconds;
487458 * };
488459 */
489
-static __be32 *xdr_encode_nfstime3(__be32 *p, const struct timespec *timep)
460
+static __be32 *xdr_encode_nfstime3(__be32 *p, const struct timespec64 *timep)
490461 {
491
- *p++ = cpu_to_be32(timep->tv_sec);
462
+ *p++ = cpu_to_be32((u32)timep->tv_sec);
492463 *p++ = cpu_to_be32(timep->tv_nsec);
493464 return p;
494465 }
495466
496
-static __be32 *xdr_decode_nfstime3(__be32 *p, struct timespec *timep)
467
+static __be32 *xdr_decode_nfstime3(__be32 *p, struct timespec64 *timep)
497468 {
498469 timep->tv_sec = be32_to_cpup(p++);
499470 timep->tv_nsec = be32_to_cpup(p++);
....@@ -560,9 +531,9 @@
560531 * set_mtime mtime;
561532 * };
562533 */
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)
564536 {
565
- struct timespec ts;
566537 u32 nbytes;
567538 __be32 *p;
568539
....@@ -595,13 +566,13 @@
595566
596567 if (attr->ia_valid & ATTR_UID) {
597568 *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));
599570 } else
600571 *p++ = xdr_zero;
601572
602573 if (attr->ia_valid & ATTR_GID) {
603574 *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));
605576 } else
606577 *p++ = xdr_zero;
607578
....@@ -612,10 +583,8 @@
612583 *p++ = xdr_zero;
613584
614585 if (attr->ia_valid & ATTR_ATIME_SET) {
615
- struct timespec ts;
616586 *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);
619588 } else if (attr->ia_valid & ATTR_ATIME) {
620589 *p++ = xdr_one;
621590 } else
....@@ -623,8 +592,7 @@
623592
624593 if (attr->ia_valid & ATTR_MTIME_SET) {
625594 *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);
628596 } else if (attr->ia_valid & ATTR_MTIME) {
629597 *p = xdr_one;
630598 } else
....@@ -650,23 +618,24 @@
650618 * nfstime3 ctime;
651619 * };
652620 */
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)
654623 {
655624 umode_t fmode;
656625 __be32 *p;
657626
658627 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;
661630
662631 p = xdr_decode_ftype3(p, &fmode);
663632
664633 fattr->mode = (be32_to_cpup(p++) & ~S_IFMT) | fmode;
665634 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++));
667636 if (!uid_valid(fattr->uid))
668637 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++));
670639 if (!gid_valid(fattr->gid))
671640 goto out_gid;
672641
....@@ -691,9 +660,6 @@
691660 out_gid:
692661 dprintk("NFS: returned invalid gid\n");
693662 return -EINVAL;
694
-out_overflow:
695
- print_overflow_msg(__func__, xdr);
696
- return -EIO;
697663 }
698664
699665 /*
....@@ -706,19 +672,17 @@
706672 * void;
707673 * };
708674 */
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)
710677 {
711678 __be32 *p;
712679
713680 p = xdr_inline_decode(xdr, 4);
714
- if (unlikely(p == NULL))
715
- goto out_overflow;
681
+ if (unlikely(!p))
682
+ return -EIO;
716683 if (*p != xdr_zero)
717
- return decode_fattr3(xdr, fattr);
684
+ return decode_fattr3(xdr, fattr, userns);
718685 return 0;
719
-out_overflow:
720
- print_overflow_msg(__func__, xdr);
721
- return -EIO;
722686 }
723687
724688 /*
....@@ -734,8 +698,8 @@
734698 __be32 *p;
735699
736700 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;
739703
740704 fattr->valid |= NFS_ATTR_FATTR_PRESIZE
741705 | NFS_ATTR_FATTR_PRECHANGE
....@@ -748,9 +712,6 @@
748712 fattr->pre_change_attr = nfs_timespec_to_change_attr(&fattr->pre_ctime);
749713
750714 return 0;
751
-out_overflow:
752
- print_overflow_msg(__func__, xdr);
753
- return -EIO;
754715 }
755716
756717 /*
....@@ -774,24 +735,22 @@
774735 __be32 *p;
775736
776737 p = xdr_inline_decode(xdr, 4);
777
- if (unlikely(p == NULL))
778
- goto out_overflow;
738
+ if (unlikely(!p))
739
+ return -EIO;
779740 if (*p != xdr_zero)
780741 return decode_wcc_attr(xdr, fattr);
781742 return 0;
782
-out_overflow:
783
- print_overflow_msg(__func__, xdr);
784
- return -EIO;
785743 }
786744
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)
788747 {
789748 int error;
790749
791750 error = decode_pre_op_attr(xdr, fattr);
792751 if (unlikely(error))
793752 goto out;
794
- error = decode_post_op_attr(xdr, fattr);
753
+ error = decode_post_op_attr(xdr, fattr, userns);
795754 out:
796755 return error;
797756 }
....@@ -809,15 +768,12 @@
809768 static int decode_post_op_fh3(struct xdr_stream *xdr, struct nfs_fh *fh)
810769 {
811770 __be32 *p = xdr_inline_decode(xdr, 4);
812
- if (unlikely(p == NULL))
813
- goto out_overflow;
771
+ if (unlikely(!p))
772
+ return -EIO;
814773 if (*p != xdr_zero)
815774 return decode_nfs_fh3(xdr, fh);
816775 zero_nfs_fh3(fh);
817776 return 0;
818
-out_overflow:
819
- print_overflow_msg(__func__, xdr);
820
- return -EIO;
821777 }
822778
823779 /*
....@@ -896,7 +852,7 @@
896852 {
897853 const struct nfs3_sattrargs *args = data;
898854 encode_nfs_fh3(xdr, args->fh);
899
- encode_sattr3(xdr, args->sattr);
855
+ encode_sattr3(xdr, args->sattr, rpc_rqst_userns(req));
900856 encode_sattrguard3(xdr, args);
901857 }
902858
....@@ -954,8 +910,8 @@
954910 const struct nfs3_readlinkargs *args = data;
955911
956912 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);
959915 }
960916
961917 /*
....@@ -984,10 +940,11 @@
984940 const void *data)
985941 {
986942 const struct nfs_pgio_args *args = data;
943
+ unsigned int replen = args->replen ? args->replen : NFS3_readres_sz;
987944
988945 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);
991948 req->rq_rcv_buf.flags |= XDRBUF_READ;
992949 }
993950
....@@ -1056,13 +1013,14 @@
10561013 * };
10571014 */
10581015 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)
10601018 {
10611019 encode_uint32(xdr, args->createmode);
10621020 switch (args->createmode) {
10631021 case NFS3_CREATE_UNCHECKED:
10641022 case NFS3_CREATE_GUARDED:
1065
- encode_sattr3(xdr, args->sattr);
1023
+ encode_sattr3(xdr, args->sattr, userns);
10661024 break;
10671025 case NFS3_CREATE_EXCLUSIVE:
10681026 encode_createverf3(xdr, args->verifier);
....@@ -1079,7 +1037,7 @@
10791037 const struct nfs3_createargs *args = data;
10801038
10811039 encode_diropargs3(xdr, args->fh, args->name, args->len);
1082
- encode_createhow3(xdr, args);
1040
+ encode_createhow3(xdr, args, rpc_rqst_userns(req));
10831041 }
10841042
10851043 /*
....@@ -1097,7 +1055,7 @@
10971055 const struct nfs3_mkdirargs *args = data;
10981056
10991057 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));
11011059 }
11021060
11031061 /*
....@@ -1114,11 +1072,12 @@
11141072 * };
11151073 */
11161074 static void encode_symlinkdata3(struct xdr_stream *xdr,
1117
- const void *data)
1075
+ const void *data,
1076
+ struct user_namespace *userns)
11181077 {
11191078 const struct nfs3_symlinkargs *args = data;
11201079
1121
- encode_sattr3(xdr, args->sattr);
1080
+ encode_sattr3(xdr, args->sattr, userns);
11221081 encode_nfspath3(xdr, args->pages, args->pathlen);
11231082 }
11241083
....@@ -1129,7 +1088,7 @@
11291088 const struct nfs3_symlinkargs *args = data;
11301089
11311090 encode_diropargs3(xdr, args->fromfh, args->fromname, args->fromlen);
1132
- encode_symlinkdata3(xdr, args);
1091
+ encode_symlinkdata3(xdr, args, rpc_rqst_userns(req));
11331092 xdr->buf->flags |= XDRBUF_WRITE;
11341093 }
11351094
....@@ -1158,24 +1117,26 @@
11581117 * };
11591118 */
11601119 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)
11621122 {
1163
- encode_sattr3(xdr, args->sattr);
1123
+ encode_sattr3(xdr, args->sattr, userns);
11641124 encode_specdata3(xdr, args->rdev);
11651125 }
11661126
11671127 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)
11691130 {
11701131 encode_ftype3(xdr, args->type);
11711132 switch (args->type) {
11721133 case NF3CHR:
11731134 case NF3BLK:
1174
- encode_devicedata3(xdr, args);
1135
+ encode_devicedata3(xdr, args, userns);
11751136 break;
11761137 case NF3SOCK:
11771138 case NF3FIFO:
1178
- encode_sattr3(xdr, args->sattr);
1139
+ encode_sattr3(xdr, args->sattr, userns);
11791140 break;
11801141 case NF3REG:
11811142 case NF3DIR:
....@@ -1192,7 +1153,7 @@
11921153 const struct nfs3_mknodargs *args = data;
11931154
11941155 encode_diropargs3(xdr, args->fh, args->name, args->len);
1195
- encode_mknoddata3(xdr, args);
1156
+ encode_mknoddata3(xdr, args, rpc_rqst_userns(req));
11961157 }
11971158
11981159 /*
....@@ -1279,7 +1240,7 @@
12791240 const struct nfs3_readdirargs *args = data;
12801241
12811242 encode_readdir3args(xdr, args);
1282
- prepare_reply_buffer(req, args->pages, 0,
1243
+ rpc_prepare_reply_pages(req, args->pages, 0,
12831244 args->count, NFS3_readdirres_sz);
12841245 }
12851246
....@@ -1321,7 +1282,7 @@
13211282 const struct nfs3_readdirargs *args = data;
13221283
13231284 encode_readdirplus3args(xdr, args);
1324
- prepare_reply_buffer(req, args->pages, 0,
1285
+ rpc_prepare_reply_pages(req, args->pages, 0,
13251286 args->count, NFS3_readdirres_sz);
13261287 }
13271288
....@@ -1365,10 +1326,12 @@
13651326
13661327 encode_nfs_fh3(xdr, args->fh);
13671328 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,
13701331 NFSACL_MAXPAGES << PAGE_SHIFT,
13711332 ACL3_getaclres_sz);
1333
+ req->rq_rcv_buf.flags |= XDRBUF_SPARSE_PAGES;
1334
+ }
13721335 }
13731336
13741337 static void nfs3_xdr_enc_setacl3args(struct rpc_rqst *req,
....@@ -1435,7 +1398,7 @@
14351398 goto out;
14361399 if (status != NFS3_OK)
14371400 goto out_default;
1438
- error = decode_fattr3(xdr, result);
1401
+ error = decode_fattr3(xdr, result, rpc_rqst_userns(req));
14391402 out:
14401403 return error;
14411404 out_default:
....@@ -1470,7 +1433,7 @@
14701433 error = decode_nfsstat3(xdr, &status);
14711434 if (unlikely(error))
14721435 goto out;
1473
- error = decode_wcc_data(xdr, result);
1436
+ error = decode_wcc_data(xdr, result, rpc_rqst_userns(req));
14741437 if (unlikely(error))
14751438 goto out;
14761439 if (status != NFS3_OK)
....@@ -1505,6 +1468,7 @@
15051468 struct xdr_stream *xdr,
15061469 void *data)
15071470 {
1471
+ struct user_namespace *userns = rpc_rqst_userns(req);
15081472 struct nfs3_diropres *result = data;
15091473 enum nfs_stat status;
15101474 int error;
....@@ -1517,14 +1481,14 @@
15171481 error = decode_nfs_fh3(xdr, result->fh);
15181482 if (unlikely(error))
15191483 goto out;
1520
- error = decode_post_op_attr(xdr, result->fattr);
1484
+ error = decode_post_op_attr(xdr, result->fattr, userns);
15211485 if (unlikely(error))
15221486 goto out;
1523
- error = decode_post_op_attr(xdr, result->dir_attr);
1487
+ error = decode_post_op_attr(xdr, result->dir_attr, userns);
15241488 out:
15251489 return error;
15261490 out_default:
1527
- error = decode_post_op_attr(xdr, result->dir_attr);
1491
+ error = decode_post_op_attr(xdr, result->dir_attr, userns);
15281492 if (unlikely(error))
15291493 goto out;
15301494 return nfs3_stat_to_errno(status);
....@@ -1560,7 +1524,7 @@
15601524 error = decode_nfsstat3(xdr, &status);
15611525 if (unlikely(error))
15621526 goto out;
1563
- error = decode_post_op_attr(xdr, result->fattr);
1527
+ error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
15641528 if (unlikely(error))
15651529 goto out;
15661530 if (status != NFS3_OK)
....@@ -1601,7 +1565,7 @@
16011565 error = decode_nfsstat3(xdr, &status);
16021566 if (unlikely(error))
16031567 goto out;
1604
- error = decode_post_op_attr(xdr, result);
1568
+ error = decode_post_op_attr(xdr, result, rpc_rqst_userns(req));
16051569 if (unlikely(error))
16061570 goto out;
16071571 if (status != NFS3_OK)
....@@ -1641,8 +1605,8 @@
16411605 __be32 *p;
16421606
16431607 p = xdr_inline_decode(xdr, 4 + 4 + 4);
1644
- if (unlikely(p == NULL))
1645
- goto out_overflow;
1608
+ if (unlikely(!p))
1609
+ return -EIO;
16461610 count = be32_to_cpup(p++);
16471611 eof = be32_to_cpup(p++);
16481612 ocount = be32_to_cpup(p++);
....@@ -1665,27 +1629,27 @@
16651629 count = recvd;
16661630 eof = 0;
16671631 goto out;
1668
-out_overflow:
1669
- print_overflow_msg(__func__, xdr);
1670
- return -EIO;
16711632 }
16721633
16731634 static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
16741635 void *data)
16751636 {
16761637 struct nfs_pgio_res *result = data;
1638
+ unsigned int pos;
16771639 enum nfs_stat status;
16781640 int error;
16791641
1642
+ pos = xdr_stream_pos(xdr);
16801643 error = decode_nfsstat3(xdr, &status);
16811644 if (unlikely(error))
16821645 goto out;
1683
- error = decode_post_op_attr(xdr, result->fattr);
1646
+ error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
16841647 if (unlikely(error))
16851648 goto out;
16861649 result->op_status = status;
16871650 if (status != NFS3_OK)
16881651 goto out_status;
1652
+ result->replen = 4 + ((xdr_stream_pos(xdr) - pos) >> 2);
16891653 error = decode_read3resok(xdr, result);
16901654 out:
16911655 return error;
....@@ -1726,21 +1690,17 @@
17261690 __be32 *p;
17271691
17281692 p = xdr_inline_decode(xdr, 4 + 4);
1729
- if (unlikely(p == NULL))
1730
- goto out_overflow;
1693
+ if (unlikely(!p))
1694
+ return -EIO;
17311695 result->count = be32_to_cpup(p++);
17321696 result->verf->committed = be32_to_cpup(p++);
17331697 if (unlikely(result->verf->committed > NFS_FILE_SYNC))
17341698 goto out_badvalue;
17351699 if (decode_writeverf3(xdr, &result->verf->verifier))
1736
- goto out_eio;
1700
+ return -EIO;
17371701 return result->count;
17381702 out_badvalue:
17391703 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:
17441704 return -EIO;
17451705 }
17461706
....@@ -1754,7 +1714,7 @@
17541714 error = decode_nfsstat3(xdr, &status);
17551715 if (unlikely(error))
17561716 goto out;
1757
- error = decode_wcc_data(xdr, result->fattr);
1717
+ error = decode_wcc_data(xdr, result->fattr, rpc_rqst_userns(req));
17581718 if (unlikely(error))
17591719 goto out;
17601720 result->op_status = status;
....@@ -1788,14 +1748,15 @@
17881748 * };
17891749 */
17901750 static int decode_create3resok(struct xdr_stream *xdr,
1791
- struct nfs3_diropres *result)
1751
+ struct nfs3_diropres *result,
1752
+ struct user_namespace *userns)
17921753 {
17931754 int error;
17941755
17951756 error = decode_post_op_fh3(xdr, result->fh);
17961757 if (unlikely(error))
17971758 goto out;
1798
- error = decode_post_op_attr(xdr, result->fattr);
1759
+ error = decode_post_op_attr(xdr, result->fattr, userns);
17991760 if (unlikely(error))
18001761 goto out;
18011762 /* The server isn't required to return a file handle.
....@@ -1804,7 +1765,7 @@
18041765 * values for the new object. */
18051766 if (result->fh->size == 0)
18061767 result->fattr->valid = 0;
1807
- error = decode_wcc_data(xdr, result->dir_attr);
1768
+ error = decode_wcc_data(xdr, result->dir_attr, userns);
18081769 out:
18091770 return error;
18101771 }
....@@ -1813,6 +1774,7 @@
18131774 struct xdr_stream *xdr,
18141775 void *data)
18151776 {
1777
+ struct user_namespace *userns = rpc_rqst_userns(req);
18161778 struct nfs3_diropres *result = data;
18171779 enum nfs_stat status;
18181780 int error;
....@@ -1822,11 +1784,11 @@
18221784 goto out;
18231785 if (status != NFS3_OK)
18241786 goto out_default;
1825
- error = decode_create3resok(xdr, result);
1787
+ error = decode_create3resok(xdr, result, userns);
18261788 out:
18271789 return error;
18281790 out_default:
1829
- error = decode_wcc_data(xdr, result->dir_attr);
1791
+ error = decode_wcc_data(xdr, result->dir_attr, userns);
18301792 if (unlikely(error))
18311793 goto out;
18321794 return nfs3_stat_to_errno(status);
....@@ -1861,7 +1823,7 @@
18611823 error = decode_nfsstat3(xdr, &status);
18621824 if (unlikely(error))
18631825 goto out;
1864
- error = decode_wcc_data(xdr, result->dir_attr);
1826
+ error = decode_wcc_data(xdr, result->dir_attr, rpc_rqst_userns(req));
18651827 if (unlikely(error))
18661828 goto out;
18671829 if (status != NFS3_OK)
....@@ -1896,6 +1858,7 @@
18961858 struct xdr_stream *xdr,
18971859 void *data)
18981860 {
1861
+ struct user_namespace *userns = rpc_rqst_userns(req);
18991862 struct nfs_renameres *result = data;
19001863 enum nfs_stat status;
19011864 int error;
....@@ -1903,10 +1866,10 @@
19031866 error = decode_nfsstat3(xdr, &status);
19041867 if (unlikely(error))
19051868 goto out;
1906
- error = decode_wcc_data(xdr, result->old_fattr);
1869
+ error = decode_wcc_data(xdr, result->old_fattr, userns);
19071870 if (unlikely(error))
19081871 goto out;
1909
- error = decode_wcc_data(xdr, result->new_fattr);
1872
+ error = decode_wcc_data(xdr, result->new_fattr, userns);
19101873 if (unlikely(error))
19111874 goto out;
19121875 if (status != NFS3_OK)
....@@ -1940,6 +1903,7 @@
19401903 static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr,
19411904 void *data)
19421905 {
1906
+ struct user_namespace *userns = rpc_rqst_userns(req);
19431907 struct nfs3_linkres *result = data;
19441908 enum nfs_stat status;
19451909 int error;
....@@ -1947,10 +1911,10 @@
19471911 error = decode_nfsstat3(xdr, &status);
19481912 if (unlikely(error))
19491913 goto out;
1950
- error = decode_post_op_attr(xdr, result->fattr);
1914
+ error = decode_post_op_attr(xdr, result->fattr, userns);
19511915 if (unlikely(error))
19521916 goto out;
1953
- error = decode_wcc_data(xdr, result->dir_attr);
1917
+ error = decode_wcc_data(xdr, result->dir_attr, userns);
19541918 if (unlikely(error))
19551919 goto out;
19561920 if (status != NFS3_OK)
....@@ -1999,18 +1963,18 @@
19991963 int nfs3_decode_dirent(struct xdr_stream *xdr, struct nfs_entry *entry,
20001964 bool plus)
20011965 {
2002
- struct nfs_entry old = *entry;
1966
+ struct user_namespace *userns = rpc_userns(entry->server->client);
20031967 __be32 *p;
20041968 int error;
20051969 u64 new_cookie;
20061970
20071971 p = xdr_inline_decode(xdr, 4);
2008
- if (unlikely(p == NULL))
2009
- goto out_overflow;
1972
+ if (unlikely(!p))
1973
+ return -EAGAIN;
20101974 if (*p == xdr_zero) {
20111975 p = xdr_inline_decode(xdr, 4);
2012
- if (unlikely(p == NULL))
2013
- goto out_overflow;
1976
+ if (unlikely(!p))
1977
+ return -EAGAIN;
20141978 if (*p == xdr_zero)
20151979 return -EAGAIN;
20161980 entry->eof = 1;
....@@ -2019,23 +1983,23 @@
20191983
20201984 error = decode_fileid3(xdr, &entry->ino);
20211985 if (unlikely(error))
2022
- return error;
1986
+ return -EAGAIN;
20231987
20241988 error = decode_inline_filename3(xdr, &entry->name, &entry->len);
20251989 if (unlikely(error))
2026
- return error;
1990
+ return error == -ENAMETOOLONG ? -ENAMETOOLONG : -EAGAIN;
20271991
20281992 error = decode_cookie3(xdr, &new_cookie);
20291993 if (unlikely(error))
2030
- return error;
1994
+ return -EAGAIN;
20311995
20321996 entry->d_type = DT_UNKNOWN;
20331997
20341998 if (plus) {
20351999 entry->fattr->valid = 0;
2036
- error = decode_post_op_attr(xdr, entry->fattr);
2000
+ error = decode_post_op_attr(xdr, entry->fattr, userns);
20372001 if (unlikely(error))
2038
- return error;
2002
+ return -EAGAIN;
20392003 if (entry->fattr->valid & NFS_ATTR_FATTR_V3)
20402004 entry->d_type = nfs_umode_to_dtype(entry->fattr->mode);
20412005
....@@ -2046,15 +2010,12 @@
20462010
20472011 /* In fact, a post_op_fh3: */
20482012 p = xdr_inline_decode(xdr, 4);
2049
- if (unlikely(p == NULL))
2050
- goto out_overflow;
2013
+ if (unlikely(!p))
2014
+ return -EAGAIN;
20512015 if (*p != xdr_zero) {
20522016 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;
20582019 } else
20592020 zero_nfs_fh3(entry->fh);
20602021 }
....@@ -2063,14 +2024,6 @@
20632024 entry->cookie = new_cookie;
20642025
20652026 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;
20742027 }
20752028
20762029 /*
....@@ -2108,11 +2061,12 @@
21082061 }
21092062
21102063 static int decode_readdir3resok(struct xdr_stream *xdr,
2111
- struct nfs3_readdirres *result)
2064
+ struct nfs3_readdirres *result,
2065
+ struct user_namespace *userns)
21122066 {
21132067 int error;
21142068
2115
- error = decode_post_op_attr(xdr, result->dir_attr);
2069
+ error = decode_post_op_attr(xdr, result->dir_attr, userns);
21162070 if (unlikely(error))
21172071 goto out;
21182072 /* XXX: do we need to check if result->verf != NULL ? */
....@@ -2137,11 +2091,11 @@
21372091 goto out;
21382092 if (status != NFS3_OK)
21392093 goto out_default;
2140
- error = decode_readdir3resok(xdr, result);
2094
+ error = decode_readdir3resok(xdr, result, rpc_rqst_userns(req));
21412095 out:
21422096 return error;
21432097 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));
21452099 if (unlikely(error))
21462100 goto out;
21472101 return nfs3_stat_to_errno(status);
....@@ -2178,8 +2132,8 @@
21782132 __be32 *p;
21792133
21802134 p = xdr_inline_decode(xdr, 8 * 6 + 4);
2181
- if (unlikely(p == NULL))
2182
- goto out_overflow;
2135
+ if (unlikely(!p))
2136
+ return -EIO;
21832137 p = xdr_decode_size3(p, &result->tbytes);
21842138 p = xdr_decode_size3(p, &result->fbytes);
21852139 p = xdr_decode_size3(p, &result->abytes);
....@@ -2188,9 +2142,6 @@
21882142 xdr_decode_size3(p, &result->afiles);
21892143 /* ignore invarsec */
21902144 return 0;
2191
-out_overflow:
2192
- print_overflow_msg(__func__, xdr);
2193
- return -EIO;
21942145 }
21952146
21962147 static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req,
....@@ -2204,7 +2155,7 @@
22042155 error = decode_nfsstat3(xdr, &status);
22052156 if (unlikely(error))
22062157 goto out;
2207
- error = decode_post_op_attr(xdr, result->fattr);
2158
+ error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
22082159 if (unlikely(error))
22092160 goto out;
22102161 if (status != NFS3_OK)
....@@ -2250,8 +2201,8 @@
22502201 __be32 *p;
22512202
22522203 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;
22552206 result->rtmax = be32_to_cpup(p++);
22562207 result->rtpref = be32_to_cpup(p++);
22572208 result->rtmult = be32_to_cpup(p++);
....@@ -2265,9 +2216,6 @@
22652216 /* ignore properties */
22662217 result->lease_time = 0;
22672218 return 0;
2268
-out_overflow:
2269
- print_overflow_msg(__func__, xdr);
2270
- return -EIO;
22712219 }
22722220
22732221 static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req,
....@@ -2281,7 +2229,7 @@
22812229 error = decode_nfsstat3(xdr, &status);
22822230 if (unlikely(error))
22832231 goto out;
2284
- error = decode_post_op_attr(xdr, result->fattr);
2232
+ error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
22852233 if (unlikely(error))
22862234 goto out;
22872235 if (status != NFS3_OK)
....@@ -2323,15 +2271,12 @@
23232271 __be32 *p;
23242272
23252273 p = xdr_inline_decode(xdr, 4 * 6);
2326
- if (unlikely(p == NULL))
2327
- goto out_overflow;
2274
+ if (unlikely(!p))
2275
+ return -EIO;
23282276 result->max_link = be32_to_cpup(p++);
23292277 result->max_namelen = be32_to_cpup(p);
23302278 /* ignore remaining fields */
23312279 return 0;
2332
-out_overflow:
2333
- print_overflow_msg(__func__, xdr);
2334
- return -EIO;
23352280 }
23362281
23372282 static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req,
....@@ -2345,7 +2290,7 @@
23452290 error = decode_nfsstat3(xdr, &status);
23462291 if (unlikely(error))
23472292 goto out;
2348
- error = decode_post_op_attr(xdr, result->fattr);
2293
+ error = decode_post_op_attr(xdr, result->fattr, rpc_rqst_userns(req));
23492294 if (unlikely(error))
23502295 goto out;
23512296 if (status != NFS3_OK)
....@@ -2388,7 +2333,7 @@
23882333 error = decode_nfsstat3(xdr, &status);
23892334 if (unlikely(error))
23902335 goto out;
2391
- error = decode_wcc_data(xdr, result->fattr);
2336
+ error = decode_wcc_data(xdr, result->fattr, rpc_rqst_userns(req));
23922337 if (unlikely(error))
23932338 goto out;
23942339 result->op_status = status;
....@@ -2406,14 +2351,15 @@
24062351 #ifdef CONFIG_NFS_V3_ACL
24072352
24082353 static inline int decode_getacl3resok(struct xdr_stream *xdr,
2409
- struct nfs3_getaclres *result)
2354
+ struct nfs3_getaclres *result,
2355
+ struct user_namespace *userns)
24102356 {
24112357 struct posix_acl **acl;
24122358 unsigned int *aclcnt;
24132359 size_t hdrlen;
24142360 int error;
24152361
2416
- error = decode_post_op_attr(xdr, result->fattr);
2362
+ error = decode_post_op_attr(xdr, result->fattr, userns);
24172363 if (unlikely(error))
24182364 goto out;
24192365 error = decode_uint32(xdr, &result->mask);
....@@ -2461,7 +2407,7 @@
24612407 goto out;
24622408 if (status != NFS3_OK)
24632409 goto out_default;
2464
- error = decode_getacl3resok(xdr, result);
2410
+ error = decode_getacl3resok(xdr, result, rpc_rqst_userns(req));
24652411 out:
24662412 return error;
24672413 out_default:
....@@ -2480,7 +2426,7 @@
24802426 goto out;
24812427 if (status != NFS3_OK)
24822428 goto out_default;
2483
- error = decode_post_op_attr(xdr, result);
2429
+ error = decode_post_op_attr(xdr, result, rpc_rqst_userns(req));
24842430 out:
24852431 return error;
24862432 out_default: