* [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read()
@ 2022-02-23 15:59 Matthew Wilcox (Oracle)
2022-02-23 17:05 ` Vlastimil Babka
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-02-23 15:59 UTC (permalink / raw)
To: stable, linux-mm, linux-kernel, kirill.shutemov, Song Liu
Cc: Matthew Wilcox (Oracle),
Adam Majer, Dirk Mueller, Takashi Iwai, Vlastimil Babka
When a THP is present in the page cache, we can return it several times,
leading to userspace seeing the same data repeatedly if doing a read()
that crosses a 64-page boundary. This is probably not a security issue
(since the data all comes from the same file), but it can be interpreted
as a transient data corruption issue. Fortunately, it is very rare as
it can only occur when CONFIG_READ_ONLY_THP_FOR_FS is enabled, and it can
only happen to executables. We don't often call read() on executables.
This bug is fixed differently in v5.17 by commit 6b24ca4a1a8d
("mm: Use multi-index entries in the page cache"). That commit is
unsuitable for backporting, so fix this in the clearest way. It
sacrifices a little performance for clarity, but this should never
be a performance path in these kernel versions.
Fixes: cbd59c48ae2b ("mm/filemap: use head pages in generic_file_buffered_read")
Cc: stable@vger.kernel.org # v5.15, v5.16
Link: https://lore.kernel.org/r/df3b5d1c-a36b-2c73-3e27-99e74983de3a@suse.cz/
Analyzed-by: Adam Majer <amajer@suse.com>
Analyzed-by: Dirk Mueller <dmueller@suse.com>
Bisected-by: Takashi Iwai <tiwai@suse.de>
Reported-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/filemap.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/mm/filemap.c b/mm/filemap.c
index 82a17c35eb96..1293c3409e42 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2354,8 +2354,12 @@ static void filemap_get_read_batch(struct address_space *mapping,
break;
if (PageReadahead(head))
break;
- xas.xa_index = head->index + thp_nr_pages(head) - 1;
- xas.xa_offset = (xas.xa_index >> xas.xa_shift) & XA_CHUNK_MASK;
+ if (PageHead(head)) {
+ xas_set(&xas, head->index + thp_nr_pages(head));
+ /* Handle wrap correctly */
+ if (xas.xa_index - 1 >= max)
+ break;
+ }
continue;
put_page:
put_page(head);
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read()
2022-02-23 15:59 [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read() Matthew Wilcox (Oracle)
@ 2022-02-23 17:05 ` Vlastimil Babka
2022-02-23 17:43 ` Patch "mm/filemap: Fix handling of THPs in generic_file_buffered_read()" has been added to the 5.15-stable tree gregkh
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Vlastimil Babka @ 2022-02-23 17:05 UTC (permalink / raw)
To: Matthew Wilcox (Oracle),
stable, linux-mm, linux-kernel, kirill.shutemov, Song Liu
Cc: Adam Majer, Dirk Mueller, Takashi Iwai
On 2/23/22 16:59, Matthew Wilcox (Oracle) wrote:
> When a THP is present in the page cache, we can return it several times,
> leading to userspace seeing the same data repeatedly if doing a read()
> that crosses a 64-page boundary. This is probably not a security issue
> (since the data all comes from the same file), but it can be interpreted
> as a transient data corruption issue. Fortunately, it is very rare as
> it can only occur when CONFIG_READ_ONLY_THP_FOR_FS is enabled, and it can
> only happen to executables. We don't often call read() on executables.
>
> This bug is fixed differently in v5.17 by commit 6b24ca4a1a8d
> ("mm: Use multi-index entries in the page cache"). That commit is
> unsuitable for backporting, so fix this in the clearest way. It
> sacrifices a little performance for clarity, but this should never
> be a performance path in these kernel versions.
>
> Fixes: cbd59c48ae2b ("mm/filemap: use head pages in generic_file_buffered_read")
> Cc: stable@vger.kernel.org # v5.15, v5.16
> Link: https://lore.kernel.org/r/df3b5d1c-a36b-2c73-3e27-99e74983de3a@suse.cz/
> Analyzed-by: Adam Majer <amajer@suse.com>
> Analyzed-by: Dirk Mueller <dmueller@suse.com>
> Bisected-by: Takashi Iwai <tiwai@suse.de>
> Reported-by: Vlastimil Babka <vbabka@suse.cz>
Replace with:
Reported-and-tested-by: Vlastimil Babka <vbabka@suse.cz>
Thanks!
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
> mm/filemap.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 82a17c35eb96..1293c3409e42 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2354,8 +2354,12 @@ static void filemap_get_read_batch(struct address_space *mapping,
> break;
> if (PageReadahead(head))
> break;
> - xas.xa_index = head->index + thp_nr_pages(head) - 1;
> - xas.xa_offset = (xas.xa_index >> xas.xa_shift) & XA_CHUNK_MASK;
> + if (PageHead(head)) {
> + xas_set(&xas, head->index + thp_nr_pages(head));
> + /* Handle wrap correctly */
> + if (xas.xa_index - 1 >= max)
> + break;
> + }
> continue;
> put_page:
> put_page(head);
^ permalink raw reply [flat|nested] 5+ messages in thread
* Patch "mm/filemap: Fix handling of THPs in generic_file_buffered_read()" has been added to the 5.15-stable tree
2022-02-23 15:59 [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read() Matthew Wilcox (Oracle)
2022-02-23 17:05 ` Vlastimil Babka
@ 2022-02-23 17:43 ` gregkh
2022-02-23 17:44 ` [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read() Greg KH
2022-02-23 18:21 ` Patch "mm/filemap: Fix handling of THPs in generic_file_buffered_read()" has been added to the 5.16-stable tree gregkh
3 siblings, 0 replies; 5+ messages in thread
From: gregkh @ 2022-02-23 17:43 UTC (permalink / raw)
To: amajer, dmueller, gregkh, kirill.shutemov, linux-mm,
songliubraving, tiwai, vbabka, willy
Cc: stable-commits
This is a note to let you know that I've just added the patch titled
mm/filemap: Fix handling of THPs in generic_file_buffered_read()
to the 5.15-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
mm-filemap-fix-handling-of-thps-in-generic_file_buffered_read.patch
and it can be found in the queue-5.15 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.
From willy@infradead.org Wed Feb 23 18:42:46 2022
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Date: Wed, 23 Feb 2022 15:59:18 +0000
Subject: mm/filemap: Fix handling of THPs in generic_file_buffered_read()
To: stable@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, Song Liu <songliubraving@fb.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>, Adam Majer <amajer@suse.com>, Dirk Mueller <dmueller@suse.com>, Takashi Iwai <tiwai@suse.de>, Vlastimil Babka <vbabka@suse.cz>
Message-ID: <20220223155918.927140-1-willy@infradead.org>
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
When a THP is present in the page cache, we can return it several times,
leading to userspace seeing the same data repeatedly if doing a read()
that crosses a 64-page boundary. This is probably not a security issue
(since the data all comes from the same file), but it can be interpreted
as a transient data corruption issue. Fortunately, it is very rare as
it can only occur when CONFIG_READ_ONLY_THP_FOR_FS is enabled, and it can
only happen to executables. We don't often call read() on executables.
This bug is fixed differently in v5.17 by commit 6b24ca4a1a8d
("mm: Use multi-index entries in the page cache"). That commit is
unsuitable for backporting, so fix this in the clearest way. It
sacrifices a little performance for clarity, but this should never
be a performance path in these kernel versions.
Fixes: cbd59c48ae2b ("mm/filemap: use head pages in generic_file_buffered_read")
Cc: stable@vger.kernel.org # v5.15, v5.16
Link: https://lore.kernel.org/r/df3b5d1c-a36b-2c73-3e27-99e74983de3a@suse.cz/
Analyzed-by: Adam Majer <amajer@suse.com>
Analyzed-by: Dirk Mueller <dmueller@suse.com>
Bisected-by: Takashi Iwai <tiwai@suse.de>
Reported-by: Vlastimil Babka <vbabka@suse.cz>
Tested-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
mm/filemap.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2354,8 +2354,12 @@ static void filemap_get_read_batch(struc
break;
if (PageReadahead(head))
break;
- xas.xa_index = head->index + thp_nr_pages(head) - 1;
- xas.xa_offset = (xas.xa_index >> xas.xa_shift) & XA_CHUNK_MASK;
+ if (PageHead(head)) {
+ xas_set(&xas, head->index + thp_nr_pages(head));
+ /* Handle wrap correctly */
+ if (xas.xa_index - 1 >= max)
+ break;
+ }
continue;
put_page:
put_page(head);
Patches currently in stable-queue which might be from willy@infradead.org are
queue-5.15/mm-filemap-fix-handling-of-thps-in-generic_file_buffered_read.patch
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read()
2022-02-23 15:59 [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read() Matthew Wilcox (Oracle)
2022-02-23 17:05 ` Vlastimil Babka
2022-02-23 17:43 ` Patch "mm/filemap: Fix handling of THPs in generic_file_buffered_read()" has been added to the 5.15-stable tree gregkh
@ 2022-02-23 17:44 ` Greg KH
2022-02-23 18:21 ` Patch "mm/filemap: Fix handling of THPs in generic_file_buffered_read()" has been added to the 5.16-stable tree gregkh
3 siblings, 0 replies; 5+ messages in thread
From: Greg KH @ 2022-02-23 17:44 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: stable, linux-mm, linux-kernel, kirill.shutemov, Song Liu,
Adam Majer, Dirk Mueller, Takashi Iwai, Vlastimil Babka
On Wed, Feb 23, 2022 at 03:59:18PM +0000, Matthew Wilcox (Oracle) wrote:
> When a THP is present in the page cache, we can return it several times,
> leading to userspace seeing the same data repeatedly if doing a read()
> that crosses a 64-page boundary. This is probably not a security issue
> (since the data all comes from the same file), but it can be interpreted
> as a transient data corruption issue. Fortunately, it is very rare as
> it can only occur when CONFIG_READ_ONLY_THP_FOR_FS is enabled, and it can
> only happen to executables. We don't often call read() on executables.
>
> This bug is fixed differently in v5.17 by commit 6b24ca4a1a8d
> ("mm: Use multi-index entries in the page cache"). That commit is
> unsuitable for backporting, so fix this in the clearest way. It
> sacrifices a little performance for clarity, but this should never
> be a performance path in these kernel versions.
>
> Fixes: cbd59c48ae2b ("mm/filemap: use head pages in generic_file_buffered_read")
> Cc: stable@vger.kernel.org # v5.15, v5.16
> Link: https://lore.kernel.org/r/df3b5d1c-a36b-2c73-3e27-99e74983de3a@suse.cz/
> Analyzed-by: Adam Majer <amajer@suse.com>
> Analyzed-by: Dirk Mueller <dmueller@suse.com>
> Bisected-by: Takashi Iwai <tiwai@suse.de>
> Reported-by: Vlastimil Babka <vbabka@suse.cz>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
> mm/filemap.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index 82a17c35eb96..1293c3409e42 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2354,8 +2354,12 @@ static void filemap_get_read_batch(struct address_space *mapping,
> break;
> if (PageReadahead(head))
> break;
> - xas.xa_index = head->index + thp_nr_pages(head) - 1;
> - xas.xa_offset = (xas.xa_index >> xas.xa_shift) & XA_CHUNK_MASK;
> + if (PageHead(head)) {
> + xas_set(&xas, head->index + thp_nr_pages(head));
> + /* Handle wrap correctly */
> + if (xas.xa_index - 1 >= max)
> + break;
> + }
> continue;
> put_page:
> put_page(head);
> --
> 2.34.1
>
Now queued up, thanks!
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread
* Patch "mm/filemap: Fix handling of THPs in generic_file_buffered_read()" has been added to the 5.16-stable tree
2022-02-23 15:59 [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read() Matthew Wilcox (Oracle)
` (2 preceding siblings ...)
2022-02-23 17:44 ` [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read() Greg KH
@ 2022-02-23 18:21 ` gregkh
3 siblings, 0 replies; 5+ messages in thread
From: gregkh @ 2022-02-23 18:21 UTC (permalink / raw)
To: amajer, dmueller, gregkh, kirill.shutemov, linux-mm,
songliubraving, tiwai, vbabka, willy
Cc: stable-commits
This is a note to let you know that I've just added the patch titled
mm/filemap: Fix handling of THPs in generic_file_buffered_read()
to the 5.16-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
mm-filemap-fix-handling-of-thps-in-generic_file_buffered_read.patch
and it can be found in the queue-5.16 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.
From willy@infradead.org Wed Feb 23 18:42:46 2022
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Date: Wed, 23 Feb 2022 15:59:18 +0000
Subject: mm/filemap: Fix handling of THPs in generic_file_buffered_read()
To: stable@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, kirill.shutemov@linux.intel.com, Song Liu <songliubraving@fb.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>, Adam Majer <amajer@suse.com>, Dirk Mueller <dmueller@suse.com>, Takashi Iwai <tiwai@suse.de>, Vlastimil Babka <vbabka@suse.cz>
Message-ID: <20220223155918.927140-1-willy@infradead.org>
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
When a THP is present in the page cache, we can return it several times,
leading to userspace seeing the same data repeatedly if doing a read()
that crosses a 64-page boundary. This is probably not a security issue
(since the data all comes from the same file), but it can be interpreted
as a transient data corruption issue. Fortunately, it is very rare as
it can only occur when CONFIG_READ_ONLY_THP_FOR_FS is enabled, and it can
only happen to executables. We don't often call read() on executables.
This bug is fixed differently in v5.17 by commit 6b24ca4a1a8d
("mm: Use multi-index entries in the page cache"). That commit is
unsuitable for backporting, so fix this in the clearest way. It
sacrifices a little performance for clarity, but this should never
be a performance path in these kernel versions.
Fixes: cbd59c48ae2b ("mm/filemap: use head pages in generic_file_buffered_read")
Cc: stable@vger.kernel.org # v5.15, v5.16
Link: https://lore.kernel.org/r/df3b5d1c-a36b-2c73-3e27-99e74983de3a@suse.cz/
Analyzed-by: Adam Majer <amajer@suse.com>
Analyzed-by: Dirk Mueller <dmueller@suse.com>
Bisected-by: Takashi Iwai <tiwai@suse.de>
Reported-by: Vlastimil Babka <vbabka@suse.cz>
Tested-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
mm/filemap.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2365,8 +2365,12 @@ static void filemap_get_read_batch(struc
break;
if (PageReadahead(head))
break;
- xas.xa_index = head->index + thp_nr_pages(head) - 1;
- xas.xa_offset = (xas.xa_index >> xas.xa_shift) & XA_CHUNK_MASK;
+ if (PageHead(head)) {
+ xas_set(&xas, head->index + thp_nr_pages(head));
+ /* Handle wrap correctly */
+ if (xas.xa_index - 1 >= max)
+ break;
+ }
continue;
put_page:
put_page(head);
Patches currently in stable-queue which might be from willy@infradead.org are
queue-5.16/mm-filemap-fix-handling-of-thps-in-generic_file_buffered_read.patch
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-02-23 18:21 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-23 15:59 [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read() Matthew Wilcox (Oracle)
2022-02-23 17:05 ` Vlastimil Babka
2022-02-23 17:43 ` Patch "mm/filemap: Fix handling of THPs in generic_file_buffered_read()" has been added to the 5.15-stable tree gregkh
2022-02-23 17:44 ` [PATCH] mm/filemap: Fix handling of THPs in generic_file_buffered_read() Greg KH
2022-02-23 18:21 ` Patch "mm/filemap: Fix handling of THPs in generic_file_buffered_read()" has been added to the 5.16-stable tree gregkh
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox