Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp526303pxx; Wed, 28 Oct 2020 10:18:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+IjfazeCC7mZ+yELIhhL1NQDbVg+kMrnS0AlBsh+vWHQ+I+JU/JKky/IDN3gG6vm5aQP0 X-Received: by 2002:a17:906:b1d6:: with SMTP id bv22mr131427ejb.60.1603905505678; Wed, 28 Oct 2020 10:18:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603905505; cv=none; d=google.com; s=arc-20160816; b=i1Gk/dGz1XiTjLigt3v0vV7VS4MwsP6xgCmKNWg5o65nDYWI/t18/V6qia/GW/JHJ4 5Z/uoFFUxWnoSx/qLYHEFf1wPUP+XfjVPpSPY/Zfp2zwSZSEpwJm16eB8BHEA7zWnx+5 sq2EqmatFWKBNkspIVx4UDkdYJHu3e3/3MlLDfrGeIeFALCQ6L9QE4SMEIMKr0MtA99N fUKB6nRyfZS5DrvZO2tE8tHFaOfDb+CMb5d6ecz1s6K85wAFS0HWiKzOvz91K6wQimdX ndI4Xg+KZHaib4sRoA3jZRKUmAulGd/fSSky5NknssVPbA9M3PaChlefFcPpEAZtYUf5 a9rQ== 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=omeeK3VW2JTD5C9nxjCbPeExuTxrEZgMqjqozylzaJU=; b=Lq1ZIIDuqocI09kki1IP3kk2pWdXIOVi5uQ3oO0NhxtwXQ7nusBZ3WaCZz6MmGjOaT KbC7eWG0FrkbuomvQ22sWl0/ozXt+WT30lWeSLG4NfpgPTIfxGRbRhnTdHEwpkDbnswd 0brtEwmnVv+n/ifY0CkxQDKOx0R9ndsB1VwVIzKYFIZ85PxNcCz1V9lXXa/z7lLCbJWi cvdgznf3tISv+29bA6W7ikKXUY1o4gkGs2G1B90oKRlalBvDiKJZbCaFZOMrRqXlrnEO ESaJKMbPSII2W9TQDmTJNYp+x0dl5CKIeB1NthfeZrl8n7AVI9/lqQvhHK+fCNIKzoZU oZQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bEGMo7Nq; 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 w23si165eds.571.2020.10.28.10.18.03; Wed, 28 Oct 2020 10:18:25 -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=bEGMo7Nq; 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 S1820708AbgJ0RhZ (ORCPT + 99 others); Tue, 27 Oct 2020 13:37:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:34410 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760641AbgJ0Ofi (ORCPT ); Tue, 27 Oct 2020 10:35: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 737D5207BB; Tue, 27 Oct 2020 14:35:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809338; bh=UJOXzxwR7uIKKD7XUluyCH7FmzcC8xmpVxeanzm1l3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bEGMo7Nq/Zqn8rdMNUd69As+xIePVW7fiH30fWaINsdqlVWF1wf43fhxptLP4YERz 1WflhTevn00OyUN0o8vnRwK3xW4kSigNvp6dBD7gG8exUxjMh25jxBPiaLGXzZBo3i YOySU4lK0+sU4Z62iJ+afIWZy8+v0/g3fFPXmCiM= 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.4 161/408] misc: mic: scif: Fix error handling path Date: Tue, 27 Oct 2020 14:51:39 +0100 Message-Id: <20201027135502.564549397@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@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 01e27682ea303..a486c6c7f4077 100644 --- a/drivers/misc/mic/scif/scif_rma.c +++ b/drivers/misc/mic/scif/scif_rma.c @@ -1381,6 +1381,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