aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2007-02-12 03:53:34 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-02-12 12:48:36 -0500
commit27459f0940e16c68e080f5fc7e85aa9eb3f74528 (patch)
treef13cd1f2005dda2b6115e2afbc49e1271b0d374b
parent2442222283918c2d1c20ae651d95fe168757938b (diff)
[PATCH] knfsd: SUNRPC: Provide room in svc_rqst for larger addresses
Expand the rq_addr field to allow it to contain larger addresses. Specifically, we replace a 'sockaddr_in' with a 'sockaddr_storage', then everywhere the 'sockaddr_in' was referenced, we use instead an accessor function (svc_addr_in) which safely casts the _storage to _in. 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>
-rw-r--r--fs/lockd/host.c2
-rw-r--r--fs/lockd/svc4proc.c6
-rw-r--r--fs/lockd/svcproc.c6
-rw-r--r--fs/nfs/callback.c2
-rw-r--r--fs/nfs/callback_xdr.c4
-rw-r--r--fs/nfsd/nfs4state.c18
-rw-r--r--fs/nfsd/nfscache.c2
-rw-r--r--include/linux/sunrpc/svc.h17
-rw-r--r--net/sunrpc/svcauth_unix.c3
-rw-r--r--net/sunrpc/svcsock.c19
10 files changed, 51 insertions, 28 deletions
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index 3d4610c2a266..22d403208973 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -192,7 +192,7 @@ struct nlm_host *
192nlmsvc_lookup_host(struct svc_rqst *rqstp, 192nlmsvc_lookup_host(struct svc_rqst *rqstp,
193 const char *hostname, int hostname_len) 193 const char *hostname, int hostname_len)
194{ 194{
195 return nlm_lookup_host(1, &rqstp->rq_addr, 195 return nlm_lookup_host(1, svc_addr_in(rqstp),
196 rqstp->rq_prot, rqstp->rq_vers, 196 rqstp->rq_prot, rqstp->rq_vers,
197 hostname, hostname_len); 197 hostname, hostname_len);
198} 198}
diff --git a/fs/lockd/svc4proc.c b/fs/lockd/svc4proc.c
index 9b591bc18341..47a66aa5d55b 100644
--- a/fs/lockd/svc4proc.c
+++ b/fs/lockd/svc4proc.c
@@ -224,7 +224,7 @@ nlm4svc_proc_granted(struct svc_rqst *rqstp, struct nlm_args *argp,
224 resp->cookie = argp->cookie; 224 resp->cookie = argp->cookie;
225 225
226 dprintk("lockd: GRANTED called\n"); 226 dprintk("lockd: GRANTED called\n");
227 resp->status = nlmclnt_grant(&rqstp->rq_addr, &argp->lock); 227 resp->status = nlmclnt_grant(svc_addr_in(rqstp), &argp->lock);
228 dprintk("lockd: GRANTED status %d\n", ntohl(resp->status)); 228 dprintk("lockd: GRANTED status %d\n", ntohl(resp->status));
229 return rpc_success; 229 return rpc_success;
230} 230}
@@ -421,7 +421,9 @@ static __be32
421nlm4svc_proc_sm_notify(struct svc_rqst *rqstp, struct nlm_reboot *argp, 421nlm4svc_proc_sm_notify(struct svc_rqst *rqstp, struct nlm_reboot *argp,
422 void *resp) 422 void *resp)
423{ 423{
424 struct sockaddr_in saddr = rqstp->rq_addr; 424 struct sockaddr_in saddr;
425
426 memcpy(&saddr, svc_addr_in(rqstp), sizeof(saddr));
425 427
426 dprintk("lockd: SM_NOTIFY called\n"); 428 dprintk("lockd: SM_NOTIFY called\n");
427 if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK) 429 if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK)
diff --git a/fs/lockd/svcproc.c b/fs/lockd/svcproc.c
index f590304d93bf..31cb48425733 100644
--- a/fs/lockd/svcproc.c
+++ b/fs/lockd/svcproc.c
@@ -253,7 +253,7 @@ nlmsvc_proc_granted(struct svc_rqst *rqstp, struct nlm_args *argp,
253 resp->cookie = argp->cookie; 253 resp->cookie = argp->cookie;
254 254
255 dprintk("lockd: GRANTED called\n"); 255 dprintk("lockd: GRANTED called\n");
256 resp->status = nlmclnt_grant(&rqstp->rq_addr, &argp->lock); 256 resp->status = nlmclnt_grant(svc_addr_in(rqstp), &argp->lock);
257 dprintk("lockd: GRANTED status %d\n", ntohl(resp->status)); 257 dprintk("lockd: GRANTED status %d\n", ntohl(resp->status));
258 return rpc_success; 258 return rpc_success;
259} 259}
@@ -452,7 +452,9 @@ static __be32
452nlmsvc_proc_sm_notify(struct svc_rqst *rqstp, struct nlm_reboot *argp, 452nlmsvc_proc_sm_notify(struct svc_rqst *rqstp, struct nlm_reboot *argp,
453 void *resp) 453 void *resp)
454{ 454{
455 struct sockaddr_in saddr = rqstp->rq_addr; 455 struct sockaddr_in saddr;
456
457 memcpy(&saddr, svc_addr_in(rqstp), sizeof(saddr));
456 458
457 dprintk("lockd: SM_NOTIFY called\n"); 459 dprintk("lockd: SM_NOTIFY called\n");
458 if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK) 460 if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK)
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index 8c790af85984..75f309c8741a 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -166,7 +166,7 @@ void nfs_callback_down(void)
166 166
167static int nfs_callback_authenticate(struct svc_rqst *rqstp) 167static int nfs_callback_authenticate(struct svc_rqst *rqstp)
168{ 168{
169 struct sockaddr_in *addr = &rqstp->rq_addr; 169 struct sockaddr_in *addr = svc_addr_in(rqstp);
170 struct nfs_client *clp; 170 struct nfs_client *clp;
171 char buf[RPC_MAX_ADDRBUFLEN]; 171 char buf[RPC_MAX_ADDRBUFLEN];
172 172
diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
index f8ea1f51f590..849a2029975d 100644
--- a/fs/nfs/callback_xdr.c
+++ b/fs/nfs/callback_xdr.c
@@ -176,7 +176,7 @@ static __be32 decode_getattr_args(struct svc_rqst *rqstp, struct xdr_stream *xdr
176 status = decode_fh(xdr, &args->fh); 176 status = decode_fh(xdr, &args->fh);
177 if (unlikely(status != 0)) 177 if (unlikely(status != 0))
178 goto out; 178 goto out;
179 args->addr = &rqstp->rq_addr; 179 args->addr = svc_addr_in(rqstp);
180 status = decode_bitmap(xdr, args->bitmap); 180 status = decode_bitmap(xdr, args->bitmap);
181out: 181out:
182 dprintk("%s: exit with status = %d\n", __FUNCTION__, status); 182 dprintk("%s: exit with status = %d\n", __FUNCTION__, status);
@@ -188,7 +188,7 @@ static __be32 decode_recall_args(struct svc_rqst *rqstp, struct xdr_stream *xdr,
188 __be32 *p; 188 __be32 *p;
189 __be32 status; 189 __be32 status;
190 190
191 args->addr = &rqstp->rq_addr; 191 args->addr = svc_addr_in(rqstp);
192 status = decode_stateid(xdr, &args->stateid); 192 status = decode_stateid(xdr, &args->stateid);
193 if (unlikely(status != 0)) 193 if (unlikely(status != 0))
194 goto out; 194 goto out;
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 9de89df961f4..9e4067999209 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -714,7 +714,7 @@ __be32
714nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 714nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
715 struct nfsd4_setclientid *setclid) 715 struct nfsd4_setclientid *setclid)
716{ 716{
717 __be32 ip_addr = rqstp->rq_addr.sin_addr.s_addr; 717 struct sockaddr_in *sin = svc_addr_in(rqstp);
718 struct xdr_netobj clname = { 718 struct xdr_netobj clname = {
719 .len = setclid->se_namelen, 719 .len = setclid->se_namelen,
720 .data = setclid->se_name, 720 .data = setclid->se_name,
@@ -749,7 +749,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
749 */ 749 */
750 status = nfserr_clid_inuse; 750 status = nfserr_clid_inuse;
751 if (!cmp_creds(&conf->cl_cred, &rqstp->rq_cred) 751 if (!cmp_creds(&conf->cl_cred, &rqstp->rq_cred)
752 || conf->cl_addr != ip_addr) { 752 || conf->cl_addr != sin->sin_addr.s_addr) {
753 printk("NFSD: setclientid: string in use by client" 753 printk("NFSD: setclientid: string in use by client"
754 "(clientid %08x/%08x)\n", 754 "(clientid %08x/%08x)\n",
755 conf->cl_clientid.cl_boot, conf->cl_clientid.cl_id); 755 conf->cl_clientid.cl_boot, conf->cl_clientid.cl_id);
@@ -769,7 +769,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
769 if (new == NULL) 769 if (new == NULL)
770 goto out; 770 goto out;
771 copy_verf(new, &clverifier); 771 copy_verf(new, &clverifier);
772 new->cl_addr = ip_addr; 772 new->cl_addr = sin->sin_addr.s_addr;
773 copy_cred(&new->cl_cred,&rqstp->rq_cred); 773 copy_cred(&new->cl_cred,&rqstp->rq_cred);
774 gen_clid(new); 774 gen_clid(new);
775 gen_confirm(new); 775 gen_confirm(new);
@@ -801,7 +801,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
801 if (new == NULL) 801 if (new == NULL)
802 goto out; 802 goto out;
803 copy_verf(new,&conf->cl_verifier); 803 copy_verf(new,&conf->cl_verifier);
804 new->cl_addr = ip_addr; 804 new->cl_addr = sin->sin_addr.s_addr;
805 copy_cred(&new->cl_cred,&rqstp->rq_cred); 805 copy_cred(&new->cl_cred,&rqstp->rq_cred);
806 copy_clid(new, conf); 806 copy_clid(new, conf);
807 gen_confirm(new); 807 gen_confirm(new);
@@ -820,7 +820,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
820 if (new == NULL) 820 if (new == NULL)
821 goto out; 821 goto out;
822 copy_verf(new,&clverifier); 822 copy_verf(new,&clverifier);
823 new->cl_addr = ip_addr; 823 new->cl_addr = sin->sin_addr.s_addr;
824 copy_cred(&new->cl_cred,&rqstp->rq_cred); 824 copy_cred(&new->cl_cred,&rqstp->rq_cred);
825 gen_clid(new); 825 gen_clid(new);
826 gen_confirm(new); 826 gen_confirm(new);
@@ -847,7 +847,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
847 if (new == NULL) 847 if (new == NULL)
848 goto out; 848 goto out;
849 copy_verf(new,&clverifier); 849 copy_verf(new,&clverifier);
850 new->cl_addr = ip_addr; 850 new->cl_addr = sin->sin_addr.s_addr;
851 copy_cred(&new->cl_cred,&rqstp->rq_cred); 851 copy_cred(&new->cl_cred,&rqstp->rq_cred);
852 gen_clid(new); 852 gen_clid(new);
853 gen_confirm(new); 853 gen_confirm(new);
@@ -881,7 +881,7 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
881 struct nfsd4_compound_state *cstate, 881 struct nfsd4_compound_state *cstate,
882 struct nfsd4_setclientid_confirm *setclientid_confirm) 882 struct nfsd4_setclientid_confirm *setclientid_confirm)
883{ 883{
884 __be32 ip_addr = rqstp->rq_addr.sin_addr.s_addr; 884 struct sockaddr_in *sin = svc_addr_in(rqstp);
885 struct nfs4_client *conf, *unconf; 885 struct nfs4_client *conf, *unconf;
886 nfs4_verifier confirm = setclientid_confirm->sc_confirm; 886 nfs4_verifier confirm = setclientid_confirm->sc_confirm;
887 clientid_t * clid = &setclientid_confirm->sc_clientid; 887 clientid_t * clid = &setclientid_confirm->sc_clientid;
@@ -900,9 +900,9 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
900 unconf = find_unconfirmed_client(clid); 900 unconf = find_unconfirmed_client(clid);
901 901
902 status = nfserr_clid_inuse; 902 status = nfserr_clid_inuse;
903 if (conf && conf->cl_addr != ip_addr) 903 if (conf && conf->cl_addr != sin->sin_addr.s_addr)
904 goto out; 904 goto out;
905 if (unconf && unconf->cl_addr != ip_addr) 905 if (unconf && unconf->cl_addr != sin->sin_addr.s_addr)
906 goto out; 906 goto out;
907 907
908 if ((conf && unconf) && 908 if ((conf && unconf) &&
diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
index f90d70475854..578f2c9d56be 100644
--- a/fs/nfsd/nfscache.c
+++ b/fs/nfsd/nfscache.c
@@ -185,7 +185,7 @@ nfsd_cache_lookup(struct svc_rqst *rqstp, int type)
185 rp->c_state = RC_INPROG; 185 rp->c_state = RC_INPROG;
186 rp->c_xid = xid; 186 rp->c_xid = xid;
187 rp->c_proc = proc; 187 rp->c_proc = proc;
188 rp->c_addr = rqstp->rq_addr; 188 memcpy(&rp->c_addr, svc_addr_in(rqstp), sizeof(rp->c_addr));
189 rp->c_prot = proto; 189 rp->c_prot = proto;
190 rp->c_vers = vers; 190 rp->c_vers = vers;
191 rp->c_timestamp = jiffies; 191 rp->c_timestamp = jiffies;
diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
index 52db9c8985c5..96c1b6ae7d96 100644
--- a/include/linux/sunrpc/svc.h
+++ b/include/linux/sunrpc/svc.h
@@ -200,8 +200,8 @@ struct svc_rqst {
200 struct list_head rq_list; /* idle list */ 200 struct list_head rq_list; /* idle list */
201 struct list_head rq_all; /* all threads list */ 201 struct list_head rq_all; /* all threads list */
202 struct svc_sock * rq_sock; /* socket */ 202 struct svc_sock * rq_sock; /* socket */
203 struct sockaddr_in rq_addr; /* peer address */ 203 struct sockaddr_storage rq_addr; /* peer address */
204 int rq_addrlen; 204 size_t rq_addrlen;
205 205
206 struct svc_serv * rq_server; /* RPC service definition */ 206 struct svc_serv * rq_server; /* RPC service definition */
207 struct svc_pool * rq_pool; /* thread pool */ 207 struct svc_pool * rq_pool; /* thread pool */
@@ -256,6 +256,19 @@ struct svc_rqst {
256}; 256};
257 257
258/* 258/*
259 * Rigorous type checking on sockaddr type conversions
260 */
261static inline struct sockaddr_in *svc_addr_in(struct svc_rqst *rqst)
262{
263 return (struct sockaddr_in *) &rqst->rq_addr;
264}
265
266static inline struct sockaddr *svc_addr(struct svc_rqst *rqst)
267{
268 return (struct sockaddr *) &rqst->rq_addr;
269}
270
271/*
259 * Check buffer bounds after decoding arguments 272 * Check buffer bounds after decoding arguments
260 */ 273 */
261static inline int 274static inline int
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 987244f95909..4b775dbf580d 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -421,6 +421,7 @@ svcauth_unix_info_release(void *info)
421static int 421static int
422svcauth_unix_set_client(struct svc_rqst *rqstp) 422svcauth_unix_set_client(struct svc_rqst *rqstp)
423{ 423{
424 struct sockaddr_in *sin = svc_addr_in(rqstp);
424 struct ip_map *ipm; 425 struct ip_map *ipm;
425 426
426 rqstp->rq_client = NULL; 427 rqstp->rq_client = NULL;
@@ -430,7 +431,7 @@ svcauth_unix_set_client(struct svc_rqst *rqstp)
430 ipm = ip_map_cached_get(rqstp); 431 ipm = ip_map_cached_get(rqstp);
431 if (ipm == NULL) 432 if (ipm == NULL)
432 ipm = ip_map_lookup(rqstp->rq_server->sv_program->pg_class, 433 ipm = ip_map_lookup(rqstp->rq_server->sv_program->pg_class,
433 rqstp->rq_addr.sin_addr); 434 sin->sin_addr);
434 435
435 if (ipm == NULL) 436 if (ipm == NULL)
436 return SVC_DENIED; 437 return SVC_DENIED;
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 6680e0f0560d..b11669670baa 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -153,7 +153,7 @@ static char *__svc_print_addr(struct sockaddr *addr, char *buf, size_t len)
153 */ 153 */
154char *svc_print_addr(struct svc_rqst *rqstp, char *buf, size_t len) 154char *svc_print_addr(struct svc_rqst *rqstp, char *buf, size_t len)
155{ 155{
156 return __svc_print_addr((struct sockaddr *) &rqstp->rq_addr, buf, len); 156 return __svc_print_addr(svc_addr(rqstp), buf, len);
157} 157}
158EXPORT_SYMBOL_GPL(svc_print_addr); 158EXPORT_SYMBOL_GPL(svc_print_addr);
159 159
@@ -473,7 +473,7 @@ svc_sendto(struct svc_rqst *rqstp, struct xdr_buf *xdr)
473 /* set the source and destination */ 473 /* set the source and destination */
474 struct msghdr msg; 474 struct msghdr msg;
475 msg.msg_name = &rqstp->rq_addr; 475 msg.msg_name = &rqstp->rq_addr;
476 msg.msg_namelen = sizeof(rqstp->rq_addr); 476 msg.msg_namelen = rqstp->rq_addrlen;
477 msg.msg_iov = NULL; 477 msg.msg_iov = NULL;
478 msg.msg_iovlen = 0; 478 msg.msg_iovlen = 0;
479 msg.msg_flags = MSG_MORE; 479 msg.msg_flags = MSG_MORE;
@@ -696,6 +696,7 @@ svc_write_space(struct sock *sk)
696static int 696static int
697svc_udp_recvfrom(struct svc_rqst *rqstp) 697svc_udp_recvfrom(struct svc_rqst *rqstp)
698{ 698{
699 struct sockaddr_in *sin = svc_addr_in(rqstp);
699 struct svc_sock *svsk = rqstp->rq_sock; 700 struct svc_sock *svsk = rqstp->rq_sock;
700 struct svc_serv *serv = svsk->sk_server; 701 struct svc_serv *serv = svsk->sk_server;
701 struct sk_buff *skb; 702 struct sk_buff *skb;
@@ -756,9 +757,12 @@ svc_udp_recvfrom(struct svc_rqst *rqstp)
756 rqstp->rq_prot = IPPROTO_UDP; 757 rqstp->rq_prot = IPPROTO_UDP;
757 758
758 /* Get sender address */ 759 /* Get sender address */
759 rqstp->rq_addr.sin_family = AF_INET; 760 sin->sin_family = AF_INET;
760 rqstp->rq_addr.sin_port = skb->h.uh->source; 761 sin->sin_port = skb->h.uh->source;
761 rqstp->rq_addr.sin_addr.s_addr = skb->nh.iph->saddr; 762 sin->sin_addr.s_addr = skb->nh.iph->saddr;
763 rqstp->rq_addrlen = sizeof(struct sockaddr_in);
764
765 /* Remember which interface received this request */
762 rqstp->rq_daddr = skb->nh.iph->daddr; 766 rqstp->rq_daddr = skb->nh.iph->daddr;
763 767
764 if (skb_is_nonlinear(skb)) { 768 if (skb_is_nonlinear(skb)) {
@@ -1298,7 +1302,8 @@ svc_sock_update_bufs(struct svc_serv *serv)
1298int 1302int
1299svc_recv(struct svc_rqst *rqstp, long timeout) 1303svc_recv(struct svc_rqst *rqstp, long timeout)
1300{ 1304{
1301 struct svc_sock *svsk =NULL; 1305 struct svc_sock *svsk = NULL;
1306 struct sockaddr_in *sin = svc_addr_in(rqstp);
1302 struct svc_serv *serv = rqstp->rq_server; 1307 struct svc_serv *serv = rqstp->rq_server;
1303 struct svc_pool *pool = rqstp->rq_pool; 1308 struct svc_pool *pool = rqstp->rq_pool;
1304 int len, i; 1309 int len, i;
@@ -1395,7 +1400,7 @@ svc_recv(struct svc_rqst *rqstp, long timeout)
1395 svsk->sk_lastrecv = get_seconds(); 1400 svsk->sk_lastrecv = get_seconds();
1396 clear_bit(SK_OLD, &svsk->sk_flags); 1401 clear_bit(SK_OLD, &svsk->sk_flags);
1397 1402
1398 rqstp->rq_secure = ntohs(rqstp->rq_addr.sin_port) < 1024; 1403 rqstp->rq_secure = ntohs(sin->sin_port) < PROT_SOCK;
1399 rqstp->rq_chandle.defer = svc_defer; 1404 rqstp->rq_chandle.defer = svc_defer;
1400 1405
1401 if (serv->sv_stats) 1406 if (serv->sv_stats)