From nobody Sun Feb 8 07:58:09 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F5E1EB64DC for ; Sat, 1 Jul 2023 07:28:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229643AbjGAH2b (ORCPT ); Sat, 1 Jul 2023 03:28:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbjGAH22 (ORCPT ); Sat, 1 Jul 2023 03:28:28 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C418A136 for ; Sat, 1 Jul 2023 00:28:26 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QtNy90p05ztQSD; Sat, 1 Jul 2023 15:25:37 +0800 (CST) Received: from huawei.com (10.174.151.185) 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.2507.27; Sat, 1 Jul 2023 15:28:24 +0800 From: Miaohe Lin To: , CC: , , Subject: [PATCH] mm: memory-failure: fix potential page refcnt leak in memory_failure() Date: Sat, 1 Jul 2023 15:28:37 +0800 Message-ID: <20230701072837.1994253-1-linmiaohe@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" put_ref_page() is not called to drop extra refcnt when comes from madvise in the case pfn is valid but pgmap is NULL leading to page refcnt leak. Fixes: 1e8aaedb182d ("mm,memory_failure: always pin the page in madvise_inj= ect_error") Signed-off-by: Miaohe Lin --- mm/memory-failure.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index e245191e6b04..65e2d4c5b50d 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -2080,8 +2080,6 @@ static int memory_failure_dev_pagemap(unsigned long p= fn, int flags, { int rc =3D -ENXIO; =20 - put_ref_page(pfn, flags); - /* device metadata space is not recoverable */ if (!pgmap_pfn_valid(pgmap, pfn)) goto out; @@ -2157,6 +2155,7 @@ int memory_failure(unsigned long pfn, int flags) =20 if (pfn_valid(pfn)) { pgmap =3D get_dev_pagemap(pfn, NULL); + put_ref_page(pfn, flags); if (pgmap) { res =3D memory_failure_dev_pagemap(pfn, flags, pgmap); --=20 2.33.0