[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <6FE46D2D-21E9-457F-91DF-0E31FBB8A501@gmail.com>
Date: Thu, 25 Jun 2015 20:05:08 +0300
From: Dmitry Kalinkin <dmitry.kalinkin@...il.com>
To: Sudip Mukherjee <sudipm.mukherjee@...il.com>
Cc: linux-kernel@...r.kernel.org, devel@...verdev.osuosl.org,
Martyn Welch <martyn.welch@...com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Manohar Vanga <manohar.vanga@...il.com>
Subject: Re: [PATCHv2 6/9] staging: vme_user: return -EFAULT on __copy_*_user errors
> On 25 Jun 2015, at 15:05, Dmitry Kalinkin <dmitry.kalinkin@...il.com> wrote:
>
>
>> On 25 Jun 2015, at 14:27, Sudip Mukherjee <sudipm.mukherjee@...il.com> wrote:
>>
>> On Tue, Jun 23, 2015 at 07:03:36PM +0300, Dmitry Kalinkin wrote:
>>> Signed-off-by: Dmitry Kalinkin <dmitry.kalinkin@...il.com>
>>> ---
>>> drivers/staging/vme/devices/vme_user.c | 47 ++++++++--------------------------
>>> 1 file changed, 11 insertions(+), 36 deletions(-)
>>>
>> <snip>
>>> @@ -178,38 +167,24 @@ static ssize_t buffer_to_user(unsigned int minor, char __user *buf,
>>> size_t count, loff_t *ppos)
>>> {
>>> void *image_ptr;
>>> - ssize_t retval;
>>>
>>> image_ptr = image[minor].kern_buf + *ppos;
>>> + if (__copy_to_user(buf, image_ptr, (unsigned long)count))
>>> + return -EFAULT;
>>>
>>> - retval = __copy_to_user(buf, image_ptr, (unsigned long)count);
>>> - if (retval != 0) {
>>> - retval = (count - retval);
>>> - pr_warn("Partial copy to userspace\n");
>>> - } else
>>> - retval = count;
>>> -
>>> - /* Return number of bytes successfully read */
>>> - return retval;
>>> + return count;
>> will it not affect the userspace code?
>> previously number of bytes successfully read was returned, now incase of
>> partial read -EFAULT is being returned.
> Exactly.
>
> Practically there is an access_ok() call in vfs_read() and vfs_write() that
> will catch this first. I don’t know exactly what is the condition for
> __copy_to_user to fail, but it is probably some rare arch-specific thing (and
> we only care for x86/powerpc here). But when it happens it better be returning
> proper error codes. This is why I think this is not a “we broke userspace”
> situation.
It seems like what I wrote above is not correct. access_ok does only coarse
checks and __copy_to_user does fail. Anyway, only a rare userspace application
would depend on “succesfull” read that was interrupted by a segfault. Also, if
__copy_to_user fails completely, the original code would return zero, which in
POSIX should mean something like “everything is good, try again later” and
this may cause infinite loops (e.g. python).--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists