From patchwork Wed Feb 26 06:35:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve French X-Patchwork-Id: 11405357 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2EEED138D for ; Wed, 26 Feb 2020 06:36:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0E342222C2 for ; Wed, 26 Feb 2020 06:36:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dhEjyFqS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726229AbgBZGgE (ORCPT ); Wed, 26 Feb 2020 01:36:04 -0500 Received: from mail-io1-f46.google.com ([209.85.166.46]:36777 "EHLO mail-io1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725890AbgBZGgE (ORCPT ); Wed, 26 Feb 2020 01:36:04 -0500 Received: by mail-io1-f46.google.com with SMTP id d15so2144878iog.3; Tue, 25 Feb 2020 22:36:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=eFo/amBiw4ra9qJF2sHSoCjzhIEMIa3Edz34Kt0xAwI=; b=dhEjyFqSp7aLk7RcKJXSEmWOU7r54o17dGXzyFHN8nQmy7U4LSAteSM9R6BMen+myC p0g18JZldQiTYVqNeQV6YphadUZyuQtae0ieyNcTIBsEbYis1+gJUWsbpDQEvqw5jOSq NcUO1qT4ZKkREme2LLJgVvHwZCK3a4TR1vnjfq8DnX8Ll4z5eO5MCtHbuzrVaIaD1KZp zViAo1aP4ibxvCnHKkBje0CNaPZN2DU9ltuFEm/0hLPcY2ScTs3C2QQxNC0o6hqVW8WW /Tb3PZgcXpcSaxOmud+91auzF6stQDtvMGZNIa6lesmFshl+iER96CluI/z0IY5yZucy BrVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=eFo/amBiw4ra9qJF2sHSoCjzhIEMIa3Edz34Kt0xAwI=; b=ugLBAhl+LFYom2qAB4LCfV09snSYzXD20iL6IT/UooELQO5kPBlYoSh1M4nWVpMIdf IS//xgsRJEBy1oo8A23hwPK60KZTJM2SiaGDi8+NJO90CqYsRfUFM68I4c4j6R5NakVA 9dgzOaxtNZ91TzO2r5PGE1uT+UrUBBIJ8je5jm7KjmtE/LWHh0bpG+rJDt+UwU8ql2TQ i6tX99DJ36KOMW0djO/uSgGhjPHPr2JLWrg2zzZwaq+hKRoWTeFP7ceefHFnaLrnFuNk l2FLMQYbJDGkiDNKuGtH+GtZfcbmvt4PsoWu7Vm74JRkC7yQV8KZ677R6Bwg5vOZnHfB 94RQ== X-Gm-Message-State: APjAAAWuIiLGPG/q1xNj5mO+L5WNw5sQIMJ5WEsSKChcheM6dpTn8beZ q0g57SogR3uAs5Jbt25wN3YK2MuY2Osh7d9GtoUX1g== X-Google-Smtp-Source: APXvYqwX8A3Hd2lbBCep5kIfXNaBAi1xmcK8jdjkUNhedPox5PQphF/+56QeowLlHLT0ZLEsa7wPK8bYwAPdQPAXIbA= X-Received: by 2002:a05:6638:149:: with SMTP id y9mr2359365jao.132.1582698963130; Tue, 25 Feb 2020 22:36:03 -0800 (PST) MIME-Version: 1.0 From: Steve French Date: Wed, 26 Feb 2020 00:35:51 -0600 Message-ID: Subject: [PATCH][CIFS] Use FS_RENAME_DOES_D_MOVE to minimize races in rename To: CIFS Cc: linux-fsdevel Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Should be safer to do the dentry move immediately after the rename rather than later. From c1bc75178780665716ad14b8c40a8d8e58d0f3e3 Mon Sep 17 00:00:00 2001 From: Steve French Date: Tue, 25 Feb 2020 18:08:54 -0600 Subject: [PATCH] cifs: do d_move in rename It is safer to do the d_move closer to the rename to avoid races. Signed-off-by: Steve French --- fs/cifs/cifsfs.c | 4 ++-- fs/cifs/inode.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index fa77fe5258b0..94e3ed4850b5 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -1018,7 +1018,7 @@ struct file_system_type cifs_fs_type = { .name = "cifs", .mount = cifs_do_mount, .kill_sb = cifs_kill_sb, - /* .fs_flags */ + .fs_flags = FS_RENAME_DOES_D_MOVE, }; MODULE_ALIAS_FS("cifs"); @@ -1027,7 +1027,7 @@ static struct file_system_type smb3_fs_type = { .name = "smb3", .mount = smb3_do_mount, .kill_sb = cifs_kill_sb, - /* .fs_flags */ + .fs_flags = FS_RENAME_DOES_D_MOVE, }; MODULE_ALIAS_FS("smb3"); MODULE_ALIAS("smb3"); diff --git a/fs/cifs/inode.c b/fs/cifs/inode.c index 6543465595f6..7bb7ff110dc6 100644 --- a/fs/cifs/inode.c +++ b/fs/cifs/inode.c @@ -1835,6 +1835,8 @@ cifs_do_rename(const unsigned int xid, struct dentry *from_dentry, CIFSSMBClose(xid, tcon, fid.netfid); } do_rename_exit: + if (rc == 0) + d_move(from_dentry, to_dentry); cifs_put_tlink(tlink); return rc; } -- 2.20.1