From: Chuck Lever Subject: [PATCH 10/13] SUNRPC: add a "generic" function to see if the peer uses a secure port Date: Mon, 13 Nov 2006 07:58:32 -0500 Message-ID: <20061113125832.4435.65114.stgit@localhost.localdomain> References: <20061113125640.4435.11957.stgit@localhost.localdomain> Reply-To: Chuck Lever Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Cc: nfs@lists.sourceforge.net Return-path: Received: from sc8-sf-mx2-b.sourceforge.net ([10.3.1.92] helo=mail.sourceforge.net) by sc8-sf-list2-new.sourceforge.net with esmtp (Exim 4.43) id 1Gjdfd-0004EV-3O for nfs@lists.sourceforge.net; Mon, 13 Nov 2006 07:24:25 -0800 Received: from agminet01.oracle.com ([141.146.126.228]) by mail.sourceforge.net with esmtps (TLSv1:AES256-SHA:256) (Exim 4.44) id 1Gjdfd-0005rO-Sr for nfs@lists.sourceforge.net; Mon, 13 Nov 2006 07:24:26 -0800 To: neilb@suse.de In-Reply-To: <20061113125640.4435.11957.stgit@localhost.localdomain> List-Id: "Discussion of NFS under Linux development, interoperability, and testing." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: nfs-bounces@lists.sourceforge.net Errors-To: nfs-bounces@lists.sourceforge.net The only reason svcsock.c looks at a sockaddr's port is to check whether the remote peer is connecting from a privileged port. Refactor this check to hide processing that is specific to address format. Signed-off-by: Chuck Lever Cc: Aurelien Charbon --- net/sunrpc/svcsock.c | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-) diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index e8a9379..47ed8d3 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -896,6 +896,20 @@ svc_tcp_data_ready(struct sock *sk, int wake_up_interruptible(sk->sk_sleep); } +static inline int svc_port_is_privileged(struct sockaddr *sin) +{ + switch (sin->sa_family) { + case AF_INET: + return ntohs(((struct sockaddr_in *)sin)->sin_port) < 1024; +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) + case AF_INET6: + return ntohs(((struct sockaddr_in6 *)sin)->sin6_port) < 1024; +#endif + default: + return 0; + } +} + /* * Accept a TCP connection */ @@ -942,7 +956,7 @@ svc_tcp_accept(struct svc_sock *svsk) * hosts here, but when we get encryption, the IP of the host won't * tell us anything. For now just warn about unpriv connections. */ - if (ntohs(sin.sin_port) >= 1024) { + if (!svc_port_is_privileged((struct sockaddr *) &sin)) { dprintk(KERN_WARNING "%s: connect from unprivileged port: %s\n", serv->sv_name, @@ -1282,7 +1296,6 @@ int svc_recv(struct svc_rqst *rqstp, long timeout) { struct svc_sock *svsk = NULL; - struct sockaddr_in *sin = (struct sockaddr_in *) &rqstp->rq_addr; struct svc_serv *serv = rqstp->rq_server; struct svc_pool *pool = rqstp->rq_pool; int len, i; @@ -1377,7 +1390,8 @@ svc_recv(struct svc_rqst *rqstp, long ti svsk->sk_lastrecv = get_seconds(); clear_bit(SK_OLD, &svsk->sk_flags); - rqstp->rq_secure = ntohs(sin->sin_port) < 1024; + rqstp->rq_secure = + svc_port_is_privileged((struct sockaddr *) &rqstp->rq_addr); rqstp->rq_chandle.defer = svc_defer; if (serv->sv_stats) ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ NFS maillist - NFS@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nfs