ovl: fix missing negative dentry check in ovl_rename()
authorZheng Liang <zhengliang6@huawei.com>
Fri, 24 Sep 2021 01:16:27 +0000 (09:16 +0800)
committerMiklos Szeredi <mszeredi@redhat.com>
Fri, 24 Sep 2021 19:00:31 +0000 (21:00 +0200)
commita295aef603e109a47af355477326bd41151765b6
tree6c51213e683f2e13c04ec7ff7348695e86568fc4
parent6880fa6c56601bb8ed59df6c30fd390cc5f6dd8f
ovl: fix missing negative dentry check in ovl_rename()

The following reproducer

  mkdir lower upper work merge
  touch lower/old
  touch lower/new
  mount -t overlay overlay -olowerdir=lower,upperdir=upper,workdir=work merge
  rm merge/new
  mv merge/old merge/new & unlink upper/new

may result in this race:

PROCESS A:
  rename("merge/old", "merge/new");
  overwrite=true,ovl_lower_positive(old)=true,
  ovl_dentry_is_whiteout(new)=true -> flags |= RENAME_EXCHANGE

PROCESS B:
  unlink("upper/new");

PROCESS A:
  lookup newdentry in new_upperdir
  call vfs_rename() with negative newdentry and RENAME_EXCHANGE

Fix by adding the missing check for negative newdentry.

Signed-off-by: Zheng Liang <zhengliang6@huawei.com>
Fixes: e9be9d5e76e3 ("overlay filesystem")
Cc: <stable@vger.kernel.org> # v3.18
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
fs/overlayfs/dir.c