Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751701AbbFYMCy (ORCPT ); Thu, 25 Jun 2015 08:02:54 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:36197 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751378AbbFYMCr convert rfc822-to-8bit (ORCPT ); Thu, 25 Jun 2015 08:02:47 -0400 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) Subject: Re: [PATCHv2 6/9] staging: vme_user: return -EFAULT on __copy_*_user errors From: Dmitry Kalinkin In-Reply-To: <20150625112758.GB13366@sudip-PC> Date: Thu, 25 Jun 2015 15:05:27 +0300 Cc: linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org, Martyn Welch , Greg Kroah-Hartman , Manohar Vanga Content-Transfer-Encoding: 8BIT Message-Id: <1423C916-AB8D-409B-B844-BCF72975625E@gmail.com> References: <20150623135124.GP28762@mwanda> <1435075419-28211-1-git-send-email-dmitry.kalinkin@gmail.com> <1435075419-28211-7-git-send-email-dmitry.kalinkin@gmail.com> <20150625112758.GB13366@sudip-PC> To: Sudip Mukherjee X-Mailer: Apple Mail (2.2098) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1813 Lines: 48 > On 25 Jun 2015, at 14:27, Sudip Mukherjee wrote: > > On Tue, Jun 23, 2015 at 07:03:36PM +0300, Dmitry Kalinkin wrote: >> Signed-off-by: Dmitry Kalinkin >> --- >> drivers/staging/vme/devices/vme_user.c | 47 ++++++++-------------------------- >> 1 file changed, 11 insertions(+), 36 deletions(-) >> > >> @@ -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. Cheers, Dmitry-- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/