mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-11-01 00:48:50 +00:00
9ef8eb6104
Patch series "squashfs: fix some regressions introduced in the readahead
code".
This patchset fixes 3 regressions introduced by the recent readahead code
changes. The first regression is causing "snaps" to randomly fail after a
couple of hours or days, which how the regression came to light.
This patch (of 3):
If a file isn't a whole multiple of the page size, the last page will have
trailing bytes unfilled.
There was a mistake in the readahead code which did this. In particular
it incorrectly assumed that the last page in the readahead page array
(page[nr_pages - 1]) will always contain the last page in the block, which
if we're at file end, will be the page that needs to be zero filled.
But the readahead code may not return the last page in the block, which
means it is unmapped and will be skipped by the decompressors (a temporary
buffer used).
In this case the zero filling code will zero out the wrong page, leading
to data corruption.
Fix this by by extending the "page actor" to return the last page if
present, or NULL if a temporary buffer was used.
Link: https://lkml.kernel.org/r/20221020223616.7571-1-phillip@squashfs.org.uk
Link: https://lkml.kernel.org/r/20221020223616.7571-2-phillip@squashfs.org.uk
Fixes: 8fc78b6fe2
("squashfs: implement readahead")
Link: https://lore.kernel.org/lkml/b0c258c3-6dcf-aade-efc4-d62a8b3a1ce2@alu.unizg.hr/
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
Reported-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
Tested-by: Mirsad Goran Todorovac <mirsad.todorovac@alu.unizg.hr>
Tested-by: Slade Watkins <srw@sladewatkins.net>
Tested-by: Bagas Sanjaya <bagasdotme@gmail.com>
Reported-by: Marc Miltenberger <marcmiltenberger@gmail.com>
Cc: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Thorsten Leemhuis <regressions@leemhuis.info>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
57 lines
1.5 KiB
C
57 lines
1.5 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
#ifndef PAGE_ACTOR_H
|
|
#define PAGE_ACTOR_H
|
|
/*
|
|
* Copyright (c) 2013
|
|
* Phillip Lougher <phillip@squashfs.org.uk>
|
|
*/
|
|
|
|
struct squashfs_page_actor {
|
|
union {
|
|
void **buffer;
|
|
struct page **page;
|
|
};
|
|
void *pageaddr;
|
|
void *tmp_buffer;
|
|
void *(*squashfs_first_page)(struct squashfs_page_actor *);
|
|
void *(*squashfs_next_page)(struct squashfs_page_actor *);
|
|
void (*squashfs_finish_page)(struct squashfs_page_actor *);
|
|
struct page *last_page;
|
|
int pages;
|
|
int length;
|
|
int next_page;
|
|
int alloc_buffer;
|
|
int returned_pages;
|
|
pgoff_t next_index;
|
|
};
|
|
|
|
extern struct squashfs_page_actor *squashfs_page_actor_init(void **buffer,
|
|
int pages, int length);
|
|
extern struct squashfs_page_actor *squashfs_page_actor_init_special(
|
|
struct squashfs_sb_info *msblk,
|
|
struct page **page, int pages, int length);
|
|
static inline struct page *squashfs_page_actor_free(struct squashfs_page_actor *actor)
|
|
{
|
|
struct page *last_page = actor->last_page;
|
|
|
|
kfree(actor->tmp_buffer);
|
|
kfree(actor);
|
|
return last_page;
|
|
}
|
|
static inline void *squashfs_first_page(struct squashfs_page_actor *actor)
|
|
{
|
|
return actor->squashfs_first_page(actor);
|
|
}
|
|
static inline void *squashfs_next_page(struct squashfs_page_actor *actor)
|
|
{
|
|
return actor->squashfs_next_page(actor);
|
|
}
|
|
static inline void squashfs_finish_page(struct squashfs_page_actor *actor)
|
|
{
|
|
actor->squashfs_finish_page(actor);
|
|
}
|
|
static inline void squashfs_actor_nobuff(struct squashfs_page_actor *actor)
|
|
{
|
|
actor->alloc_buffer = 0;
|
|
}
|
|
#endif
|