public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ocfs2: fix NULL pointer dereference in ocfs2_get_refcount_rec
@ 2026-01-17 16:16 Jiasheng Jiang
  2026-01-18 13:41 ` Markus Elfring
  0 siblings, 1 reply; 9+ messages in thread
From: Jiasheng Jiang @ 2026-01-17 16:16 UTC (permalink / raw)
  To: Mark Fasheh, Joel Becker, Joseph Qi, linux-kernel
  Cc: ocfs2-devel, Jiasheng Jiang

In ocfs2_get_refcount_rec(), the 'rec' pointer is initialized to NULL.
If the extent list is empty (el->l_next_free_rec == 0), the loop skips
assignment, leaving 'rec' as NULL and 'found' as 0.

Currently, the code skips the 'if (found)' block but proceeds directly to
dereference 'rec' at line 767 (le64_to_cpu(rec->e_blkno)), causing a
NULL pointer dereference panic.

This patch adds an 'else' branch to the 'if (found)' check. If no valid
record is found, it reports a filesystem error and exits, preventing
the invalid memory access.

Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
 fs/ocfs2/refcounttree.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
index c92e0ea85bca..464bdd6e0a8e 100644
--- a/fs/ocfs2/refcounttree.c
+++ b/fs/ocfs2/refcounttree.c
@@ -1122,6 +1122,11 @@ static int ocfs2_get_refcount_rec(struct ocfs2_caching_info *ci,
 
 		if (cpos_end < low_cpos + len)
 			len = cpos_end - low_cpos;
+	} else {
+		ret = ocfs2_error(sb, "Refcount tree %llu has no extent record covering cpos %u\n",
+				  (unsigned long long)ocfs2_metadata_cache_owner(ci),
+				  low_cpos);
+		goto out;
 	}
 
 	ret = ocfs2_read_refcount_block(ci, le64_to_cpu(rec->e_blkno),
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-01-20  1:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-17 16:16 [PATCH] ocfs2: fix NULL pointer dereference in ocfs2_get_refcount_rec Jiasheng Jiang
2026-01-18 13:41 ` Markus Elfring
2026-01-18 19:05   ` [PATCH v2] " Jiasheng Jiang
2026-01-19  6:37     ` Greg KH
2026-01-19  9:42     ` Markus Elfring
2026-01-19  9:49       ` Greg KH
2026-01-19 14:43     ` Heming Zhao
2026-01-19 17:12       ` [PATCH v2] ocfs2: Fix NULL pointer dereference in ocfs2_get_refcount_rec() Jiasheng Jiang
2026-01-20  1:46         ` Heming Zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox