Skip to contentSkip to conversation

RFC: Proposed rpc.statd clean up

PATCH In review Chuck Lever 2 participants 5 messages Sep 2, 2008 – Sep 4, 2008 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover RFC: Proposed rpc.statd clean up

Hi guys-

Here's a start at removing the RESTRICTED_STATD macro from rpc.statd. It would make IPv6 support a little simpler.

Comments welcome.

---

Chuck Lever (2):
rpc.statd: eliminate --secure_statd
rpc.statd: refactor check to see if call is from loopback address

 configure.ac          |    9 -----
 utils/statd/monitor.c |   93 +++++++++++++------------------------------------
 utils/statd/simu.c    |   38 ++++++++------------
 3 files changed, 40 insertions(+), 100 deletions(-)
Signature · 1 line
Chuck Lever

A message that is not in the archive (sent off-list or not yet received): 20080902215132.31328.44934.stgit-meopP2rzCrTwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org

#2 lore raw

PATCH 1/2 rpc.statd: refactor check to see if call is from loopback address

Refactor common logic to check if call is from loopback address.

We'll have to do something about this for IPv6. On IPv6 systems, there will be only one listener, for AF_INET6 calls. The loopback caller will get either an IPv6 loopback address, or a mapped IPv4 loopback -- either way this will be an AF_INET6 address.

---

 utils/statd/monitor.c |   77 ++++++++++++++++++++++---------------------------
 1 files changed, 35 insertions(+), 42 deletions(-)
utils/statd/monitor.c +35 -42
index eadc434..66faa8f 100644
@@ -29,6 +29,35 @@ notify_list *		rtnl = NULL;	/* Run-time notify list. */
 
 #define LINELEN (4*(8+1)+SM_PRIV_SIZE*2+1)
 
+#ifdef RESTRICTED_STATD
+/*
+ * Reject anyone not calling from a loopback address.
+ */
+static int
+caller_is_localhost(struct svc_req *rqstp)
+{
+	struct in_addr	caller;
+
+	caller = svc_getcaller(rqstp->rq_xprt)->sin_addr;
+	if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
+		note(N_WARNING,
+			"Call to statd from non-local host %s",
+			inet_ntoa(caller));
+		return 0;
+	}
+	return 1;
+}
+#else	/* RESTRICTED_STATD */
+/*
+ * No restrictions for remote callers.
+ */
+static int
+caller_is_localhost(struct svc_req *rqstp)
+{
+	return 1;
+}
+#endif	/* RESTRICTED_STATD */
+
 /*
  * Services SM_MON requests.
  */
@@ -45,9 +74,6 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
 	notify_list	*clnt;
 	struct in_addr	my_addr;
 	char		*dnsname;
-#ifdef RESTRICTED_STATD
-	struct in_addr	caller;
-#endif
 	struct hostent	*hostinfo = NULL;
 
 	/* Assume that we'll fail. */
@@ -59,17 +85,12 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
 	 * statd.			--okir
 	 */
 #ifdef RESTRICTED_STATD
-	/* 1.	Reject anyone not calling from 127.0.0.1.
+	/* 1.	Reject any remote callers.
 	 *	Ignore the my_name specified by the caller, and
 	 *	use "127.0.0.1" instead.
 	 */
-	caller = svc_getcaller(rqstp->rq_xprt)->sin_addr;
-	if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
-		note(N_WARNING,
-			"Call to statd from non-local host %s",
-			inet_ntoa(caller));
+	if (!caller_is_localhost(rqstp))
 		goto failure;
-	}
 	my_addr.s_addr = htonl(INADDR_LOOPBACK);
 
 	/* 2.	Reject any registrations for non-lockd services.
@@ -329,25 +350,12 @@ sm_unmon_1_svc(struct mon_id *argp, struct svc_req *rqstp)
 			*my_name  = argp->my_id.my_name;
 	struct my_id	*id = &argp->my_id;
 	char		*cp;
-#ifdef RESTRICTED_STATD
-	struct in_addr	caller;
-#endif
 
 	result.state = MY_STATE;
 
-#ifdef RESTRICTED_STATD
-	/* 1.	Reject anyone not calling from 127.0.0.1.
-	 *	Ignore the my_name specified by the caller, and
-	 *	use "127.0.0.1" instead.
-	 */
-	caller = svc_getcaller(rqstp->rq_xprt)->sin_addr;
-	if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
-		note(N_WARNING,
-			"Call to statd from non-local host %s",
-			inet_ntoa(caller));
+	if (!caller_is_localhost(rqstp))
 		goto failure;
-	}
-#endif
+
 	/* my_name must not have white space */
 	for (cp=my_name ; *cp ; cp++)
 		if (*cp == ' ' || *cp == '\t' || *cp == '\r' || *cp == '\n')
