From nobody Thu Dec 18 13:15:20 2025 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 CF19AEB64D9 for ; Thu, 29 Jun 2023 14:18:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231537AbjF2OSZ (ORCPT ); Thu, 29 Jun 2023 10:18:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232060AbjF2OSJ (ORCPT ); Thu, 29 Jun 2023 10:18:09 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34DDA1737 for ; Thu, 29 Jun 2023 07:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1688048287; x=1719584287; h=from:date:subject:mime-version:content-transfer-encoding: message-id:to:cc; bh=/EACAvCkqaq5SWsngoSCmDYPrtH4Wz7SJv4BW6QmdMI=; b=bBbcSEsxarDnMjaFAdXLmJ7oTwjegItzZ/M7U3u74beXPcGsDYIHb4Zc sdWSQxjmRwlgSOioXtJuD0vvzdEQSLP9raqfyIg81NV76oXmf2BLc7F+O rQBuITpEmfASG+DRmMBZc14gHcXJ94THixkb2NudyWrxSbE3AkFTmfWki Ug2s9eaNojh83qZINUM8yxXj13MGbWLSIWMJwSf88nKs89PgjwN06JQtB 0sgWscodyCeeEATB1gI4B7fScMvfAMqAFtjf38nsF7GptBT6OxwiCT8qP v4ywD5cV9DTr0a3qXHAlvYYBtGXNGyynBvmZTNi8myn/h620TKyZRU911 g==; From: Vincent Whitchurch Date: Thu, 29 Jun 2023 16:17:57 +0200 Subject: [PATCH] squashfs: fix cache race with migration MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20230629-squashfs-cache-migration-v1-1-d50ebe55099d@axis.com> X-B4-Tracking: v=1; b=H4sIAJSSnWQC/x2NQQ7CMAwEv1L5jKU0TUHlK4iDG5zGBxKwASFV/ Tspx1lpZlcwVmGDc7eC8kdMamnQHzqImcrCKLfG4J0f3NFPaM83WU6GkWJmvMui9GoS+lM/Bhp dCmGCps9kjLNSiXkPpFqHfX4oJ/n+Hy/XbfsByl3ZJYEAAAA= To: Phillip Lougher , Andrew Morton CC: Christoph Hellwig , , , Vincent Whitchurch X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Migration replaces the page in the mapping before copying the contents and the flags over from the old page, so check that the page in the page cache is really up to date before using it. Without this, stressing squashfs reads with parallel compaction sometimes results in squashfs reporting data corruption. Fixes: e994f5b677ee ("squashfs: cache partial compressed blocks") Signed-off-by: Vincent Whitchurch --- fs/squashfs/block.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c index 6aa9c2e1e8ebe..581ce95193390 100644 --- a/fs/squashfs/block.c +++ b/fs/squashfs/block.c @@ -166,6 +166,26 @@ static int squashfs_bio_read_cached(struct bio *fullbi= o, return 0; } =20 +static struct page *squashfs_get_cache_page(struct address_space *mapping, + pgoff_t index) +{ + struct page *page; + + if (!mapping) + return NULL; + + page =3D find_get_page(mapping, index); + if (!page) + return NULL; + + if (!PageUptodate(page)) { + put_page(page); + return NULL; + } + + return page; +} + static int squashfs_bio_read(struct super_block *sb, u64 index, int length, struct bio **biop, int *block_offset) { @@ -190,11 +210,10 @@ static int squashfs_bio_read(struct super_block *sb, = u64 index, int length, for (i =3D 0; i < page_count; ++i) { unsigned int len =3D min_t(unsigned int, PAGE_SIZE - offset, total_len); - struct page *page =3D NULL; + pgoff_t index =3D (read_start >> PAGE_SHIFT) + i; + struct page *page; =20 - if (cache_mapping) - page =3D find_get_page(cache_mapping, - (read_start >> PAGE_SHIFT) + i); + page =3D squashfs_get_cache_page(cache_mapping, index); if (!page) page =3D alloc_page(GFP_NOIO); =20 --- base-commit: 3a8a670eeeaa40d87bd38a587438952741980c18 change-id: 20230629-squashfs-cache-migration-27154a50f449 Best regards, --=20 Vincent Whitchurch