ovl: check whiteout in ovl_create_over_whiteout()
authorMiklos Szeredi <mszeredi@redhat.com>
Wed, 31 Oct 2018 11:15:23 +0000 (12:15 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 21 Nov 2018 08:24:17 +0000 (09:24 +0100)
commit 5e1275808630ea3b2c97c776f40e475017535f72 upstream.

Kaixuxia repors that it's possible to crash overlayfs by removing the
whiteout on the upper layer before creating a directory over it.  This is a
reproducer:

 mkdir lower upper work merge
 touch lower/file
 mount -t overlay overlay -olowerdir=lower,upperdir=upper,workdir=work merge
 rm merge/file
 ls -al merge/file
 rm upper/file
 ls -al merge/
 mkdir merge/file

Before commencing with a vfs_rename(..., RENAME_EXCHANGE) verify that the
lookup of "upper" is positive and is a whiteout, and return ESTALE
otherwise.

Reported by: kaixuxia <xiakaixu1987@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Fixes: e9be9d5e76e3 ("overlay filesystem")
Cc: <stable@vger.kernel.org> # v3.18
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/overlayfs/dir.c

index 0568898393f231b892b68a7a23d0546fb51c6d07..ef11fa7b869e72f65047d4c5c3e4f87ba0205071 100644 (file)
@@ -392,6 +392,10 @@ static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode,
        if (IS_ERR(upper))
                goto out_dput;
 
+       err = -ESTALE;
+       if (d_is_negative(upper) || !IS_WHITEOUT(d_inode(upper)))
+               goto out_dput2;
+
        err = ovl_create_real(wdir, newdentry, cattr, hardlink, true);
        if (err)
                goto out_dput2;