Message ID | 20230519013710.34954-1-suhui@nfschina.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp922264vqo; Thu, 18 May 2023 18:54:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7bH2XE5ddJIuXbkEV/sny716RiI3TKaZ6UerNp72Q1210Oe2TV3CV2NL8RxBpld0SI49es X-Received: by 2002:a05:6a20:548a:b0:102:345f:593b with SMTP id i10-20020a056a20548a00b00102345f593bmr549872pzk.4.1684461267360; Thu, 18 May 2023 18:54:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684461267; cv=none; d=google.com; s=arc-20160816; b=mqhFicoCvcANkvmLXidI1scIYpqfqQneZCYIhKL4pTEARDxm+yxLKNLznbwrHlKMZi KSCAOdz8lb2obIv7UjS3tMk6Pu2bvrIxI89FWE8XmBG7eLPj7hhUyhmybduQalzSuFQ4 f8txseEcboCW4uIHySZZnkdlm5p/Q7BHqgqMIFYT9sXMRGQpuCsn5v3qd3gVrm7nuyEV sg20hKm9JvLqACVuyQ3zlm6588q6Ocf8jHi6keLUY0pi4MI1I0NZlt1iXiOo7I9bCWqF ijMF4ewgrnsEV7M6mLWSaoKFwd40Ci3S2VYVd+9y+A0I0s+0KYttaiTJ0ASx4Vrit6Wn 8mkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=LVeYG9ofG1g0Blrd9i0H2K414vQ7/QXVpdg1hQOFnpE=; b=IMK/HCTXJ5mMGXZFTeM7PH4cLJaGsemlCoR0MY16PWj5loCPXoZicJs48iUUa/756C pEY867/iw5cRdGoFYOhCqzX2xQsRvU+QaGy4ss/fIQu2i8RUW3AfbFckQSI+S5dZ23q5 RIpQei7zSFVweGCBD0pEVkwVGZ4AMKDCu1STyQjIulfxHdKdKFAIJrcwT7xXRPDXlEws gmdIDg9DqY51KZPrE2wmISfcAjf1fCiiBbEx0gI5eep5iTl/7aVPVgkr68s+MKxrE5bZ uzFbrAuZvZCqRKHwrByXFEGyBK8JAofNpGpVZ4dWJ3s46xAccg8oVwopZ10VSHoRWXDd 0g6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i14-20020a056a00004e00b0063b13efdd06si2937362pfk.345.2023.05.18.18.54.15; Thu, 18 May 2023 18:54:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229566AbjESBhk (ORCPT <rfc822;cscallsign@gmail.com> + 99 others); Thu, 18 May 2023 21:37:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbjESBhi (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 18 May 2023 21:37:38 -0400 Received: from mail.nfschina.com (unknown [42.101.60.195]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 9366910C2; Thu, 18 May 2023 18:37:34 -0700 (PDT) Received: from localhost.localdomain (unknown [180.167.10.98]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPA id 2B0331801097CD; Fri, 19 May 2023 09:37:12 +0800 (CST) X-MD-Sfrom: suhui@nfschina.com X-MD-SrcIP: 180.167.10.98 From: Su Hui <suhui@nfschina.com> To: Jeremy Kerr <jk@ozlabs.org>, Joel Stanley <joel@jms.id.au>, Alistar Popple <alistair@popple.id.au>, Eddie James <eajames@linux.ibm.com> Cc: eajames@us.ibm.com, cbostic@linux.vnet.ibm.com, gregkh@linuxfoundation.org, linux-fsi@lists.ozlabs.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Su Hui <suhui@nfschina.com> Subject: [PATCH] drivers/fsi/scom: Return -EFAULT if copy fails Date: Fri, 19 May 2023 09:37:10 +0800 Message-Id: <20230519013710.34954-1-suhui@nfschina.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,RDNS_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766285657516802237?= X-GMAIL-MSGID: =?utf-8?q?1766285657516802237?= |
Series |
drivers/fsi/scom: Return -EFAULT if copy fails
|
|
Commit Message
Su Hui
May 19, 2023, 1:37 a.m. UTC
The copy_to/from_user() functions return the number of bytes remaining
to be copied, but we want to return -EFAULT to the user.
Fixes: 680ca6dcf5c2 ("drivers/fsi: Add SCOM FSI client device driver")
Signed-off-by: Su Hui <suhui@nfschina.com>
---
drivers/fsi/fsi-scom.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri, May 19, 2023 at 09:37:10AM +0800, Su Hui wrote: > The copy_to/from_user() functions return the number of bytes remaining > to be copied, but we want to return -EFAULT to the user. > Why ? EFAULT means that a bad address was provided, and it is not immediately obvious why that would be the case. Guenter > Fixes: 680ca6dcf5c2 ("drivers/fsi: Add SCOM FSI client device driver") > Signed-off-by: Su Hui <suhui@nfschina.com> > --- > drivers/fsi/fsi-scom.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/fsi/fsi-scom.c b/drivers/fsi/fsi-scom.c > index bcb756dc9866..caaf7738eb98 100644 > --- a/drivers/fsi/fsi-scom.c > +++ b/drivers/fsi/fsi-scom.c > @@ -335,7 +335,7 @@ static ssize_t scom_read(struct file *filep, char __user *buf, size_t len, > if (rc) > dev_dbg(dev, "copy to user failed:%d\n", rc); > > - return rc ? rc : len; > + return rc ? -EFAULT : len; > } > > static ssize_t scom_write(struct file *filep, const char __user *buf, > -- > 2.30.2 >
On 2023/5/23 06:30, Guenter Roeck wrote: > On Fri, May 19, 2023 at 09:37:10AM +0800, Su Hui wrote: >> The copy_to/from_user() functions return the number of bytes remaining >> to be copied, but we want to return -EFAULT to the user. >> > Why ? EFAULT means that a bad address was provided, and it is not > immediately obvious why that would be the case. When copy_to/from_user() functions failed, the error code is -EFAULT in most case. git grep -A1 "copy_from_user" | grep EFAULT | wc -l 1985 git grep -A1 "copy_to_user" | grep EFAULT | wc -l 1871 I think return -EFAULT is also right in this case. Su Hui > Guenter > >> Fixes: 680ca6dcf5c2 ("drivers/fsi: Add SCOM FSI client device driver") >> Signed-off-by: Su Hui <suhui@nfschina.com> >> --- >> drivers/fsi/fsi-scom.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/drivers/fsi/fsi-scom.c b/drivers/fsi/fsi-scom.c >> index bcb756dc9866..caaf7738eb98 100644 >> --- a/drivers/fsi/fsi-scom.c >> +++ b/drivers/fsi/fsi-scom.c >> @@ -335,7 +335,7 @@ static ssize_t scom_read(struct file *filep, char __user *buf, size_t len, >> if (rc) >> dev_dbg(dev, "copy to user failed:%d\n", rc); >> >> - return rc ? rc : len; >> + return rc ? -EFAULT : len; >> } >> >> static ssize_t scom_write(struct file *filep, const char __user *buf, >> -- >> 2.30.2 >>
On Mon, May 22, 2023 at 03:30:06PM -0700, Guenter Roeck wrote: > On Fri, May 19, 2023 at 09:37:10AM +0800, Su Hui wrote: > > The copy_to/from_user() functions return the number of bytes remaining > > to be copied, but we want to return -EFAULT to the user. > > > Why ? EFAULT means that a bad address was provided, and it is not > immediately obvious why that would be the case. > Right now the function is returning success so that's definitely wrong. The copy_to/from_user() function will only fail if a bad address is provided so -EFAULT is correct. There is a different Smatch warning for when people return a different error code such as -EINVAL. drivers/fsi/fsi-scom.c:337 scom_read() warn: return -EFAULT instead of '-EINVAL' The return affects the user and -EFAULT but that level of pendantry feel like possibly too much? There aren't many instances of this warning. regards, dan carpenter
diff --git a/drivers/fsi/fsi-scom.c b/drivers/fsi/fsi-scom.c index bcb756dc9866..caaf7738eb98 100644 --- a/drivers/fsi/fsi-scom.c +++ b/drivers/fsi/fsi-scom.c @@ -335,7 +335,7 @@ static ssize_t scom_read(struct file *filep, char __user *buf, size_t len, if (rc) dev_dbg(dev, "copy to user failed:%d\n", rc); - return rc ? rc : len; + return rc ? -EFAULT : len; } static ssize_t scom_write(struct file *filep, const char __user *buf,