From patchwork Fri Sep 8 09:31:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 13377250 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 153A6EE57E3 for ; Fri, 8 Sep 2023 08:38:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68FDE6B00A4; Fri, 8 Sep 2023 04:38:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 618516B00A5; Fri, 8 Sep 2023 04:38:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B9746B00A6; Fri, 8 Sep 2023 04:38:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 37C5A6B00A4 for ; Fri, 8 Sep 2023 04:38:00 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0D4681A101F for ; Fri, 8 Sep 2023 08:38:00 +0000 (UTC) X-FDA: 81212777520.09.C2DAE1C Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf17.hostedemail.com (Postfix) with ESMTP id 99B9D40018 for ; Fri, 8 Sep 2023 08:37:57 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694162278; 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=VJYtCf16okteyaA12BwXS/2CVwJo1xNPxjFVgBJeX+A=; b=x77xjw41hh4U09pks83UAxeMejecaWE1FiLvpN15taT1q5kVyFGkOSJaPGeypQ2ec1QQbj eNSREeJVII0Pmf48AcIWOVX4r49ABgy2ZT332Nzb5tuLcZVTjGT4stD9n3UqQ4hcfJLfey qFIcTTekI8IBK+21xIucvbuynreMp6g= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf17.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694162278; a=rsa-sha256; cv=none; b=CmHvYHNl/fukpkqR8/Fa12VPfzGHjusXG7Q2XLEDH3UhAyf2FBWxNzcPWfC24rFGnVId1M FbrMbDhllsaDTG45UP1G775BL9S2rOWpRb7iyhK+G6xynGuv9QoCIC1MhWuzjmydnSIPlR hYljYg4axrOuDPmdySTA4BGPeebLdew= Received: from dggpemm500009.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4RhqDh2qY6z1M9Cr; Fri, 8 Sep 2023 16:35:16 +0800 (CST) Received: from huawei.com (10.175.113.32) by dggpemm500009.china.huawei.com (7.185.36.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Fri, 8 Sep 2023 16:37:05 +0800 From: Liu Shixin To: Sachin Sant , Michael Ellerman , Andrew Morton , Yosry Ahmed , Huang Ying , Kefeng Wang CC: , , Liu Shixin Subject: [PATCH] mm: vmscan: fix NULL pointer dereference in can_reclaim_anon_pages Date: Fri, 8 Sep 2023 17:31:03 +0800 Message-ID: <20230908093103.2620512-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm500009.china.huawei.com (7.185.36.225) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 99B9D40018 X-Stat-Signature: uooyaigdfkoo87owon5x7ohuzkjugqah X-HE-Tag: 1694162277-94084 X-HE-Meta: U2FsdGVkX1/umINNm2NS+LEi1+sdbZwKVfHC6MSjtM0qzyVRmN/DiKaEtF6z0zL5GGz93PUpQqcFVIKGxX5n1WU4qZoVo+hCUVLGgzF+Dk4kpT40NP/2xtvSRH+DxAv5Df5iyLvMi7hZfPMerR4HuN7+6k9ArPshDxNf9/LgJDA67wUD4TubLmMguu69cWA7goaI9ENMwFtGkhwNRkE9LWdI4sSqTDJz77JXqY8rWOd7kTyydYeV8SR8CVWTUzmEe8nKOwPmYvFf2BklhMDevasTOq39nwVQalMECBS1JXkt/GQxwKIuSjy7SL2b1m3+fRf+OPW+nzli8ZTNDtq0WMXi9BFLnaRwCbD6qklgmYYpReAI+XYHot5Q3KXTfwnykb2eAm57yXi3HquS6qQwsReVxASXxR1UU/qU4FX53rgA+YkOcjiXXGf4YUpRUmIk4MyV/n9x28ELfmoey/QsvwyUuPWosfqwgn/7gfdhHKEYP0dMcz9nn6IgNV1D7zkCyFieTfFAbMSF8C3I5H69Vz6+oPLrD64MwG4hySoZ6kjth9gRu/6yMCoRbwl2bi8pZGUbH4YuWrB30KVIUFDqfUmppo936KD8Vp6kinpriTvsgBzlviRUbZPAiG+q6g1S+NxeGj0czjS9OBZ25yVT0GqZ5z44SypQdhdF0lipr2Y8dhEy1vvZbHLIFleNh6pvvTCXCBLPXrhCYuq5Vtn8c2gib2zXAFwVL7A1tAkbQv5Gb3qXEmZ0ynjAK/bJ+5hJwZr+YT5eeRs4BLuTL7C3MmpaKtKbrZFwX2s6OcKm432ikWlYwndrh2jkST/hYwY9aAKYRZvBjU0waDLnVQl0ZI3QR/kseuyfxm8l0Um+RTPQLIki5XfDPw4iRFptcvrqtdHi7M2Aii9fNMiF14waWwPHDROErm2EqYKSYECI9wlqrJ0hVxMzTP3k4QA3tAIQEhvWXIhU9XCsjjFCEE4 2ofWUfuJ 0FsydX2WpFxxrZXVKsEMi1cjWKDdImS8L8QygXNWsv5UF+u6Dse+qvQ2TPKR9vVOns4WkvulUZXLfaKNS5wh7VDtcpWjQbPPQll8DGv+Lwaz/12QNTK0U/T3scGdLKdoIyI0Jpnvq8I+T3RuJWz+VjtgXHVUg1lh9OBew7dn1mV3aNHfCt26JR7vMRtsAPppZPEY6Wkw7MyzM5yJBkivRKXu5IgNkwlRM5mvsJUwYzqaet1vuYhBEC/helirje9XhM029ScOI6ER0wpwXmYwim1kBA4x158yvq/1VoLsmow9FUsRoqvTbnayASyQj/WPPqX9h 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: The variable sc is NULL pointer in can_reclaim_anon_pages() when called from zone_reclaimable_pages(). Check it before setting swapcache_only. Reported-by: Sachin Sant Link: https://lore.kernel.org/linux-mm/F00144DE-2A3F-4463-8203-45E0D57E313E@linux.ibm.com/T/ Fixes: 92039ae85e8d("mm: vmscan: try to reclaim swapcache pages if no swap space") Signed-off-by: Liu Shixin --- mm/vmscan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index f1dc0dbf1cdb..5eb85ddf403f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -617,7 +617,7 @@ static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, if (get_nr_swap_pages() > 0) return true; /* Is there any swapcache pages to reclaim? */ - if (total_swapcache_pages() > 0) { + if (sc && total_swapcache_pages() > 0) { sc->swapcache_only = 1; return true; } @@ -626,7 +626,7 @@ static inline bool can_reclaim_anon_pages(struct mem_cgroup *memcg, if (mem_cgroup_get_nr_swap_pages(memcg) > 0) return true; /* Is there any swapcache pages in memcg to reclaim? */ - if (mem_cgroup_get_nr_swapcache_pages(memcg) > 0) { + if (sc && mem_cgroup_get_nr_swapcache_pages(memcg) > 0) { sc->swapcache_only = 1; return true; }