From nobody Sun Sep 7 15:32:04 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F4E0C54EE9 for ; Tue, 13 Sep 2022 15:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235326AbiIMPGI (ORCPT ); Tue, 13 Sep 2022 11:06:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235306AbiIMPED (ORCPT ); Tue, 13 Sep 2022 11:04:03 -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 B143C3123D; Tue, 13 Sep 2022 07:29: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 ams.source.kernel.org (Postfix) with ESMTPS id D68C0B80FC0; Tue, 13 Sep 2022 14:29:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54581C4314D; Tue, 13 Sep 2022 14:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079381; bh=W6mz/4aUOCmFU+fZ0Hl3r5TRNfIk2dRA5A63NJtEndE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1h9pmURXq+ZnjvwIR0ZxfiRW+gdMGOI7j1hebEslCS24PQDh2GMoCeUX1dcPLBLOv uE7RSUDGLhj8yN+QfkgITQGT1sSNU9LUubLrSSt33h+f5r5zfjFNFeimi+HfC2kbSE HucCEAq1ZMqYeNMowH8JRtx//7tI/BQv666GXHrc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Howells , Steve French , Sasha Levin Subject: [PATCH 5.4 088/108] smb3: missing inode locks in punch hole Date: Tue, 13 Sep 2022 16:06:59 +0200 Message-Id: <20220913140357.402911770@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140353.549108748@linuxfoundation.org> References: <20220913140353.549108748@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: David Howells [ Upstream commit ba0803050d610d5072666be727bca5e03e55b242 ] 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 Signed-off-by: Sasha Levin --- fs/cifs/smb2ops.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c index 6ae281cff0d50..6039b0cdfe04e 100644 --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -3051,7 +3051,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 =3D file_inode(file); struct cifsFileInfo *cfile =3D file->private_data; struct file_zero_data_information fsctl_buf; long rc; @@ -3060,14 +3060,12 @@ static long smb3_punch_hole(struct file *file, stru= ct cifs_tcon *tcon, =20 xid =3D get_xid(); =20 - inode =3D 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 =3D -EOPNOTSUPP; - free_xid(xid); - return rc; + goto out; } =20 /* @@ -3086,6 +3084,8 @@ static long smb3_punch_hole(struct file *file, struct= cifs_tcon *tcon, true /* is_fctl */, (char *)&fsctl_buf, sizeof(struct file_zero_data_information), CIFSMaxBufSize, NULL, NULL); +out: + inode_unlock(inode); free_xid(xid); return rc; } --=20 2.35.1