Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4413324imw; Tue, 19 Jul 2022 06:17:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tyrqbfM9VcKP3zE+ZzJeoNnd4L9Z2xvHKx7CBVmL4ZcMMZVf9eXhRu4347VljtsbIBau+k X-Received: by 2002:a17:907:7fa7:b0:72e:f88c:db16 with SMTP id qk39-20020a1709077fa700b0072ef88cdb16mr20025021ejc.366.1658236679029; Tue, 19 Jul 2022 06:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658236679; cv=none; d=google.com; s=arc-20160816; b=Og3W2j01t7x18JchbZRQ2i0TvZlSye52UYlJ6f6JtBLvXzAh3xy8NbPB1z6ZR9c7a8 Uy7eYI7NzalQ1GhKagELsbctV5TDYBsug/ciHyzbEFyWpmSzW9U4EEPkMtVoELNIA0Ue mgnA0Z7ZN/GSVUL8lxYJZ3DelUwTsglOVY29Xm7IV21TJvjero2B1j3uqj04xClCLbb2 k/DKP+8QJt75++0terjglY87JYwzCOSDBVhu1RUfle+v1HZPouhXH9CLzpb7Q4+Qc1yF MIlGguP+BU8OTW1M1Of2Gh962yOeBxIOiw+BJf4TbsVsnfcO4gFEmmOJqgOLTyq1saSs wJgQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qfVO5w92ma+4g/Nz8lO33hBLsgq8LcdBtd4nFAek77I=; b=FzNEkbcpOf97aPj+4QsNfkziCf6Fbox0bw0LgvVfef32/K2+J2m8WX0iwe6qTDDsz/ QXE6XgmzT0Xwk/K17dRsgWxDZiPCLgPGgdkgZ0BBLaqRIBtzZJo5U5thb1ODOaiQIhMl YXlNqtlmWKXPGBuDYeFsfg057mH7XB/hykt+cM1whgA7gWgj3eotKxEAIuGfIrYs1loM j8V7IWkwJfGtWiBkSzEInNLCc2FubgqbU7gLJYYSkU4iwl/hp2beBCGsayaJIalrrxN3 WoAoVcj+cWOc2VoeTn6YfDphjrunoPsDo1ELJMfN8biVfR4oBn5gW++KgTN9oSr/mFvl wPgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0kzWar6o; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g9-20020a50d0c9000000b0043b6f4991cfsi5754328edf.495.2022.07.19.06.17.31; Tue, 19 Jul 2022 06:17:59 -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 header.i=@linuxfoundation.org header.s=korg header.b=0kzWar6o; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239503AbiGSMVd (ORCPT + 99 others); Tue, 19 Jul 2022 08:21:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239924AbiGSMUC (ORCPT ); Tue, 19 Jul 2022 08:20:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 632A95926E; Tue, 19 Jul 2022 05:07:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 53546B81B1A; Tue, 19 Jul 2022 12:07:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BBBEC341C6; Tue, 19 Jul 2022 12:07:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1658232438; bh=LImAdXCTNx1YClH8FEaycD4Q8yoRVyjvoe4rawmcKfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0kzWar6ocDn1rs6p6Q75jKoV0rwoD9NggWDr86NOFKnybZmbEhutzrDgynG3FK3YM rtAeuL2UZlpftL2B4gzpYUIXyeffhqAHyOCoFuWafiXmtWRQ0z72Y305b/nnmBlJlF +6rA0xur8Rl+f9rq30G5hI4Nipmuho8g6JH7xLWI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Ansgar=20L=C3=B6=C3=9Fer?= , Dave Chinner , Linus Torvalds Subject: [PATCH 5.10 020/112] fs/remap: constrain dedupe of EOF blocks Date: Tue, 19 Jul 2022 13:53:13 +0200 Message-Id: <20220719114627.940205141@linuxfoundation.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220719114626.156073229@linuxfoundation.org> References: <20220719114626.156073229@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Dave Chinner commit 5750676b64a561f7ec920d7c6ba130fc9c7378f3 upstream. If dedupe of an EOF block is not constrainted to match against only other EOF blocks with the same EOF offset into the block, it can match against any other block that has the same matching initial bytes in it, even if the bytes beyond EOF in the source file do not match. Fix this by constraining the EOF block matching to only match against other EOF blocks that have identical EOF offsets and data. This allows "whole file dedupe" to continue to work without allowing eof blocks to randomly match against partial full blocks with the same data. Reported-by: Ansgar Lößer Fixes: 1383a7ed6749 ("vfs: check file ranges before cloning files") Link: https://lore.kernel.org/linux-fsdevel/a7c93559-4ba1-df2f-7a85-55a143696405@tu-darmstadt.de/ Signed-off-by: Dave Chinner Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/remap_range.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/fs/remap_range.c +++ b/fs/remap_range.c @@ -71,7 +71,8 @@ static int generic_remap_checks(struct f * Otherwise, make sure the count is also block-aligned, having * already confirmed the starting offsets' block alignment. */ - if (pos_in + count == size_in) { + if (pos_in + count == size_in && + (!(remap_flags & REMAP_FILE_DEDUP) || pos_out + count == size_out)) { bcount = ALIGN(size_in, bs) - pos_in; } else { if (!IS_ALIGNED(count, bs))