From patchwork Sat Jul 1 07:28:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miaohe Lin X-Patchwork-Id: 13298981 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 C97DAEB64DD for ; Sat, 1 Jul 2023 07:28:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EAA068E0066; Sat, 1 Jul 2023 03:28:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E5AC08E0059; Sat, 1 Jul 2023 03:28:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D49E88E0066; Sat, 1 Jul 2023 03:28:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C34F98E0059 for ; Sat, 1 Jul 2023 03:28:36 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 8EADFAFBD7 for ; Sat, 1 Jul 2023 07:28:36 +0000 (UTC) X-FDA: 80962215432.15.02FFC56 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf19.hostedemail.com (Postfix) with ESMTP id 614BE1A0005 for ; Sat, 1 Jul 2023 07:28:31 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688196514; 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=KAM55iUfe+YQBA/wn3l0jspOCq+DXYKe25TYxny2d/E=; b=Jfj058VD88btv2qpsSpRuvMj/V2WafEZaHn1v5Wqk04ng/5+WgSoQ1SoqfYgc9lLuHfJXo 22XfV5ubdcO2nEqdNmdBED8k4ssR08l9xqgWsOX26Nf6F5XhJVsPAxtYRN+TYlyFGwA9Mz ZV8gY4Xm5eAY4XrMCAI7/LE7TBjPVjI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688196514; a=rsa-sha256; cv=none; b=P5wan7UKfzj+V60+0YydUkWO66wz6VLV+Hl2ncIMXOaa8Zo/zFm/lejAv6QDCsvO0vHHa4 p6vuv5LS5tN1dKGDoD0FYu69W2untEQewjK5ylCNwDOfOr04ifTYwqXgySkVGwzOX3S4Bf 6j+cF0J4CZcwCf8Iw29Hy2VEKtVNiwg= 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 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 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 614BE1A0005 X-Stat-Signature: sywgi68oibzh33x1k1cs83f3kjz5qmhm X-HE-Tag: 1688196511-324415 X-HE-Meta: U2FsdGVkX18gbDA2ovd9XyeMZ32Evr7OGeY7XjlNG9dzgmeWNYLsGF2Qn4WXg3wtdAgarbd2Gqb+xNgk27uPvzIWWHgdi2wqf1KjxyNLsk/CLuSWly54FpvhIzH9qU5A5PtWlkXB+1Am4qVZrlUc1eGU25iH/xTNAZ21pzb8ORU4+Ad2hX7aDamj7et0WApl3edRE0dlv58XHw8ofQau+v4iPjUnoOLjZRgkqC7m4+vctmx/0ZF3Gsu6uE0SWout6oZDFR+C6PbJnYx3wm9gAcOV+k6Rt4n66DxV0eMlf0W2mfOgJhUbpsXAO3sbI0u9xQjgG6RJRGF/QONPNv9vtIqNECMMK0G/vqy4vioiMt9H22bwy9kWaz/lgwciN7hPAH8VprztFlHVevT0zSXOO1rJdeNtKy/Wx8erOYk6WnECMkjoNZBMSvCVXlzA/PqCBxzR9e/tN8jNbJVcoZPQUlRQRNifpFuwIHa93edU8BMxBeoe/KiMZ5BXyN7KSIo2h2wMDMCixnZAPD3p0cwkB/EHyETCEZ795myJKYS16u5nDayK+Fig5+OJUwcXKbRm271hjcscbKytp0+hlTp+QGa4VCA4MmIZQwhQ34xvEd4QIaZEfZJgmvFoqL3M3KIBlZqLueNxHWqdDPVt5QAupkriJd4AxfU5tLPS5/No5lIOBVYEnsaUJlWJdq0dArhDULanBSCBFfKTApT6LZMv3y63BMUmIwZv79KbiouLHL0F/AxltlPIf427xGR43TF0HE/UefITIGR1LQzAhQVEvXU3n8Gd10Gakv1X4d9C4/uki83qT+4i8ipi1Wc6+YV1v0JOufU6FPzUtolXTVAFolL638l8HcOJcd9wJGdILBL74u9xsSxFZ+98DdCJz5s0hi7bLkIR/bL44ySusPwPEwsrFb4t9+IBpfCNxzDngnALSnlnIerD5vfm+dNAC1RpeiGqsz/IvM13OVn0Ll3 CFeGgbDy pH87SlFuaBRvAyVrXmgh8mKofu8idbo5cV0CBzb0tereHdYu1gw7+53dw7v2OxCAMnsZpNl8fUtuGnllZypq0dhIv2ro+9K7E4jChpazdx0QqG0ytJkihU0IB/nfLfRWAmOTvG4KQxn/fvhoMAxK390LQzU83MRq+2axHJHmp4BonYhQ367cVbaPNFL8JyFf8uIgK 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: 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_inject_error") Signed-off-by: Miaohe Lin Acked-by: Naoya Horiguchi --- 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 pfn, int flags, { int rc = -ENXIO; - 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) if (pfn_valid(pfn)) { pgmap = get_dev_pagemap(pfn, NULL); + put_ref_page(pfn, flags); if (pgmap) { res = memory_failure_dev_pagemap(pfn, flags, pgmap);