Skip to contentSkip to conversation

rpc.mountd: set libtirpc nonblocking mode to avoid DOS

PATCH NeilBrown 2 participants 2 messages Nov 5, 2014 – Nov 6, 2014 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

NeilBrown

author Reviewed-by
#1 lore raw
Quoted 48 lines · On 05 Nov 2014 21:24:29 +0100 [email protected] wrote:

From: Bodo Stroesser <[email protected]>
Date: Thu, 09 Oct 2014 13:06:19 +0200
Subject: [nfs-utils] [PATCH 3/3] rpc.mountd: set libtirpc nonblocking mode to avoid DOS

This patch is experimental. In works fine in that it removes the vulnerability against a DOS attack. rpc.mountd can be blocked by a bad client, that sends many RPC requests but never reads the responses. This might happen intentionally or caused by a wrong network config (MTU).
The patch switches on the nonblocking mode of libtirpc. In that mode writes can block for a max. of 2 seconds. Attackers are forced to send requests slower, as libtirpc will close a connection if it finds two requests to read at the same time.
I do not know, whether setting MAXREC could cause trouble e.g. with big replies.

---

support/nfs/svc_create.c +10 -0
@@ -49,6 +49,8 @@
 
 #ifdef HAVE_LIBTIRPC
 
+#include <rpc/rpc_com.h>
+
 #define SVC_CREATE_XPRT_CACHE_SIZE	(8)
 static SVCXPRT *svc_create_xprt_cache[SVC_CREATE_XPRT_CACHE_SIZE] = { NULL, };
 
@@ -401,6 +403,7 @@
 	const struct sigaction create_sigaction = {
 		.sa_handler	= SIG_IGN,
 	};
+	int maxrec = RPC_MAXDATASIZE;
 	unsigned int visible, up, servport;
 	struct netconfig *nconf;
 	void *handlep;
@@ -412,6 +415,20 @@
 	 */
 	(void)sigaction(SIGPIPE, &create_sigaction, NULL);
 
+	/*
+	 * Setting MAXREC also enables non-blocking mode for tcp connections.
+	 * This avoids DOS attacks by a client sending many requests but never
+	 * reading the reply:
+	 * - if a second request already is present for reading in the socket,
+	 *   after the first request just was read, libtirpc will break the
+	 *   connection. Thus an attacker can't simply send requests as fast as

support/nfs/svc_create.c line 434

Quoted 10 lines
support/nfs/svc_create.c +7 -0
+	 *   he can without waiting for the response.
+	 * - if the write buffer of the socket is full, the next write() will
+	 *   fail with EAGAIN. libtirpc will retry the write in a loop for max.
+	 *   2 seconds. If write still fails, the connection will be closed.
+	 */   
+	rpc_control(RPC_SVC_CONNMAXREC_SET, &maxrec);
+
 	handlep = setnetconfig();
 	if (handlep == NULL) {
 		xlog(L_ERROR, "Failed to access local netconfig database: %s",

RPC_MAXDATASIZE is 9000.
This number is only relevant on the receive size.
When sending, the "sendsz" passed to svc_tli_create (which default to 64K for TCP) is used for the 'record size'.
When receiving, any 'record' in a tcp connection which is larger than 9000 bytes will be rejected.
No message to mountd or statd could ever be that large, so this number does not impose a problematic limit.

As far as I can tell, this patch is safe and is a clear improvement.

Thanks,
NeilBrown

#2 lore raw
Quoted 9 lines

-----Original Message-----
From: NeilBrown [mailto:[email protected]]
Sent: Wednesday, November 05, 2014 11:35 PM
To: Strösser, Bodo
Cc: [email protected]; [email protected]
Subject: Re: [nfs-utils] [PATCH 3/3] rpc.mountd: set libtirpc nonblocking mode to avoid DOS

...

Quoted 8 lines

RPC_MAXDATASIZE is 9000.
This number is only relevant on the receive size.
When sending, the "sendsz" passed to svc_tli_create (which default to 64K for TCP) is used for the 'record size'.
When receiving, any 'record' in a tcp connection which is larger than 9000 bytes will be rejected.
No message to mountd or statd could ever be that large, so this number does not impose a problematic limit.

Thank you for this explanation. That's what I wanted to but didn't know.

Bodo

Quoted 7 lines

As far as I can tell, this patch is safe and is a clear improvement.

Thanks,
NeilBrown