From patchwork Sat Jul 9 09:26:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 12912131 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E29BAC433EF for ; Sat, 9 Jul 2022 09:26:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7C8756B0073; Sat, 9 Jul 2022 05:26:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 77886940008; Sat, 9 Jul 2022 05:26:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6679D940007; Sat, 9 Jul 2022 05:26:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 530F46B0073 for ; Sat, 9 Jul 2022 05:26:42 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 278143551A for ; Sat, 9 Jul 2022 09:26:42 +0000 (UTC) X-FDA: 79667031444.08.C5F2769 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf01.hostedemail.com (Postfix) with ESMTP id 8DF724001F for ; Sat, 9 Jul 2022 09:26:41 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Lg4SK4xJWzTgTd; Sat, 9 Jul 2022 17:22:57 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 9 Jul 2022 17:26:36 +0800 From: Miaohe Lin To: , , CC: , , Subject: [PATCH] hugetlb: fix memoryleak in hugetlb_mcopy_atomic_pte Date: Sat, 9 Jul 2022 17:26:29 +0800 Message-ID: <20220709092629.54291-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657358801; a=rsa-sha256; cv=none; b=tdZ7EZoRpsA4tiYB3D3c7u8ZDHJdJbhP0cZY/8t9HCUKbPs69ou9Og4jw+pF14wgg6wmVM mwhEc9ZOS6jaV/T0hQYXgwordcpY8Feb5Wn6NGtrD0QFEp5+FxUE9ewKdpOdZpymLwcYLL XwSOXFBkm7dgTMD8ea4NSHODWjor644= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657358801; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=dsIQAqO7o34nue81j2oQ9H1A2IWEuQBDQAJvR3KDbNM=; b=NxrkrbIolfgZNF6MdWAm7sT1ulFlCnqAqm1BsYkgU3dSwuMJ1oNO7gSjGfpnrRxq15H5+b cNSNfKdnZzL/y8rna96GTgWokG8j8UBgDjAmZWh2bQLIr2mXSfARw8trKor+Z0+Y0/VDkx AIkKGSHkUsfuEALTZwfXiPcy36yEPpo= X-Rspamd-Server: rspam08 X-Rspam-User: Authentication-Results: imf01.hostedemail.com; dkim=none; spf=pass (imf01.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Stat-Signature: qpz1abwucbw9wz38nxrye5p87fs8tbyq X-Rspamd-Queue-Id: 8DF724001F X-HE-Tag: 1657358801-410450 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When alloc_huge_page fails, *pagep is set to NULL without put_page first. So the hugepage indicated by *pagep is leaked. Fixes: 8cc5fcbb5be8 ("mm, hugetlb: fix racy resv_huge_pages underflow on UFFDIO_COPY") Signed-off-by: Miaohe Lin Acked-by: Muchun Song Reviewed-by: Mike Kravetz Reviewed-by: Baolin Wang Reviewed-by: Anshuman Khandual --- mm/hugetlb.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 06c2d86b1ba3..598c37279fee 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5962,6 +5962,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, page = alloc_huge_page(dst_vma, dst_addr, 0); if (IS_ERR(page)) { + put_page(*pagep); ret = -ENOMEM; *pagep = NULL; goto out;