From: Pavel Emelyanov <xemul@parallels.com>
To: Chuck Lever <chuck.lever@oracle.com>
Cc: "J. Bruce Fields" <bfields@fieldses.org>,
"linux-nfs@vger.kernel.org" <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH 9/13] sunrpc: Merge the xs_bind code
Date: Tue, 05 Oct 2010 09:42:03 +0400 [thread overview]
Message-ID: <4CAABAAB.8040608@parallels.com> (raw)
In-Reply-To: <66FA6AAD-87DC-4B81-8DAC-8F1D4FF7B72E@oracle.com>
>> -static int xs_bind4(struct sock_xprt *transport, struct socket *sock)
>> +static int xs_bind(struct sock_xprt *transport, struct socket *sock)
>> {
>> - struct sockaddr_in myaddr = {
>> - .sin_family = AF_INET,
>> - };
>> - struct sockaddr_in *sa;
>> + struct sockaddr myaddr;
>
> You want "struct sockaddr_storage" here. A "struct sockaddr" is required by
> standard (iirc) to be only as large as a "struct sockaddr_in". So this can't
> possibly hold an IPv6 socket address without overflowing.
OK
>> int err, nloop = 0;
>> unsigned short port = xs_get_srcport(transport);
>> unsigned short last;
>>
>> - sa = (struct sockaddr_in *)&transport->srcaddr;
>> - myaddr.sin_addr = sa->sin_addr;
>> + memcpy(&myaddr, &transport->srcaddr, transport->xprt.addrlen);
>> do {
>> - myaddr.sin_port = htons(port);
>> - err = kernel_bind(sock, (struct sockaddr *) &myaddr,
>> - sizeof(myaddr));
>> + BUILD_BUG_ON(offsetof(struct sockaddr_in, sin_port) !=
>> + offsetof(struct sockaddr_in6, sin6_port));
>> + ((struct sockaddr_in *)&myaddr)->sin_port = htons(port);
>
> This series of patches looks mostly OK at first blush, but this little
> change is a bit offensive. :-)
>
> There should be some static inline helper functions that can get and set the
> port number in a socket address without a lot of magic, and I would prefer you
> use those instead. (I would point you directly to them, but I can't easily
> access kernel source at the moment -- hotel internet sucks).
>
> There should be one or two code examples in the RPC module or in headers that
> set and get ports in an automatic struct sockaddr_storage variable to give you
> an idea of what this needs to look like to avoid stack overruns and bad
> pointer aliasing.
I believe you mean the rpc_set_port() one. Will do!
Thanks,
Pavel
next prev parent reply other threads:[~2010-10-05 5:42 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-04 12:50 [PATCH 0/13] sunrpc: Compact the xprtsock code a bit Pavel Emelyanov
2010-10-04 12:51 ` [PATCH 1/13] sunrpc: Remove unused sock arg from xs_get_srcport Pavel Emelyanov
2010-10-04 12:51 ` [PATCH 2/13] sunrpc: Remove unused sock arg from xs_next_srcport Pavel Emelyanov
2010-10-04 12:52 ` [PATCH 3/13] sunrpc: Get xprt pointer once in xs_tcp_setup_socket Pavel Emelyanov
2010-10-04 12:52 ` [PATCH 4/13] sunrpc: Remove duplicate xprt/transport arguments from calls Pavel Emelyanov
2010-10-04 12:53 ` [PATCH 5/13] sunrpc: Factor out udp sockets creation Pavel Emelyanov
2010-10-04 12:54 ` [PATCH 6/13] sunrpc: Factor out v4 " Pavel Emelyanov
2010-10-04 12:54 ` [PATCH 7/13] sunrpc: Factor out v6 " Pavel Emelyanov
2010-10-04 12:55 ` [PATCH 8/13] sunrpc: Call xs_create_sockX directly from setup_socket Pavel Emelyanov
2010-10-04 12:56 ` [PATCH 9/13] sunrpc: Merge the xs_bind code Pavel Emelyanov
2010-10-05 3:20 ` Chuck Lever
2010-10-05 5:42 ` Pavel Emelyanov [this message]
2010-10-05 11:53 ` [PATCH v2 " Pavel Emelyanov
2010-10-06 3:04 ` Chuck Lever
2010-10-15 16:05 ` J. Bruce Fields
2010-10-15 16:24 ` Pavel Emelyanov
2010-10-15 16:39 ` Chuck Lever
2010-10-15 18:08 ` J. Bruce Fields
2010-10-15 18:09 ` J. Bruce Fields
2010-10-15 18:11 ` Chuck Lever
2010-10-18 21:15 ` J. Bruce Fields
2010-10-18 21:43 ` J. Bruce Fields
2010-10-18 21:53 ` Chuck Lever
2010-10-18 21:57 ` J. Bruce Fields
2010-10-18 22:37 ` Chuck Lever
2010-10-18 23:55 ` J. Bruce Fields
2010-10-19 14:35 ` Chuck Lever
2010-10-19 15:20 ` J. Bruce Fields
2010-10-20 9:19 ` Pavel Emelyanov
2010-10-04 12:56 ` [PATCH 10/13] sunrpc: Merge xs_create_sock code Pavel Emelyanov
2010-10-04 12:57 ` [PATCH 11/13] sunrpc: Pass family to setup_socket calls Pavel Emelyanov
2010-10-04 12:57 ` [PATCH 12/13] sunrpc: Remove TCP worker wrappers Pavel Emelyanov
2010-10-04 12:58 ` [PATCH 13/13] sunrpc: Remove UDP " Pavel Emelyanov
2010-10-11 23:47 ` [PATCH 0/13] sunrpc: Compact the xprtsock code a bit J. Bruce Fields
2010-10-12 7:51 ` Pavel Emelyanov
2010-10-12 13:50 ` J. Bruce Fields
2010-10-12 15:21 ` Pavel Emelyanov
2010-10-15 15:03 ` J. Bruce Fields
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CAABAAB.8040608@parallels.com \
--to=xemul@parallels.com \
--cc=bfields@fieldses.org \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).