From nobody Thu Apr 9 12:00:54 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B10EEC433FE for ; Thu, 20 Oct 2022 22:36:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229735AbiJTWgp (ORCPT ); Thu, 20 Oct 2022 18:36:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229697AbiJTWgm (ORCPT ); Thu, 20 Oct 2022 18:36:42 -0400 Received: from p3plwbeout18-05.prod.phx3.secureserver.net (p3plsmtp18-05-2.prod.phx3.secureserver.net [173.201.193.190]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A19FB208828 for ; Thu, 20 Oct 2022 15:36:40 -0700 (PDT) Received: from mailex.mailcore.me ([94.136.40.145]) by :WBEOUT: with ESMTP id le9XojAFew7vale9YoyLo6; Thu, 20 Oct 2022 15:36:40 -0700 X-CMAE-Analysis: v=2.4 cv=f5eNuM+M c=1 sm=1 tr=0 ts=6351cd78 a=7e6w4QD8YWtpVJ/7+iiidw==:117 a=84ok6UeoqCVsigPHarzEiQ==:17 a=ggZhUymU-5wA:10 a=Qawa6l4ZSaYA:10 a=FXvPX3liAAAA:8 a=VwQbUJbxAAAA:8 a=z1XB94rXoAV2oHx9HPIA:9 a=UObqyxdv-6Yh2QiB9mM_:22 a=AjGcO6oz07-iQ99wixmX:22 X-SECURESERVER-ACCT: phillip@squashfs.org.uk X-SID: le9XojAFew7va Received: from 82-69-79-175.dsl.in-addr.zen.co.uk ([82.69.79.175] helo=phoenix.fritz.box) by smtp12.mailcore.me with esmtpa (Exim 4.94.2) (envelope-from ) id 1ole9W-0006zQ-Jd; Thu, 20 Oct 2022 23:36:38 +0100 From: Phillip Lougher To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org Cc: hsinyi@chromium.org, regressions@leemhuis.info, regressions@lists.linux.dev, dimitri.ledkov@canonical.com, michael.vogt@canonical.com, phillip.lougher@gmail.com, ogra@ubuntu.com, olivier.tilloy@canonical.com, Phillip Lougher , stable@vger.kernel.org Subject: [PATCH 2/3] squashfs: fix extending readahead beyond end of file Date: Thu, 20 Oct 2022 23:36:15 +0100 Message-Id: <20221020223616.7571-3-phillip@squashfs.org.uk> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221020223616.7571-1-phillip@squashfs.org.uk> References: <20221020223616.7571-1-phillip@squashfs.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailcore-Auth: 439999529 X-Mailcore-Domain: 1394945 X-123-reg-Authenticated: phillip@squashfs.org.uk X-Originating-IP: 82.69.79.175 X-CMAE-Envelope: MS4xfLVqZTEL6y7WsBl/SilQq+U1I+1q4XI20YGsxlSG6b6FvIDoNoiBLvr05x4IIAc/kR2HNK4sLo6vrmVcrjy5dV+7dIO+qm/RXszzjmVbMt2lTGdGRXkt +S4wdVtVa/HvyQDkUxjhOraK7i8NuQbTctmdMwT7yl5whWtsElFhZ85ctsMi7jMtpt5DLuWxEhqqNakxtLBqZdx1X6f50IyoalsrllYkslRC3u3gzuOKpBsh I9ugfyuiK3q9ok9o873C6A== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The readahead code will try to extend readahead to the entire size of the Squashfs data block. But, it didn't take into account that the last block at the end of the file may not be a whole block. In this case, the code would extend readahead to beyond the end of the file, leaving trailing pages. Fix this by only requesting the expected number of pages. Fixes: 8fc78b6fe24c ("squashfs: implement readahead") Signed-off-by: Phillip Lougher Cc: --- fs/squashfs/file.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index e526eb7a1658..f0afd4d6fd30 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c @@ -559,6 +559,12 @@ static void squashfs_readahead(struct readahead_contro= l *ractl) unsigned int expected; struct page *last_page; =20 + expected =3D start >> msblk->block_log =3D=3D file_end ? + (i_size_read(inode) & (msblk->block_size - 1)) : + msblk->block_size; + + max_pages =3D (expected + PAGE_SIZE - 1) >> PAGE_SHIFT; + nr_pages =3D __readahead_batch(ractl, pages, max_pages); if (!nr_pages) break; @@ -567,13 +573,10 @@ static void squashfs_readahead(struct readahead_contr= ol *ractl) goto skip_pages; =20 index =3D pages[0]->index >> shift; + if ((pages[nr_pages - 1]->index >> shift) !=3D index) goto skip_pages; =20 - expected =3D index =3D=3D file_end ? - (i_size_read(inode) & (msblk->block_size - 1)) : - msblk->block_size; - if (index =3D=3D file_end && squashfs_i(inode)->fragment_block !=3D SQUASHFS_INVALID_BLK) { res =3D squashfs_readahead_fragment(pages, nr_pages, --=20 2.35.1