mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: Jiaming Zhang <r772577952@gmail.com>,
	mark@fasheh.com, jlbec@evilplan.org
Cc: linux-kernel@vger.kernel.org, ocfs2-devel@lists.linux.dev,
	syzkaller@googlegroups.com
Subject: Re: [PATCH] ocfs2: fix hung task in orphan recovery
Date: Thu, 2 Jul 2026 11:54:31 +0800	[thread overview]
Message-ID: <fc9e15ad-5e53-4aab-88f0-61c73e6739c9@linux.alibaba.com> (raw)
In-Reply-To: <20260701091613.1008755-1-r772577952@gmail.com>



On 7/1/26 5:16 PM, Jiaming Zhang wrote:
> A crafted OCFS2 image with corrupted orphan-directory extent metadata can make
> umount hang.
> 
> During unmount, ocfs2_recovery_disable() waits for the ocfs2_complete_recovery
> work item to finish. The worker scans the orphan directory through
> ocfs2_queue_orphans() and ocfs2_dir_foreach(). If ocfs2_read_dir_block() fails
> on a corrupted directory block, ocfs2_dir_foreach_blk_el() skips the block and
> continues walking. On a badly corrupted directory this can keep orphan recovery
> busy for a long time, leaving umount blocked while flushing osb->ocfs2_wq.
> 
> Return the read error immediately for full directory scans and propagate the
> error from ocfs2_dir_foreach(). When ocfs2_empty_dir() receives such an error,
> report the directory as non-empty so unlink/rmdir does not proceed on an
> unreadable directory.
> 
> Closes: https://lore.kernel.org/lkml/CANypQFbWH76Y6LWHEwAvTP7aQL04uMJ=dDyL6YDmxa3fv3Tyjg@mail.gmail.com/
> Assisted-by: Codex:gpt-5.5-xhigh
> Signed-off-by: Jiaming Zhang <r772577952@gmail.com>
> ---
>  fs/ocfs2/dir.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c
> index 8e6b03238327..9bebf28f4b77 100644
> --- a/fs/ocfs2/dir.c
> +++ b/fs/ocfs2/dir.c
> @@ -1866,6 +1866,7 @@ static int ocfs2_dir_foreach_blk_el(struct inode *inode,
>  	struct super_block * sb = inode->i_sb;
>  	unsigned int ra_sectors = 16;
>  	int stored = 0;
> +	int ret = 0;
>  
>  	bh = NULL;
>  
> @@ -1873,9 +1874,13 @@ static int ocfs2_dir_foreach_blk_el(struct inode *inode,
>  
>  	while (ctx->pos < i_size_read(inode)) {
>  		blk = ctx->pos >> sb->s_blocksize_bits;
> -		if (ocfs2_read_dir_block(inode, blk, &bh, 0)) {
> +		ret = ocfs2_read_dir_block(inode, blk, &bh, 0);
> +		if (ret) {
> +			if (persist)
> +				return ret;
>  			/* Skip the corrupt dirblock and keep trying */
>  			ctx->pos += sb->s_blocksize - offset;
> +			offset = 0;
>  			continue;
>  		}
>  
> @@ -1950,7 +1955,7 @@ static int ocfs2_dir_foreach_blk_el(struct inode *inode,
>  		if (!persist && stored)
>  			break;
>  	}
> -	return 0;
> +	return ret;
>  }
>  
>  static int ocfs2_dir_foreach_blk(struct inode *inode, u64 *f_version,
> @@ -1969,8 +1974,7 @@ static int ocfs2_dir_foreach_blk(struct inode *inode, u64 *f_version,
>  int ocfs2_dir_foreach(struct inode *inode, struct dir_context *ctx)
>  {
>  	u64 version = inode_query_iversion(inode);
> -	ocfs2_dir_foreach_blk(inode, &version, ctx, true);
> -	return 0;
> +	return ocfs2_dir_foreach_blk(inode, &version, ctx, true);
>  }
>  
>  /*
> @@ -2189,8 +2193,10 @@ int ocfs2_empty_dir(struct inode *inode)
>  	}
>  
>  	ret = ocfs2_dir_foreach(inode, &priv.ctx);
> -	if (ret)
> +	if (ret) {
>  		mlog_errno(ret);
> +		return 0;

Here returns 0 when a read fails, and it then converts to -ENOTEMPTY.
It seems we'd better not swallow the real error. So a cleaner approach
would be to propagate the actual error. And caller distinguish it like:

status = ocfs2_empty_dir(inode);
if (status < 0)
	goto leave;
if (inode->i_nlink != 2 || !status) {
	status = -ENOTEMPTY;
	goto leave;
}

Thanks,
Joseph

> +	}
>  
>  	if (!priv.seen_dot || !priv.seen_dot_dot) {
>  		mlog(ML_ERROR, "bad directory (dir #%llu) - no `.' or `..'\n",


  reply	other threads:[~2026-07-02  3:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26  8:08 [Linux Kernel Bug] INFO: task hung in ocfs2_recovery_disable Jiaming Zhang
2026-07-01  9:16 ` [PATCH] ocfs2: fix hung task in orphan recovery Jiaming Zhang
2026-07-02  3:54   ` Joseph Qi [this message]
2026-07-02  9:05     ` [PATCH v2] " Jiaming Zhang
2026-07-02 12:18       ` Joseph Qi

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=fc9e15ad-5e53-4aab-88f0-61c73e6739c9@linux.alibaba.com \
    --to=joseph.qi@linux.alibaba.com \
    --cc=jlbec@evilplan.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark@fasheh.com \
    --cc=ocfs2-devel@lists.linux.dev \
    --cc=r772577952@gmail.com \
    --cc=syzkaller@googlegroups.com \
    /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

all inboxes | Powered by JetHome®