From: Matthew Wilcox (Oracle) Date: Sat, 30 Jul 2022 04:25:18 +0000 (+0100) Subject: shmem: update folio if shmem_replace_page() updates the page X-Git-Tag: baikal/aarch64/sdk6.1~3174^2~15 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=75ed33e12a1c56c6e939156a5ac156dc38cebed0;p=kernel.git shmem: update folio if shmem_replace_page() updates the page If we allocate a new page, we need to make sure that our folio matches that new page. If we do end up in this code path, we store the wrong page in the shmem inode's page cache, and I would rather imagine that data corruption ensues. This will be solved by changing shmem_replace_page() to shmem_replace_folio(), but this is the minimal fix. Link: https://lkml.kernel.org/r/20220730042518.1264767-1-willy@infradead.org Fixes: 0e01d2697a7d ("mm/shmem: convert shmem_swapin_page() to shmem_swapin_folio()") Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: William Kucharski Cc: Hugh Dickins Cc: Signed-off-by: Andrew Morton --- diff --git a/mm/shmem.c b/mm/shmem.c index d075dd2dcc484..42e5888bf84d8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1782,6 +1782,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, if (shmem_should_replace_folio(folio, gfp)) { error = shmem_replace_page(&page, gfp, info, index); + folio = page_folio(page); if (error) goto failed; }