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=unavailable 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 26AC3C433E0 for ; Tue, 7 Jul 2020 15:32:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F1A7F20663 for ; Tue, 7 Jul 2020 15:32:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594135969; bh=0qalr7sIiMTBZq9KLn36jOZE90c4K1KFip6Z3LVqhJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=2KEei7AEEVLzjfWQbEY0xREM9oWiGtd0fD7mGzg5N30kAdX+YlAnf0mDNjZQNicuW SwAPbTbJzHD7NfqZrXVdUhrpbO2K2ZZJrPwZciXv93dGQA21GQxROuAonQeO2RxCey qTsD1aYsjaAWTyMXUVX/O236fD1SbG9gaTkwHTF8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730037AbgGGPcr (ORCPT ); Tue, 7 Jul 2020 11:32:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:33996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728655AbgGGPVo (ORCPT ); Tue, 7 Jul 2020 11:21: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 7D6CB20663; Tue, 7 Jul 2020 15:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594135304; bh=0qalr7sIiMTBZq9KLn36jOZE90c4K1KFip6Z3LVqhJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wbzf1eMNwIMdzKJtgh6Zq5U0hUifGAWsWT9OWtgYGWW6j/Gk69N8rbfof3T+7cX1O E1KE29hyHAEeljdOXXnye3KuwIeMawbJqnncsZjYQ5CezlbOsYkYt7a+DnRE2EUxHT 92wy0MO1uGNuTZADgc1ynLz1oRYo5LbiXwPFs10Y= 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 5.4 53/65] cifs: Fix the target file was deleted when rename failed. Date: Tue, 7 Jul 2020 17:17:32 +0200 Message-Id: <20200707145755.031759759@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200707145752.417212219@linuxfoundation.org> References: <20200707145752.417212219@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 @@ -1791,6 +1791,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; @@ -1867,8 +1868,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