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

mirimmad@outlook.com posted 1 patch 2 years, 7 months ago
fs/jfs/namei.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
[PATCH] FS: JFS: Fix null-ptr-deref Read in txBegin
Posted by mirimmad@outlook.com 2 years, 7 months ago
From: Immad Mir <mirimmad17@gmail.com>

 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>
---
 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
Re: [PATCH] FS: JFS: Fix null-ptr-deref Read in txBegin
Posted by Dave Kleikamp 2 years, 7 months ago
On 6/23/23 8:44AM, mirimmad@outlook.com wrote:
> From: Immad Mir <mirimmad17@gmail.com>
> 
>   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.

Looks good. I'm going to change it to just an if clause without the else 
and push it to jfs-next.

Thanks,
> 
> Reported-By: syzbot+f1faa20eec55e0c8644c@syzkaller.appspotmail.com
> Link: https://syzkaller.appspot.com/bug?id=be7e52c50c5182cc09a09ea6fc456446b2039de3
> 
> Signed-off-by: Immad Mir <mirimmad17@gmail.com>
> ---
>   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
>