public inbox for linux-erofs@ozlabs.org
 help / color / mirror / Atom feed
From: Utkal Singh <singhutkal015@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: hsiangkao@linux.alibaba.com, Utkal Singh <singhutkal015@gmail.com>
Subject: [PATCH] fsck.erofs: fix directory loop detection by tracking current nid
Date: Thu,  5 Mar 2026 17:59:34 +0000	[thread overview]
Message-ID: <20260305175934.23921-1-singhutkal015@gmail.com> (raw)

The directory cycle detection in erofsfsck_check_inode() pushes the
parent nid (pnid) onto the dirstack, but checks the current inode's
nid against the stack entries. This means a self-referencing directory
(a directory containing an entry whose nid points back to itself) is
never detected, because the directory's own nid is never recorded in
the ancestor stack.

Fix this by pushing the current directory's nid instead of pnid. This
ensures that any descendant entry pointing back to any ancestor
directory in the traversal path will be correctly identified as a loop
and reported as -ELOOP.

This is critical for processing untrusted EROFS images from container
registries, where a crafted image with directory cycles would cause
fsck.erofs to recurse infinitely until stack overflow.

Signed-off-by: Utkal Singh <singhutkal015@gmail.com>
---
 fsck/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fsck/main.c b/fsck/main.c
index cf07829..cd2cb3b 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -1021,7 +1021,7 @@ static int erofsfsck_check_inode(erofs_nid_t pnid, erofs_nid_t nid)
 		for (i = 0; i < fsckcfg.dirstack.top; ++i)
 			if (inode.nid == fsckcfg.dirstack.dirs[i])
 				return -ELOOP;
-		fsckcfg.dirstack.dirs[fsckcfg.dirstack.top++] = pnid;
+		fsckcfg.dirstack.dirs[fsckcfg.dirstack.top++] = nid;
 		ret = erofs_iterate_dir(&ctx, true);
 		--fsckcfg.dirstack.top;
 	}
-- 
2.43.0



                 reply	other threads:[~2026-03-05 17:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260305175934.23921-1-singhutkal015@gmail.com \
    --to=singhutkal015@gmail.com \
    --cc=hsiangkao@linux.alibaba.com \
    --cc=linux-erofs@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox