From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77399C433DF for ; Tue, 7 Jul 2020 15:17:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4EC6920663 for ; Tue, 7 Jul 2020 15:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594135022; bh=2ERbcQ7cGP/23y0D4cEPHXs1LKTxeDYDYXSpj3NCvDw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=1g+iLsGo8rdQdJdugDJTDpcGsjurGlOTJSaq11wvmizIMd/CPMe07tvA26sKBJ7Jb hKyIuvBJ1db9bVGpDXZKF0hFKYOrD94ju9DEWoc3fbHuezBwtbCe1ieOqpt4FAXk/w NdMRNaKapTZv/RM9jUwVXZSgFBEa+MdpCz5Vc1PU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729161AbgGGPRB (ORCPT ); Tue, 7 Jul 2020 11:17:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:56606 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728500AbgGGPRA (ORCPT ); Tue, 7 Jul 2020 11:17:00 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 630622065D; Tue, 7 Jul 2020 15:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594135019; bh=2ERbcQ7cGP/23y0D4cEPHXs1LKTxeDYDYXSpj3NCvDw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o2Jgs+wgvUQ7bVcRAL85T10Al4NPySXP4YQxaFoT4DYK/0m3iD4GM6+AZTzi2DRHq Ve31rxz24d6i1K1OhwiHZwHgWBwEX5E5eUa91Pt8e32E8ZQ5/uO4JWpTgfwYCRDvJK 1C5PxKr8xuxLE8cIytwkV1ahAWBfs7qHMPSkZpRU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Zhang Xiaoxu , Steve French , Aurelien Aptel Subject: [PATCH 4.14 23/27] cifs: Fix the target file was deleted when rename failed. Date: Tue, 7 Jul 2020 17:15:50 +0200 Message-Id: <20200707145750.052596097@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200707145748.944863698@linuxfoundation.org> References: <20200707145748.944863698@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Xiaoxu commit 9ffad9263b467efd8f8dc7ae1941a0a655a2bab2 upstream. When xfstest generic/035, we found the target file was deleted if the rename return -EACESS. In cifs_rename2, we unlink the positive target dentry if rename failed with EACESS or EEXIST, even if the target dentry is positived before rename. Then the existing file was deleted. We should just delete the target file which created during the rename. Reported-by: Hulk Robot Signed-off-by: Zhang Xiaoxu Cc: stable@vger.kernel.org Signed-off-by: Steve French Reviewed-by: Aurelien Aptel Signed-off-by: Greg Kroah-Hartman --- fs/cifs/inode.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -1778,6 +1778,7 @@ cifs_rename2(struct inode *source_dir, s FILE_UNIX_BASIC_INFO *info_buf_target; unsigned int xid; int rc, tmprc; + bool new_target = d_really_is_negative(target_dentry); if (flags & ~RENAME_NOREPLACE) return -EINVAL; @@ -1854,8 +1855,13 @@ cifs_rename2(struct inode *source_dir, s */ unlink_target: - /* Try unlinking the target dentry if it's not negative */ - if (d_really_is_positive(target_dentry) && (rc == -EACCES || rc == -EEXIST)) { + /* + * If the target dentry was created during the rename, try + * unlinking it if it's not negative + */ + if (new_target && + d_really_is_positive(target_dentry) && + (rc == -EACCES || rc == -EEXIST)) { if (d_is_dir(target_dentry)) tmprc = cifs_rmdir(target_dir, target_dentry); else