linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: linux-nfs@vger.kernel.org
Subject: [PATCH v1 09/61] NFSD: Replace READ* macros in nfsd4_decode_create()
Date: Fri, 13 Nov 2020 10:03:10 -0500	[thread overview]
Message-ID: <160527979096.6186.164949251806384511.stgit@klimt.1015granger.net> (raw)
In-Reply-To: <160527962905.6186.17550620763636619885.stgit@klimt.1015granger.net>

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 fs/nfsd/nfs4xdr.c |   65 +++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 48 insertions(+), 17 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 2c69bf10d556..3cd5b2c843d8 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -90,6 +90,8 @@ check_filename(char *str, int len)
 
 	if (len == 0)
 		return nfserr_inval;
+	if (len > NFS4_MAXNAMLEN)
+		return nfserr_nametoolong;
 	if (isdotent(str, len))
 		return nfserr_badname;
 	for (i = 0; i < len; i++)
@@ -203,6 +205,32 @@ static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
 	return ret;
 }
 
+static __be32 nfsd4_decode_component4(struct nfsd4_compoundargs *argp,
+				      char **namp, u32 *lenp)
+{
+	__be32 *p, status;
+
+	if (xdr_stream_decode_u32(argp->xdr, lenp) < 0)
+		goto xdr_error;
+	p = xdr_inline_decode(argp->xdr, *lenp);
+	if (!p)
+		goto xdr_error;
+	status = check_filename((char *)p, *lenp);
+	if (status)
+		goto out;
+	*namp = svcxdr_tmpalloc(argp, *lenp);
+	if (!*namp)
+		goto nomem;
+	memcpy(*namp, p, *lenp);
+	status = nfs_ok;
+out:
+	return status;
+xdr_error:
+	return nfserr_bad_xdr;
+nomem:
+	return nfserr_jukebox;
+}
+
 static __be32
 nfsd4_decode_time(struct nfsd4_compoundargs *argp, struct timespec64 *tv)
 {
@@ -583,24 +611,27 @@ nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit
 static __be32
 nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create)
 {
-	DECODE_HEAD;
+	__be32 *p, status;
 
-	READ_BUF(4);
-	create->cr_type = be32_to_cpup(p++);
+	if (xdr_stream_decode_u32(argp->xdr, &create->cr_type) < 0)
+		goto xdr_error;
 	switch (create->cr_type) {
 	case NF4LNK:
-		READ_BUF(4);
-		create->cr_datalen = be32_to_cpup(p++);
-		READ_BUF(create->cr_datalen);
+		if (xdr_stream_decode_u32(argp->xdr, &create->cr_datalen) < 0)
+			goto xdr_error;
+		p = xdr_inline_decode(argp->xdr, create->cr_datalen);
+		if (!p)
+			goto xdr_error;
 		create->cr_data = svcxdr_dupstr(argp, p, create->cr_datalen);
 		if (!create->cr_data)
 			return nfserr_jukebox;
 		break;
 	case NF4BLK:
 	case NF4CHR:
-		READ_BUF(8);
-		create->cr_specdata1 = be32_to_cpup(p++);
-		create->cr_specdata2 = be32_to_cpup(p++);
+		if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata1) < 0)
+			goto xdr_error;
+		if (xdr_stream_decode_u32(argp->xdr, &create->cr_specdata2) < 0)
+			goto xdr_error;
 		break;
 	case NF4SOCK:
 	case NF4FIFO:
@@ -609,20 +640,20 @@ nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create
 		break;
 	}
 
-	READ_BUF(4);
-	create->cr_namelen = be32_to_cpup(p++);
-	READ_BUF(create->cr_namelen);
-	SAVEMEM(create->cr_name, create->cr_namelen);
-	if ((status = check_filename(create->cr_name, create->cr_namelen)))
-		return status;
-
+	status = nfsd4_decode_component4(argp, &create->cr_name,
+					 &create->cr_namelen);
+	if (status)
+		goto out;
 	status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr,
 				    &create->cr_acl, &create->cr_label,
 				    &create->cr_umask);
 	if (status)
 		goto out;
 
