linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chuck Lever <chuck.lever@oracle.com>
To: linux-rdma@vger.kernel.org, linux-nfs@vger.kernel.org
Subject: [PATCH v1 05/17] svcrdma: Improve Read chunk sanity checking
Date: Tue, 30 May 2017 14:14:42 -0400	[thread overview]
Message-ID: <20170530181442.2992.70479.stgit@klimt.1015granger.net> (raw)
In-Reply-To: <20170530175808.2992.60365.stgit@klimt.1015granger.net>

Identify malformed transport headers and unsupported chunk
combinations as early as possible.

- Reject RPC-over-RDMA messages that contain more than one Read chunk,
  since this implementation currently does not support more than one
  per RPC transaction.

- Ensure that segment lengths are not crazy.

- Remove the segment count check. With a 1KB inline threshold, the
  largest number of Read segments that can be conveyed is about 40
  (for a RDMA_NOMSG Call message). This is nowhere near
  RPCSVC_MAXPAGES. As far as I can tell, that was just a sanity
  check and does not enforce an implementation limit.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 net/sunrpc/xprtrdma/svc_rdma_recvfrom.c |   55 +++++++++++++++++++++----------
 1 file changed, 37 insertions(+), 18 deletions(-)

diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
index 55ad335..885ad95 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
@@ -117,15 +117,47 @@ static void rdma_build_arg_xdr(struct svc_rqst *rqstp,
 	rqstp->rq_arg.tail[0].iov_len = 0;
 }
 
-static __be32 *xdr_check_read_list(__be32 *p, __be32 *end)
+/* This accommodates the largest possible Position-Zero
+ * Read chunk or Reply chunk, in one segment.
+ */
+#define MAX_BYTES_SPECIAL_SEG	((u32)((RPCSVC_MAXPAGES + 2) << PAGE_SHIFT))
+
+/* Sanity check the Read list.
+ *
+ * Implementation limits:
+ * - This implementation supports only one Read chunk.
+ *
+ * Sanity checks:
+ * - Read list does not overflow buffer.
+ * - Segment size limited by largest NFS data payload.
+ *
+ * The segment count is limited to how many segments can
+ * fit in the transport header without overflowing the
+ * buffer. That's about 40 Read segments for a 1KB inline
+ * threshold.
+ *
+ * Returns pointer to the following Write list.
+ */
+static __be32 *xdr_check_read_list(__be32 *p, const __be32 *end)
 {
-	__be32 *next;
+	u32 position;
+	bool first;
 
+	first = true;
 	while (*p++ != xdr_zero) {
-		next = p + rpcrdma_readchunk_maxsz - 1;
-		if (next > end)
+		if (first) {
+			position = be32_to_cpup(p++);
+			first = false;
+		} else if (be32_to_cpup(p++) != position) {
+			return NULL;
+		}
+		p++;	/* handle */
+		if (be32_to_cpup(p++) > MAX_BYTES_SPECIAL_SEG)
+			return NULL;
+		p += 2;	/* offset */
+
+		if (p > end)
 			return NULL;
-		p = next;
 	}
 	return p;
 }
@@ -478,16 +510,6 @@ int rdma_read_chunk_frmr(struct svcxprt_rdma *xprt,
 	return ret;
 }
 
-static unsigned int
-rdma_rcl_chunk_count(struct rpcrdma_read_chunk *ch)
-{
-	unsigned int count;
-
-	for (count = 0; ch->rc_discrim != xdr_zero; ch++)
-		count++;
-	return count;
-}
-
 /* If there was additional inline content, append it to the end of arg.pages.
  * Tail copy has to be done after the reader function has determined how many
  * pages are needed for RDMA READ.
@@ -567,9 +589,6 @@ static int rdma_read_chunks(struct svcxprt_rdma *xprt,
 	if (!ch)
 		return 0;
 
-	if (rdma_rcl_chunk_count(ch) > RPCSVC_MAXPAGES)
-		return -EINVAL;
-
 	/* The request is completed when the RDMA_READs complete. The
 	 * head context keeps all the pages that comprise the
 	 * request.


  parent reply	other threads:[~2017-05-30 18:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-30 18:14 [PATCH v1 00/17] Server-side NFS/RDMA changes proposed for v4.13 Chuck Lever
2017-05-30 18:14 ` [PATCH v1 01/17] ib_core: Enable and expose force_mr module parameter Chuck Lever
2017-05-31  4:36   ` Leon Romanovsky
2017-05-30 18:14 ` [PATCH v1 02/17] svcrdma: Squelch disconnection messages Chuck Lever
2017-05-30 18:14 ` [PATCH v1 03/17] svcrdma: Avoid Send Queue overflow Chuck Lever
2017-05-30 18:14 ` [PATCH v1 04/17] svcrdma: Remove svc_rdma_marshal.c Chuck Lever
2017-05-30 18:14 ` Chuck Lever [this message]
2017-05-30 18:14 ` [PATCH v1 06/17] svcrdma: Improve Write chunk sanity checking Chuck Lever
2017-05-30 18:14 ` [PATCH v1 07/17] svcrdma: Improve Reply " Chuck Lever
2017-05-30 18:15 ` [PATCH v1 08/17] svcrdma: Don't account for Receive queue "starvation" Chuck Lever
2017-05-30 18:15 ` [PATCH v1 09/17] sunrpc: Allocate one more page per svc_rqst Chuck Lever
2017-05-30 18:15 ` [PATCH v1 10/17] svcrdma: Add recvfrom helpers to svc_rdma_rw.c Chuck Lever
2017-05-30 18:15 ` [PATCH v1 11/17] svcrdma: Use generic RDMA R/W API in RPC Call path Chuck Lever
2017-05-30 18:15 ` [PATCH v1 12/17] svcrdma: Properly compute .len and .buflen for received RPC Calls Chuck Lever
2017-05-30 18:15 ` [PATCH v1 13/17] svcrdma: Remove unused Read completion handlers Chuck Lever
2017-05-30 18:15 ` [PATCH v1 14/17] svcrdma: Remove frmr cache Chuck Lever
2017-05-30 18:16 ` [PATCH v1 15/17] svcrdma: Clean-up svc_rdma_unmap_dma Chuck Lever
2017-05-30 18:16 ` [PATCH v1 16/17] svcrdma: Clean up after converting svc_rdma_recvfrom to rdma_rw API Chuck Lever
2017-05-30 18:16 ` [PATCH v1 17/17] svcrdma: use offset_in_page() macro 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=20170530181442.2992.70479.stgit@klimt.1015granger.net \
    --to=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).