stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* FAILED: patch "[PATCH] mm/page_io.c: do not free shared swap slots" failed to apply to 4.19-stable tree
@ 2019-11-18 16:37 gregkh
  2019-11-18 16:40 ` Greg KH
  0 siblings, 1 reply; 5+ messages in thread
From: gregkh @ 2019-11-18 16:37 UTC (permalink / raw)
  To: vinmenon, akpm, hughd, mhocko, minchan, minchan, stable, torvalds; +Cc: stable


The patch below does not apply to the 4.19-stable tree.
If someone wants it applied there, or to any other stable or longterm
tree, then please email the backport, including the original git commit
id to <stable@vger.kernel.org>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 5df373e95689b9519b8557da7c5bd0db0856d776 Mon Sep 17 00:00:00 2001
From: Vinayak Menon <vinmenon@codeaurora.org>
Date: Fri, 15 Nov 2019 17:35:00 -0800
Subject: [PATCH] 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/1571743294-14285-1-git-send-email-vinmenon@codeaurora.org
Fixes: aa8d22a11da9 ("mm: swap: SWP_SYNCHRONOUS_IO: skip swapcache only if swapped page has no other reference")
Signed-off-by: Vinayak Menon <vinmenon@codeaurora.org>
Suggested-by: Minchan Kim <minchan@google.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

diff --git a/mm/page_io.c b/mm/page_io.c
index 24ee600f9131..60a66a58b9bf 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -73,6 +73,7 @@ static void swap_slot_free_notify(struct page *page)
 {
 	struct swap_info_struct *sis;
 	struct gendisk *disk;
+	swp_entry_t entry;
 
 	/*
 	 * 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)
 	 * we again wish to reclaim it.
 	 */
 	disk = sis->bdev->bd_disk;
-	if (disk->fops->swap_slot_free_notify) {
-		swp_entry_t entry;
+	entry.val = page_private(page);
+	if (disk->fops->swap_slot_free_notify && __swap_count(entry) == 1) {
 		unsigned long offset;
 
-		entry.val = page_private(page);
 		offset = swp_offset(entry);
 
 		SetPageDirty(page);


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

* Re: FAILED: patch "[PATCH] mm/page_io.c: do not free shared swap slots" failed to apply to 4.19-stable tree
  2019-11-18 16:37 FAILED: patch "[PATCH] mm/page_io.c: do not free shared swap slots" failed to apply to 4.19-stable tree gregkh
@ 2019-11-18 16:40 ` Greg KH
  2019-11-19 10:57   ` Vinayak Menon
  0 siblings, 1 reply; 5+ messages in thread
From: Greg KH @ 2019-11-18 16:40 UTC (permalink / raw)
  To: vinmenon, akpm, hughd, mhocko, minchan, minchan, stable, torvalds

On Mon, Nov 18, 2019 at 05:37:16PM +0100, gregkh@linuxfoundation.org wrote:
> 
> The patch below does not apply to the 4.19-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <stable@vger.kernel.org>.

Note, this applies, but just breaks the build, so it needs a backport
for 4.19 if people want to see it there.

thanks,

greg k-h

> ------------------ original commit in Linus's tree ------------------
> 
> >From 5df373e95689b9519b8557da7c5bd0db0856d776 Mon Sep 17 00:00:00 2001
> From: Vinayak Menon <vinmenon@codeaurora.org>
> Date: Fri, 15 Nov 2019 17:35:00 -0800
> Subject: [PATCH] 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/1571743294-14285-1-git-send-email-vinmenon@codeaurora.org
> Fixes: aa8d22a11da9 ("mm: swap: SWP_SYNCHRONOUS_IO: skip swapcache only if swapped page has no other reference")
> Signed-off-by: Vinayak Menon <vinmenon@codeaurora.org>
> Suggested-by: Minchan Kim <minchan@google.com>
> Acked-by: Minchan Kim <minchan@kernel.org>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Hugh Dickins <hughd@google.com>
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
> 
> diff --git a/mm/page_io.c b/mm/page_io.c
> index 24ee600f9131..60a66a58b9bf 100644
> --- a/mm/page_io.c
> +++ b/mm/page_io.c
> @@ -73,6 +73,7 @@ static void swap_slot_free_notify(struct page *page)
>  {
>  	struct swap_info_struct *sis;
>  	struct gendisk *disk;
> +	swp_entry_t entry;
>  
>  	/*
>  	 * 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)
>  	 * we again wish to reclaim it.
>  	 */
>  	disk = sis->bdev->bd_disk;
> -	if (disk->fops->swap_slot_free_notify) {
> -		swp_entry_t entry;
> +	entry.val = page_private(page);
> +	if (disk->fops->swap_slot_free_notify && __swap_count(entry) == 1) {
>  		unsigned long offset;
>  
> -		entry.val = page_private(page);
>  		offset = swp_offset(entry);
>  
>  		SetPageDirty(page);
> 

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

* Re: FAILED: patch "[PATCH] mm/page_io.c: do not free shared swap slots" failed to apply to 4.19-stable tree
  2019-11-18 16:40 ` Greg KH
