gfs2 filesystem and dlm development
 help / color / mirror / Atom feed
From: Chunjie Zhu <chunjie.zhu@cloud.com>
To: Bob Peterson <rpeterso@redhat.com>,
	Andreas Gruenbacher <agruenba@redhat.com>
Cc: Chunjie Zhu <chunjie.zhu@cloud.com>,
	gfs2@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: [v2] fix "NULL pointer dereference in gfs2_recover_func"
Date: Wed, 19 Feb 2025 02:30:44 +0000	[thread overview]
Message-ID: <20250219023045.45240-1-chunjie.zhu@cloud.com> (raw)
In-Reply-To: <20250218093003.41966-1-chunjie.zhu@cloud.com>

before checking WITHDRAW flag, we have to check inode pointer

v2:
  fix gfs2_sbd NULL pointer deference

Signed-off-by: Chunjie Zhu <chunjie.zhu@cloud.com>
---
 fs/gfs2/recovery.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c
index 44806513fc06..8434dd385ac5 100644
--- a/fs/gfs2/recovery.c
+++ b/fs/gfs2/recovery.c
@@ -400,7 +400,7 @@ static void recover_local_statfs(struct gfs2_jdesc *jd,
 
 void gfs2_recover_func(struct work_struct *work)
 {
-	struct gfs2_jdesc *jd = NULL;
+	struct gfs2_jdesc *jd = container_of(work, struct gfs2_jdesc, jd_work);
 	struct gfs2_inode *ip = NULL;
 	struct gfs2_sbd *sdp = NULL;
 	struct gfs2_log_header_host head;
@@ -411,16 +411,20 @@ void gfs2_recover_func(struct work_struct *work)
 	int error = 0;
 	int jlocked = 0;
 
-	if (gfs2_withdrawn(sdp)) {
-		fs_err(sdp, "jid=%u: Recovery not attempted due to withdraw.\n",
-		       jd->jd_jid);
+	if (unlikely(!jd->jd_inode)) {
+		fs_err(sdp, "jid=%u: Looks like withdraw is ongoing, skip recovery.\n",
+			   jd->jd_jid);
 		goto fail;
 	}
 
-	jd = container_of(work, struct gfs2_jdesc, jd_work);
 	ip = GFS2_I(jd->jd_inode);
 	sdp = GFS2_SB(jd->jd_inode);
 
+	if (gfs2_withdrawn(sdp)) {
+		fs_err(sdp, "jid=%u: Recovery not attempted due to withdraw.\n",
+		       jd->jd_jid);
+		goto fail;
+	}
 	t_start = ktime_get();
 	if (sdp->sd_args.ar_spectator)
 		goto fail;
-- 
2.34.1


      reply	other threads:[~2025-02-19  2:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-18  9:30 [PATCH] fix "NULL pointer dereference in gfs2_recover_func" Chunjie Zhu
2025-02-19  2:30 ` Chunjie Zhu [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=20250219023045.45240-1-chunjie.zhu@cloud.com \
    --to=chunjie.zhu@cloud.com \
    --cc=agruenba@redhat.com \
    --cc=gfs2@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rpeterso@redhat.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