Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1614124pxb; Mon, 11 Oct 2021 09:30:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxA/vElyrV2DWe3s1ERRGUIbLdKsCJIQsa6bkNOi3Jbu34orsKZfbiIPyQ+dqyTpKjJ/aWW X-Received: by 2002:a17:90b:3e86:: with SMTP id rj6mr31312503pjb.78.1633969850462; Mon, 11 Oct 2021 09:30:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633969850; cv=none; d=google.com; s=arc-20160816; b=M2sK47ChzoDESIb99OdnONj/U7EzL99xcAvb2Fhfv84Vs8wFn4y4C7L30eM5ydf4D9 w8OpTCT00pG0PGy2YSoqP0FlKWquVJMGWi8Y6d0Tm3HetbJyrLVMXPmEWN3ntDeR2cfc MHm7WhDAvfYH/e9PfrL/WlSEs77FL84AbFIq2a0AJ5KwgNHUSO4XCIlgn421/KvWTK49 s0k7J/BBE5XuY5HuLdTOOUn2XbuxjUcqMhRDbv7Ea10Lww6zG0e/VEywt+ZA2hmpcDkE hpwRNdrqnKOCOBxC3oP3CSr4f189EJGAaJCZ5z6+wkslozQQFV9VxbF8PmEzH+HQJSHU Pb0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CzPwtTVStaKdudmOW0DXUSbAS8I9GQB50ZoP2E7xo5A=; b=uiVSKTeiAwfA4FmjSqxM5JiCvuEwTDbDh0mCnP2Y3bn4P7p/oK+EGLzXz0lO97o3cR IMAwLS9U576ana+IzCvkOYRP7XlYo7W5HalqP8yk+e8dL2ywKIM0FkZz9Liwh5gYkwwA 7C6nPsWrH2bN3QikG+EDYKM1+p9KZTl7CGQMli6d445kTwlmN+5MfonPk2rVNLfMThmq IUTbbFn4Ci29mYWqJM3JcmQ8aWzBL2z/M5PXWAp5GhZSMowM113/RVH/HFK5LfnsuY3X Vj1EfiX7DMAjzT1mbVqeAnsPOGJi1WMRBbSYcfZUBbbiqJtTd7P7dU0nZ48MflPl00Po KqCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="y/po3rut"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o9si10339424pfh.359.2021.10.11.09.30.36; Mon, 11 Oct 2021 09:30:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="y/po3rut"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237802AbhJKNy3 (ORCPT + 99 others); Mon, 11 Oct 2021 09:54:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:39336 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236596AbhJKNxD (ORCPT ); Mon, 11 Oct 2021 09:53:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 01A11610E7; Mon, 11 Oct 2021 13:50:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633960250; bh=mxWIgSPjwO4Pev4RGiDdug/jv5W4ZsfnbZBK68wu9pQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y/po3rutYqa17/oIVYuIWv7mVsdlubmKbl2FE9kz9Plu9rYNM9z3165ml6ou+uiQ3 gHZ+C4CZ/VV86VCuPJihHWAtq4qWfFdHLoMJIx/DNKC3WjPXeDULEpCCK3GsckY73E 8AhIGJFko/OZQ/JwrMQbc0MX3G++qq3CAJ2tJJBQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zheng Liang , Miklos Szeredi Subject: [PATCH 5.10 11/83] ovl: fix missing negative dentry check in ovl_rename() Date: Mon, 11 Oct 2021 15:45:31 +0200 Message-Id: <20211011134508.748956131@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211011134508.362906295@linuxfoundation.org> References: <20211011134508.362906295@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 @@ -1214,9 +1214,13 @@ static int ovl_rename(struct inode *oldd 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)