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,URIBL_BLOCKED,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 85DD4C433E0 for ; Tue, 7 Jul 2020 15:19:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53934206F6 for ; Tue, 7 Jul 2020 15:19:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594135189; bh=zf+acchBvmWz+dfLqoQTn9oqkEE+4yFBrlZPW0GgMsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=F5bNOzc/beBruZgBkUOB7TsBkV4CB+AxyL06M3TfTCu+pptLWkbcXZhOC7LRraGUY LM/qfnzr9XF6U+01wVwt/WFrQZrWnkl4LM+A2zFa451wvCA+n0opMlKWWtv9tq1H8I 73v8p+L2QPql4MtsWKohxuPPo/8fkiAgr6A31VyQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728357AbgGGPTs (ORCPT ); Tue, 7 Jul 2020 11:19:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:59518 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729398AbgGGPTo (ORCPT ); Tue, 7 Jul 2020 11:19:44 -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 492212065D; Tue, 7 Jul 2020 15:19:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594135183; bh=zf+acchBvmWz+dfLqoQTn9oqkEE+4yFBrlZPW0GgMsc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pEjjMq2IkTFi8kHXvyM/EBQic395iRVqt+BHS26AEvaIKDpEQC2O6XIkoylr4P567 bf9vXhAv+PVwLqyxJF5RHZogMqAEBmetd5sEuaQXDFom4+CGsapXqxoRyx+WUrgeU1 L9LtqngT5j8OWKDiVKOsFY6w+IXjaufaONn69Uow= 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.19 32/36] cifs: Fix the target file was deleted when rename failed. Date: Tue, 7 Jul 2020 17:17:24 +0200 Message-Id: <20200707145750.699595706@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200707145749.130272978@linuxfoundation.org> References: <20200707145749.130272978@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 @@ -1783,6 +1783,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; @@ -1859,8 +1860,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