linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: vmscan: fix NULL pointer dereference in can_reclaim_anon_pages
@ 2023-09-08  9:31 Liu Shixin
  2023-09-08 12:56 ` Sachin Sant
  2023-09-08 16:52 ` Yosry Ahmed
  0 siblings, 2 replies; 4+ messages in thread
From: Liu Shixin @ 2023-09-08  9:31 UTC (permalink / raw)
  To: Sachin Sant, Michael Ellerman, Andrew Morton, Yosry Ahmed,
	Huang Ying, Kefeng Wang
  Cc: linux-mm, linux-kernel, Liu Shixin

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 <sachinp@linux.ibm.com>
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 <liushixin2@huawei.com>
---
 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;
 		}
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-09-15 10:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-08  9:31 [PATCH] mm: vmscan: fix NULL pointer dereference in can_reclaim_anon_pages Liu Shixin
2023-09-08 12:56 ` Sachin Sant
2023-09-15 10:11   ` Liu Shixin
2023-09-08 16:52 ` Yosry Ahmed

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).