Signed-off-by: Chuck Lever <chuck.lever@xxxxxxxxxx> --- fs/nfsd/nfs3xdr.c | 150 ++++++++++++++++++++++++++++++++++++++++----- include/uapi/linux/nfs3.h | 6 ++ 2 files changed, 139 insertions(+), 17 deletions(-) diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c index b27c04c642b7..5c46ab972a23 100644 --- a/fs/nfsd/nfs3xdr.c +++ b/fs/nfsd/nfs3xdr.c @@ -39,12 +39,18 @@ encode_time3(__be32 *p, struct timespec64 *time) return p; } -static __be32 * -decode_time3(__be32 *p, struct timespec64 *time) +static enum xdr_decode_result +svcxdr_decode_nfstime3(struct xdr_stream *xdr, struct timespec64 *timep) { - time->tv_sec = ntohl(*p++); - time->tv_nsec = ntohl(*p++); - return p; + __be32 *p; + + p = xdr_inline_decode(xdr, sizeof(__be32) * 2); + if (!p) + return XDR_DECODE_FAILED; + timep->tv_sec = be32_to_cpup(p++); + timep->tv_nsec = be32_to_cpup(p); + + return XDR_DECODE_DONE; } static enum xdr_decode_result @@ -151,6 +157,122 @@ svcxdr_decode_diropargs3(struct xdr_stream *xdr, struct svc_fh *fhp, return svcxdr_decode_filename3(xdr, name, len); } +static enum xdr_decode_result +svcxdr_decode_sattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr, + struct iattr *iap) +{ + u32 set_it; + __be32 *p; + + iap->ia_valid = 0; + + p = xdr_inline_decode(xdr, sizeof(__be32)); + if (!p) + return XDR_DECODE_FAILED; + if (xdr_item_is_present(p)) { + u32 mode; + + if (xdr_stream_decode_u32(xdr, &mode) < 0) + return XDR_DECODE_FAILED; + iap->ia_valid |= ATTR_MODE; + iap->ia_mode = mode; + } + + p = xdr_inline_decode(xdr, sizeof(__be32)); + if (!p) + return XDR_DECODE_FAILED; + if (xdr_item_is_present(p)) { + u32 uid; + + if (xdr_stream_decode_u32(xdr, &uid) < 0) + return XDR_DECODE_FAILED; + iap->ia_uid = make_kuid(nfsd_user_namespace(rqstp), uid); + if (uid_valid(iap->ia_uid)) + iap->ia_valid |= ATTR_UID; + } + + p = xdr_inline_decode(xdr, sizeof(__be32)); + if (!p) + return XDR_DECODE_FAILED; + if (xdr_item_is_present(p)) { + u32 gid; + + if (xdr_stream_decode_u32(xdr, &gid) < 0) + return XDR_DECODE_FAILED; + iap->ia_gid = make_kgid(nfsd_user_namespace(rqstp), gid); + if (gid_valid(iap->ia_gid)) + iap->ia_valid |= ATTR_GID; + } + + p = xdr_inline_decode(xdr, sizeof(__be32)); + if (!p) + return XDR_DECODE_FAILED; + if (xdr_item_is_present(p)) { + u64 newsize; + + if (xdr_stream_decode_u64(xdr, &newsize) < 0) + return XDR_DECODE_FAILED; + iap->ia_valid |= ATTR_SIZE; + iap->ia_size = min_t(u64, newsize, NFS_OFFSET_MAX); + } + + if (xdr_stream_decode_u32(xdr, &set_it) < 0) + return XDR_DECODE_FAILED; + switch (set_it) { + case DONT_CHANGE: + break; + case SET_TO_SERVER_TIME: + iap->ia_valid |= ATTR_ATIME; + break; + case SET_TO_CLIENT_TIME: + if (!svcxdr_decode_nfstime3(xdr, &iap->ia_atime)) + return XDR_DECODE_FAILED; + iap->ia_valid |= ATTR_ATIME | ATTR_ATIME_SET; + break; + default: + return XDR_DECODE_FAILED; + } + + if (xdr_stream_decode_u32(xdr, &set_it) < 0) + return XDR_DECODE_FAILED; + switch (set_it) { + case DONT_CHANGE: + break; + case SET_TO_SERVER_TIME: + iap->ia_valid |= ATTR_MTIME; + break; + case SET_TO_CLIENT_TIME: + if (!svcxdr_decode_nfstime3(xdr, &iap->ia_mtime)) + return XDR_DECODE_FAILED; + iap->ia_valid |= ATTR_MTIME | ATTR_MTIME_SET; + break; + default: + return XDR_DECODE_FAILED; + } + + return XDR_DECODE_DONE; +} + +static enum xdr_decode_result +svcxdr_decode_sattrguard3(struct xdr_stream *xdr, struct nfsd3_sattrargs *args) +{ + __be32 *p; + + p = xdr_inline_decode(xdr, sizeof(__be32)); + if (!p) + return XDR_DECODE_FAILED; + if (xdr_item_is_present(p)) { + p = xdr_inline_decode(xdr, sizeof(__be32) * 2); + if (!p) + return XDR_DECODE_FAILED; + args->check_guard = 1; + args->guardtime = be32_to_cpup(p); + } else + args->check_guard = 0; + + return XDR_DECODE_DONE; +} + static __be32 * decode_sattr3(__be32 *p, struct iattr *iap, struct user_namespace *userns) { @@ -372,20 +494,14 @@ nfs3svc_decode_fhandleargs(struct svc_rqst *rqstp, __be32 *p) int nfs3svc_decode_sattrargs(struct svc_rqst *rqstp, __be32 *p) { + struct xdr_stream *xdr = &rqstp->rq_xdr_stream; struct nfsd3_sattrargs *args = rqstp->rq_argp; - p = decode_fh(p, &args->fh); - if (!p) - return 0; - p = decode_sattr3(p, &args->attrs, nfsd_user_namespace(rqstp)); - - if ((args->check_guard = ntohl(*p++)) != 0) { - struct timespec64 time; - p = decode_time3(p, &time); - args->guardtime = time.tv_sec; - } - - return xdr_argsize_check(rqstp, p); + if (!svcxdr_decode_nfs_fh3(xdr, &args->fh)) + return XDR_DECODE_FAILED; + if (!svcxdr_decode_sattr3(rqstp, xdr, &args->attrs)) + return XDR_DECODE_FAILED; + return svcxdr_decode_sattrguard3(xdr, args); } int diff --git a/include/uapi/linux/nfs3.h b/include/uapi/linux/nfs3.h index 37e4b34e6b43..c22ab77713bd 100644 --- a/include/uapi/linux/nfs3.h +++ b/include/uapi/linux/nfs3.h @@ -63,6 +63,12 @@ enum nfs3_ftype { NF3BAD = 8 }; +enum nfs3_time_how { + DONT_CHANGE = 0, + SET_TO_SERVER_TIME = 1, + SET_TO_CLIENT_TIME = 2, +}; + struct nfs3_fh { unsigned short size; unsigned char data[NFS3_FHSIZE];