From patchwork Thu Oct 20 22:36:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Lougher X-Patchwork-Id: 6440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp353522wrr; Thu, 20 Oct 2022 15:39:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7XfOMLM5ajw2Na3tL0WXoEFed1LeujTie+z9uBLOC067Wq85ekDrvIrdMpxy6v3/gBrz00 X-Received: by 2002:a05:6402:510f:b0:45d:353e:dd37 with SMTP id m15-20020a056402510f00b0045d353edd37mr14446899edd.362.1666305557430; Thu, 20 Oct 2022 15:39:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666305557; cv=none; d=google.com; s=arc-20160816; b=STevHv3s55r+z+WT2ve7g3UkJcNUVNk+gHG0XbKDWHJcta9mRZ7g4vADTRsC9hCrlS PKykNS5AgPNhoKd+wHLGXQkWUwqJaitKRxlJKyg4EO/DGp9UY20ZN4QNL5V6Qqvb9pAm lRfP2bSZeP3L3yp/wdZqZ0kKmprMGHcEWvLdV55hw0xjRsp9tGaKfrEy/yKj0kROk7Rx qa4MU4JreaR5eklAQ9dzIdVk9KbTuA33wYGAkRc5CkN/WiFzYiMQln/DgV71OVaxqD0o nLvbb4I6edKK5CNZQMK9Njn85jCE1XPy65jZ8mGUs0flfDrPQUy4Pezh3moahtL01dhW 27aQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=kphgiqNW7sBh1CYtdd6+sBnhHsfqswAk9T53Cul7rXk=; b=nWYzpYB3HLaYpnLxZ5qQwGKckdJpaQ7k1grbIk4SlQ/8qpbCVDZOKb30SK1U6av3vQ yIrwW/n8ZVJvz+0+0ePkuCY8SEFJ+EuNTE33l8lcF8uDs7HAX9Lq2pG4ESSXpVtT5SQb JoMcxNfrSgvw796ZAgExOTCD6jWaE9bnzA4J0TQTfrBSaGWlDgwS8j/Qyfg3MM4qcKQ/ VtJYag6x4doNeWL/eYHuAIbVYW2XT3sF/xsWeH+fjiWjZwr0T7k2egnMWVYhY7NkxxXu B/wRRDGAL/ORPIwurFJ4YD5I/KJ/q0dubjq++C6oh1FqFRUOAZKhMXEsIfhVZVVh2JCC rRYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qk36-20020a1709077fa400b007919fc02ce8si7499321ejc.971.2022.10.20.15.38.52; Thu, 20 Oct 2022 15:39:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbiJTWgn (ORCPT + 99 others); Thu, 20 Oct 2022 18:36:43 -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 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== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747248016218835661?= X-GMAIL-MSGID: =?utf-8?q?1747248016218835661?= 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_control *ractl) unsigned int expected; struct page *last_page; + expected = start >> msblk->block_log == file_end ? + (i_size_read(inode) & (msblk->block_size - 1)) : + msblk->block_size; + + max_pages = (expected + PAGE_SIZE - 1) >> PAGE_SHIFT; + nr_pages = __readahead_batch(ractl, pages, max_pages); if (!nr_pages) break; @@ -567,13 +573,10 @@ static void squashfs_readahead(struct readahead_control *ractl) goto skip_pages; index = pages[0]->index >> shift; + if ((pages[nr_pages - 1]->index >> shift) != index) goto skip_pages; - expected = index == file_end ? - (i_size_read(inode) & (msblk->block_size - 1)) : - msblk->block_size; - if (index == file_end && squashfs_i(inode)->fragment_block != SQUASHFS_INVALID_BLK) { res = squashfs_readahead_fragment(pages, nr_pages,