Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3772334rwa; Tue, 23 Aug 2022 09:52:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR4VBjpzev8kxdnTtMNEZpXDz0fU9Db85fQYch51POH2s3eHpVzZ5m2T/SgN1j/4Hub/KXV/ X-Received: by 2002:a17:90b:4a83:b0:1fb:cf3:7d9a with SMTP id lp3-20020a17090b4a8300b001fb0cf37d9amr4043367pjb.241.1661273549696; Tue, 23 Aug 2022 09:52:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661273549; cv=none; d=google.com; s=arc-20160816; b=JHHpELSmootBqzt/Zx4mTaIjIO7tBwu+rNKqwSo/BoqHwC4Uo6+ZXX4J9yNgxaVMbW 5Tkv4m5HzJbKyTWX3dJuRl01QoD6DUYTIu/8UbsxPwAj2RVNDIl0sJkH4MXKhWYj0Nz1 rm9YMUOUKfd88q1lW1ku8MEHAQt+/HC88cNpoiHcxh/33KwjZkEEnGbg7I7vzBC5OQMq XPe9XcLYg3Khap778oILaNnboYmkgikcDTcydgLpkNNYTtdULLB8b48RVc3ruQ4OPBMG ppKBpVfTEpo0Lx7XV2YzuJlDUPzF1zG2qZz1AfaIOuB+t7jDaZK2XU1ufrtoEn8V3UYB ANFA== 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=41srhtC1DtBCiKuNUZse2LJ9UWvjGkyUijYd/UmDvl8=; b=h4tgyHFG0LeW0jTatoCiFP70Moezo1vVVh9dhXaBzneownngWgdsovyOolWqEFJw6y 62DWDVpA/m4BbWC2rAa05fhMS2I60HtTcd1d37Ne1cqXRiXpk6wakU7UNWbhxBeb+ku1 +teHorl1aL+UYaaox8TcC40Pqsmd5eoUVBWP7wJZ2iqKeQjEN5tkNOmXBMHesOr1SfFY kC/WJ+LLJInt5G4E2pcijoS8zeCZFXPg1Y7cEPnoGgn3QDkulAaDdZHrlh2WOESi7j7S 9bR8FBYRCBfor+skYwQYPTKq3a9DLvQX0EipqTdmXLiiq033HTX7fuGkKab+kmGoMH6M PhOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WTAQrnXa; 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 o3-20020a639203000000b00427567b8438si8788239pgd.871.2022.08.23.09.52.18; Tue, 23 Aug 2022 09:52:29 -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=WTAQrnXa; 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 S245301AbiHWQlZ (ORCPT + 99 others); Tue, 23 Aug 2022 12:41:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245232AbiHWQjW (ORCPT ); Tue, 23 Aug 2022 12:39:22 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0169169F54 for ; Tue, 23 Aug 2022 06:07:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661260076; 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=41srhtC1DtBCiKuNUZse2LJ9UWvjGkyUijYd/UmDvl8=; b=WTAQrnXaCC/zjR5pGjvqPRjFWxooxVOsYtGwGSoEbnGk0QJwxT8wj1oCle+zF2zhz+tfN7 xRy9HSz/ZZM9g5oVkij/2EPJgk0WJGGxfZuCUwFU10YhDx+I3xKGWnxl2aWJVrGMTu+b4q zwjbLUzi+vanjN9FxaxyCiI+vqzMXmI= 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-483-Qpmpwwt-O9i9IEC4IzE4_A-1; Tue, 23 Aug 2022 09:07:51 -0400 X-MC-Unique: Qpmpwwt-O9i9IEC4IzE4_A-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 71E7B3C0CD5D; Tue, 23 Aug 2022 13:07:50 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.72]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4FEE940CFD0A; Tue, 23 Aug 2022 13:07:49 +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 4/5] smb3: missing inode locks in punch hole 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:48 +0100 Message-ID: <166126006871.548536.9826412629988468617.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.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, 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 smb3 fallocate punch hole was not grabbing the inode or filemap_invalidate locks so could have race with pagemap reinstantiating the page. Cc: stable@vger.kernel.org Signed-off-by: David Howells Signed-off-by: Steve French --- fs/cifs/smb2ops.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 75fcf6a0df56..5b5ddc1b4638 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -3375,7 +3375,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, loff_t offset, loff_t len) { - struct inode *inode; + struct inode *inode = file_inode(file); struct cifsFileInfo *cfile = file->private_data; struct file_zero_data_information fsctl_buf; long rc; @@ -3384,14 +3384,12 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, xid = get_xid(); - inode = d_inode(cfile->dentry); - + inode_lock(inode); /* Need to make file sparse, if not already, before freeing range. */ /* Consider adding equivalent for compressed since it could also work */ if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) { rc = -EOPNOTSUPP; - free_xid(xid); - return rc; + goto out; } filemap_invalidate_lock(inode->i_mapping); @@ -3411,8 +3409,10 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, (char *)&fsctl_buf, sizeof(struct file_zero_data_information), CIFSMaxBufSize, NULL, NULL); - free_xid(xid); filemap_invalidate_unlock(inode->i_mapping); +out: + inode_unlock(inode); + free_xid(xid); return rc; }