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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79750C433EF for ; Thu, 14 Oct 2021 14:56:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 625E8611C2 for ; Thu, 14 Oct 2021 14:56:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232577AbhJNO7A (ORCPT ); Thu, 14 Oct 2021 10:59:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:42680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232321AbhJNO6X (ORCPT ); Thu, 14 Oct 2021 10:58:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 06F4261183; Thu, 14 Oct 2021 14:56:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634223378; bh=KdZgOG/j1kgHlnEKfl3w4zUeRAeuOOc0nH2WYkG8wmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YX56xjXLWfo73zHTA7wcf9Kkke1PdT4U8D9bMZ13YF/Lb/KxqVvJSXMJboeO4bdKB qfr5snck+zdpnGn2qHDxNOj9XAMDLgZOvovJV4UwUiUl5i0WEU8PV74egVXGeYtgyJ 4dQngviTYRLYGYgEsnMLkpbqYd/ej76y4TDe2zBo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zheng Liang , Miklos Szeredi Subject: [PATCH 4.9 04/25] ovl: fix missing negative dentry check in ovl_rename() Date: Thu, 14 Oct 2021 16:53:35 +0200 Message-Id: <20211014145207.721337418@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014145207.575041491@linuxfoundation.org> References: <20211014145207.575041491@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zheng Liang commit a295aef603e109a47af355477326bd41151765b6 upstream. 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 Fixes: e9be9d5e76e3 ("overlay filesystem") Cc: # v3.18 Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/overlayfs/dir.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/fs/overlayfs/dir.c +++ b/fs/overlayfs/dir.c @@ -926,9 +926,13 @@ static int ovl_rename2(struct inode *old goto out_dput; } } else { - if (!d_is_negative(newdentry) && - (!new_opaque || !ovl_is_whiteout(newdentry))) - goto out_dput; + if (!d_is_negative(newdentry)) { + if (!new_opaque || !ovl_is_whiteout(newdentry)) + goto out_dput; + } else { + if (flags & RENAME_EXCHANGE) + goto out_dput; + } } if (olddentry == trap)