mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joseph Qi <joseph.qi@linux.alibaba.com>
To: Jiakai Xu <xujiakai24@mails.ucas.ac.cn>
Cc: Joel Becker <jlbec@evilplan.org>, Mark Fasheh <mark@fasheh.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"ocfs2-devel@lists.linux.dev" <ocfs2-devel@lists.linux.dev>
Subject: Re: [PATCH] ocfs2: fix NULL deref in ocfs2_wait_for_recovery after recovery_exit
Date: Tue, 19 May 2026 19:41:36 +0800	[thread overview]
Message-ID: <878d31bf-a50c-4f48-a451-bcab0bb46c8f@linux.alibaba.com> (raw)
In-Reply-To: <20260519013629.1105967-1-xujiakai24@mails.ucas.ac.cn>



On 5/19/26 9:36 AM, Jiakai Xu wrote:
> In ocfs2_recovery_exit(), the recovery_map is freed via kfree() but
> osb->recovery_map is not set to NULL afterward. If ocfs2_wait_for_recovery()
> is called subsequently (e.g. during inode eviction in the dismount path or

evict_inodes() runs before ocfs2_recovery_exit(), which is called through put_super.

> via a racing stat() syscall), ocfs2_recovery_completed() dereferences the
> stale pointer, leading to a NULL pointer dereference at rm->rm_used.
> 
> Fix this by:
> 1. Setting osb->recovery_map = NULL after kfree() in ocfs2_recovery_exit()
> 2. Adding a NULL guard in ocfs2_recovery_completed() so that it safely
>    returns "recovery completed" when the map has been freed
> 
> Fixes: 553abd046af6 ("ocfs2: Change the recovery map to an array of node numbers.")
> Signed-off-by: Jiakai Xu <xujiakai24@mails.ucas.ac.cn>
> ---
>  fs/ocfs2/journal.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
> index f9bf3bac085d..5529a177f90e 100644
> --- a/fs/ocfs2/journal.c
> +++ b/fs/ocfs2/journal.c
> @@ -243,6 +243,7 @@ void ocfs2_recovery_exit(struct ocfs2_super *osb)
>  	/* XXX: Should we bug if there are dirty entries? */
>  
>  	kfree(rm);
> +	osb->recovery_map = NULL;
>  }
>  
>  static int __ocfs2_recovery_map_test(struct ocfs2_super *osb,
> @@ -1225,6 +1226,9 @@ static int ocfs2_recovery_completed(struct ocfs2_super *osb)
>  	int empty;
>  	struct ocfs2_recovery_map *rm = osb->recovery_map;
>  
Seems still cannot fully close the race?

Thanks,
Joseph

> +	if (!rm)
> +		return 1;
> +
>  	spin_lock(&osb->osb_lock);
>  	empty = (rm->rm_used == 0);
>  	spin_unlock(&osb->osb_lock);


      parent reply	other threads:[~2026-05-19 11:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-19  1:36 Jiakai Xu
2026-05-19  1:38 ` Jiakai Xu
2026-05-19 11:41 ` Joseph Qi [this message]

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=878d31bf-a50c-4f48-a451-bcab0bb46c8f@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=xujiakai24@mails.ucas.ac.cn \
    /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®