Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp243667pxf; Wed, 10 Mar 2021 05:31:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGCDKMUc+2bXoVFbe8ETXvhXyZcTiuMr6aavDRhsqI7QIKBxesklA7d/Z7ONauFIBAEtqh X-Received: by 2002:a05:6402:9:: with SMTP id d9mr3252041edu.67.1615383075830; Wed, 10 Mar 2021 05:31:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615383075; cv=none; d=google.com; s=arc-20160816; b=jaGR721k+1nv8hXk2lavWDOXDQZl+rXgSlmTEIrqPX4hWqojvQ1thcqQc/ja6AnSi0 AvkLbZ8ruPkfLC/VgMhbhyd4oE1OByHKLoOQocEKZbepbUYJCfKI5qmb++RCqhxWUili T34CFVFVC5XUZ51ALjyfSXyh7DvQJYnXKL4ePe1M81SWI61GtbddHxmuLzQILPAwgXhD BlO+xhJBt0x+XET5fBflxYGRIjRYVkdVYG7TGjJUdSEPssYkVTNZIPsAUTmWpulYHr+F 5bc1Tg/MD/PLF1FAXJP9tprEWLDovm44z4/oeoEWyttAXRsQkN/ktSElyagYjTvhQ4qb wC5w== 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=OeKuDstOcPgzMF06qKDJl8faOIVyW/8alKib+R0FANo=; b=OmEKbLOu5HZ3ms0Jnpzfdx2sDhbbsU8AF6gw4zYIhd+yzHXTKeihs8a/ax+p/3wJn7 1VhJaQXQiskW4eZv6txyWv1cfgEsumtiaOuTek+q/s59PEdcnIUAzQ6mieyZD+4Zp36O vH40e0oDst5++lCKkKBRC6JnRgY3iZt+AWgXTug1mf9Ri2Dq7WYnibDdNIxIUo8t6DIE z0bYsn/SOU6OdP5BM8GF0CPBQdNagjPYLhPj0ZyNUEzbmHFWIihpk0BUKIocKcBRgF/Z Deyw2G+B+WRjc1jS3VdUhiikyeBorktUKu+PgBj4PJdRpag6eQL42VqrlYwS/DyeqgFo ww+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="JMkJiGB/"; 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 j19si11156003edp.531.2021.03.10.05.30.53; Wed, 10 Mar 2021 05:31:15 -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="JMkJiGB/"; 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 S234260AbhCJN3q (ORCPT + 99 others); Wed, 10 Mar 2021 08:29:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:47184 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233356AbhCJNZ1 (ORCPT ); Wed, 10 Mar 2021 08:25:27 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 02D5A65048; 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=DaZjTtdi5Bkrn+oxuyZCBH9oot1Hoa7szxfIGlHnk6c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JMkJiGB/hqwWH84HpsBRG0L7omZAHMiEZjE4NqbhbPbKqeTSZcTKeK/DFAJSPd3XD 54016agPPP0KeP+Hv//IqJ64shYuQ/7G2nK4Waaor1rESTLqNXqBxwO5C0y7Y9cfel nzd3yqryCQPFKh9/D5vHiX1fLvKXvC3D43czOYQE= 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.19 18/39] rsxx: Return -EFAULT if copy_to_user() fails Date: Wed, 10 Mar 2021 14:24:26 +0100 Message-Id: <20210310132320.296254245@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210310132319.708237392@linuxfoundation.org> References: <20210310132319.708237392@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(-) --- a/drivers/block/rsxx/core.c +++ b/drivers/block/rsxx/core.c @@ -179,15 +179,17 @@ static ssize_t rsxx_cram_read(struct fil { 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;