Skip to contentSkip to conversation

nfsd41: check the size of request

PATCH In review Mi Jinlong 2 participants 2 messages May 18, 2011 – May 19, 2011

Subsystems (2)
lore
Share & tools
lore

Mi Jinlong

author
#0 lore raw

PATCH 1/1 nfsd41: check the size of request

This patch just check request's size when it consists SEQUENCE.

---
 fs/nfsd/nfs4state.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
fs/nfsd/nfs4state.c +33 -0
index 4cf04e1..de4e6d4 100644
@@ -1725,6 +1725,38 @@ static void nfsd4_sequence_check_conn(struct nfsd4_conn *new, struct nfsd4_sessi
 	return;
 }
 
+static int nfsd4_check_request_size(struct nfsd4_compoundargs *args,
+				    struct nfsd4_compound_state *cstate)
+{
+	int status = 0;
+	struct xdr_buf *xb = &args->rqstp->rq_arg;
+	struct nfsd4_session *session = NULL;
+	u32 length, tlen = 0, pad = 8;
+
+	if (!nfsd4_has_session(cstate))
+		return status;
+
+	session = cstate->session;
+	if (session == NULL)
+		return status;
+
+	if (xb->page_len == 0) {
+		length = (char *)args->p - (char *)xb->head[0].iov_base + pad;
+	} else {
+		if (xb->tail[0].iov_base && xb->tail[0].iov_len > 0)
+			tlen = (char *)args->p - (char *)xb->tail[0].iov_base;
+
+		 length = xb->head[0].iov_len + xb->page_len + tlen + pad;
+	}
+	dprintk("%s length %u, xb->page_len %u tlen %u pad %u\n", __func__,
+		length, xb->page_len, tlen, pad);
+
+	if (length > session->se_fchannel.maxreq_sz)
+		return nfserr_req_too_big;
+
+	return status;
+}
+
 __be32
 nfsd4_sequence(struct svc_rqst *rqstp,
 	       struct nfsd4_compound_state *cstate,
@@ -1789,6 +1821,7 @@ nfsd4_sequence(struct svc_rqst *rqstp,
 	cstate->slot = slot;
 	cstate->session = session;
 
+	status = nfsd4_check_request_size(rqstp->rq_argp, cstate);
 out:
 	/* Hold a session reference until done processing the compound. */
 	if (cstate->session) {
Signature · 1 line
1.7.4.5
#1 lore raw
Quoted 15 lines · Mi Jinlong

This patch just check request's size when it consists SEQUENCE.

---
 fs/nfsd/nfs4state.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
fs/nfsd/nfs4state.c +0 -0
index 4cf04e1..de4e6d4 100644
@@ -1725,6 +1725,38 @@ static void nfsd4_sequence_check_conn(struct nfsd4_conn *new, struct nfsd4_sessi
 	return;
 }
 

fs/nfsd/nfs4state.c static void nfsd4_sequence_check_conn(struct nfsd4_conn *new, struct nfsd4_sessi · line 1737

Quoted 10 lines
fs/nfsd/nfs4state.c +10 -0
+static int nfsd4_check_request_size(struct nfsd4_compoundargs *args,
+				    struct nfsd4_compound_state *cstate)
+{
+	int status = 0;
+	struct xdr_buf *xb = &args->rqstp->rq_arg;
+	struct nfsd4_session *session = NULL;
+	u32 length, tlen = 0, pad = 8;
+
+	if (!nfsd4_has_session(cstate))
+		return status;

If we're only called from nfsd4_sequence(), then this check is redundant. (It should always return true.)

fs/nfsd/nfs4state.c static void nfsd4_sequence_check_conn(struct nfsd4_conn *new, struct nfsd4_sessi · line 1741

Quoted 4 lines
fs/nfsd/nfs4state.c +4 -0
+
+	session = cstate->session;
+	if (session == NULL)
+		return status;

Ditto, cstate->session was set by the caller just before calling us.

fs/nfsd/nfs4state.c static void nfsd4_sequence_check_conn(struct nfsd4_conn *new, struct nfsd4_sessi · line 1750

Quoted 9 lines
fs/nfsd/nfs4state.c +9 -0
+
+	if (xb->page_len == 0) {
+		length = (char *)args->p - (char *)xb->head[0].iov_base + pad;
+	} else {
+		if (xb->tail[0].iov_base && xb->tail[0].iov_len > 0)
+			tlen = (char *)args->p - (char *)xb->tail[0].iov_base;
+
+		 length = xb->head[0].iov_len + xb->page_len + tlen + pad;
+	}

There's gotta be something simpler.... Looking at svc_tcp_recvfrom. Won't xb->len do it?

Quoted 24 lines
fs/nfsd/nfs4state.c +10 -0
+	dprintk("%s length %u, xb->page_len %u tlen %u pad %u\n", __func__,
+		length, xb->page_len, tlen, pad);
+
+	if (length > session->se_fchannel.maxreq_sz)
+		return nfserr_req_too_big;
+
+	return status;
+}
+
 __be32
 nfsd4_sequence(struct svc_rqst *rqstp,
 	       struct nfsd4_compound_state *cstate,
@@ -1789,6 +1821,7 @@ nfsd4_sequence(struct svc_rqst *rqstp,
 	cstate->slot = slot;
 	cstate->session = session;
 
+	status = nfsd4_check_request_size(rqstp->rq_argp, cstate);
 out:
 	/* Hold a session reference until done processing the compound. */
 	if (cstate->session) {
Signature · 1 line
1.7.4.5