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: 137799 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ab0a:0:b0:3f2:4152:657d with SMTP id m10csp808000vqo; Fri, 8 Sep 2023 14:48:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvr6Je20nmDkrYtE383he9476XbOQy1llzgH0ABQGga9J0Pd5UXegzG+nmnRhltMNKquXF X-Received: by 2002:a17:902:db09:b0:1bf:8132:d1a5 with SMTP id m9-20020a170902db0900b001bf8132d1a5mr4383886plx.26.1694209735032; Fri, 08 Sep 2023 14:48:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694209735; cv=none; d=google.com; s=arc-20160816; b=vjIahM0L8qwkTH8OztnQSxGzodyEXMsgBDARmJUFbXZy2MgliE/ppifXyu+9Cz5XCS hHmg2jfwcV5hnA59R+Cgg7+kP+c98Eyy0Cz/V7O9fOhuX7XVSigMGGqvnVc8BE41kCql oAnjOhVcWkSbdSdDwEDoxPGcwu6ljuHHKVLJtEK0TWL01zgqoLKIn43wJJ9h18/8Auld wOxPhAjBQj7jOuLd0+4Gwabt4tVHWPk3n6ZdtSYz3ubbWP7xD6db5eh4beho1WbIHxI4 WwxCpzoFE6VVBq54EQ6knmnYvkN1CV7ILhGdCuerKGN6eFfQNcR7f0KvIVHmVw7L/3uO 9Gmg== 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 :message-id:date:subject:cc:to:from; bh=VJYtCf16okteyaA12BwXS/2CVwJo1xNPxjFVgBJeX+A=; fh=WAmmZETR5a9YIZy2XHYlcSGcEcoUZPkwF2F0Sni3Ciw=; b=u9o+vVmCVwVhNwN6jSUgEb1xcCtwop+0WECcbIILZ29D+qOK7Nmq7+IykoRxReDNus NBjxFAtSnB5UJW4kVsKN6gb69T9J9b3W1roVBpgWvm6B1YyUNHG7z9I5NztCYQmVVY7P Rs1cu89Y6swZQknk1EvCVuFNb5CpasqS/1tB3HjTlIc3kTle7ZXWZn+hoit1VQjseKxU pNkABru/MerHdsRSWRSI5IzQpdmvrEmtNABuR6qlEBnGIGB+Z1J9WRLbjj1PPLVXhfDS wHsC5/LD+ol3NTqA2LcFAHn0NNJJDdAsDFyNjfaz7b55NlWdgZ3DS+tUfH6Lk0rJEJ2U m4AA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b14-20020a170903228e00b001ab29e00303si2146569plh.426.2023.09.08.14.48.39; Fri, 08 Sep 2023 14:48:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238850AbjIHIhS (ORCPT + 99 others); Fri, 8 Sep 2023 04:37:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237077AbjIHIhQ (ORCPT ); Fri, 8 Sep 2023 04:37:16 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B7CF1BEE for ; Fri, 8 Sep 2023 01:37:08 -0700 (PDT) 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776507667182072312 X-GMAIL-MSGID: 1776507667182072312 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; }