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 7BD182E736D; Tue, 21 Jul 2026 17:21:00 +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=1784654461; cv=none; b=WyonFgiS3cJxTuLhkCYbeLR/u5AekiK23zwxzQtkDaFwxziJm9ObRlmIrKCSYYQrWE5lcMWCJnEXCIozz04c2mSLsA9qMO6aCfjyc/8NDBBNXrq794p11ccn88dJLYvPIWnbPApW41w+Z8IasN+UoOLwFty59LzMNQyAoZ4ot9Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784654461; c=relaxed/simple; bh=zip+R7yxhLbx69seDue7vJnHAuQ1FKpFhiakr8aiGOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SG5rNe2OvkJ9oNHrfc5f2ox0+QNezCEBghMU/og/1dKryBvZrdOy8Y4eXNnc0d7aeA5FWz8IK0rjigjvK1WsBgYBBxXMOyCw7xXge3bNC1YUKD6Fv3aHcZeCw24aGDlKbZS7+UytTYLYU5pEyrjlQhe8vKbohb2lkJtX8WUTI8g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=T6IWBYD0; 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="T6IWBYD0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0C671F000E9; Tue, 21 Jul 2026 17:20:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784654460; bh=TMnj+Ykym+6RM0BTX8Aff1VnEL0ehftx9VnodKtpUyw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=T6IWBYD0vhajVYa7g6zUvC3/b1QPbiV0KyBA/sNaFkPvnSDzPEypIwMixnouyPq5E Jq8Qqz5/535auKWQcz2oP4HgEs5JYxnt6ope9bycmaF+rcE3qtW45phTG2W7PCxziL 9ohRstRrdjR7ZtkgyJ9TcKIkoRJyU/4k/syDe7T4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Michael Bommarito , Konstantin Komarov Subject: [PATCH 7.1 1706/2077] fs/ntfs3: add depth limit to indx_find_buffer to prevent stack overflow Date: Tue, 21 Jul 2026 17:22:59 +0200 Message-ID: <20260721152632.997758935@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152552.646164743@linuxfoundation.org> References: <20260721152552.646164743@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 7.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael Bommarito commit 1ebd684b8f627f75bc3e03f8b2ad8400fd1f02cd upstream. indx_find_buffer() recursively descends the B+ tree index with no depth limit. A crafted NTFS image with circular index node references causes unbounded recursion, overflowing the kernel stack and panicking the system. This is reachable by mounting a malicious NTFS filesystem (e.g. from a USB drive via desktop automount) and deleting a file whose index entry triggers the rebalancing fallback path in indx_delete_entry(). Add a depth parameter and bail out with -EINVAL when it reaches the fnd->nodes array bound, matching the constraint already enforced by fnd_push() in indx_find(). The related function indx_find() was previously patched for a similar infinite-loop issue (commit 1732053c8a6b), but indx_find_buffer() was missed. Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4-6 Assisted-by: Codex:gpt-5-4 Signed-off-by: Michael Bommarito Signed-off-by: Konstantin Komarov Signed-off-by: Greg Kroah-Hartman --- fs/ntfs3/index.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -2022,13 +2022,21 @@ out1: static struct indx_node *indx_find_buffer(struct ntfs_index *indx, struct ntfs_inode *ni, const struct INDEX_ROOT *root, - __le64 vbn, struct indx_node *n) + __le64 vbn, struct indx_node *n, + int depth) { int err; const struct NTFS_DE *e; struct indx_node *r; const struct INDEX_HDR *hdr = n ? &n->index->ihdr : &root->ihdr; + /* + * Limit recursion depth to prevent stack overflow from crafted + * images. Use the same bound as the fnd->nodes array (20). + */ + if (depth > ARRAY_SIZE(((struct ntfs_fnd *)NULL)->nodes)) + return ERR_PTR(-EINVAL); + /* Step 1: Scan one level. */ for (e = hdr_first_de(hdr);; e = hdr_next_de(hdr, e)) { if (!e) @@ -2049,7 +2057,8 @@ static struct indx_node *indx_find_buffe if (err) return ERR_PTR(err); - r = indx_find_buffer(indx, ni, root, vbn, n); + r = indx_find_buffer(indx, ni, root, vbn, n, + depth + 1); if (r) return r; } @@ -2462,7 +2471,7 @@ int indx_delete_entry(struct ntfs_index fnd_clear(fnd); - in = indx_find_buffer(indx, ni, root, sub_vbn, NULL); + in = indx_find_buffer(indx, ni, root, sub_vbn, NULL, 0); if (IS_ERR(in)) { err = PTR_ERR(in); goto out;