Skip to content

Commit 5df373e

Browse files
Vinayak Menontorvalds
authored andcommitted
mm/page_io.c: do not free shared swap slots
The following race is observed due to which a processes faulting on a swap entry, finds the page neither in swapcache nor swap. This causes zram to give a zero filled page that gets mapped to the process, resulting in a user space crash later. Consider parent and child processes Pa and Pb sharing the same swap slot with swap_count 2. Swap is on zram with SWP_SYNCHRONOUS_IO set. Virtual address 'VA' of Pa and Pb points to the shared swap entry. Pa Pb fault on VA fault on VA do_swap_page do_swap_page lookup_swap_cache fails lookup_swap_cache fails Pb scheduled out swapin_readahead (deletes zram entry) swap_free (makes swap_count 1) Pb scheduled in swap_readpage (swap_count == 1) Takes SWP_SYNCHRONOUS_IO path zram enrty absent zram gives a zero filled page Fix this by making sure that swap slot is freed only when swap count drops down to one. Link: http://lkml.kernel.org/r/[email protected] Fixes: aa8d22a ("mm: swap: SWP_SYNCHRONOUS_IO: skip swapcache only if swapped page has no other reference") Signed-off-by: Vinayak Menon <[email protected]> Suggested-by: Minchan Kim <[email protected]> Acked-by: Minchan Kim <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 2c91f8f commit 5df373e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

mm/page_io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static void swap_slot_free_notify(struct page *page)
7373
{
7474
struct swap_info_struct *sis;
7575
struct gendisk *disk;
76+
swp_entry_t entry;
7677

7778
/*
7879
* There is no guarantee that the page is in swap cache - the software
@@ -104,11 +105,10 @@ static void swap_slot_free_notify(struct page *page)
104105
* we again wish to reclaim it.
105106
*/
106107
disk = sis->bdev->bd_disk;
107-
if (disk->fops->swap_slot_free_notify) {
108-
swp_entry_t entry;
108+
entry.val = page_private(page);
109+
if (disk->fops->swap_slot_free_notify && __swap_count(entry) == 1) {
109110
unsigned long offset;
110111

111-
entry.val = page_private(page);
112112
offset = swp_offset(entry);
113113

114114
SetPageDirty(page);

0 commit comments

Comments
 (0)