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 8FB2B43E4B9; Tue, 21 Jul 2026 22:20:12 +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=1784672413; cv=none; b=qXpbYfVLB77LUIQEeNbhES/zh4Cx9bgjJVvsyJDk34eFKGjk+5ixHOq3us18pztyV4/mqXTik9N+61ditasku0IuTm05FQJ3RC2ZQcEbL6idpQ53EX4JCIQzapen0zNbgN0niKS/k4wftSdoXowoQmtz7eaP3xeuJIhZ+z0q3O8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784672413; c=relaxed/simple; bh=mgmXSNBQn47Zp+Wmmlo4GsNB0kpjMsvo7gQ7FmiwCEA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Is1j6829MgTYOV0deoMyAk1+SxqQvONPxZYyVUbVJLCAnkOX1otMPdP/ZSMGNn2UIGs0pvYWV17vW+ODaVWrUgHaXIgo9TNZT+VuZlSf8ORnvNpIsuikjn7WFONZ/fcONZSQ4PpYgvY3w/TpM8Zn3tRDuMNVh+aKvwsrwAz588w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=JhfhDpWA; 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="JhfhDpWA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 020F81F000E9; Tue, 21 Jul 2026 22:20:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784672412; bh=VAQP84tsyskPqoyNPrdBhndENbyAVaHqeZBJYd2Hl5M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=JhfhDpWAHOqs337vXJiOiRNyzzwD/gqQfD29nBPFWjfI1AW8ai4jPUNn9543jhIEo M+ucMZAWTVlwIaEqV31ukDfGqcQiv9wQSkGzMR8usQDLFnW1KHnPRt5vV2zf/rFlQR emxohnL/FpZp7l+Xt3mS/UwN75Yj+D59qkwzRcis= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Michael Bommarito , Konstantin Komarov Subject: [PATCH 5.15 614/843] fs/ntfs3: add depth limit to indx_find_buffer to prevent stack overflow Date: Tue, 21 Jul 2026 17:24:09 +0200 Message-ID: <20260721152419.866810560@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: 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 @@ -1998,13 +1998,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) @@ -2025,7 +2033,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; } @@ -2426,7 +2435,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;