[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20260117173556.36601-1-jiashengjiangcool@gmail.com>
Date: Sat, 17 Jan 2026 17:35:56 +0000
From: Jiasheng Jiang <jiashengjiangcool@...il.com>
To: Mark Fasheh <mark@...heh.com>,
Joel Becker <jlbec@...lplan.org>,
Joseph Qi <joseph.qi@...ux.alibaba.com>,
linux-kernel@...r.kernel.org
Cc: ocfs2-devel@...ts.linux.dev,
Jiasheng Jiang <jiashengjiangcool@...il.com>
Subject: [PATCH] ocfs2: fix NULL pointer dereference in ocfs2_xattr_get_rec
In ocfs2_xattr_get_rec, the variable 'rec' is initialized to NULL.
If the extent list 'el' is empty (l_next_free_rec == 0), the loop
iterating over the records is skipped, leaving 'rec' as NULL.
Since 'e_blkno' is initialized to 0, the function enters the error
handling block 'if (!e_blkno)'. Inside this block, the function calls
ocfs2_error() and attempts to dereference 'rec' via
'le32_to_cpu(rec->e_cpos)' and 'ocfs2_rec_clusters(el, rec)'. This
results in a NULL pointer dereference and a kernel panic.
Fix this by ensuring 'rec' is not NULL before accessing its members
within the error handling path, or by checking for an empty list
explicitly.
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@...il.com>
---
fs/ocfs2/xattr.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
index 1b21fbc16d73..b018c84dbc05 100644
--- a/fs/ocfs2/xattr.c
+++ b/fs/ocfs2/xattr.c
@@ -3757,10 +3757,16 @@ static int ocfs2_xattr_get_rec(struct inode *inode,
}
if (!e_blkno) {
- ret = ocfs2_error(inode->i_sb, "Inode %lu has bad extent record (%u, %u, 0) in xattr\n",
- inode->i_ino,
- le32_to_cpu(rec->e_cpos),
- ocfs2_rec_clusters(el, rec));
+ if (rec)
+ ret = ocfs2_error(inode->i_sb,
+ "Inode %lu has bad extent record (%u, %u, 0) in xattr\n",
+ inode->i_ino,
+ le32_to_cpu(rec->e_cpos),
+ ocfs2_rec_clusters(el, rec));
+ else
+ ret = ocfs2_error(inode->i_sb,
+ "Inode %lu has bad extent record (NULL) in xattr\n",
+ inode->i_ino);
goto out;
}
--
2.25.1
Powered by blists - more mailing lists