@@ -388,9 +396,7 @@ sm_unmon_1_svc(struct mon_id *argp, struct svc_req *rqstp)
 			clnt = NL_NEXT(clnt);
 	}
 
-#ifdef RESTRICTED_STATD
  failure:
-#endif
 	note(N_WARNING, "Received erroneous SM_UNMON request from %s for %s",
 		my_name, mon_name);
 	return (&result);
@@ -404,21 +410,9 @@ sm_unmon_all_1_svc(struct my_id *argp, struct svc_req *rqstp)
 	static sm_stat  result;
 	notify_list	*clnt;
 	char		*my_name = argp->my_name;
-#ifdef RESTRICTED_STATD
-	struct in_addr	caller;
 
-	/* 1.	Reject anyone not calling from 127.0.0.1.
-	 *	Ignore the my_name specified by the caller, and
-	 *	use "127.0.0.1" instead.
-	 */
-	caller = svc_getcaller(rqstp->rq_xprt)->sin_addr;
-	if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
-		note(N_WARNING,
-			"Call to statd from non-local host %s",
-			inet_ntoa(caller));
+	if (!caller_is_localhost(rqstp))
 		goto failure;
-	}
-#endif
 
 	result.state = MY_STATE;
 
@@ -457,8 +451,7 @@ sm_unmon_all_1_svc(struct my_id *argp, struct svc_req *rqstp)
 		dprintf(N_DEBUG, "SM_UNMON_ALL request from %s with no "
 			"SM_MON requests from it.", my_name);
 	}
-#ifdef RESTRICTED_STATD
+
  failure:
-#endif
 	return (&result);
 }
#3 lore raw

PATCH 2/2 rpc.statd: eliminate --secure_statd

In reply to a message not in the archive

Clean up: Remove RESTRICTED_STATD to help make IPv6 changes simpler. We keep the code behind RESTRICTED_STATD, and toss anything that is compiled out when it is set.

RESTRICTED_STATD was added almost 10 years ago in response to CERT CERT CA-99.05, which addresses exposures in rpc.statd that might allow an attacker to take advantage of buffer overflows in rpc.statd while it is running in privileged mode.

These days, I can't think of a reason why anyone would want to run rpc.statd without setting RESTRICTED_STATD. In addition, I don't think rpc.statd is ever tested without it.

Removing RESTRICTED_STATD will get rid of some address storage and comparison issues that will make IPv6 support simpler. Plus it will make our test matrix smaller!
---

 configure.ac          |    9 ---------
 utils/statd/monitor.c |   38 --------------------------------------
 utils/statd/simu.c    |   38 ++++++++++++++++----------------------
 3 files changed, 16 insertions(+), 69 deletions(-)
configure.ac +0 -9
index 6ae6c6d..1ab89db 100644
@@ -95,15 +95,6 @@ AC_ARG_ENABLE(kprefix,
 	test "$enableval" = "yes" && kprefix=k,
 	kprefix=)
 	AC_SUBST(kprefix)
-AC_ARG_ENABLE(secure-statd,
-	[AC_HELP_STRING([--enable-secure-statd],
-                        [Only lockd can use statd (security)])],
-	test "$enableval" = "yes" && secure_statd=yes,
-	secure_statd=yes)
-	if test "$secure_statd" = yes; then
-		AC_DEFINE(RESTRICTED_STATD, 1, [Define this if you want to enable various security checks in statd. These checks basically keep anyone but lockd from using this service.])
-	fi
-	AC_SUBST(secure_statd)
 AC_ARG_WITH(rpcgen,
 	[AC_HELP_STRING([--with-rpcgen=internal], [use internal rpcgen instead of system one])],
 	rpcgen_path=$withval,
utils/statd/monitor.c +0 -38
index 66faa8f..4811f5c 100644
@@ -29,7 +29,6 @@ notify_list *		rtnl = NULL;	/* Run-time notify list. */
 
 #define LINELEN (4*(8+1)+SM_PRIV_SIZE*2+1)
 
-#ifdef RESTRICTED_STATD
 /*
  * Reject anyone not calling from a loopback address.
  */
@@ -47,16 +46,6 @@ caller_is_localhost(struct svc_req *rqstp)
 	}
 	return 1;
 }
-#else	/* RESTRICTED_STATD */
-/*
- * No restrictions for remote callers.
- */
-static int
-caller_is_localhost(struct svc_req *rqstp)
-{
-	return 1;
-}
-#endif	/* RESTRICTED_STATD */
 
 /*
  * Services SM_MON requests.
@@ -80,11 +69,6 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
 	result.res_stat = STAT_FAIL;
 	result.state = -1;	/* State is undefined for STAT_FAIL. */
 
