From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795035636; b=vtdiy+czzLInvjf5mxfFlfpfPNyYlshhEF43uUOKCGpdRt9vnLygTydtpLf7wGzF/Igr 8zov0hHpF7nlcKyPpVbgXm4A1WFLmZ4JkJDFG/ccdV1OXvb5D0xISYSp8C9QwK86pq5WU JknAlbz0HB92rq7M4g5c5ONFFhrKwvp8OpXHu57WBhTJTbT2hFhwd8m9r2mPMxol98eWp QSBPwpw+invnjdZDnNUytn8gvqAKco0nVnOuhzxi9oJAWZIdMRpNAHbWg6cWtx1dAX6aE P1l8Fv4VPbIA6W00PPUZvyQwhEhIp9O/oURYfw+0o1+iGIZPD/rOVCZ8foomnQVCDSQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795035636; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=yk96W9Zh3QVFso7UDfNCMyalufGDkRfgIctECbXx3tE=; b=4BtsFss7MEIGkcYpuqPGC+Ie456xLsuR1YymOxwPdyIzMM1qqyoMy0I7sqBh/8iIFeji iqI1pOXqT8QiAMv+75oAYtiym5F7v+Jc5yTpg4DD8BU+YYYIfpKTXUCYQ6XI1JUicX+m9 syaoutXH0TUcNXttJ6rxqeWTxG/hnsdZKKVD2c9NIaTpPdo8suoMCuDtkwSeFV7MCpdoT O67sMDRyadfDhfpA5+Ce5XnKksQzb+T/+aRmzG39pYmz99m/fLRlFpd4NjViFj0hwOPA3 iNYsiqrsba1bLsQ7wRz3HkDpAbbLcOxULo4ztMR7scwAlIzKFx8MUx90KU4SLigcBTg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Ub2AUJbp; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4F9E606A320; Wed, 18 Nov 2026 21:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Ub2AUJbp Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DBA51F000C4; Wed, 18 Nov 2026 21:00:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795035636; bh=yk96W9Zh3QVFso7UDfNCMyalufGDkRfgIctECbXx3tE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ub2AUJbpx+kjYsQKxHi0Q5nENM124Qhv3QFoRaTpTnLFCm0LJODU6eLnwc/OiEuSq B0X4wuty6mwqfLzuiGubGe6H6qmVj38mDeL+i5MFg88Z2nciTSIEXqm1fxpN0PjmhB 3MVJ5+ECkg8Dx8NoL4twN8ehg1+1eg9HwhIsKufs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chris Mason , Josef Bacik , Amir Goldstein , Sasha Levin Subject: [PATCH 6.6 0773/3318] ovl: check that the parents of volatile/dirty are dirs Date: Wed, 18 Nov 2026 15:23:15 +0100 Message-ID: <20261118150341.966409208@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chris Mason commit e34d2ef818e4c7676d8d8e1bf43e6a1ed39efb2a upstream. An unprivileged user crashes the kernel by mounting overlayfs with the volatile option. A dentry that serves as the parent of a lookup must be a directory. ovl_create_volatile_dirty() walks work/incompat/volatile/dirty by name, and ovl_lookup_or_create() returns an existing entry whatever its type. A file or a symlink that another task creates during the mount becomes the parent of the next lookup, which calls a NULL ->lookup. An unprivileged user mounted overlayfs with "volatile" in a user namespace while a second process created a symlink named work/incompat, and the mount task oopsed on a NULL ->lookup call. Fix this by returning -ENOTDIR from ovl_lookup_or_create() when the caller asked for a directory and the existing entry is a non-dir. Fixes: c86243b090bc ("ovl: provide a mount option "volatile"") Cc: stable@vger.kernel.org Signed-off-by: Chris Mason Signed-off-by: Josef Bacik Signed-off-by: Amir Goldstein [backport: no ovl_start_creating_upper(), check the child of ovl_lookup_upper() in ovl_lookup_or_create() instead] Signed-off-by: Amir Goldstein Signed-off-by: Sasha Levin --- fs/overlayfs/super.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 76316d143aaa2..67a54ae3644e6 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -660,16 +660,23 @@ static int ovl_check_rename_whiteout(struct ovl_fs *ofs) static struct dentry *ovl_lookup_or_create(struct ovl_fs *ofs, struct dentry *parent, - const char *name, umode_t mode) + const char *name, bool is_dir) { size_t len = strlen(name); struct dentry *child; inode_lock_nested(parent->d_inode, I_MUTEX_PARENT); child = ovl_lookup_upper(ofs, name, parent, len); - if (!IS_ERR(child) && !child->d_inode) - child = ovl_create_real(ofs, parent->d_inode, child, - OVL_CATTR(mode)); + if (!IS_ERR(child)) { + if (!child->d_inode) { + child = ovl_create_real(ofs, parent->d_inode, child, + OVL_CATTR(is_dir ? S_IFDIR : + S_IFREG)); + } else if (is_dir && !d_can_lookup(child)) { + dput(child); + child = ERR_PTR(-ENOTDIR); + } + } inode_unlock(parent->d_inode); dput(parent); @@ -690,7 +697,7 @@ static int ovl_create_volatile_dirty(struct ovl_fs *ofs) const char *const *name = volatile_path; for (ctr = ARRAY_SIZE(volatile_path); ctr; ctr--, name++) { - d = ovl_lookup_or_create(ofs, d, *name, ctr > 1 ? S_IFDIR : S_IFREG); + d = ovl_lookup_or_create(ofs, d, *name, ctr > 1); if (IS_ERR(d)) return PTR_ERR(d); } -- 2.53.0