Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp261737pxx; Wed, 28 Oct 2020 04:24:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLJc+lfgfrrteoEVcItSb3hvavB2ZcrjNsdFk1FzKjHW//8bVTL7vkic/xv27shtgKgqMk X-Received: by 2002:aa7:df0c:: with SMTP id c12mr7317219edy.234.1603884254777; Wed, 28 Oct 2020 04:24:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603884254; cv=none; d=google.com; s=arc-20160816; b=J1g8JHWcQT2WRr8oXo5Kaz5J3H+BbUCdJIZ3CjcS4IMMwtox2W3TzCwrbHUaDpNwqb N+R4Pim+WF3f/cnYvWzLzmX8lyGqGgJMR4jl3JmSCmJDHWIRKxKzkb7oTzjhaBAgdXS/ PAzJkVqdVF9le/Ias3HZOhvPpEteX6KRXpy0CBioQzHspCBv0l9QM9GAR+rARhf6Jo2E HRbktPGmpXpruvWuQa2RFIl7qmtLilasPQqGu8eiQES5xCpNqOg9ylCwvdJy6piH0cuQ uw2TbrXxqOl3uNQ8IY0bLo/0E6c0fSazSkwTH1kdO2MvQwYcSID/VqjHrXB5uS77Kj1D mpEA== 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=fNNvYe6vM/EyzD2LMdIfXiWPDGT+wYQiGK/hJ5ZBXFQ=; b=OxWcn3pdEX52VqXXbdnLt4E0nx45hcAWboR0hf7tp3JUKYhxwQ+//Hh7ft3wNfDsJk lAZG2JnRuXNP/X6qk14D+hf6ANFG/U/xLheZZb82+JxNIW1bSiyV47x8Z4YGO5Z7QTs4 ErDDGVvMyMebZzwHhiGTaBx/5QcG1Wq5WeQiZqRFHmj0VJ6O6Eg1lEaLyp/yU6xBii77 zBnf1hKBcUEbzqX8fjcbHpIk5yuH3g0nPFQ8yBbFfKLne3kdOOJzGeyhXskxpYLEFsQj ydoe5uFWc2B34t87zYTIrR6PoF1GYsuU2K62uaA8TWdZMyLtBBtW1AQFBzIRFdAWMLtk RYKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=k9WXiron; 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 i19si2816688ejh.153.2020.10.28.04.23.52; Wed, 28 Oct 2020 04:24:14 -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=k9WXiron; 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 S1789756AbgJ0PCw (ORCPT + 99 others); Tue, 27 Oct 2020 11:02:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:33048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1784724AbgJ0O7i (ORCPT ); Tue, 27 Oct 2020 10:59:38 -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 9947E22281; Tue, 27 Oct 2020 14:59:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810778; bh=838kLNn+K13lIKne6GHx05EbvVunaJoK6lVG4g/2iCM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k9WXironhFwjE4znIckOzVTTbjcUNY22nRG0d25MSMXMYMBLv+EUHqHgVJ4ww+cQk x9Et+XRyJmGbzPFCgKZ8mT+R8eq/p0wflIy0eHgWrGtjNe1dDNniqGhr6LY/UrnQHf sYqV7sUPsIyARKxoURy55k+0JKzYcnpiMI0TlWSY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Hubbard , Ira Weiny , Dan Carpenter , Souptick Joarder , Sasha Levin Subject: [PATCH 5.8 261/633] misc: mic: scif: Fix error handling path Date: Tue, 27 Oct 2020 14:50:04 +0100 Message-Id: <20201027135534.906964620@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@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 a81072a9c0ae734b7889929b0bc070fe3f353f0e ] Inside __scif_pin_pages(), when map_flags != SCIF_MAP_KERNEL it will call pin_user_pages_fast() to map nr_pages. However, pin_user_pages_fast() might fail with a return value -ERRNO. The return value is stored in pinned_pages->nr_pages. which in turn is passed to unpin_user_pages(), which expects pinned_pages->nr_pages >=0, else disaster. Fix this by assigning pinned_pages->nr_pages to 0 if pin_user_pages_fast() returns -ERRNO. Fixes: ba612aa8b487 ("misc: mic: SCIF memory registration and unregistration") Cc: John Hubbard Cc: Ira Weiny Cc: Dan Carpenter Reviewed-by: John Hubbard Signed-off-by: Souptick Joarder Link: https://lore.kernel.org/r/1600570295-29546-1-git-send-email-jrdr.linux@gmail.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/misc/mic/scif/scif_rma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/misc/mic/scif/scif_rma.c b/drivers/misc/mic/scif/scif_rma.c index 406cd5abfa726..56c784699eb8e 100644 --- a/drivers/misc/mic/scif/scif_rma.c +++ b/drivers/misc/mic/scif/scif_rma.c @@ -1384,6 +1384,8 @@ int __scif_pin_pages(void *addr, size_t len, int *out_prot, (prot & SCIF_PROT_WRITE) ? FOLL_WRITE : 0, pinned_pages->pages); if (nr_pages != pinned_pages->nr_pages) { + if (pinned_pages->nr_pages < 0) + pinned_pages->nr_pages = 0; if (try_upgrade) { if (ulimit) __scif_dec_pinned_vm_lock(mm, nr_pages); @@ -1400,7 +1402,6 @@ int __scif_pin_pages(void *addr, size_t len, int *out_prot, if (pinned_pages->nr_pages < nr_pages) { err = -EFAULT; - pinned_pages->nr_pages = nr_pages; goto dec_pinned; } @@ -1413,7 +1414,6 @@ int __scif_pin_pages(void *addr, size_t len, int *out_prot, __scif_dec_pinned_vm_lock(mm, nr_pages); /* Something went wrong! Rollback */ error_unmap: - pinned_pages->nr_pages = nr_pages; scif_destroy_pinned_pages(pinned_pages); *pages = NULL; dev_dbg(scif_info.mdev.this_device, -- 2.25.1