Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp4638072iob; Sun, 8 May 2022 20:10:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyw/t8lEHvAvfc0dwsoBoe7ARlMxHvExSYili/xk2KYVGwrYIN89NbvLkI5kM3Xk8tZ00Fs X-Received: by 2002:a17:902:ec8c:b0:15e:a371:ad7d with SMTP id x12-20020a170902ec8c00b0015ea371ad7dmr14223378plg.12.1652065817886; Sun, 08 May 2022 20:10:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652065817; cv=none; d=google.com; s=arc-20160816; b=blph0rcualhkgtd/x9MRgjpnX9dVQVTR41OJmYo0aXs88r7NiflsCy1sm/0cSAKfJV YFtvZrgcUEY9UhGRdWsiaaeXd9Nv1Ss7Z9QKyoEC33kcBTOYr300gf7ybhv/XnBi+3qc eNn4+xAwg+r8z+pCzmr/rKAt8M2aEHPDnzweIb6JX6wkYMQE9NY+b1ZJF10bkqDgdmIm vD4IwLE2cFVBfvqbEYQA4oYfOOXbp/EsOBI/1EOvXsLPJvzg5sedX9DT0oHXPUZ7xi61 EdF1+00UZWKaCpFg7C4jgGwP3nkdHbsYzaDivAKtu7dcMXN896wiNjgr6FM/rPH5dukD C6MA== 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=y/GQDuyrXGCSHE0iKQW8vx14cyHANWcrQEmrFErK/dE=; b=M1LYJTCqDVKHyO11x96TL5mqHXsfxQMOpuAVpWmSUtX6as2z9bammflvwdUB7wpD/C oYPX55r/tfWGcTJyEI1wHXg5OQbf2Nr77vEOMXWeLYeeFU4gp5bLSWrU0pMyCjnh0KHW jBn2/wn+cENJIcjotM5zO7rdnA7VRAwpeKnHQCKu6xx1q4kz4RaaRxUqxkUIpDtK+YTL I8qqDoo9ch8/KqaEhs/ipOwguPl2mY04EEVbuoXL7JjJbFhtPXigQgPma25ljYWWRKBv XJJvUptvNqXQNkko92QO7xtc18NNk5ZadGSR6UpVTJol6USb6RmGQXlqKvqOkCKNu39B qukg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uU6RIg1v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u14-20020a056a00124e00b004fa3a8e0041si13247638pfi.248.2022.05.08.20.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 May 2022 20:10:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uU6RIg1v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C93008E1BF; Sun, 8 May 2022 20:10:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356931AbiEDRJt (ORCPT + 99 others); Wed, 4 May 2022 13:09:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355579AbiEDRAQ (ORCPT ); Wed, 4 May 2022 13:00:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 693994B869; Wed, 4 May 2022 09:51:52 -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 dfw.source.kernel.org (Postfix) with ESMTPS id B52DE617C2; Wed, 4 May 2022 16:51:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E602C385A5; Wed, 4 May 2022 16:51:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1651683111; bh=Fibnfz6UKMUBj//0u9tJTPvRAWqgcl6ZhEU2wPNikR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uU6RIg1vbcC5VqVVgvlxX8+7uyiXV80bq0xyxhBlXcjgBCfqsrVBw5yTDQO4medRb XfMz8INGhGpqLUQUL2+woImTCJmaZZwBJMVcyrPpwUBqDaNk5sLeG3YTRp7sa9oShJ +trmrIQPP8D2sYlkdB33YFQW1SB5MhJ6TVYAU2yI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiaoli Feng , Ronnie Sahlberg , Steve French , Sasha Levin Subject: [PATCH 5.10 103/129] cifs: destage any unwritten data to the server before calling copychunk_write Date: Wed, 4 May 2022 18:44:55 +0200 Message-Id: <20220504153029.123978567@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220504153021.299025455@linuxfoundation.org> References: <20220504153021.299025455@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=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: Ronnie Sahlberg [ Upstream commit f5d0f921ea362636e4a2efb7c38d1ead373a8700 ] because the copychunk_write might cover a region of the file that has not yet been sent to the server and thus fail. A simple way to reproduce this is: truncate -s 0 /mnt/testfile; strace -f -o x -ttT xfs_io -i -f -c 'pwrite 0k 128k' -c 'fcollapse 16k 24k' /mnt/testfile the issue is that the 'pwrite 0k 128k' becomes rearranged on the wire with the 'fcollapse 16k 24k' due to write-back caching. fcollapse is implemented in cifs.ko as a SMB2 IOCTL(COPYCHUNK_WRITE) call and it will fail serverside since the file is still 0b in size serverside until the writes have been destaged. To avoid this we must ensure that we destage any unwritten data to the server before calling COPYCHUNK_WRITE. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1997373 Reported-by: Xiaoli Feng Signed-off-by: Ronnie Sahlberg Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/cifs/smb2ops.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 0e8f484031da..c758ff41b638 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1744,9 +1744,17 @@ smb2_copychunk_range(const unsigned int xid, int chunks_copied = 0; bool chunk_sizes_updated = false; ssize_t bytes_written, total_bytes_written = 0; + struct inode *inode; pcchunk = kmalloc(sizeof(struct copychunk_ioctl), GFP_KERNEL); + /* + * We need to flush all unwritten data before we can send the + * copychunk ioctl to the server. + */ + inode = d_inode(trgtfile->dentry); + filemap_write_and_wait(inode->i_mapping); + if (pcchunk == NULL) return -ENOMEM; -- 2.35.1