Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3770988rwa; Tue, 23 Aug 2022 09:51:00 -0700 (PDT) X-Google-Smtp-Source: AA6agR4CRVdtQaos3GFbYID6Dic29P64rlOtCLkJeKlqyJLRSr2UrBnOqGZInmcoZhrGqzxsgREg X-Received: by 2002:a17:90a:e7cd:b0:1fb:6490:2d6a with SMTP id kb13-20020a17090ae7cd00b001fb64902d6amr3578886pjb.77.1661273460108; Tue, 23 Aug 2022 09:51:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661273460; cv=none; d=google.com; s=arc-20160816; b=g7nn3lIFZ3Fw+MgYCkjm4sBL2EmAQ9yD2LUw/n6FvRLRwUpD9k8VYt1hU/HKZNXzm6 zv7Z9rfsXPRAlyF8xN6fabBKDKhfEHYlQ0dTFihnZF30ZxKrUSp1mPQ4JndPkiMmipQM xArIu4Tf+noMUpz61Z/bCSaXV8k3YS4ixqcDcGUNiTsG94u6HoMkg+JDgyYIkAIt3vCK CGM+avu3ZkEtD58Tw1icTfQR5k7RPZ9HomTghaNnBtwx4Zv7+d8lc44aUkwSroBF+Fdy yYxGUv9nkoWx5WjP8R/OrdqCr8aJBPrB5vBD2W7QYwXGbSWsdUvEUzVWGflucCZ94Hlx oZFA== 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:cc:to:from :subject:organization:dkim-signature; bh=YAOIxblxocTtO3BL0vdfFElttBlZxbKdOb+H6jWEd7M=; b=JTKKiN2wO0F9SV5QxTRRf/hg/hmRkkALcIzkQ0MqL0mcxlV9qbqjm5AcxtNs+Cbd1G WxWR2e+Y+aoEIYy8cJ2jNSzacQRndBepmbEI2A+nBTJ4AZW+MjXC+wweCSY4buMSURee nAecD5uMPPwnSiErLZ+PFzj4ERhF4cvJhDnI+7zOGeZh4col/tWBFfIbHSmREgNQsba8 ZjZmntciRFcugw0wJ3eW32tqzdbsxx6jvezpAVW+twkQXjYxSmOTjSgZy8Kc+tlEEtD/ Ji7yyj5S4eys/K8SE4km8pd5z+UxFbRFRcS4OHVM1lm3SjgIE29lVJTWaMavqXnsGpDT +rcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fNgdcccu; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b12-20020a63714c000000b003c64eaa98cbsi16386511pgn.58.2022.08.23.09.50.47; Tue, 23 Aug 2022 09:51:00 -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=@redhat.com header.s=mimecast20190719 header.b=fNgdcccu; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245014AbiHWQjl (ORCPT + 99 others); Tue, 23 Aug 2022 12:39:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244834AbiHWQjM (ORCPT ); Tue, 23 Aug 2022 12:39:12 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7579E606A7 for ; Tue, 23 Aug 2022 06:07:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661260070; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YAOIxblxocTtO3BL0vdfFElttBlZxbKdOb+H6jWEd7M=; b=fNgdcccuRlVz9pfgy7SxPPjNWf573WoXc/Kygaf5nFUC5eWjL6ig0VMFcOmiU3G5jMs9b2 T9C3rPFaOGpLpfvdFx05yMYGuyXdMs64/wWVhyNFuxTgkA5g8Lkt2cg2V5qzPYJ1TbpxsD 8Bax1hUhIuRvBqy5tUcpPi3bDBEMIRI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-464-lxsTvF6MOa6DNJO6C88fTQ-1; Tue, 23 Aug 2022 09:07:47 -0400 X-MC-Unique: lxsTvF6MOa6DNJO6C88fTQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8CDD43C0CD5A; Tue, 23 Aug 2022 13:07:43 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6817F40CFD0A; Tue, 23 Aug 2022 13:07:42 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 3/5] smb3: fix temporary data corruption in collapse range From: David Howells To: sfrench@samba.org, linux-cifs@vger.kernel.org Cc: lsahlber@redhat.com, jlayton@kernel.org, dchinner@redhat.com, willy@infradead.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, samba-technical@lists.samba.org Date: Tue, 23 Aug 2022 14:07:41 +0100 Message-ID: <166126006184.548536.12909933168251738646.stgit@warthog.procyon.org.uk> In-Reply-To: <166126004083.548536.11195647088995116235.stgit@warthog.procyon.org.uk> References: <166126004083.548536.11195647088995116235.stgit@warthog.procyon.org.uk> User-Agent: StGit/1.4 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_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: Steve French collapse range doesn't discard the affected cached region so can risk temporarily corrupting the file data. This fixes xfstest generic/031 I also decided to merge a minor cleanup to this into the same patch (avoiding rereading inode size repeatedly unnecessarily) to make it clearer. Cc: stable@vger.kernel.org Fixes: 5476b5dd82c8b ("cifs: add support for FALLOC_FL_COLLAPSE_RANGE") Reported-by: David Howells Tested-by: David Howells Reviewed-by: David Howells Signed-off-by: Steve French cc: Ronnie Sahlberg --- fs/cifs/smb2ops.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 1c5a93ced946..75fcf6a0df56 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -3669,41 +3669,47 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, { int rc; unsigned int xid; - struct inode *inode; + struct inode *inode = file_inode(file); struct cifsFileInfo *cfile = file->private_data; - struct cifsInodeInfo *cifsi; + struct cifsInodeInfo *cifsi = CIFS_I(inode); __le64 eof; + loff_t old_eof; xid = get_xid(); - inode = d_inode(cfile->dentry); - cifsi = CIFS_I(inode); + inode_lock(inode); - if (off >= i_size_read(inode) || - off + len >= i_size_read(inode)) { + old_eof = i_size_read(inode); + if ((off >= old_eof) || + off + len >= old_eof) { rc = -EINVAL; goto out; } + filemap_invalidate_lock(inode->i_mapping); filemap_write_and_wait(inode->i_mapping); + truncate_pagecache_range(inode, off, old_eof); rc = smb2_copychunk_range(xid, cfile, cfile, off + len, - i_size_read(inode) - off - len, off); + old_eof - off - len, off); if (rc < 0) - goto out; + goto out_2; - eof = cpu_to_le64(i_size_read(inode) - len); + eof = cpu_to_le64(old_eof - len); rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, cfile->fid.volatile_fid, cfile->pid, &eof); if (rc < 0) - goto out; + goto out_2; rc = 0; cifsi->server_eof = i_size_read(inode) - len; truncate_setsize(inode, cifsi->server_eof); fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof); +out_2: + filemap_invalidate_unlock(inode->i_mapping); out: + inode_unlock(inode); free_xid(xid); return rc; }