Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp20838894rwd; Thu, 29 Jun 2023 07:38:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlEIp2x+CKAhizt7uHDy1WVTJ34qmh9wpaeOp1EVUFauU1pSUqFd7S72Vy3oFz59AwCs3Rt2 X-Received: by 2002:a62:7b07:0:b0:682:57f0:7c00 with SMTP id w7-20020a627b07000000b0068257f07c00mr158512pfc.3.1688049498546; Thu, 29 Jun 2023 07:38:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688049498; cv=none; d=google.com; s=arc-20160816; b=wbomNfHAegqvF3PBMXZHmCdT7lTGLFJzWNCkV3TRHei/gXvz9Q6pMQs36+psjRZHE9 G8M+4Efe1Zu9BkcP7VKFGy52ys5HjxzzPQfL7JhmisjFPh5HjGvGxBEH1JQUi5VomNvM xRhvC5k2kzwpWlhi0TAspXgSJJ0XayiRQR03a5hPQZo6QG3+lvcy9vq1YsxsqnnQjMex zI9T2m5DBEYEqqiE8AWFi1Xl3xDymDiK3d9Y57/hkU4AbbN3317F978jd4nIaJkw3KZL v9uUYdphOdq9hAizxwS9DFydwQaed0ttVPD1kRpZPJawKpzqHdMrozB0HXL0RprQ01jc Unog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=/EACAvCkqaq5SWsngoSCmDYPrtH4Wz7SJv4BW6QmdMI=; fh=SGmGsssWH0U0avnEN+LznPu5QDdML/kD+hwJB+00Ip4=; b=T57JGT3xbMEdR1LID86bxHgvhiR39cPz52K6tFTkkt0LO1Uv7qAxpw/xdu3YMxLkCF RRbqLHVG1koAYzPpAvGxoaELbquCrIyxJ/DDaTrAREa0CYl27aBJ4nVqCDmDJekpk8Nc 9J1aCePstSiky0AHkqBsxwn3RsgkBX4u+UBmu5Icfuaa/OP1ATNOAGltEAaGpPpQB458 irnT6Pa8RLrjoNoVjeJaNRCd8ZgT8Wdybu0WZsmAMCu4+JAVpB7mMANPJS+Iedeo/73q rzFcXExzAtQgblwQS2px2wUuflbU6h8hTtbestkHDbWBdtrdgvuPasKTrmUIADoBABPf ueLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=bBbcSEsx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q27-20020a056a0002bb00b0064d45bbba8csi8794931pfs.62.2023.06.29.07.38.04; Thu, 29 Jun 2023 07:38:18 -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; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=bBbcSEsx; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230198AbjF2OSX (ORCPT + 99 others); Thu, 29 Jun 2023 10:18:23 -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: 7bit 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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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 *fullbio, return 0; } +static struct page *squashfs_get_cache_page(struct address_space *mapping, + pgoff_t index) +{ + struct page *page; + + if (!mapping) + return NULL; + + page = 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 = 0; i < page_count; ++i) { unsigned int len = min_t(unsigned int, PAGE_SIZE - offset, total_len); - struct page *page = NULL; + pgoff_t index = (read_start >> PAGE_SHIFT) + i; + struct page *page; - if (cache_mapping) - page = find_get_page(cache_mapping, - (read_start >> PAGE_SHIFT) + i); + page = squashfs_get_cache_page(cache_mapping, index); if (!page) page = alloc_page(GFP_NOIO); --- base-commit: 3a8a670eeeaa40d87bd38a587438952741980c18 change-id: 20230629-squashfs-cache-migration-27154a50f449 Best regards, -- Vincent Whitchurch