blob: f16506cee5604bc67351687f3628a3d522cd7cf9 [file] [log] [blame]
From: Usama Arif <usamaarif642@gmail.com>
Subject: mm: set p->zeromap to NULL after freeing it
Date: Wed Jul 10 18:37:57 2024 +0100
alloc_swap_info can reuse swap_info_struct from previously used swap.
Reset p->zeromap to NULL so that its not set to a corrupted pointer from
previous swap.
Signed-off-by: Usama Arif <usamaarif642@gmail.com>
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202407101031.c6c3c651-lkp@intel.com
Cc: Hugh Dickins <hughd@google.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: David Hildenbrand <david@redhat.com>
Cc: Huang Ying <ying.huang@intel.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Yosry Ahmed <yosryahmed@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/swapfile.c | 2 ++
1 file changed, 2 insertions(+)
--- a/mm/swapfile.c~mm-set-p-zeromap-to-null-after-freeing-it
+++ a/mm/swapfile.c
@@ -2654,6 +2654,7 @@ SYSCALL_DEFINE1(swapoff, const char __us
p->cluster_next_cpu = NULL;
vfree(swap_map);
kvfree(p->zeromap);
+ p->zeromap = NULL;
kvfree(cluster_info);
/* Destroy swap account information */
swap_cgroup_swapoff(p->type);
@@ -3346,6 +3347,7 @@ bad_swap:
spin_unlock(&swap_lock);
vfree(swap_map);
kvfree(p->zeromap);
+ p->zeromap = NULL;
kvfree(cluster_info);
if (inced_nr_rotate_swap)
atomic_dec(&nr_rotate_swap);
_