SUNRPC: Fix a client regression when handling oversized replies
Subsystems (3)
PATCH 1/6 SUNRPC: Fix a client regression when handling oversized replies
If the server sends a reply that is larger than the pre-allocated buffer, then the current code may fail to register how much of the stream that it has finished reading. This again can lead to hangs.
--- net/sunrpc/xprtsock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/xprtsock.c +1 -1
@@ -453,7 +453,7 @@ xs_read_xdr_buf(struct socket *sock, struct msghdr *msg, int flags, goto out;if (ret != want) goto out; - }else + }else if (offset < seek_init) offset = seek_init; ret = -EMSGSIZE ; out:
Signature · 1 line
2.20.1
PATCH 2/6 SUNRPC: Fix the minimal size for reply buffer allocation
We must at minimum allocate enough memory to be able to see any auth errors in the reply from the server.
--- net/sunrpc/clnt.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/sunrpc/clnt.c +6 -1
@@ -1730,7 +1730,12 @@ call_allocate(struct rpc_task *task) req->rq_callsize =RPC_CALLHDRSIZE + (auth->au_cslack <<1 ) + proc->p_arglen; req->rq_callsize <<=2 ; - req->rq_rcvsize =RPC_REPHDRSIZE + auth->au_rslack + proc->p_replen; +/* +* Note: the reply buffer must at minimum allocate enough space +* for the 'struct accepted_reply' from RFC5531. +*/ + req->rq_rcvsize =RPC_REPHDRSIZE + auth->au_rslack + \ +max_t (size_t, proc->p_replen,2 ); req->rq_rcvsize <<=2 ; status = xprt->ops->buf_alloc (task);
Signature · 1 line
2.20.1
PATCH 3/6 SUNRPC: Use the ENOTCONN error on socket disconnect
When the socket is closed, we currently send an EAGAIN error to all pending requests in order to ask them to retransmit. Use ENOTCONN instead, to ensure that they try to reconnect before attempting to transmit.
This also helps SOFTCONN tasks to behave correctly in this situation.
--- net/sunrpc/xprt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/xprt.c +1 -1
@@ -664,7 +664,7 @@ void xprt_disconnect_done(struct rpc_xprt *xprt)spin_lock_bh (&xprt->transport_lock);xprt_clear_connected (xprt);xprt_clear_write_space_locked (xprt); -xprt_wake_pending_tasks (xprt, -EAGAIN ); +xprt_wake_pending_tasks (xprt, -ENOTCONN );spin_unlock_bh (&xprt->transport_lock); }EXPORT_SYMBOL_GPL (xprt_disconnect_done);
Signature · 1 line
2.20.1
PATCH 4/6 SUNRPC: rpc_decode_header() must always return a non-zero value on error
Ensure that when the "garbage args" case falls through, we do set an error of EIO.
--- net/sunrpc/clnt.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
net/sunrpc/clnt.c +7 -13
@@ -2454,7 +2454,7 @@ static noinline int rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr) { struct rpc_clnt *clnt = task->tk_client; -int error = -EACCES ; +int error;__be32 *p;/* RFC-1014 says that the representation of XDR data must be a
@@ -2463,7 +2463,7 @@ rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr)* undefined results */ if (task->tk_rqstp->rq_rcv_buf.len &3 ) - goto out_badlen; + goto out_unparsable; p =xdr_inline_decode (xdr,3 *sizeof (*p));if (!p)
@@ -2498,9 +2498,10 @@ rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr) goto out_err;case rpc_garbage_args:trace_rpc__garbage_args (task); + error = -EIO ;break ;default : -trace_rpc__unparsable (task); + goto out_unparsable; } out_garbage:
@@ -2514,11 +2515,6 @@ rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr)rpc_exit (task, error);return error; -out_badlen: -trace_rpc__unparsable (task); - error = -EIO ; - goto out_err; - out_unparsable:trace_rpc__unparsable (task); error = -EIO ;
@@ -2529,6 +2525,7 @@ rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr) goto out_garbage; out_msg_denied: + error = -EACCES ; p =xdr_inline_decode (xdr,sizeof (*p));if (!p) goto out_unparsable;
@@ -2540,9 +2537,7 @@ rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr) error = -EPROTONOSUPPORT ; goto out_err;default : -trace_rpc__unparsable (task); - error = -EIO ; - goto out_err; + goto out_unparsable; } p =xdr_inline_decode (xdr,sizeof (*p));
@@ -2577,8 +2572,7 @@ rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr) task->tk_xprt->servername);break ;default : -trace_rpc__unparsable (task); - error = -EIO ; + goto out_unparsable; } goto out_err; }
Signature · 1 line
2.20.1
PATCH 5/6 SUNRPC: Handle the SYSTEM_ERR rpc error
Handle the SYSTEM_ERR rpc error by retrying the RPC call as if it were a garbage argument.
--- net/sunrpc/clnt.c | 1 + 1 file changed, 1 insertion(+)
net/sunrpc/clnt.c +1 -0
@@ -2497,6 +2497,7 @@ rpc_decode_header(struct rpc_task *task, struct xdr_stream *xdr) error = -EOPNOTSUPP ; goto out_err;case rpc_garbage_args: +case rpc_system_err:trace_rpc__garbage_args (task); error = -EIO ;break ;
Signature · 1 line
2.20.1
PATCH 6/6 SUNRPC: Remove redundant check for the reply length in call_decode()
Now that we're using the xdr_stream functions to decode the header, the test for the minimum reply length is redundant.
--- net/sunrpc/clnt.c | 4 ---- 1 file changed, 4 deletions(-)
net/sunrpc/clnt.c +0 -4
@@ -2392,9 +2392,6 @@ call_decode(struct rpc_task *task)WARN_ON (memcmp (&req->rq_rcv_buf, &req->rq_private_buf,sizeof (req->rq_rcv_buf)) !=0 ); -if (req->rq_rcv_buf.len <12 ) - goto out_retry; -xdr_init_decode (&xdr, &req->rq_rcv_buf, req->rq_rcv_buf.head[0 ].iov_base, req);switch (rpc_decode_header (task, &xdr)) {
@@ -2405,7 +2402,6 @@ call_decode(struct rpc_task *task) task->tk_pid, __func__, task->tk_status);return ;case -EAGAIN : -out_retry: task->tk_status =0 ;/* Note: rpc_decode_header() may have freed the RPC slot */ if (task->tk_rqstp == req) {
Signature · 1 line
2.20.1