Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp6232238iob; Tue, 10 May 2022 13:29:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpfYMYpMYfh6O+KRdOaBv9DFmmPId2Hl7WbNXiuOcHxJKZqWGAaINngG+7imxV7U5PLt+C X-Received: by 2002:a17:907:9490:b0:6fa:7970:3eb8 with SMTP id dm16-20020a170907949000b006fa79703eb8mr11314370ejc.457.1652214550273; Tue, 10 May 2022 13:29:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652214550; cv=none; d=google.com; s=arc-20160816; b=hwDRCzJ8Cm0lmj7jpgWvYRJHZeQjozxpZiDvCjQS4mTkhV77dKdJtreaNP5/JLw2FZ 0jltOO7IJAdoVXJc5dvRx09CFGPmW16AnntH82kinJBzj2eh83xS6dNWHoNPh5KkGDDC s9zWh/qtdSWWkudPMYa/Ofd8KI3FvRlzRvFOdipvxmGjT08GfvUgxKLmPoq3fO7RcN9d A9OKtLlQubulH1ICtqAITXBW278FBdD3ZsPg96SKR51dmnaHqVPsE98q6HtVmOFE4ISX rqGGgc4vW+oPzsmyoj4CSwVUuROZ+uE3YnAK3bE0lWlHXrwA4jJ1sWMmHMfkGpy2KrD7 jGnQ== 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=OeR4onpfGPPipqQhnIK+5HIYYl9uJQpz2J9wQJYgNQw=; b=T02mBbjnErOn0fP9hjA0IeaCYC7U1JHXmGTTKesR8yyDfsKX2ROW8btq8QkOAxZi74 +XpL2m3qO37Qrv3WobZWpVWur67nKFXRKPRrFfDmsoewOx6MrE8T9jQZlNGNffcfHnxa jmHwxhahHT6QA3NaR26OZ352I0pmmkZWkv6sLpoOQRVDiiTi2tYAdPiD92oMfXTjE9ad YGSrzfVnrTQZpdr2gs9LtgOke9u40xfL3jV0qzFogyNJu+bGHZITBvYx0aXuYHAATTqI VJP5mEK6Tx/Z4/sax8w6xf6vY2v2Mm7ItDBl+rFDz4txOamq3pci19iEuCrBNIzaVhwD cXCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="t1leVvz/"; 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 ne5-20020a1709077b8500b006f476161a18si240121ejc.744.2022.05.10.13.28.46; Tue, 10 May 2022 13:29:10 -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="t1leVvz/"; 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 S243158AbiEJN2x (ORCPT + 99 others); Tue, 10 May 2022 09:28:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243401AbiEJNVv (ORCPT ); Tue, 10 May 2022 09:21:51 -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 307DA4B846; Tue, 10 May 2022 06:15:58 -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 2E18D615DD; Tue, 10 May 2022 13:15:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 388C5C385A6; Tue, 10 May 2022 13:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1652188544; bh=KR943c8CFkXLKMhnK9yAbS4g5Lha2CsC/opzgmgUJ6o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t1leVvz/ppVsGjIz4KVsoYjkrq2SNw74QqZwyQwGawEaHSkAzuDiV5CAbc9LiAidO 8isfNi0GJCPp0+VmWF+w9GQ3gEuFgA2UXUjBr+63eyimpniWRUyk/cYhzLAxD4Yk3R UVKo5ELyuqq189wlMBoynbctT3MLCKkd0zKa69Ek= 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 4.14 43/78] cifs: destage any unwritten data to the server before calling copychunk_write Date: Tue, 10 May 2022 15:07:29 +0200 Message-Id: <20220510130733.809826225@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220510130732.522479698@linuxfoundation.org> References: <20220510130732.522479698@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.7 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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: 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 ba56c00f2650..3280a801b1d7 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -855,9 +855,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