[PATCH] FS: JFS: Check for read-only mounted filesystem in txBegin

mirimmad@outlook.com posted 1 patch 2 years, 7 months ago
fs/jfs/jfs_txnmgr.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
[PATCH] FS: JFS: Check for read-only mounted filesystem in txBegin
Posted by mirimmad@outlook.com 2 years, 7 months ago
From: Immad Mir <mirimmad17@gmail.com>

 This patch adds a check for read-only mounted filesystem
 in txBegin before starting a transaction potentially saving
 from NULL pointer deref.

Signed-off-by: Immad Mir <mirimmad17@gmail.com>
---
 fs/jfs/jfs_txnmgr.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c
index ffd4feece..87dc4e3a4 100644
--- a/fs/jfs/jfs_txnmgr.c
+++ b/fs/jfs/jfs_txnmgr.c
@@ -353,7 +353,10 @@ tid_t txBegin(struct super_block *sb, int flag)
 
 	jfs_info("txBegin: flag = 0x%x", flag);
 	log = JFS_SBI(sb)->log;
-
+	if (!log) {
+		jfs_error(sb, "read-only filesystem\n");
+		return 0;
+	}
 	TXN_LOCK();
 
 	INCREMENT(TxStat.txBegin);
-- 
2.40.0
Re: [PATCH] FS: JFS: Check for read-only mounted filesystem in txBegin
Posted by Dave Kleikamp 2 years, 7 months ago
On 6/23/23 8:47AM, mirimmad@outlook.com wrote:
> From: Immad Mir <mirimmad17@gmail.com>
> 
>   This patch adds a check for read-only mounted filesystem
>   in txBegin before starting a transaction potentially saving
>   from NULL pointer deref.

Thanks. I like this. Not much else we can do since none of the callers 
anticipate an error. I'll push it to jfs-next.

Shaggy

> 
> Signed-off-by: Immad Mir <mirimmad17@gmail.com>
> ---
>   fs/jfs/jfs_txnmgr.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/jfs/jfs_txnmgr.c b/fs/jfs/jfs_txnmgr.c
> index ffd4feece..87dc4e3a4 100644
> --- a/fs/jfs/jfs_txnmgr.c
> +++ b/fs/jfs/jfs_txnmgr.c
> @@ -353,7 +353,10 @@ tid_t txBegin(struct super_block *sb, int flag)
>   
>   	jfs_info("txBegin: flag = 0x%x", flag);
>   	log = JFS_SBI(sb)->log;
> -
> +	if (!log) {
> +		jfs_error(sb, "read-only filesystem\n");
> +		return 0;
> +	}
>   	TXN_LOCK();
>   
>   	INCREMENT(TxStat.txBegin);