From: "J. Bruce Fields" <bfields@fieldses.org>
To: Chuck Lever <chuck.lever@oracle.com>
Cc: Neil Brown <neilb@suse.de>,
Linux NFS Mailing List <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH 08/22] SUNRPC: pass buffer size to svc_addsock() and svc_sock_names()
Date: Tue, 30 Dec 2008 14:38:52 -0500 [thread overview]
Message-ID: <20081230193852.GA28182@fieldses.org> (raw)
In-Reply-To: <926E9A27-74B3-438D-B314-96CBE67697D9@oracle.com>
On Mon, Dec 29, 2008 at 02:24:15PM -0500, Chuck Lever wrote:
> On Dec 24, 2008, at Dec 24, 2008, 11:43 PM, J. Bruce Fields wrote:
>> On Fri, Dec 12, 2008 at 04:58:05PM -0500, Chuck Lever wrote:
>>> Pass the size of the output buffer to the RPC functions that
>>> construct
>>> the list of socket names in that buffer. Add documenting comments to
>>> these functions.
>>>
>>> This is a cosmetic change for now. A subsequent patch will make sure
>>> the buffer length is passed to one_sock_name(), where the length will
>>> actually be useful.
>>>
>>> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
>>> ---
>>>
>>> fs/nfsd/nfsctl.c | 12 ++++++++----
>>> include/linux/sunrpc/svcsock.h | 6 ++++--
>>> net/sunrpc/svcsock.c | 34 ++++++++++++++++++++++++++++
>>> +-----
>>> 3 files changed, 41 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
>>> index 22fc8e5..19db9f4 100644
>>> --- a/fs/nfsd/nfsctl.c
>>> +++ b/fs/nfsd/nfsctl.c
>>> @@ -898,7 +898,7 @@ static ssize_t __write_ports_names(char *buf,
>>> size_t size)
>>> static ssize_t __write_ports_addfd(char *buf, size_t size)
>>> {
>>> char *mesg = buf;
>>> - int fd, err;
>>> + int fd, err, len;
>>>
>>> err = get_int(&mesg, &fd);
>>> if (err || fd < 0)
>>> @@ -908,13 +908,16 @@ static ssize_t __write_ports_addfd(char *buf,
>>> size_t size)
>>> if (err)
>>> return err;
>>>
>>> - err = svc_addsock(nfsd_serv, fd, buf);
>>> + len = SIMPLE_TRANSACTION_LIMIT;
>>> + err = svc_addsock(nfsd_serv, fd, buf, len);
>>> if (err < 0)
>>> return err;
>>> + len -= err;
>>>
>>> err = lockd_up();
>>> if (err < 0)
>>> - svc_sock_names(buf + strlen(buf) + 1, nfsd_serv, buf);
>>> + svc_sock_names(nfsd_serv, buf + strlen(buf) + 1,
>>> + len - strlen(buf) - 1, buf);
>>
>> Since you already did len -= err above, aren't you effectly subtracing
>> off strlen(buf) twice here?
>
> Yeah, that's a bug, but relatively harmless. I'll change that.
>
>> (And should that "len -= err" actually have
>> been a "len -= err + 1"?)
>
> Looking at this again, I think the pre-existing "+ 1" is incorrect.
>
> Say we have an 8 byte buffer, and svc_addsock() returns a 4-byte name,
> let's say "xyz\n".
>
> It's my impression that we then want svc_sock_names() to start filling
> in at the 5th byte in the buffer, which is buf[4] (or buf + 4) because C
> arrays are indexed starting at zero.
>
> There are four bytes remaining in the buffer, so 8 - 4 = 4 is still
> correct.
>
> So we want something like this:
>
> len = svc_addsock(nfsd_serv, fd, buf, SIMPLE_TRANSACTION_LIMIT);
> /* error checking snipped */
> svc_socknames(nfsd_serv, buf + len, SIMPLE_TRANSACTION_LIMIT - len,
> buf);
>
> Do you agree?
Hm, sounds right.
> It's hard to see how today's nfs-utils would even exercise this case.
> NFSD appears to open portlist for reading only to get the current set of
> listeners; and when adding a new listener, it only writes. I was not
> able to find a case where it reads back what was written -- the portlist
> file is opened WR_ONLY.
Could you try a test program? I started with the below but didn't get
far.
--b.
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <fcntl.h>
#include <err.h>
int main(int argc, char *argv[])
{
int fd;
int so;
int ret;
char buf[1023];
struct sockaddr_in addr = {
.sin_family = AF_INET,
.sin_port = 9999,
.sin_addr = INADDR_ANY
};
so = socket(PF_INET, SOCK_STREAM, 0);
if (so == -1)
err(1, "socket");
ret = bind(so, (struct sockaddr *)&addr, sizeof(struct sockaddr_in));
fd = open("/proc/fs/nfsd/portlist", O_RDWR);
if (ret == -1)
err(1, "open");
sprintf(buf, "%d\n", so);
ret = write(fd, buf, strlen(buf));
if (ret < strlen(buf))
err(1, "write");
ret = read(fd, buf, 0);
if (ret < 0)
err(1, "read");
close(fd);
printf("returned %d bytes: %s\n", ret, buf);
}
next prev parent reply other threads:[~2008-12-30 19:38 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-12 21:57 [PATCH 00/22] IPv6 support NFSD Chuck Lever
[not found] ` <20081212215340.24332.88416.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-12 21:57 ` [PATCH 01/22] NFSD: clean up failover sysctl function naming Chuck Lever
2008-12-12 21:57 ` [PATCH 02/22] NFSD: Fix a handful of coding style issues in write_filehandle() Chuck Lever
2008-12-12 21:57 ` [PATCH 03/22] NFSD: Replace open-coded integer with macro Chuck Lever
2008-12-12 21:57 ` [PATCH 04/22] NFSD: Add documenting comments for nfsctl interface Chuck Lever
2008-12-12 21:57 ` [PATCH 05/22] NFSD: Add helper functions for __write_ports() Chuck Lever
[not found] ` <20081212215742.24332.36578.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-25 4:15 ` J. Bruce Fields
2008-12-29 17:04 ` Chuck Lever
2008-12-29 18:42 ` J. Bruce Fields
2008-12-12 21:57 ` [PATCH 06/22] NFSD: Refactor __write_ports() Chuck Lever
2008-12-12 21:57 ` [PATCH 07/22] NFSD: Prevent a buffer overflow in svc_xprt_names() Chuck Lever
[not found] ` <20081212215757.24332.77904.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-25 4:32 ` J. Bruce Fields
2008-12-12 21:58 ` [PATCH 08/22] SUNRPC: pass buffer size to svc_addsock() and svc_sock_names() Chuck Lever
[not found] ` <20081212215804.24332.24605.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-14 17:33 ` Tom Tucker
2008-12-15 16:40 ` Chuck Lever
2008-12-15 21:05 ` Tom Tucker
2008-12-15 21:17 ` J. Bruce Fields
2008-12-25 4:43 ` J. Bruce Fields
2008-12-29 19:24 ` Chuck Lever
2008-12-30 19:38 ` J. Bruce Fields [this message]
2008-12-12 21:58 ` [PATCH 09/22] SUNRPC: Switch one_sock_name() to use snprintf() Chuck Lever
2008-12-12 21:58 ` [PATCH 10/22] SUNRPC: Support AF_INET6 in one_sock_name() Chuck Lever
2008-12-12 21:58 ` [PATCH 11/22] SUNRPC: Clean up one_sock_name() Chuck Lever
2008-12-12 21:58 ` [PATCH 12/22] NFSD: Support AF_INET6 in svc_addsock() function Chuck Lever
2008-12-12 21:58 ` [PATCH 13/22] NFS: Move NFS client's IP address parser to nfs_common/ Chuck Lever
[not found] ` <20081212215842.24332.47093.stgit-07a7zB5ZJzbwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-12-25 4:47 ` J. Bruce Fields
2008-12-12 21:58 ` [PATCH 14/22] NFSD: Support IPv6 addresses in write_failover_ip() Chuck Lever
2008-12-12 21:58 ` [PATCH 15/22] NFSD: Enable NFS server use of AF_INET6 Chuck Lever
2008-12-12 21:59 ` [PATCH 16/22] NFSD: Prevent buffer overflow in write_threads() Chuck Lever
2008-12-12 21:59 ` [PATCH 17/22] NFSD: Prevent buffer overflow in write_versions() Chuck Lever
2008-12-12 21:59 ` [PATCH 18/22] NFSD: Prevent buffer overflow in write_maxblksize() Chuck Lever
2008-12-12 21:59 ` [PATCH 19/22] NFSD: Prevent buffer overflow in write_leasetime() Chuck Lever
2008-12-12 21:59 ` [PATCH 20/22] NFSD: Prevent buffer overflow in write_recoverydir() Chuck Lever
2008-12-12 21:59 ` [PATCH 21/22] NLM: Refactor make_socks() function Chuck Lever
2008-12-12 21:59 ` [PATCH 22/22] NLM: Clean up flow of control in " Chuck Lever
2008-12-16 16:53 ` [PATCH 00/22] IPv6 support NFSD J. Bruce Fields
2008-12-25 5:01 ` 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=20081230193852.GA28182@fieldses.org \
--to=bfields@fieldses.org \
--cc=chuck.lever@oracle.com \
--cc=linux-nfs@vger.kernel.org \
--cc=neilb@suse.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.