All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benny Halevy <bhalevy@panasas.com>
To: Dan Carpenter <error27@gmail.com>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>,
	wharms@bfs.de, linux-nfs@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [patch] nfs: check kmalloc() return
Date: Fri, 29 Oct 2010 07:33:29 +0000	[thread overview]
Message-ID: <4CCA78C9.5000308@panasas.com> (raw)
In-Reply-To: <20101028165708.GH6062@bicker>

On 2010-10-28 18:57, Dan Carpenter wrote:
> On Thu, Oct 28, 2010 at 04:14:12PM +0200, Benny Halevy wrote:
>>>>> diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
>>>>> index 51fe64a..098113c 100644
>>>>> --- a/fs/nfs/nfs4filelayoutdev.c
>>>>> +++ b/fs/nfs/nfs4filelayoutdev.c
>>>>> @@ -219,6 +219,8 @@ decode_and_add_ds(__be32 **pp, struct inode *inode)
>>>>>  		goto out_err;
>>>>>  	}
>>>>>  	buf = kmalloc(rlen + 1, GFP_KERNEL);
>>>>> +	if (!buf)
>>>>> +		goto out_err;
>>>>>  	buf[rlen] = '\0';
>>>>>  	memcpy(buf, r_addr, rlen);
>>>>>  
>>>>
>>>> it seems that r_addr is a string, then kstdup() is emulated here.
>>>>
>>>> re,
>>>>  wh
>>>
>>> Not quite. kstrdup() requires that the argument be a NUL-terminated
>>> string. The above code doesn't.
>>
>> Right.  kmemdup is the right one.
>>
> 
> We need to duplicate the data and also add a NUL char on the end.

You're right.

> kmemdup() only does the first bit.  You could copy one char past the end
> so you have space for the NUL but that's not the right idea.

If rlen is divisible by 4 you can't be sure you'll have an extra character to
copy.

So the check you added is probably the simplest solution.

Benny

> 
> Anyway, I'm out of here for the next few days.  :)  See you after the
> weekend.
> 
> regards,
> dan carpenter
> 

WARNING: multiple messages have this Message-ID (diff)
From: Benny Halevy <bhalevy@panasas.com>
To: Dan Carpenter <error27@gmail.com>
Cc: Trond Myklebust <Trond.Myklebust@netapp.com>,
	wharms@bfs.de, linux-nfs@vger.kernel.org,
	kernel-janitors@vger.kernel.org
Subject: Re: [patch] nfs: check kmalloc() return
Date: Fri, 29 Oct 2010 09:33:29 +0200	[thread overview]
Message-ID: <4CCA78C9.5000308@panasas.com> (raw)
In-Reply-To: <20101028165708.GH6062@bicker>

On 2010-10-28 18:57, Dan Carpenter wrote:
> On Thu, Oct 28, 2010 at 04:14:12PM +0200, Benny Halevy wrote:
>>>>> diff --git a/fs/nfs/nfs4filelayoutdev.c b/fs/nfs/nfs4filelayoutdev.c
>>>>> index 51fe64a..098113c 100644
>>>>> --- a/fs/nfs/nfs4filelayoutdev.c
>>>>> +++ b/fs/nfs/nfs4filelayoutdev.c
>>>>> @@ -219,6 +219,8 @@ decode_and_add_ds(__be32 **pp, struct inode *inode)
>>>>>  		goto out_err;
>>>>>  	}
>>>>>  	buf = kmalloc(rlen + 1, GFP_KERNEL);
>>>>> +	if (!buf)
>>>>> +		goto out_err;
>>>>>  	buf[rlen] = '\0';
>>>>>  	memcpy(buf, r_addr, rlen);
>>>>>  
>>>>
>>>> it seems that r_addr is a string, then kstdup() is emulated here.
>>>>
>>>> re,
>>>>  wh
>>>
>>> Not quite. kstrdup() requires that the argument be a NUL-terminated
>>> string. The above code doesn't.
>>
>> Right.  kmemdup is the right one.
>>
> 
> We need to duplicate the data and also add a NUL char on the end.

You're right.

> kmemdup() only does the first bit.  You could copy one char past the end
> so you have space for the NUL but that's not the right idea.

If rlen is divisible by 4 you can't be sure you'll have an extra character to
copy.

So the check you added is probably the simplest solution.

Benny

> 
> Anyway, I'm out of here for the next few days.  :)  See you after the
> weekend.
> 
> regards,
> dan carpenter
> 

  reply	other threads:[~2010-10-29  7:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-28  4:44 [patch] nfs: check kmalloc() return Dan Carpenter
2010-10-28  4:44 ` Dan Carpenter
2010-10-28  7:16 ` walter harms
2010-10-28  7:16   ` walter harms
2010-10-28 13:41   ` Trond Myklebust
2010-10-28 13:41     ` Trond Myklebust
2010-10-28 14:14     ` Benny Halevy
2010-10-28 14:14       ` Benny Halevy
2010-10-28 16:57       ` Dan Carpenter
2010-10-28 16:57         ` Dan Carpenter
2010-10-29  7:33         ` Benny Halevy [this message]
2010-10-29  7:33           ` Benny Halevy

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=4CCA78C9.5000308@panasas.com \
    --to=bhalevy@panasas.com \
    --cc=Trond.Myklebust@netapp.com \
    --cc=error27@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=wharms@bfs.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.