Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp443467pxx; Wed, 28 Oct 2020 08:27:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvgxjG58P9cMXTa+LJKMTQb2fKwLKzgPu/s4kG4m9P3wM7R4W5eSx5wTCxiCh+jK8NE8Ht X-Received: by 2002:a17:906:791:: with SMTP id l17mr7596143ejc.361.1603898876463; Wed, 28 Oct 2020 08:27:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603898876; cv=none; d=google.com; s=arc-20160816; b=blKRAX2OGSJLKxMI73+UWgmqLqbkiIZiIt/GNK/93/jxsZSoqGZ/6DAB4FFmcHoN89 gNQebCxrt1hDP5bQysj/h3Zm6rwgLveu2mGAGrpOcO0i+VFveSiWAmJ7335aLuvQv/QN UMJ401ZbKwLFBuJZ1+sEfmNHmq3iAaVKQna60ryiab6nRaMVUIDhjSuJ7YMJ7BzzceF3 YyWV1FeRmfMeDKBspZT3HIBxLBUbvWT2sTmmTQFAIVk0cGQmy5gGsz5hDffiflqdkFn+ XgFDKafXC5WXlvNejaJJ/ByzpYPZo1umEGO+3nF/KtbQ+dzvJJaH2sG6kIAzVEC+HkDM AfyA== 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=Ivg/CjR2bb/f6ZXAEGDs0vjJ4ShByVXY500pToYr9kY=; b=FJmkciKbyGrN4xzqS0ge7em1elsImBk705vkXN9OAaOz9FqavmTa/3djb8feVdj9Nz t3ZoNk8oA5ThXeOZrafLuNeYslS7z8w3d23v8drgZNKUGX86AApquJkFnKx3+TR61yrl Ark1lmGzGRyAV1QfXPYFl2SNpmz6uCuTinkkywlJ2tjAk1gcA3sv14r1vLqBGhA/17z5 l+I7enZPa+xa7jCBzIVKmIDOI695N8qoW3tWK+nVaFuIfPtI1gNEkURRsMa3Z0qCL0FR l833YKvXft/4uUvXomjiZfwp00opa0+RLNemBQujj8xjimdNw5QjKdOggWnmEnMV19bm BqlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=caZjnxWX; 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=fail (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 b6si3402013edu.343.2020.10.28.08.27.34; Wed, 28 Oct 2020 08:27:56 -0700 (PDT) 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=@kernel.org header.s=default header.b=caZjnxWX; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1811318AbgJ0QjA (ORCPT + 99 others); Tue, 27 Oct 2020 12:39:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:36698 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1800260AbgJ0Pne (ORCPT ); Tue, 27 Oct 2020 11:43:34 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2894D22403; Tue, 27 Oct 2020 15:43:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603813413; bh=mrXDFDzumSc0lnTRT+bKw8DPM5Pk49dlklK8cQZ8GDU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=caZjnxWXLqVzTBrzKUL5AjrVo0bzf3PQbxp05hn7DkH3kRxUgTrqljncR9zPy4T6b psEv1AAFh9RZV+b+3dTG/hGK4AoX7KgC+UXka4Q+lTcrraUBMVGPdS1sibG6OO7Biv Ce7Sk8GKGzjCWL0bHJfXGyjaGg1Cx2NnNQlsnKpc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Souptick Joarder , Andrew Morton , Ira Weiny , John Hubbard , Matthew Wilcox , Matt Porter , Alexandre Bounine , "Gustavo A. R. Silva" , Madhuparna Bhowmik , Dan Carpenter , Linus Torvalds , Sasha Levin Subject: [PATCH 5.9 512/757] rapidio: fix error handling path Date: Tue, 27 Oct 2020 14:52:42 +0100 Message-Id: <20201027135514.490096453@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@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: Souptick Joarder [ Upstream commit fa63f083b3492b5ed5332b8d7c90b03b5ef24a1d ] rio_dma_transfer() attempts to clamp the return value of pin_user_pages_fast() to be >= 0. However, the attempt fails because nr_pages is overridden a few lines later, and restored to the undesirable -ERRNO value. The return value is ultimately stored in nr_pages, which in turn is passed to unpin_user_pages(), which expects nr_pages >= 0, else, disaster. Fix this by fixing the nesting of the assignment to nr_pages: nr_pages should be clamped to zero if pin_user_pages_fast() returns -ERRNO, or set to the return value of pin_user_pages_fast(), otherwise. [jhubbard@nvidia.com: new changelog] Fixes: e8de370188d09 ("rapidio: add mport char device driver") Signed-off-by: Souptick Joarder Signed-off-by: Andrew Morton Reviewed-by: Ira Weiny Reviewed-by: John Hubbard Cc: Matthew Wilcox Cc: Matt Porter Cc: Alexandre Bounine Cc: Gustavo A. R. Silva Cc: Madhuparna Bhowmik Cc: Dan Carpenter Link: https://lkml.kernel.org/r/1600227737-20785-1-git-send-email-jrdr.linux@gmail.com Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- drivers/rapidio/devices/rio_mport_cdev.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/rapidio/devices/rio_mport_cdev.c b/drivers/rapidio/devices/rio_mport_cdev.c index a30342942e26f..163b6c72501d6 100644 --- a/drivers/rapidio/devices/rio_mport_cdev.c +++ b/drivers/rapidio/devices/rio_mport_cdev.c @@ -871,15 +871,16 @@ rio_dma_transfer(struct file *filp, u32 transfer_mode, rmcd_error("pin_user_pages_fast err=%ld", pinned); nr_pages = 0; - } else + } else { rmcd_error("pinned %ld out of %ld pages", pinned, nr_pages); + /* + * Set nr_pages up to mean "how many pages to unpin, in + * the error handler: + */ + nr_pages = pinned; + } ret = -EFAULT; - /* - * Set nr_pages up to mean "how many pages to unpin, in - * the error handler: - */ - nr_pages = pinned; goto err_pg; } -- 2.25.1