-	/* Restrict access to statd.
-	 * In the light of CERT CA-99.05, we tighten access to
-	 * statd.			--okir
-	 */
-#ifdef RESTRICTED_STATD
 	/* 1.	Reject any remote callers.
 	 *	Ignore the my_name specified by the caller, and
 	 *	use "127.0.0.1" instead.
@@ -110,28 +94,6 @@ sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp)
 		goto failure;
 	}
 
-#if 0
-	This is not usable anymore.  Linux-kernel can be configured to use
-	host names with NSM so that multi-homed hosts are handled properly.
-		NeilBrown 15mar2007
-
-	/* 3.	mon_name must be an address in dotted quad.
-	 *	Again, specific to the linux kernel lockd.
-	 */
-	if (!inet_aton(mon_name, &mon_addr)) {
-		note(N_WARNING,
-			"Attempt to register host %s (not a dotted quad)",
-			mon_name);
-		goto failure;
-	}
-#endif
-#else
-	if (!(hostinfo = gethostbyname(my_name))) {
-		note(N_WARNING, "gethostbyname error for %s", my_name);
-		goto failure;
-	} else
-		my_addr = *(struct in_addr *) hostinfo->h_addr;
-#endif
 	/*
 	 * Check hostnames.  If I can't look them up, I won't monitor.  This
 	 * might not be legal, but it adds a little bit of safety and sanity.
utils/statd/simu.c +16 -22
index 82d794e..bc09162 100644
@@ -22,35 +22,29 @@ void *
 sm_simu_crash_1_svc (void *argp, struct svc_req *rqstp)
 {
   static char *result = NULL;
+  struct in_addr caller;
+
+  /* 1.	Reject anyone not calling from 127.0.0.1.
+   *	Ignore the my_name specified by the caller, and
+   *	use "127.0.0.1" instead.
+   */
+  caller = svc_getcaller(rqstp->rq_xprt)->sin_addr;
+  if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
+    note(N_WARNING, "Call to statd from non-local host %s",
+      inet_ntoa(caller));
+    goto failure;
+  }
+  if (ntohs(svc_getcaller(rqstp->rq_xprt)->sin_port) >= 1024) {
+    note(N_WARNING, "Call to statd-simu-crash from unprivileged port\n");
+    goto failure;
+  }
 
-#ifdef RESTRICTED_STATD
-	struct in_addr	caller;
-
-	/* 1.	Reject anyone not calling from 127.0.0.1.
-	 *	Ignore the my_name specified by the caller, and
-	 *	use "127.0.0.1" instead.
-	 */
-	caller = svc_getcaller(rqstp->rq_xprt)->sin_addr;
-	if (caller.s_addr != htonl(INADDR_LOOPBACK)) {
-		note(N_WARNING,
-			"Call to statd from non-local host %s",
-			inet_ntoa(caller));
-		goto failure;
-	}
-	if (ntohs(svc_getcaller(rqstp->rq_xprt)->sin_port) >= 1024) {
-		note(N_WARNING,
-		     "Call to statd-simu-crash from unprivileged port\n");
-		goto failure;
-	}
-#endif
   note (N_WARNING, "*** SIMULATING CRASH! ***");
   my_svc_exit ();
 
   if (rtnl)
     nlist_kill (&rtnl);
 
-#ifdef RESTRICTED_STATD
  failure:
-#endif
   return ((void *)&result);
 }
Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] rpc.statd: eliminate --secure_statd

utils/statd/monitor.c sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp) · line 86

Quoted 4 lines · On Tuesday September 2, [email protected] wrote:
utils/statd/monitor.c +0 -4
-	/* Restrict access to statd.
-	 * In the light of CERT CA-99.05, we tighten access to
-	 * statd.			--okir
-	 */

This is my only concern. You've removed the reference to CERT CA-99.05.
Maybe put it back in the new "caller_is_localhost" function??

Otherwise

A message that is not in the archive (sent off-list or not yet received): 18623.31606.828680.632520-wvvUuzkyo1EYVZTmpyfIwg@public.gmane.org

#6 lore raw

Re: [PATCH 2/2] rpc.statd: eliminate --secure_statd

Quoted 9 lines · Neil Brown

utils/statd/monitor.c sm_mon_1_svc(struct mon *argp, struct svc_req *rqstp) · line 86

Quoted 4 lines · On Tuesday September 2, [email protected] wrote:
utils/statd/monitor.c +0 -4
-     /* Restrict access to statd.
-      * In the light of CERT CA-99.05, we tighten access to
-      * statd.                       --okir
-      */

This is my only concern. You've removed the reference to CERT CA-99.05.
Maybe put it back in the new "caller_is_localhost" function??

Sure. A signpost for those future developers who might consider removing this function.

--
Chuck Lever