Blob Blame History Raw
From 47cfdc338d674d38f4b2f22b7612cc6a2763ba27 Mon Sep 17 00:00:00 2001
From: Immad Mir <mirimmad17@gmail.com>
Date: Fri, 23 Jun 2023 19:14:01 +0530
Subject: [PATCH] FS: JFS: Fix null-ptr-deref Read in txBegin
Git-commit: 47cfdc338d674d38f4b2f22b7612cc6a2763ba27
Patch-mainline: v6.5-rc1
References: git-fixes

 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@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?id=be7e52c50c5182cc09a09ea6fc456446b2039de3

Signed-off-by: Immad Mir <mirimmad17@gmail.com>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
Acked-by: Anthony Iliopoulos <ailiop@suse.com>

---
 fs/jfs/namei.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index b29d68b5eec5..f370c7605120 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -799,6 +799,11 @@ static int jfs_link(struct dentry *old_dentry,
 	if (rc)
 		goto out;
 
+	if (isReadOnly(ip)) {
+		jfs_error(ip->i_sb, "read-only filesystem\n");
+		return -EROFS;
+	}
+
 	tid = txBegin(ip->i_sb, 0);
 
 	mutex_lock_nested(&JFS_IP(dir)->commit_mutex, COMMIT_MUTEX_PARENT);
-- 
2.35.3