Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp1162500pxt; Sat, 7 Aug 2021 02:38:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz58d55c7KyFYAgw+SFqT7f9lTD+ChXOarV29hdv64b0Rrh+1cwDS0KJgvdVIkKNc0K2FOJ X-Received: by 2002:a5d:8456:: with SMTP id w22mr166298ior.63.1628329097201; Sat, 07 Aug 2021 02:38:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628329097; cv=none; d=google.com; s=arc-20160816; b=gW1HAq66Gp34PBDPkznV3yRTlPUgKWxYPRewOKTN+LAp5vuJeSPW4FeJtNoYhjLcrv iaHqQJWV99pjJneScTasV6S/IEEOSQQkDT63NMTml7YNUqe7qIvk90HyNJbr4GTL6IA9 4rUYJ8PF0ZBnUVhZ8OhUURIPNvDfc6V9Q+ezOyFqEQKtxDPeASUVBzAs/hF7XrlPMU+X 0D7Pru2ylFcF2oAmPT/x45HfMHeWyA2VVAl+9uYRh1rbWi1R51/A34CZF4Q4FqoYSH2O HdtTbOcHyH9LWwwQmIaJTEChBrw5V4yJ7/kuTGYg2BCuseLuSBN7WonAPBfHG424EEHS IA3A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Wy24cnC1zE7UIaGd7M4pPzgDRQHxDRdBOErNLZDe9mg=; b=favibcNvwekIoq5E+yUggWshWT6V7e+61FuifuilS+HJyh+EEEzlk7WCA41bcfTlhW jxpduWiYGwbbtAx2RMdwbaLaLfGyAOXVAPz6KhU/MWp5FOEM2bfGZLDXQUILSpFb2Z0h Do7x1gGWpV2tJd1j+OwH7gpkuJxb87/RnEEFgOBbMMAqik8KUrzUkOpaGF5mgZSRqfls lyARsoMuWsISQ9UXlLSEDYWljr1sWh/BnflrtN8gqO7G7pjlT7qXsslyI778ccKEpL+r pUz79ctvbiNydAY+5T/qQf2vkR3ly8aQ/09+s7C6qmkfbPfBwf+0K4BqJVbv8NzlL+zk 6sJg== ARC-Authentication-Results: i=1; mx.google.com; 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=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i4si6576420ilv.135.2021.08.07.02.38.05; Sat, 07 Aug 2021 02:38:17 -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; 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=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231778AbhHGJgm (ORCPT + 99 others); Sat, 7 Aug 2021 05:36:42 -0400 Received: from szxga08-in.huawei.com ([45.249.212.255]:13247 "EHLO szxga08-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231681AbhHGJgh (ORCPT ); Sat, 7 Aug 2021 05:36:37 -0400 Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Ghcfd6sNTz1CT3G; Sat, 7 Aug 2021 17:36:09 +0800 (CST) Received: from huawei.com (10.175.124.27) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Sat, 7 Aug 2021 17:36:19 +0800 From: Miaohe Lin To: CC: , , , , , , Subject: [PATCH 4/5] mm: gup: fix potential pgmap refcnt leak in __gup_device_huge() Date: Sat, 7 Aug 2021 17:36:19 +0800 Message-ID: <20210807093620.21347-5-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20210807093620.21347-1-linmiaohe@huawei.com> References: <20210807093620.21347-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When failed to try_grab_page, put_dev_pagemap() is missed. So pgmap refcnt will leak in this case. Also we remove the check for pgmap against NULL as it's also checked inside the put_dev_pagemap(). Signed-off-by: Miaohe Lin Fixes: 3faa52c03f44 ("mm/gup: track FOLL_PIN pages") --- mm/gup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index d7e4507de6b1..8c89e614d4aa 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2253,14 +2253,14 @@ static int __gup_device_huge(unsigned long pfn, unsigned long addr, pages[*nr] = page; if (unlikely(!try_grab_page(page, flags))) { undo_dev_pagemap(nr, nr_start, flags, pages); + put_dev_pagemap(pgmap); return 0; } (*nr)++; pfn++; } while (addr += PAGE_SIZE, addr != end); - if (pgmap) - put_dev_pagemap(pgmap); + put_dev_pagemap(pgmap); return 1; } -- 2.23.0