From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F4EC35C682; Tue, 21 Jul 2026 22:06:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784671565; cv=none; b=lecYCruHoPaw3M4E7ZtAXD0GR5PWD15J+UeMPmu1LMtruyEdms710pi6rPQcKqINwa8t3VLHb7jcAJ1b3jxQWHLXfJHZ1fZLKG2DMBwfgJMgwABaTL9Xcnr6qs02D5Bb17w2ByE8xqlqmxLAHfzhlmltmG8+6QwLRKjPMjcB8uc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784671565; c=relaxed/simple; bh=qQnDVcJCVsL47+y+f5SflO4VUMtCEhHWOxfXaLmJIWs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TcB69PB/DFrZZUGL0mzcXQ8yQLsXsFhtA7+8zMwdG7d2iNXwnV+Mo/ylUig2PVfGx2smeC0VSAzl3XPm5389g06laMVSoIXs3ltqxcOSZbw9o5bE7NL/4XDVbyR+VX9PIITtdL4Le1gqbCK+5wmeVBaA8gKUfT48IjyD0GfWHhQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Afm+bDAb; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Afm+bDAb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DEAB11F000E9; Tue, 21 Jul 2026 22:06:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784671564; bh=dWak0eHzX31jMRmPdFWHVlhlt1QdI3bvIL34Z+xNiqA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Afm+bDAbwtgz+XTG7DqO2b00aJyR/fkuUZXXOav3NoX6OFPIsWQRJqhgtqI+hyRz6 +LIR1irwk5eknEEBnE82AnylisOlCrWBUjE4bc8uNRDBeeMH/2kZMeGRHDaHaW8j74 ybqSZFC0kY60VOcjsb8w+fBRLl8NCvGjA9AdZ8z0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jan Kara , Breno Leitao , Al Viro , Sasha Levin Subject: [PATCH 5.15 293/843] configfs_lookup(): dont leave ->s_dentry dangling on failure Date: Tue, 21 Jul 2026 17:18:48 +0200 Message-ID: <20260721152412.620788281@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152405.946368001@linuxfoundation.org> References: <20260721152405.946368001@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Al Viro [ Upstream commit 10da12d352b7b2bb330a8609fdda9a58bf0e9856 ] Normally ->s_dentry is cleared when dentry it's pointing to becomes negative (on eviction, realistically). However, that only happens if dentry gets to be positive in the first place; in case of inode allocation failure dentry never becomes positive, so ->d_iput() is not called at all. We do part of what normally would've been done by configfs_d_iput() (dropping the reference to configfs_dirent) manually, but we do not clear ->s_dentry there. Sloppy as it is, it does not matter in case of configfs_create_{dir,link}() - there configfs_dirent does not survive dropping the sole reference to it. However, for configfs_lookup() it *does* survive, with a dangling pointer to soon to be freed dentry sitting it its ->s_dentry. Subsequent getdents(2) in that directory will end up dereferencing that pointer in order to pick the inode number. Use after free... This is the minimal fix; the right approach is to set the linkage between dentry and configfs_dirent only after we know that we have an inode, but that takes more surgery and the bug had been there since 2006, so... Fixes: 3d0f89bb1694 ("configfs: Add permission and ownership to configfs objects") # 2.6.16-rc3 Reviewed-by: Jan Kara Reviewed-by: Breno Leitao Signed-off-by: Al Viro Signed-off-by: Sasha Levin --- fs/configfs/dir.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index e017ba188f7b5c..afe2b802eb3193 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c @@ -462,6 +462,9 @@ static struct dentry * configfs_lookup(struct inode *dir, inode = configfs_create(dentry, mode); if (IS_ERR(inode)) { + spin_lock(&configfs_dirent_lock); + sd->s_dentry = NULL; + spin_unlock(&configfs_dirent_lock); configfs_put(sd); return ERR_CAST(inode); } -- 2.53.0