-	DECODE_TAIL;
+out:
+	return status;
+xdr_error:
+	return nfserr_bad_xdr;
 }
 
 static inline __be32



  parent reply	other threads:[~2020-11-13 15:03 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-13 15:02 [PATCH v1 00/61] Update NFSD XDR functions Chuck Lever
2020-11-13 15:02 ` [PATCH v1 01/61] NFSD: Fix returned READDIR offset cookie Chuck Lever
2020-11-13 15:02 ` [PATCH v1 02/61] SUNRPC: Add xdr_set_scratch_page() and xdr_reset_scratch_buffer() Chuck Lever
2020-11-13 15:02 ` [PATCH v1 03/61] SUNRPC: Prepare for xdr_stream-style decoding on the server-side Chuck Lever
2020-11-13 15:02 ` [PATCH v1 04/61] NFSD: Add common helpers to decode void args and encode void results Chuck Lever
2020-11-13 15:02 ` [PATCH v1 05/61] NFSD: Replace the internals of the READ_BUF() macro Chuck Lever
2020-11-13 15:02 ` [PATCH v1 06/61] NFSD: Replace READ* macros in nfsd4_decode_access() Chuck Lever
2020-11-14  9:28   ` Christoph Hellwig
2020-11-14 18:26     ` Chuck Lever
2020-11-14 18:45       ` Christoph Hellwig
2020-11-14 18:48         ` Chuck Lever
2020-11-14 18:49           ` Christoph Hellwig
2020-11-13 15:03 ` [PATCH v1 07/61] NFSD: Replace READ* macros in nfsd4_decode_close() Chuck Lever
2020-11-14  9:29   ` Christoph Hellwig
2020-11-14 18:30     ` Chuck Lever
2020-11-14 18:47       ` Christoph Hellwig
2020-11-13 15:03 ` [PATCH v1 08/61] NFSD: Replace READ* macros in nfsd4_decode_commit() Chuck Lever
2020-11-13 15:03 ` Chuck Lever [this message]
2020-11-13 15:03 ` [PATCH v1 10/61] NFSD: Replace READ* macros in nfsd4_decode_bitmap() Chuck Lever
2020-11-13 15:03 ` [PATCH v1 11/61] NFSD: Replace READ* macros in nfsd4_decode_link() Chuck Lever
2020-11-13 15:03 ` [PATCH v1 12/61] NFSD: Relocate nfsd4_decode_opaque() Chuck Lever
2020-11-13 15:03 ` [PATCH v1 13/61] NFSD: Replace READ* macros in nfsd4_decode_lock() Chuck Lever
2020-11-13 15:03 ` [PATCH v1 14/61] NFSD: Replace READ* macros in nfsd4_decode_lockt() Chuck Lever
2020-11-13 15:03 ` [PATCH v1 15/61] NFSD: Replace READ* macros in nfsd4_decode_locku() Chuck Lever
2020-11-13 15:03 ` [PATCH v1 16/61] NFSD: Replace READ* macros in nfsd4_decode_lookup() Chuck Lever
2020-11-13 15:03 ` [PATCH v1 17/61] NFSD: Replace READ* macros in nfsd4_decode_time() Chuck Lever
2020-11-13 15:03 ` [PATCH v1 18/61] NFSD: Replace READ* macros in nfsd4_decode_fattr() Chuck Lever
2020-11-13 15:04 ` [PATCH v1 19/61] NFSD: Replace READ* macros in nfsd4_decode_open() Chuck Lever
2020-11-13 15:04 ` [PATCH v1 20/61] NFSD: Replace READ* macros in nfsd4_decode_open_confirm() Chuck Lever
2020-11-13 15:04 ` [PATCH v1 21/61] NFSD: Replace READ* macros in nfsd4_decode_open_downgrade() Chuck Lever
2020-11-13 15:04 ` [PATCH v1 22/61] NFSD: Replace READ* macros in nfsd4_decode_putfh() Chuck Lever
2020-11-13 15:04 ` [PATCH v1 23/61] NFSD: Replace READ* macros in nfsd4_decode_read() Chuck Lever
2020-11-13 15:04 ` [PATCH v1 24/61] NFSD: Replace READ* macros in nfsd4_decode_readdir() Chuck Lever
2020-11-13 15:04 ` [PATCH v1 25/61] NFSD: Replace READ* macros in nfsd4_decode_remove() Chuck Lever
2020-11-13 15:04 ` [PATCH v1 26/61] NFSD: Replace READ* macros in nfsd4_decode_rename() Chuck Lever
2020-11-13 15:04 ` [PATCH v1 27/61] NFSD: Replace READ* macros in nfsd4_decode_renew() Chuck Lever
2020-11-13 15:04 ` [PATCH v1 28/61] NFSD: Replace READ* macros in nfsd4_decode_secinfo() Chuck Lever
2020-11-13 15:04 ` [PATCH v1 29/61] NFSD: Replace READ* macros in nfsd4_decode_setclientid() Chuck Lever
2020-11-13 15:05 ` [PATCH v1 30/61] NFSD: Replace READ* macros in nfsd4_decode_setclientid_confirm() Chuck Lever
2020-11-13 15:05 ` [PATCH v1 31/61] NFSD: Replace READ* macros in nfsd4_decode_verify() Chuck Lever
2020-11-13 15:05 ` [PATCH v1 32/61] NFSD: Replace READ* macros in nfsd4_decode_write() Chuck Lever
2020-11-13 15:05 ` [PATCH v1 33/61] NFSD: Replace READ* macros in nfsd4_decode_release_lockowner() Chuck Lever
2020-11-13 15:05 ` [PATCH v1 34/61] NFSD: Replace READ* macros in nfsd4_decode_cb_sec() Chuck Lever
2020-11-13 15:05 ` [PATCH v1 35/61] NFSD: Replace READ* macros in nfsd4_decode_backchannel_ctl() Chuck Lever
2020-11-13 15:05 ` [PATCH v1 36/61] NFSD: Replace READ* macros in nfsd4_decode_bind_conn_to_session() Chuck Lever
2020-11-13 15:05 ` [PATCH v1 37/61] NFSD: Add a separate decoder to handle state_protect_ops Chuck Lever
2020-11-13 15:05 ` [PATCH v1 38/61] NFSD: Add a separate decoder for ssv_sp_parms Chuck Lever
2020-11-13 15:05 ` [PATCH v1 39/61] NFSD: Add a helper to decode state_protect4_a Chuck Lever
2020-11-13 15:05 ` [PATCH v1 40/61] NFSD: Replace READ* macros in nfsd4_decode_exchange_id() Chuck Lever
2020-11-13 15:05 ` [PATCH v1 41/61] NFSD: Replace READ* macros in nfsd4_decode_create_session() Chuck Lever
2020-11-13 15:06 ` [PATCH v1 42/61] NFSD: Replace READ* macros in nfsd4_decode_destroy_session() Chuck Lever
2020-11-13 15:06 ` [PATCH v1 43/61] NFSD: Replace READ* macros in nfsd4_decode_free_stateid() Chuck Lever
2020-11-13 15:06 ` [PATCH v1 44/61] NFSD: Replace READ* macros in nfsd4_decode_getdeviceinfo() Chuck Lever
2020-11-13 15:06 ` [PATCH v1 45/61] NFSD: Replace READ* macros in nfsd4_decode_layoutcommit() Chuck Lever
2020-11-13 15:06 ` [PATCH v1 46/61] NFSD: Replace READ* macros in nfsd4_decode_layoutget() Chuck Lever
2020-11-13 15:06 ` [PATCH v1 47/61] NFSD: Replace READ* macros in nfsd4_decode_layoutreturn() Chuck Lever
2020-11-13 15:06 ` [PATCH v1 48/61] NFSD: Replace READ* macros in nfsd4_decode_secinfo_no_name() Chuck Lever
2020-11-13 15:06 ` [PATCH v1 49/61] NFSD: Replace READ* macros in nfsd4_decode_sequence() Chuck Lever
2020-11-13 15:06 ` [PATCH v1 50/61] NFSD: Replace READ* macros in nfsd4_decode_test_stateid() Chuck Lever
2020-11-13 15:06 ` [PATCH v1 51/61] NFSD: Replace READ* macros in nfsd4_decode_destroy_clientid() Chuck Lever
2020-11-13 15:06 ` [PATCH v1 52/61] NFSD: Replace READ* macros in nfsd4_decode_reclaim_complete() Chuck Lever
2020-11-13 15:07 ` [PATCH v1 53/61] NFSD: Replace READ* macros in nfsd4_decode_fallocate() Chuck Lever
2020-11-13 15:07 ` [PATCH v1 54/61] NFSD: Replace READ* macros in nfsd4_decode_clone() Chuck Lever
2020-11-13 15:07 ` [PATCH v1 55/61] NFSD: Replace READ* macros in nfsd4_decode_copy() Chuck Lever
2020-11-13 15:07 ` [PATCH v1 56/61] NFSD: Replace READ* macros in nfsd4_decode_seek() Chuck Lever
2020-11-13 15:07 ` [PATCH v1 57/61] NFSD: Replace READ* macros in nfsd4_decode_xattr_name() Chuck Lever
2020-11-13 15:07 ` [PATCH v1 58/61] NFSD: Replace READ* macros in nfsd4_decode_setxattr() Chuck Lever
2020-11-13 15:07 ` [PATCH v1 59/61] NFSD: Replace READ* macros in nfsd4_decode_listxattrs() Chuck Lever
2020-11-13 15:07 ` [PATCH v1 60/61] NFSD: Replace READ* macros in nfsd4_decode_compound() Chuck Lever
2020-11-13 15:07 ` [PATCH v1 61/61] NFSD: Remove macros that are no longer used Chuck Lever

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=160527979096.6186.164949251806384511.stgit@klimt.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --subject='Re: [PATCH v1 09/61] NFSD: Replace READ* macros in nfsd4_decode_create()' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox