Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp244234pxf; Wed, 10 Mar 2021 05:32:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcV3LT+z0vWD+dnSlQIAzEgysipPCYYepNbnD0O/y21kf5txllt9/Gg/Hw1YZTV+Dycqp9 X-Received: by 2002:a17:906:3ac3:: with SMTP id z3mr3754993ejd.106.1615383121639; Wed, 10 Mar 2021 05:32:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615383121; cv=none; d=google.com; s=arc-20160816; b=HlmQ9PiDOJuikPD0Y6YmKKsl2lOOUfHHKGICsYFQzle6EUHL2FcsDCDdD8vNDBdAYH imee7yrXNk82XGyWV18CHwQm/jLBDQZRq2aqUyjVjr3sKYmHFyrZsligLyctvegGki3k 1mgcBy3X2VlINMpMfb08iyYjEwd2z+SWQLtd6K9VjSOObUTqmGXYcd3mXp5Gpozfa3Yh wY7Fu3FHC+We46sm6zLjRFELdOueIEYz/ITkSOnzSneKAa1t6Vpz9hPz8sXrmTqDzbeI 2YoCMqLGAAEQuRwFj3kpF22jGCf3KTyCHvIrixz2Zz/vTlyIw7dEhmdr7gsD80v+XjIt SsjA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jM+XoCsfchmPzIatyWiYQcO9uJ6MMlfkdVaLGCRegrs=; b=YRrOhRwI4fjCs/FVWlWRpy2FOvkX/XZK1NizJ/cz9uEaXxhh0KCRp3KBOPKKeU9sDW CcpijzLFiKdvQSorZ4dHn9yy6ZDgLnxlC19wE7OsZxzDjmsQ26NDVXHJCJHemeR1Uvk1 FdrXfxuppbGZHxFiw/KEqQJHnCVKv1sEEh1ZEvRwLXUUdQbReWVuIl9jEoP/+uMhkWJB ikVk36dJbzO89BsJhuj8JtNb6HDuz3qRsoYoGEq/jl36pjj4HxRtxLDYMX4Q6RkRkSOb qg/OoW3YFyZEZjr7EcKmeJQLjuwgJahdqXcwFzAoAC4xaUt3LFmigDzYstoURJXS77Bm fDgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R2QrNcnV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id kb16si11019479ejb.190.2021.03.10.05.31.38; Wed, 10 Mar 2021 05:32:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=R2QrNcnV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234222AbhCJN2o (ORCPT + 99 others); Wed, 10 Mar 2021 08:28:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:47046 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232992AbhCJNZM (ORCPT ); Wed, 10 Mar 2021 08:25:12 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id DD4E36500D; Wed, 10 Mar 2021 13:25:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615382712; bh=MiV04bqF3ixUNe7h/QK4ahwdf1u6hJlFjfA3uVWr7UM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R2QrNcnVyXcGRIhVqimRx2pANAeF3VbLw02QTqxHvmI/gqW01HhHFD2XBvXjB43IR dhwc5RfEak1yvdXLWyFduGT6LhR5PGGLESvk9u/znJLl9p/5buw21XWg7eqS2lsHfo SW+FP5u+q5DD1xzpWe49d3FMOOo1rgYZY8rOVHOo= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Jens Axboe , Sasha Levin Subject: [PATCH 4.14 06/20] rsxx: Return -EFAULT if copy_to_user() fails Date: Wed, 10 Mar 2021 14:24:43 +0100 Message-Id: <20210310132320.718226591@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210310132320.512307035@linuxfoundation.org> References: <20210310132320.512307035@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Dan Carpenter [ Upstream commit 77516d25f54912a7baedeeac1b1b828b6f285152 ] The copy_to_user() function returns the number of bytes remaining but we want to return -EFAULT to the user if it can't complete the copy. The "st" variable only holds zero on success or negative error codes on failure so the type should be int. Fixes: 36f988e978f8 ("rsxx: Adding in debugfs entries.") Signed-off-by: Dan Carpenter Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/rsxx/core.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/block/rsxx/core.c b/drivers/block/rsxx/core.c index 6beafaa335c7..97b678c0ea13 100644 --- a/drivers/block/rsxx/core.c +++ b/drivers/block/rsxx/core.c @@ -180,15 +180,17 @@ static ssize_t rsxx_cram_read(struct file *fp, char __user *ubuf, { struct rsxx_cardinfo *card = file_inode(fp)->i_private; char *buf; - ssize_t st; + int st; buf = kzalloc(cnt, GFP_KERNEL); if (!buf) return -ENOMEM; st = rsxx_creg_read(card, CREG_ADD_CRAM + (u32)*ppos, cnt, buf, 1); - if (!st) - st = copy_to_user(ubuf, buf, cnt); + if (!st) { + if (copy_to_user(ubuf, buf, cnt)) + st = -EFAULT; + } kfree(buf); if (st) return st; -- 2.30.1