[PATCH] FS: JFS: Fix null-ptr-deref Read in txBegin

From: mirimmad
Date: Fri Jun 23 2023 - 09:45:59 EST


From: Immad Mir <mirimmad17@xxxxxxxxx>

Syzkaller reported an issue where txBegin may be called
on a superblock in a read-only mounted filesystem which leads
to NULL pointer deref. This could be solved by checking if
the filesystem is read-only before calling txBegin, and returning
with appropiate error code.

Reported-By: syzbot+f1faa20eec55e0c8644c@xxxxxxxxxxxxxxxxxxxxxxxxx
Link: https://syzkaller.appspot.com/bug?id=be7e52c50c5182cc09a09ea6fc456446b2039de3

Signed-off-by: Immad Mir <mirimmad17@xxxxxxxxx>
---
fs/jfs/namei.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index b29d68b5e..12e95431c 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -798,8 +798,13 @@ static int jfs_link(struct dentry *old_dentry,
rc = dquot_initialize(dir);
if (rc)
goto out;
-
- tid = txBegin(ip->i_sb, 0);
+ if (!isReadOnly(ip)) {
+ tid = txBegin(ip->i_sb, 0);
+ } else {
+ jfs_error(ip->i_sb, "read-only filesystem\n");
+ rc = -EROFS;
+ goto out;
+ }

mutex_lock_nested(&JFS_IP(dir)->commit_mutex, COMMIT_MUTEX_PARENT);
mutex_lock_nested(&JFS_IP(ip)->commit_mutex, COMMIT_MUTEX_CHILD);
--
2.40.0