All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] FS: JFS: Fix null-ptr-deref Read in txBegin
@ 2023-03-26 16:20 mirimmad
  2023-06-23 13:44 ` mirimmad
       [not found] ` <CY5PR12MB64551AB18AB4DB2D3F1CA5A9C65DA@CY5PR12MB6455.namprd12.prod.outlook.com>
  0 siblings, 2 replies; 4+ messages in thread
From: mirimmad @ 2023-03-26 16:20 UTC (permalink / raw)
  Cc: mirimmad, skhan, Immad Mir, syzbot+f1faa20eec55e0c8644c,
	Dave Kleikamp, jfs-discussion, linux-kernel

From: Immad Mir <mirimmad17@gmail.com>

syzkaller reported the following issue:

BUG: KASAN: null-ptr-deref in instrument_atomic_read include/linux/instrumented.h:72 [inline]
BUG: KASAN: null-ptr-deref in _test_bit include/asm-generic/bitops/instrumented-non-atomic.h:141 [inline]
BUG: KASAN: null-ptr-deref in txBegin+0x131/0x6c0 fs/jfs/jfs_txnmgr.c:366
Read of size 8 at addr 0000000000000040 by task syz-executor.0/5098

CPU: 0 PID: 5098 Comm: syz-executor.0 Not tainted 6.3.0-rc3-syzkaller-00005-g7d31677bb7b1 #0
Hardware name: Google Compute Engine/Google Compute Engine, BIOS Google 03/02/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1e7/0x2d0 lib/dump_stack.c:106
 print_report+0xe6/0x540 mm/kasan/report.c:433
 kasan_report+0x176/0x1b0 mm/kasan/report.c:536
 kasan_check_range+0x283/0x290 mm/kasan/generic.c:187
 instrument_atomic_read include/linux/instrumented.h:72 [inline]
 _test_bit include/asm-generic/bitops/instrumented-non-atomic.h:141 [inline]
 txBegin+0x131/0x6c0 fs/jfs/jfs_txnmgr.c:366
 jfs_link+0x1ac/0x5e0 fs/jfs/namei.c:802
 vfs_link+0x4ed/0x680 fs/namei.c:4522
 do_linkat+0x5cc/0x9e0 fs/namei.c:4593
 __do_sys_linkat fs/namei.c:4621 [inline]
 __se_sys_linkat fs/namei.c:4618 [inline]
 __x64_sys_linkat+0xdd/0xf0 fs/namei.c:4618
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd

The issue can be resolved by checking whethere "log"
for a given superblock exists in the jfs_link function
before beginning a transaction.

Tested with syzbot.
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 | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
index b29d68b5e..cd43b68e2 100644
--- a/fs/jfs/namei.c
+++ b/fs/jfs/namei.c
@@ -799,6 +799,8 @@ static int jfs_link(struct dentry *old_dentry,
 	if (rc)
 		goto out;

+	if (!(JFS_SBI(ip->i_sb)->log))
+		goto out;
 	tid = txBegin(ip->i_sb, 0);

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH]  FS: JFS: Fix null-ptr-deref Read in txBegin
  2023-03-26 16:20 [PATCH] FS: JFS: Fix null-ptr-deref Read in txBegin mirimmad
@ 2023-06-23 13:44 ` mirimmad
  2023-06-23 13:51   ` Dave Kleikamp
       [not found] ` <CY5PR12MB64551AB18AB4DB2D3F1CA5A9C65DA@CY5PR12MB6455.namprd12.prod.outlook.com>
  1 sibling, 1 reply; 4+ messages in thread
From: mirimmad @ 2023-06-23 13:44 UTC (permalink / raw)
  Cc: Immad Mir, syzbot+f1faa20eec55e0c8644c, Dave Kleikamp,
	jfs-discussion, linux-kernel

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] FS: JFS: Fix null-ptr-deref Read in txBegin
       [not found]     ` <CAJfv2=A-b7yVtNA_T2kYyk_xK_suWrVX=gC3b+Am4LmNmvq02A@mail.gmail.com>
@ 2023-06-23 13:48       ` Dave Kleikamp
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Kleikamp @ 2023-06-23 13:48 UTC (permalink / raw)
  To: Immad Mir
  Cc: Immad Mir, skhan, syzbot+f1faa20eec55e0c8644c, jfs-discussion,
	linux-kernel

On 6/23/23 8:40AM, Immad Mir wrote:
> Thanks for the feedback. I've prepared two patches to fix the bug.
> 
>  >Does this test case attempt to remount a read-only file system as 
> read-write? I see a potential bug there.
> I'm not really sure about this.
> 
>  > Should be setting rc to an error here. I suggest -EROFS, but anything 
> is better than returning zero. Calling jfs_error() might also be in 
> order, as that would explicitly mark the file system to read-only. (The 
> default behavior at least.)
> 
> I've incorporated your suggested changes.
> 
>  > It'd be nice if we could move the check to txBegin(), but it is 
> assumed to always succeed, so there's no good error recovery there 
> without changing all of the callers. Maybe we can call jfs_error() there 
> in case we get there from another syscall.
> 
> I am not sure what to do here. I am calling jfs_error and returning 0 
> which is not what the caller would expect.

jfs_error returns void. What it does is mark the superblock dirty and 
either panics, marks sets the filesystem read-only, or does nothing 
else, depending on a mount flag which I doubt anyone uses, so the 
default action is to set it read-only. You still have to set a return 
code, etc. after calling it.

I'm sorry I wasn't more specific the first time.

> 
> Thanks,
> Immad.
> 
> 
> On Thu, Jun 22, 2023 at 8:38 PM Dave Kleikamp <dave.kleikamp@oracle.com 
> <mailto:dave.kleikamp@oracle.com>> wrote:
> 
>     On 6/20/23 10:53PM, Immad Mir wrote:
> 
>>
>>
>>     Hi. May I please request a review on this patch.
> 
>     Sorry for the delay. See below.
> 
>>
>>     Thanks,
>>     Immad
>>
>>     ------------------------------------------------------------------------
>>     *From:* mirimmad@outlook.com <mailto:mirimmad@outlook.com>
>>     <mirimmad@outlook.com> <mailto:mirimmad@outlook.com>
>>     *Sent:* Sunday, March 26, 2023 9:51:15 PM
>>     *Cc:* mirimmad@outlook.com <mailto:mirimmad@outlook.com>
>>     <mirimmad@outlook.com> <mailto:mirimmad@outlook.com>;
>>     skhan@linuxfoundation.org <mailto:skhan@linuxfoundation.org>
>>     <skhan@linuxfoundation.org> <mailto:skhan@linuxfoundation.org>;
>>     Immad Mir <mirimmad17@gmail.com> <mailto:mirimmad17@gmail.com>;
>>     syzbot+f1faa20eec55e0c8644c@syzkaller.appspotmail.com
>>     <mailto:syzbot+f1faa20eec55e0c8644c@syzkaller.appspotmail.com>
>>     <syzbot+f1faa20eec55e0c8644c@syzkaller.appspotmail.com>
>>     <mailto:syzbot+f1faa20eec55e0c8644c@syzkaller.appspotmail.com>;
>>     Dave Kleikamp <shaggy@kernel.org> <mailto:shaggy@kernel.org>;
>>     jfs-discussion@lists.sourceforge.net
>>     <mailto:jfs-discussion@lists.sourceforge.net>
>>     <jfs-discussion@lists.sourceforge.net>
>>     <mailto:jfs-discussion@lists.sourceforge.net>;
>>     linux-kernel@vger.kernel.org <mailto:linux-kernel@vger.kernel.org>
>>     <linux-kernel@vger.kernel.org> <mailto:linux-kernel@vger.kernel.org>
>>     *Subject:* [PATCH] FS: JFS: Fix null-ptr-deref Read in txBegin
>>
>>     From: Immad Mir <mirimmad17@gmail.com> <mailto:mirimmad17@gmail.com>
>>
>>     syzkaller reported the following issue:
>>
>>     BUG: KASAN: null-ptr-deref in instrument_atomic_read
>>     include/linux/instrumented.h:72 [inline]
>>     BUG: KASAN: null-ptr-deref in _test_bit
>>     include/asm-generic/bitops/instrumented-non-atomic.h:141 [inline]
>>     BUG: KASAN: null-ptr-deref in txBegin+0x131/0x6c0
>>     fs/jfs/jfs_txnmgr.c:366
>>     Read of size 8 at addr 0000000000000040 by task syz-executor.0/5098
>>
>>     CPU: 0 PID: 5098 Comm: syz-executor.0 Not tainted
>>     6.3.0-rc3-syzkaller-00005-g7d31677bb7b1 #0
>>     Hardware name: Google Compute Engine/Google Compute Engine, BIOS
>>     Google 03/02/2023
>>     Call Trace:
>>      <TASK>
>>      __dump_stack lib/dump_stack.c:88 [inline]
>>      dump_stack_lvl+0x1e7/0x2d0 lib/dump_stack.c:106
>>      print_report+0xe6/0x540 mm/kasan/report.c:433
>>      kasan_report+0x176/0x1b0 mm/kasan/report.c:536
>>      kasan_check_range+0x283/0x290 mm/kasan/generic.c:187
>>      instrument_atomic_read include/linux/instrumented.h:72 [inline]
>>      _test_bit
>>     include/asm-generic/bitops/instrumented-non-atomic.h:141 [inline]
>>      txBegin+0x131/0x6c0 fs/jfs/jfs_txnmgr.c:366
>>      jfs_link+0x1ac/0x5e0 fs/jfs/namei.c:802
>>      vfs_link+0x4ed/0x680 fs/namei.c:4522
>>      do_linkat+0x5cc/0x9e0 fs/namei.c:4593
>>      __do_sys_linkat fs/namei.c:4621 [inline]
>>      __se_sys_linkat fs/namei.c:4618 [inline]
>>      __x64_sys_linkat+0xdd/0xf0 fs/namei.c:4618
>>      do_syscall_x64 arch/x86/entry/common.c:50 [inline]
>>      do_syscall_64+0x41/0xc0 arch/x86/entry/common.c:80
>>      entry_SYSCALL_64_after_hwframe+0x63/0xcd
>>
>>     The issue can be resolved by checking whethere "log"
>>     for a given superblock exists in the jfs_link function
>>     before beginning a transaction.
> 
>     I'm not sure how we got here. log should only be null if the file
>     system is mounted read-only. Does this test case attempt to remount
>     a read-only file system as read-write? I see a potential bug there.
> 
>>
>>     Tested with syzbot.
>>     Reported-by: syzbot+f1faa20eec55e0c8644c@syzkaller.appspotmail.com
>>     <mailto:syzbot+f1faa20eec55e0c8644c@syzkaller.appspotmail.com>
>>     Link:
>>     https://syzkaller.appspot.com/bug?id=be7e52c50c5182cc09a09ea6fc456446b2039de3 <https://syzkaller.appspot.com/bug?id=be7e52c50c5182cc09a09ea6fc456446b2039de3>
>>
>>     Signed-off-by: Immad Mir <mirimmad17@gmail.com>
>>     <mailto:mirimmad17@gmail.com>
>>     ---
>>      fs/jfs/namei.c | 2 ++
>>      1 file changed, 2 insertions(+)
>>
>>     diff --git a/fs/jfs/namei.c b/fs/jfs/namei.c
>>     index b29d68b5e..cd43b68e2 100644
>>     --- a/fs/jfs/namei.c
>>     +++ b/fs/jfs/namei.c
>>     @@ -799,6 +799,8 @@ static int jfs_link(struct dentry *old_dentry,
>>              if (rc)
>>                      goto out;
>>
>>     +       if (!(JFS_SBI(ip->i_sb)->log))
>>     +               goto out;
> 
>     Should be setting rc to an error here. I suggest -EROFS, but
>     anything is better than returning zero. Calling jfs_error() might
>     also be in order, as that would explicitly mark the file system to
>     read-only. (The default behavior at least.)
> 
>>              tid = txBegin(ip->i_sb, 0);
>     It'd be nice if we could move the check to txBegin(), but it is
>     assumed to always succeed, so there's no good error recovery there
>     without changing all of the callers. Maybe we can call jfs_error()
>     there in case we get there from another syscall.
>>
>>     mutex_lock_nested(&JFS_IP(dir)->commit_mutex, COMMIT_MUTEX_PARENT);
>>     --
>>     2.40.0
>>
>>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] FS: JFS: Fix null-ptr-deref Read in txBegin
  2023-06-23 13:44 ` mirimmad
@ 2023-06-23 13:51   ` Dave Kleikamp
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Kleikamp @ 2023-06-23 13:51 UTC (permalink / raw)
  To: mirimmad
  Cc: Immad Mir, syzbot+f1faa20eec55e0c8644c, Dave Kleikamp,
	jfs-discussion, linux-kernel

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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-23 13:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-26 16:20 [PATCH] FS: JFS: Fix null-ptr-deref Read in txBegin mirimmad
2023-06-23 13:44 ` mirimmad
2023-06-23 13:51   ` Dave Kleikamp
     [not found] ` <CY5PR12MB64551AB18AB4DB2D3F1CA5A9C65DA@CY5PR12MB6455.namprd12.prod.outlook.com>
     [not found]   ` <a0493c88-358a-9d77-110a-18449314193b@oracle.com>
     [not found]     ` <CAJfv2=A-b7yVtNA_T2kYyk_xK_suWrVX=gC3b+Am4LmNmvq02A@mail.gmail.com>
2023-06-23 13:48       ` Dave Kleikamp

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.