@ 2019-11-19 10:57   ` Vinayak Menon
  2019-11-21 20:34     ` Greg KH
  2019-11-25 16:43     ` Sasha Levin
  0 siblings, 2 replies; 5+ messages in thread
From: Vinayak Menon @ 2019-11-19 10:57 UTC (permalink / raw)
  To: Greg KH, akpm, hughd, mhocko, minchan, minchan, stable, torvalds


On 11/18/2019 10:10 PM, Greg KH wrote:
> On Mon, Nov 18, 2019 at 05:37:16PM +0100, gregkh@linuxfoundation.org wrote:
>> The patch below does not apply to the 4.19-stable tree.
>> If someone wants it applied there, or to any other stable or longterm
>> tree, then please email the backport, including the original git commit
>> id to <stable@vger.kernel.org>.
> Note, this applies, but just breaks the build, so it needs a backport
> for 4.19 if people want to see it there.

The version below fixes the build on 4.19.

>
> thanks,
>
> greg k-h

From 3745cc4bb5cddbc1058889e4f779492060d5e550 Mon Sep 17 00:00:00 2001
From: Vinayak Menon <vinmenon@codeaurora.org>
Date: Fri, 15 Nov 2019 17:35:00 -0800
Subject: [PATCH] mm/page_io.c: do not free shared swap slots

commit 5df373e95689b9519b8557da7c5bd0db0856d776 upstream.

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/1571743294-14285-1-git-send-email-vinmenon@codeaurora.org
Fixes: aa8d22a11da9 ("mm: swap: SWP_SYNCHRONOUS_IO: skip swapcache only if swapped page has no other reference")
Signed-off-by: Vinayak Menon <vinmenon@codeaurora.org>
Suggested-by: Minchan Kim <minchan@google.com>
Acked-by: Minchan Kim <minchan@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 mm/page_io.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index abc1466..e763047 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -77,6 +77,7 @@ static void swap_slot_free_notify(struct page *page)
 {
        struct swap_info_struct *sis;
        struct gendisk *disk;
+       swp_entry_t entry;

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

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

                SetPageDirty(page);
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a
member of the Code Aurora Forum, hosted by The Linux Foundation

>
>> ------------------ original commit in Linus's tree ------------------
>>
>> >From 5df373e95689b9519b8557da7c5bd0db0856d776 Mon Sep 17 00:00:00 2001
>> From: Vinayak Menon <vinmenon@codeaurora.org>
>> Date: Fri, 15 Nov 2019 17:35:00 -0800
>> Subject: [PATCH] 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/1571743294-14285-1-git-send-email-vinmenon@codeaurora.org
>> Fixes: aa8d22a11da9 ("mm: swap: SWP_SYNCHRONOUS_IO: skip swapcache only if swapped page has no other reference")
>> Signed-off-by: Vinayak Menon <vinmenon@codeaurora.org>
>> Suggested-by: Minchan Kim <minchan@google.com>
>> Acked-by: Minchan Kim <minchan@kernel.org>
>> Cc: Michal Hocko <mhocko@suse.com>
>> Cc: Hugh Dickins <hughd@google.com>
>> Cc: <stable@vger.kernel.org>
>> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
>> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
>>
>> diff --git a/mm/page_io.c b/mm/page_io.c
>> index 24ee600f9131..60a66a58b9bf 100644
>> --- a/mm/page_io.c
>> +++ b/mm/page_io.c
>> @@ -73,6 +73,7 @@ static void swap_slot_free_notify(struct page *page)
>>  {
>>  	struct swap_info_struct *sis;
>>  	struct gendisk *disk;
>> +	swp_entry_t entry;
>>  
>>  	/*
>>  	 * 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)
>>  	 * we again wish to reclaim it.
>>  	 */
>>  	disk = sis->bdev->bd_disk;
>> -	if (disk->fops->swap_slot_free_notify) {
>> -		swp_entry_t entry;
>> +	entry.val = page_private(page);
>> +	if (disk->fops->swap_slot_free_notify && __swap_count(entry) == 1) {
>>  		unsigned long offset;
>>  
>> -		entry.val = page_private(page);
>>  		offset = swp_offset(entry);
>>  
>>  		SetPageDirty(page);
>>

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

* Re: FAILED: patch "[PATCH] mm/page_io.c: do not free shared swap slots" failed to apply to 4.19-stable tree
  2019-11-19 10:57   ` Vinayak Menon
