Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp3078689rwe; Mon, 29 Aug 2022 05:35:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR7DRv7ciIumhVM3PsIKXuVLJ8626T+hdSVhu59b9IzKw7uqgQHs/9AfpkHzGzkohq1KwXHv X-Received: by 2002:a17:90b:3b41:b0:1fb:5376:fb06 with SMTP id ot1-20020a17090b3b4100b001fb5376fb06mr18153386pjb.240.1661776531149; Mon, 29 Aug 2022 05:35:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661776531; cv=none; d=google.com; s=arc-20160816; b=DKX5l3w5Qa1HGvz62+ve4nyuseQANy044/K8jWtl7AV2pwMBsgqrNgkrr5jfvrzdpz y3DIdvuLMFBOvln4NdZRKOuYf426aP0mUPSmA9C5HyoDAr6Gc2kUvMinrbbUXND49ZOh YjL/YiPS1lhMPmAaX/aEZxKzzh40afWxyoU4/qd65ATi67LIM1i+SLEcy7nDSV5Cykf+ QrQuWV1QQMT/qK2yo58af8ZGyxmv/EgMAmPVGrwVrX/1DlLGkvui7oPK7bSJl3nf0pOc NzMVIkHMD7NXdE5roNMDBuyxUbCydnUUEesvOh5raaWESrsM5GDlbBVvve3AdaP9OOT0 5smA== 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=Ondy3+NB99YmlMaXLIytGdemnAtZRelq8vCkqiWTex4=; b=BF+OkSXbpZ63x1RRmQUkDgHZDw7ZD8t1J6Ym39eRvc4BWSmtJG4+NIJ4PbzLjBWLpX KXq3FlRiXJ0yCpetZ31DMrxI0K0edGr/wWBKsuNzIWcWff/ja6lx+iYz8Y7MjrYt6QLz sGNYTQiOJanUI062z1xKLdgqzFwvXF9lDzRtnwDMHALrcqAD3Tllt+IprQKq4FC0agUS V/M3yhfd5s92wbQlT5CdVuBrWmY22V2B7q+TRWNW+XZb4Ylx4VVzW6oEDf/FDbLdinVJ 0+sx+8NrApv1ifX+EFB6f9ApvAoDzwDtF8709QxJwTrIaGQpD5Tttdxjz4X0snKVJeRw nONA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cDvaxdlw; 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 b10-20020a056a000a8a00b0052d5f874fa8si10008158pfl.164.2022.08.29.05.35.20; Mon, 29 Aug 2022 05:35:31 -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=cDvaxdlw; 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 S232402AbiH2Lcq (ORCPT + 99 others); Mon, 29 Aug 2022 07:32:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232734AbiH2L3r (ORCPT ); Mon, 29 Aug 2022 07:29:47 -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 AC30F7C191; Mon, 29 Aug 2022 04:18:09 -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 E052361214; Mon, 29 Aug 2022 11:17:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D512BC433C1; Mon, 29 Aug 2022 11:17:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661771872; bh=7++Nr++HgOMxjyxbs3OmthF94zfoso/08sA2ksR5Zkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cDvaxdlwGLzXhKy3lha5D9enoFlDL7iFnjtiDmcAbcdo6jKscG7iRJUuj3TkWb9aH BR/2K/TNpe/VZpQwH0iNQbf2IvddqvkMYYrjgtvH5fU6PraCxKfpB5bSFcYLrm6OPR 54rkKqhNjIWLI9j0RFzvbkFJt6gg3UrB9pKyssTQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Howells , Steve French Subject: [PATCH 5.19 126/158] smb3: missing inode locks in punch hole Date: Mon, 29 Aug 2022 12:59:36 +0200 Message-Id: <20220829105814.385048397@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220829105808.828227973@linuxfoundation.org> References: <20220829105808.828227973@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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 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: David Howells commit ba0803050d610d5072666be727bca5e03e55b242 upstream. 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: Greg Kroah-Hartman --- fs/cifs/smb2ops.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -3671,7 +3671,7 @@ static long smb3_zero_range(struct file 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; @@ -3680,14 +3680,12 @@ static long smb3_punch_hole(struct file 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); @@ -3707,8 +3705,10 @@ static long smb3_punch_hole(struct file true /* is_fctl */, (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; }