[PATCH] knfsd: SUNRPC: add a "generic" function to see if the peer uses a secure port
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 <chuck.lever@oracle.com> Cc: Aurelien Charbon <aurelien.charbon@ext.bull.net> Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
Linus Torvalds
parent
b92503b25c
commit
bcdb81ae29
@@ -938,6 +938,22 @@ svc_tcp_data_ready(struct sock *sk, int count)
|
|||||||
wake_up_interruptible(sk->sk_sleep);
|
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)
|
||||||
|
< PROT_SOCK;
|
||||||
|
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
|
||||||
|
case AF_INET6:
|
||||||
|
return ntohs(((struct sockaddr_in6 *)sin)->sin6_port)
|
||||||
|
< PROT_SOCK;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Accept a TCP connection
|
* Accept a TCP connection
|
||||||
*/
|
*/
|
||||||
@@ -984,7 +1000,7 @@ svc_tcp_accept(struct svc_sock *svsk)
|
|||||||
* hosts here, but when we get encryption, the IP of the host won't
|
* hosts here, but when we get encryption, the IP of the host won't
|
||||||
* tell us anything. For now just warn about unpriv connections.
|
* 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
|
dprintk(KERN_WARNING
|
||||||
"%s: connect from unprivileged port: %s\n",
|
"%s: connect from unprivileged port: %s\n",
|
||||||
serv->sv_name,
|
serv->sv_name,
|
||||||
@@ -1334,7 +1350,6 @@ int
|
|||||||
svc_recv(struct svc_rqst *rqstp, long timeout)
|
svc_recv(struct svc_rqst *rqstp, long timeout)
|
||||||
{
|
{
|
||||||
struct svc_sock *svsk = NULL;
|
struct svc_sock *svsk = NULL;
|
||||||
struct sockaddr_in *sin = svc_addr_in(rqstp);
|
|
||||||
struct svc_serv *serv = rqstp->rq_server;
|
struct svc_serv *serv = rqstp->rq_server;
|
||||||
struct svc_pool *pool = rqstp->rq_pool;
|
struct svc_pool *pool = rqstp->rq_pool;
|
||||||
int len, i;
|
int len, i;
|
||||||
@@ -1431,7 +1446,7 @@ svc_recv(struct svc_rqst *rqstp, long timeout)
|
|||||||
svsk->sk_lastrecv = get_seconds();
|
svsk->sk_lastrecv = get_seconds();
|
||||||
clear_bit(SK_OLD, &svsk->sk_flags);
|
clear_bit(SK_OLD, &svsk->sk_flags);
|
||||||
|
|
||||||
rqstp->rq_secure = ntohs(sin->sin_port) < PROT_SOCK;
|
rqstp->rq_secure = svc_port_is_privileged(svc_addr(rqstp));
|
||||||
rqstp->rq_chandle.defer = svc_defer;
|
rqstp->rq_chandle.defer = svc_defer;
|
||||||
|
|
||||||
if (serv->sv_stats)
|
if (serv->sv_stats)
|
||||||
|
Reference in New Issue
Block a user