@ 2019-11-21 20:34     ` Greg KH
  2019-11-25 16:43     ` Sasha Levin
  1 sibling, 0 replies; 5+ messages in thread
From: Greg KH @ 2019-11-21 20:34 UTC (permalink / raw)
  To: Vinayak Menon; +Cc: akpm, hughd, mhocko, minchan, minchan, stable, torvalds

On Tue, Nov 19, 2019 at 10:57:13AM +0000, Vinayak Menon wrote:
> 
> On 11/18/2019 10:10 PM, Greg KH wrote:
> > On Mon, Nov 18, 2019 at 05:37:16PM +0100, gregkh@linuxfoundation.org wrote:
> >> The patch below does not apply to the 4.19-stable tree.
> >> If someone wants it applied there, or to any other stable or longterm
> >> tree, then please email the backport, including the original git commit
> >> id to <stable@vger.kernel.org>.
> > Note, this applies, but just breaks the build, so it needs a backport
> > for 4.19 if people want to see it there.
> 
> The version below fixes the build on 4.19.

The patch you sent was totally corrupted, I couldn't figure out how to
fix it up.  Please resend it in a format I can apply it in.

thanks,

greg k-h

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

* Re: FAILED: patch "[PATCH] mm/page_io.c: do not free shared swap slots" failed to apply to 4.19-stable tree
  2019-11-19 10:57   ` Vinayak Menon
  2019-11-21 20:34     ` Greg KH
@ 2019-11-25 16:43     ` Sasha Levin
  1 sibling, 0 replies; 5+ messages in thread
From: Sasha Levin @ 2019-11-25 16:43 UTC (permalink / raw)
  To: Vinayak Menon
  Cc: Greg KH, akpm, hughd, mhocko, minchan, minchan, stable, torvalds

On Tue, Nov 19, 2019 at 10:57:13AM +0000, Vinayak Menon wrote:
>
>On 11/18/2019 10:10 PM, Greg KH wrote:
>> On Mon, Nov 18, 2019 at 05:37:16PM +0100, gregkh@linuxfoundation.org wrote:
>>> The patch below does not apply to the 4.19-stable tree.
>>> If someone wants it applied there, or to any other stable or longterm
>>> tree, then please email the backport, including the original git commit
>>> id to <stable@vger.kernel.org>.
>> Note, this applies, but just breaks the build, so it needs a backport
>> for 4.19 if people want to see it there.
>
>The version below fixes the build on 4.19.

I've fixed it up based on the version sent by Vinayak and queued it up
for 4.19.

-- 
Thanks,
Sasha

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

end of thread, other threads:[~2019-11-25 16:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-18 16:37 FAILED: patch "[PATCH] mm/page_io.c: do not free shared swap slots" failed to apply to 4.19-stable tree gregkh
2019-11-18 16:40 ` Greg KH
2019-11-19 10:57   ` Vinayak Menon
2019-11-21 20:34     ` Greg KH
2019-11-25 16:43     ` Sasha Levin

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).