Skip to content

Commit 84e0e03

Browse files
plougherbrauner
authored andcommitted
Squashfs: Ensure all readahead pages have been used
In the recent work to remove page->index, a sanity check that ensured all the readhead pages were covered by the Squashfs data block was removed [1]. To avoid any regression, this commit adds the sanity check back in an equivalent way. Namely the page actor will now return error if any pages are unused after completion. [1] https://lore.kernel.org/all/20240818235847.170468-3-phillip@squashfs.org.uk/ -- Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk> Link: https://lore.kernel.org/r/20240822233106.121522-1-phillip@squashfs.org.uk V3: last_page should be actor->last_page Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent d937c81 commit 84e0e03

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

fs/squashfs/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ static int squashfs_readahead_fragment(struct page **page,
535535

536536
last_page = squashfs_page_actor_free(actor);
537537

538-
if (copied == expected) {
538+
if (copied == expected && !IS_ERR(last_page)) {
539539
/* Last page (if present) may have trailing bytes not filled */
540540
bytes = copied % PAGE_SIZE;
541541
if (bytes && last_page)
@@ -625,7 +625,7 @@ static void squashfs_readahead(struct readahead_control *ractl)
625625

626626
last_page = squashfs_page_actor_free(actor);
627627

628-
if (res == expected) {
628+
if (res == expected && !IS_ERR(last_page)) {
629629
int bytes;
630630

631631
/* Last page (if present) may have trailing bytes not filled */

fs/squashfs/file_direct.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ int squashfs_readpage_block(struct page *target_page, u64 block, int bsize,
8080
if (res < 0)
8181
goto mark_errored;
8282

83-
if (res != expected) {
83+
if (res != expected || IS_ERR(last_page)) {
8484
res = -EIO;
8585
goto mark_errored;
8686
}

fs/squashfs/page_actor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ extern struct squashfs_page_actor *squashfs_page_actor_init_special(
3333
loff_t start_index);
3434
static inline struct page *squashfs_page_actor_free(struct squashfs_page_actor *actor)
3535
{
36-
struct page *last_page = actor->last_page;
36+
struct page *last_page = actor->next_page == actor->pages ? actor->last_page : ERR_PTR(-EIO);
3737

3838
kfree(actor->tmp_buffer);
3939
kfree(actor);
40+
4041
return last_page;
4142
}
4243
static inline void *squashfs_first_page(struct squashfs_page_actor *actor)

0 commit comments

Comments
 (0)