[PATCH 1/1] rmtcalls: Don't use privileged ports for remote calls.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sockets use for remote calls are preallocated which
mean the a port will be tied up for as long as
rpcbind runs. Make sure that port is not a privileged
port by binding the socket before calling svc_tli_create()

Signed-off-by: Steve Dickson <steved@xxxxxxxxxx>
---
 src/rpcb_svc_com.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/rpcb_svc_com.c b/src/rpcb_svc_com.c
index 9c1c3af..b9aeaaf 100644
--- a/src/rpcb_svc_com.c
+++ b/src/rpcb_svc_com.c
@@ -501,9 +501,12 @@ static struct rmtcallfd_list *rmttail;
 int
 create_rmtcall_fd(struct netconfig *nconf)
 {
-	int fd;
+	int fd, cc;
 	struct rmtcallfd_list *rmt;
 	SVCXPRT *xprt;
+	struct __rpc_sockinfo si;
+	struct sockaddr_storage ss;
+	struct t_bind bindaddr;
 
 	if ((fd = __rpc_nconf2fd(nconf)) == -1) {
 		if (debugging)
@@ -512,6 +515,20 @@ create_rmtcall_fd(struct netconfig *nconf)
 			nconf->nc_device, errno);
 		return (-1);
 	}
+
+	if (!__rpc_nconf2sockinfo(nconf, &si)) {
+		xlog(LOG_ERR, "create_rmtcall_fd: cannot get information for %s",
+		    nconf->nc_netid);
+		return (-1);
+	}
+	memset(&ss, 0, sizeof ss);
+	ss.ss_family = si.si_af;
+	cc = bind(fd, (struct sockaddr *)(void *)&ss,
+		(socklen_t)si.si_alen);
+	if (cc < 0) {
+		xlog(LOG_ERR, "create_rmtcall_fd: could not bind to anonymous port");
+		return (-1);
+	}
 	xprt = svc_tli_create(fd, 0, (struct t_bind *) 0, 0, 0);
 	if (xprt == NULL) {
 		if (debugging)
-- 
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux