Received: from m16.mail.163.com (m16.mail.163.com [117.135.210.5]) (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 CDAF8215F5C for ; Wed, 28 Jan 2026 03:18:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=117.135.210.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769570302; cv=none; b=GeQlE/7yn1LKZ6EbLrJYLdU1Plc5Fr9r4MXHDNP9JKlVA0nTNuG1k010wB13kt5h8CR07AYBluQdaak2EZGcaIbX+F3wubrm8vnflhfn2cOuRXPcT9jMO5iMAl8uIvUgUuyqo03s1ZlP8L+opP3OXE1wWiupzm630JYdiai9O5M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769570302; c=relaxed/simple; bh=h0l1Mv/3F3yTNBUOsbtZasBQQ4YKUDFYMvbBRnOXJg4=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=cETfyY0iGhBBlF5AZBYSp346/X/5V/hsbkYuRqtEU8WeXkO5wD79rCPIqTZRq8uFyRtAJRe2NKyiUZnP08j2t0CN7pUsNsFszTgmUub+uGFqsiniuZ7+0KDbUpHe4KrMcMdpTuyBjM8j4W18ewcNW+yRMat9w7ocleBs46m/riE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=a19E0KW4; arc=none smtp.client-ip=117.135.210.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="a19E0KW4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=ER IoYrU1eDLQ+qwJUq2n3UoxV/nptYEGF7WTyVjg5Ds=; b=a19E0KW4xN6gKHeBLN /jtV1zgOf5dsPKn85vhA1qKgOU68N21yPQclcID2bpQVjyuLerD2HleKekNIlaaY 0DVQVn5uNSBfMHMpfMekdZod5l1GhmCIF6TCI5Vo08WgmkdZvya/k1s1d0umcpwl bvo8ITZ7BN/y7zyWy9vv2aSw8= Received: from pek-lpg-core6.wrs.com (unknown []) by gzsmtp1 (Coremail) with SMTP id PCgvCgA3j9flf3lpB0X7MA--.1570S2; Wed, 28 Jan 2026 11:17:59 +0800 (CST) From: Rahul Sharma To: gregkh@linuxfoundation.org, stable@vger.kernel.org Cc: Andreas Gruenbacher , Rahul Sharma Subject: [PATCH v6.1] gfs2: Fix NULL pointer dereference in gfs2_log_flush Date: Wed, 28 Jan 2026 11:17:52 +0800 Message-Id: <20260128031752.222018-1-black.hawk@163.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:PCgvCgA3j9flf3lpB0X7MA--.1570S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7uw15Aw13CrW3KryUWry5CFg_yoW8ur4xpr ykKr1rAr4DXF45W3W7KrsYqrnYganY9F13Zr4rCwsrXF4aq3ZI93ZxKaykAFs3Xr4fZryj 9FWDWa13Gry5GrJanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0JUUMa8UUUUU= X-CM-SenderInfo: 5eoduy4okd4yi6rwjhhfrp/xtbC3QfRa2l5f+dUxQAA35 From: Andreas Gruenbacher [ Upstream commit 35264909e9d1973ab9aaa2a1b07cda70f12bb828 ] In gfs2_jindex_free(), set sdp->sd_jdesc to NULL under the log flush lock to provide exclusion against gfs2_log_flush(). In gfs2_log_flush(), check if sdp->sd_jdesc is non-NULL before dereferencing it. Otherwise, we could run into a NULL pointer dereference when outstanding glock work races with an unmount (glock_work_func -> run_queue -> do_xmote -> inode_go_sync -> gfs2_log_flush). Signed-off-by: Andreas Gruenbacher [ The context change is due to the commit 4d927b03a688 ("gfs2: Rename gfs2_withdrawn to gfs2_withdrawing_or_withdrawn") in v6.8 which is irrelevant to the logic of this patch. ] Signed-off-by: Rahul Sharma --- fs/gfs2/log.c | 3 ++- fs/gfs2/super.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c index 8fd8bb860486..45f519ececd9 100644 --- a/fs/gfs2/log.c +++ b/fs/gfs2/log.c @@ -1102,7 +1102,8 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl, u32 flags) lops_before_commit(sdp, tr); if (gfs2_withdrawn(sdp)) goto out_withdraw; - gfs2_log_submit_bio(&sdp->sd_jdesc->jd_log_bio, REQ_OP_WRITE); + if (sdp->sd_jdesc) + gfs2_log_submit_bio(&sdp->sd_jdesc->jd_log_bio, REQ_OP_WRITE); if (gfs2_withdrawn(sdp)) goto out_withdraw; diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c index 8d90a5e48147..14b3f66938ea 100644 --- a/fs/gfs2/super.c +++ b/fs/gfs2/super.c @@ -67,9 +67,13 @@ void gfs2_jindex_free(struct gfs2_sbd *sdp) sdp->sd_journals = 0; spin_unlock(&sdp->sd_jindex_spin); + down_write(&sdp->sd_log_flush_lock); sdp->sd_jdesc = NULL; + up_write(&sdp->sd_log_flush_lock); + while (!list_empty(&list)) { jd = list_first_entry(&list, struct gfs2_jdesc, jd_list); + BUG_ON(jd->jd_log_bio); gfs2_free_journal_extents(jd); list_del(&jd->jd_list); iput(jd->jd_inode); -- 2.34.1