Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp245129pxf; Wed, 10 Mar 2021 05:33:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwyOXP8aHpKCZjMIKXYtSZd8U0Itg35X3fIJXfusvWWBpLWw4Pv9EYM4g9ayWhtDXwcm7wv X-Received: by 2002:a17:906:c181:: with SMTP id g1mr3565869ejz.96.1615383199370; Wed, 10 Mar 2021 05:33:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615383199; cv=none; d=google.com; s=arc-20160816; b=Oin8Y38CrHfByCWYu/zD6Btp1ynd73/tNz9LZ87ZamqzbXGnkKSNPYVLLklCOQQySX n1A2i/fwmiv0sOzKo7HRQtDdQHGOne9XrYX1Ovrj5Ox93fJvzN4jNj44nZBu915ap6yv G+JpCQDjUePqJ0emm+bKf3DuuUgOcYNLGWmdMF2z3rG2A4e6BJKOkkcmcrEyxcuRRa15 ztQkbsWXRv9KiFY6A4MEKafLcv+KRnlkMIQJ+LFwtk2/jnJiD41bDp3MfAr+eTD9cAx5 mVj5sNntphIVDFkrcuyitzTIMRlaLiTqn05bBlzRuYBYe7MDEgeb5+hV7+Tay80r+syp l3kw== 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=x9hCkcJ6hSAOPNXzxZnXuo1QprKfGiGZCtOCg1LBag4PmHCNPUQsvSiOsneElzI7yi 1vBA5qRhTErFrzv+pjkrZlTaHyN2+0ztUD8fYOTgRD1e9aAvXUyaThxDHVyLA25B5N5/ if2je35DNwwiy6nBPVnUAHT1qBnmjUpf6EX/xE3fWr8NadMtTKQ4CBrhzMuLO2JfK9ke KhGacumfpbWjwnf+kVIbpcSoevC+vxDGiWojdIq15xihFZhL6zuKNcOl/eqkOagDWpcU LehrxUqgmL0Zwix6dchD4PE9F3S56TNh0tiZ7HhBmRvpova3xOTtFp0ORFQC4SFqBuOG uAEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OlEgkw5E; 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 r24si11516777ejs.40.2021.03.10.05.32.57; Wed, 10 Mar 2021 05:33:19 -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=OlEgkw5E; 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 S233842AbhCJN3r (ORCPT + 99 others); Wed, 10 Mar 2021 08:29:47 -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 S232868AbhCJNZ1 (ORCPT ); Wed, 10 Mar 2021 08:25:27 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id D3611650EE; Wed, 10 Mar 2021 13:25:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615382724; bh=MiV04bqF3ixUNe7h/QK4ahwdf1u6hJlFjfA3uVWr7UM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OlEgkw5E86hY3ht/U4RwXUzeSFKIL8q3tbAdqOHcrDNepT0526RWmkAH1i+gX5Cdm DfaUqcQBhDQxkSjqOMOD3rwQxA+4Lj0xjtT39xkYzHQuQQ2/z68kA2ZC91wc0G5+N2 M/XgQpbaFXWUEymScvlirf76fA4hxqazEs6Clxhw= 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.9 05/11] rsxx: Return -EFAULT if copy_to_user() fails Date: Wed, 10 Mar 2021 14:25:04 +0100 Message-Id: <20210310132320.559778671@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210310132320.393957501@linuxfoundation.org> References: <20210310132320.393957501@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