public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Coly Li <colyli@suse.de>
To: Bart Van Assche <Bart.VanAssche@wdc.com>,
	"mlyle@lyle.org" <mlyle@lyle.org>,
	"kent.overstreet@gmail.com" <kent.overstreet@gmail.com>
Cc: "hch@lst.de" <hch@lst.de>,
	"linux-bcache@vger.kernel.org" <linux-bcache@vger.kernel.org>,
	"linux-block@vger.kernel.org" <linux-block@vger.kernel.org>
Subject: Re: [PATCH 13/16] bcache: Make bch_dump_read() fail if copying to user space fails
Date: Fri, 16 Mar 2018 12:33:01 +0800	[thread overview]
Message-ID: <f1adca76-6aee-e37d-1d38-325a019ba81f@suse.de> (raw)
In-Reply-To: <1521133564.2834.10.camel@wdc.com>

On 16/03/2018 1:06 AM, Bart Van Assche wrote:
> On Fri, 2018-03-16 at 01:00 +0800, Coly Li wrote:
>> On 15/03/2018 11:08 PM, Bart Van Assche wrote:
>>> copy_to_user() returns the number of remaining bytes. Avoid that
>>> a larger value is returned than the number of bytes that have
>>> been copied by returning -EFAULT if not all bytes have been copied.
>>>
>>> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
>>> ---
>>>  drivers/md/bcache/debug.c | 5 ++---
>>>  1 file changed, 2 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/drivers/md/bcache/debug.c b/drivers/md/bcache/debug.c
>>> index af89408befe8..376899cfcbf1 100644
>>> --- a/drivers/md/bcache/debug.c
>>> +++ b/drivers/md/bcache/debug.c
>>> @@ -175,9 +175,8 @@ static ssize_t bch_dump_read(struct file *file, char __user *buf,
>>>  		struct keybuf_key *w;
>>>  		unsigned bytes = min(i->bytes, size);
>>>  
>>> -		int err = copy_to_user(buf, i->buf, bytes);
>>> -		if (err)
>>> -			return err;
>>> +		if (copy_to_user(buf, i->buf, bytes))
>>> +			return -EFAULT;
>>>  
>>
>> Hi Bart,
>>
>> I am not sure whether this change is correct. -EFAULT seems not an
>> expected return value of read(2), while -1 is the expected return value
>> when error occurs.
>>
>> Maybe if copy_to_user() returns value in (0, size], "ret + (size - err)"
>> should be returned. An exception is when copy_to_user() returns 0 and
>> ret is 0 too, in this situation -1 should be returned.
>>
>> Correct me if I am wrong.
> 
> Hello Coly,
> 
> I'm not familiar enough with bcache to provide the answer to your question so
> I will drop this patch from this series.

Hi Bart,

It seems you catch a code bug here. I will look into this and handle it
here.

Thanks for the hint :-)

Coly Li

  reply	other threads:[~2018-03-16  4:33 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-15 15:07 [PATCH 00/16] bcache: Compiler, sparse and smatch fixes Bart Van Assche
2018-03-15 15:07 ` [PATCH 01/16] bcache: Fix indentation Bart Van Assche
2018-03-15 15:49   ` Coly Li
2018-03-15 16:13   ` Coly Li
2018-03-16 18:45   ` Michael Lyle
2018-03-15 15:08 ` [PATCH 02/16] bcache: Add __printf annotation to __bch_check_keys() Bart Van Assche
2018-03-16 18:48   ` Michael Lyle
2018-03-15 15:08 ` [PATCH 03/16] bcache: Annotate switch fall-through Bart Van Assche
2018-03-15 15:48   ` Coly Li
2018-03-16 18:51   ` Michael Lyle
2018-03-15 15:08 ` [PATCH 04/16] bcache: Fix kernel-doc warnings Bart Van Assche
2018-03-16 18:50   ` Michael Lyle
2018-03-15 15:08 ` [PATCH 05/16] bcache: Remove an unused variable Bart Van Assche
2018-03-15 15:51   ` Coly Li
2018-03-15 16:11   ` Coly Li
2018-03-15 16:13     ` Christoph Hellwig
2018-03-15 16:43       ` Coly Li
2018-03-16 18:52   ` Michael Lyle
2018-03-15 15:08 ` [PATCH 06/16] bcache: Suppress more warnings about set-but-not-used variables Bart Van Assche
2018-03-15 16:20   ` Coly Li
2018-03-15 16:50     ` Bart Van Assche
2018-03-15 16:55       ` Coly Li
2018-03-15 15:08 ` [PATCH 07/16] bcache: Reduce the number of sparse complaints about lock imbalances Bart Van Assche
2018-03-16 18:53   ` Michael Lyle
2018-03-15 15:08 ` [PATCH 08/16] bcache: Fix a compiler warning in bcache_device_init() Bart Van Assche
2018-03-15 16:07   ` Coly Li
2018-03-16 18:44   ` Michael Lyle
2018-03-15 15:08 ` [PATCH 09/16] bcache: Remove a redundant assignment Bart Van Assche
2018-03-15 16:22   ` Coly Li
2018-03-15 15:08 ` [PATCH 10/16] bcache: Suppress a compiler warning in bch_##name##_h() Bart Van Assche
2018-03-15 15:08 ` [PATCH 11/16] bcache: Check the d->disk pointer before using it Bart Van Assche
2018-03-15 16:25   ` Coly Li
2018-03-15 15:08 ` [PATCH 12/16] bcache: Make it easier for static analyzers to analyze bch_allocator_thread() Bart Van Assche
2018-03-15 16:29   ` Coly Li
2018-03-15 16:52     ` Bart Van Assche
2018-03-16  0:59       ` Coly Li
2018-03-15 15:08 ` [PATCH 13/16] bcache: Make bch_dump_read() fail if copying to user space fails Bart Van Assche
2018-03-15 17:00   ` Coly Li
2018-03-15 17:06     ` Bart Van Assche
2018-03-16  4:33       ` Coly Li [this message]
2018-03-15 15:08 ` [PATCH 14/16] bcache: Make csum_set() implementation easier to read Bart Van Assche
2018-03-15 15:57   ` Christoph Hellwig
2018-03-15 15:08 ` [PATCH 15/16] bcache: Fix an endianness bug Bart Van Assche
2018-03-16  4:47   ` Coly Li
2018-03-16 15:00     ` Bart Van Assche
2018-03-17 10:05       ` Coly Li
2018-03-15 15:08 ` [PATCH 16/16] bcache: Fix endianness annotations Bart Van Assche
2018-03-15 15:59   ` Christoph Hellwig
2018-03-16  4:51   ` Coly Li
2018-03-16 18:16 ` [PATCH 00/16] bcache: Compiler, sparse and smatch fixes Michael Lyle
2018-03-16 19:27   ` Bart Van Assche

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=f1adca76-6aee-e37d-1d38-325a019ba81f@suse.de \
    --to=colyli@suse.de \
    --cc=Bart.VanAssche@wdc.com \
    --cc=hch@lst.de \
    --cc=kent.overstreet@gmail.com \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=mlyle@lyle.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