All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mi Jinlong <mijinlong@cn.fujitsu.com>
To: Jesper Juhl <jj@chaosbits.net>
Cc: linux-nfs@vger.kernel.org,
	Trond Myklebust <Trond.Myklebust@netapp.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] NFS4: Avoid potential NULL pointer dereference in decode_and_add_ds().
Date: Mon, 17 Jan 2011 11:10:02 +0800	[thread overview]
Message-ID: <4D33B30A.8050507@cn.fujitsu.com> (raw)
In-Reply-To: <alpine.LNX.2.00.1101162145290.13377@swampdragon.chaosbits.net>



Jesper Juhl:
> strrchr() can return NULL if nothing is found. If this happens we'll 
> dereference a NULL pointer in 
> fs/nfs/nfs4filelayoutdev.c::decode_and_add_ds().
> 
> I tried to find some other code that guarantees that this can never 
> happen but I was unsuccessful. So, unless someone else can point to some 
> code that ensures this can never be a problem, I believe this patch is 
> needed.
> 
> While I was changing this code I also noticed that all the dprintk() 
> statements, except one, start with "%s:". The one missing the ":" I added 
> it to.

  Maybe another one also should be changed at decode_and_add_ds() at line 243:

   243  printk("%s Decoded address and port %s\n", __func__, buf);

-- 
----
thanks
Mi Jinlong

> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>
> ---
>  nfs4filelayoutdev.c |    7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
>   only compile tested.
> 
> diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
> index 51fe64a..5a85b8f 100644
> --- a/fs/nfs/nfs4filelayoutdev.c
> +++ b/fs/nfs/nfs4filelayoutdev.c
> @@ -214,7 +214,7 @@ decode_and_add_ds(__be32 **pp, struct inode *inode)
>  
>  	/* ipv6 length plus port is legal */
>  	if (rlen > INET6_ADDRSTRLEN + 8) {
> -		dprintk("%s Invalid address, length %d\n", __func__,
> +		dprintk("%s: Invalid address, length %d\n", __func__,
>  			rlen);
>  		goto out_err;
>  	}
> @@ -225,6 +225,11 @@ decode_and_add_ds(__be32 **pp, struct inode *inode)
>  	/* replace the port dots with dashes for the in4_pton() delimiter*/
>  	for (i = 0; i < 2; i++) {
>  		char *res = strrchr(buf, '.');
> +		if (!res) {
> +			dprintk("%s: Failed finding expected dots in port\n",
> +				__func__);
> +			goto out_free;
> +		}
>  		*res = '-';
>  	}
>  
> 


  reply	other threads:[~2011-01-17  3:06 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-16 20:50 [PATCH] NFS4: Avoid potential NULL pointer dereference in decode_and_add_ds() Jesper Juhl
2011-01-17  3:10 ` Mi Jinlong [this message]
2011-01-17 18:41   ` Jesper Juhl
     [not found]     ` <alpine.LNX.2.00.1101171940480.27021-h2p7t3/P30RzeRGmFJ5qR7ZzlVVXadcDXqFh9Ls21Oc@public.gmane.org>
2011-01-18 14:43       ` Andy Adamson
2011-01-18 14:43         ` Andy Adamson
2011-01-17 17:04 ` Fred Isaman
     [not found]   ` <AANLkTik+Z5C89Hb9Xu3az=deMsXj4rqvYpU=i7vXgdFx-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-01-17 18:42     ` Jesper Juhl
2011-01-17 18:42       ` Jesper Juhl
     [not found]       ` <alpine.LNX.2.00.1101171941560.27021-h2p7t3/P30RzeRGmFJ5qR7ZzlVVXadcDXqFh9Ls21Oc@public.gmane.org>
2011-01-17 19:09         ` Fred Isaman
2011-01-17 19:09           ` Fred Isaman

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=4D33B30A.8050507@cn.fujitsu.com \
    --to=mijinlong@cn.fujitsu.com \
    --cc=Trond.Myklebust@netapp.com \
    --cc=jj@chaosbits.net \
    --cc=linux-kernel@vger.kernel.org \
    --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 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.