Linux NFS development
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Chuck Lever <chuck.lever@oracle.com>
Cc: linux-nfs@vger.kernel.org
Subject: Re: [PATCH] NFS: fix nfs_parse_ip_address() corner case
Date: Tue, 26 Aug 2008 16:28:08 -0400	[thread overview]
Message-ID: <20080826202808.GO4380@fieldses.org> (raw)
In-Reply-To: <4C1CDB1D-8EE6-4303-B8CE-814F059E5BAD@oracle.com>

On Tue, Aug 26, 2008 at 04:24:12PM -0400, Chuck Lever wrote:
> On Aug 26, 2008, at Aug 26, 2008, 2:39 PM, J. Bruce Fields wrote:
>> On Fri, Aug 22, 2008 at 02:24:22PM -0400, Chuck Lever wrote:
>>> Bruce observed that nfs_parse_ip_address() will successfully parse  
>>> an IPv6
>>> address that looks like this:
>>>
>>>  "::1%"
>>>
>>> A scope delimiter is present, but there is no scope ID following it.
>>> This is harmless, as it would simply set the scope ID to zero.   
>>> However,
>>> in some cases we would like to flag this as an improperly formed
>>> address.
>>>
>>> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
>>> ---
>>>
>>> fs/nfs/super.c |   24 +++++++++++++++---------
>>> 1 files changed, 15 insertions(+), 9 deletions(-)
>>>
>>> diff --git a/fs/nfs/super.c b/fs/nfs/super.c
>>> index 5b2aa04..f73e068 100644
>>> --- a/fs/nfs/super.c
>>> +++ b/fs/nfs/super.c
>>> @@ -727,19 +727,21 @@ static void nfs_parse_ipv4_address(char  
>>> *string, size_t str_len,
>>> #define IPV6_SCOPE_DELIMITER	'%'
>>>
>>> #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
>>> -static void nfs_parse_ipv6_scope_id(const char *string, const  
>>> size_t str_len,
>>> -				    const char *delim,
>>> -				    struct sockaddr_in6 *sin6)
>>> +static int nfs_parse_ipv6_scope_id(const char *string, const size_t 
>>> str_len,
>>> +				   const char *delim,
>>> +				   struct sockaddr_in6 *sin6)
>>> {
>>> 	char *p;
>>> 	size_t len;
>>>
>>> 	if (!(ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL))
>>> -		return ;
>>> +		return 0;
>>> 	if (*delim != IPV6_SCOPE_DELIMITER)
>>> -		return;
>>> -
>>> +		return 0;
>>
>> What happens in the case where there's no scope delimiter?  In that  
>> case
>> can't *delim correctly point to something else here?
>
> When we get to nfs_parse_ipv6_scope_id(), *delim points to the first  
> character following the 128-bit IPv6 address string.  We should fail if 
> *delim doesn't point to either '%' or '\0'.  So we need another check 
> here -- succeed immediately if *delim points to '\0'.

The string isn't necessarily null-delimited.

> Then, I think we should check if the address is link-local _after_ we  
> know we have a valid scope delimiter.
>
>> Arguably kstrndup() and dev_get_by_name() failures should also result 
>> in
>> parser failures.  It seems safer to me to reject bad addresses than to
>> try to use them anyway (possibly resulting in mounting a different
>> server from what was intended).
>
> Well, if kstrndup() fails, that doesn't necessarily mean we have a bad  
> address; simply that there wasn't memory to parse it.  But it's  
> reasonable to return 0 in that case.
>
> If dev_get_by_name() fails, then the next step is to check if we were  
> passed a numeric value instead of a device name.  If the strtoul() call 
> fails to find a real numeric there, then yes, address parsing should 
> fail.

What does %numeric-value mean?

--b.

>
> If you agree I will repost with corrections.

  reply	other threads:[~2008-08-26 20:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-22 18:24 [PATCH] NFS: fix nfs_parse_ip_address() corner case Chuck Lever
     [not found] ` <20080822182419.19572.34705.stgit-meopP2rzCrTwdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-08-26 18:39   ` J. Bruce Fields
2008-08-26 20:24     ` Chuck Lever
2008-08-26 20:28       ` J. Bruce Fields [this message]
2008-08-26 20:36         ` Chuck Lever
2008-08-26 20:45           ` J. Bruce Fields
  -- strict thread matches above, loose matches on Subject: below --
2008-09-03 20:35 Chuck Lever
     [not found] ` <20080903203414.3322.97607.stgit-lQeC5l55kZ7wdl/1UfZZQIVfYA8g3rJ/@public.gmane.org>
2008-09-04 20:23   ` J. Bruce Fields
2008-09-04 21:36     ` Chuck Lever
     [not found]       ` <76bd70e30809041436y4a8fc1d2hb8230cb7aba17f26-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2008-09-05 21:58         ` 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=20080826202808.GO4380@fieldses.org \
    --to=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